Collection.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <div class="collection">
  3. <div class="d-body" v-if="paging.total > 0">
  4. <ul>
  5. <li
  6. class="collectionHover"
  7. @mouseenter="moveLike = i"
  8. @mouseleave="moveLike = null"
  9. @click="clickItem($event, item)"
  10. v-for="(item, i) in tableData"
  11. :key="i"
  12. >
  13. <div>
  14. <!-- 点赞和投票 -->
  15. <i class="like" v-show="moveLike === i">
  16. <img
  17. v-if="item.isLike"
  18. v-show="likeOFF.isLike"
  19. class="like_img"
  20. :src="require(`@/assets/dianzan/${theme}Z.png`)"
  21. alt=""
  22. title="取消点赞"
  23. @click="praiseNo(item.id)"
  24. />
  25. <img
  26. v-else
  27. v-show="likeOFF.isLike"
  28. class="like_img"
  29. src="../../assets/dianzan/dianzan.png"
  30. alt=""
  31. title="点赞"
  32. @click="praise(item.id)"
  33. />
  34. <img
  35. v-if="item.isVote"
  36. v-show="likeOFF.isVote"
  37. class="like_img"
  38. :src="require(`@/assets/dianzan/${theme}T.png`)"
  39. alt=""
  40. title="取消投票"
  41. @click="voteNo(item.id)"
  42. />
  43. <img
  44. v-else
  45. v-show="likeOFF.isVote"
  46. class="like_img"
  47. src="../../assets/dianzan/toupiao.png"
  48. alt=""
  49. title="投票"
  50. @click="vote(item.id)"
  51. />
  52. </i>
  53. <img :src="item.thumb" :alt="item.title" />
  54. </div>
  55. <div>
  56. <span :title="item.name">{{ item.name || "-" }}</span>
  57. <img :src="require('@/assets/images/xinjiang/enter.png')" alt="" />
  58. </div>
  59. </li>
  60. </ul>
  61. <Paging
  62. :key="likeOFF.id"
  63. class="paging"
  64. @changeCurrent="
  65. (data) => {
  66. this.$emit('changeCurrent', data);
  67. }
  68. "
  69. v-if="paging.total > 0"
  70. :paging="paging"
  71. />
  72. </div>
  73. <div class="norecord" v-else>暂无数据</div>
  74. </div>
  75. </template>
  76. <script>
  77. import "element-ui/lib/theme-chalk/index.css";
  78. import { Notification } from "element-ui";
  79. import {
  80. goodsLikeApi,
  81. goodsLikeDelApi,
  82. goodsVoteApi,
  83. goodsVoteDelApi,
  84. } from "@/config/api";
  85. import Paging from "@/components/Paging";
  86. export default {
  87. name: "GOODSLIKE",
  88. props: {
  89. tableData: Array,
  90. paging: Object,
  91. likeOFF: {
  92. type: Object,
  93. default: () => {},
  94. },
  95. },
  96. components: {
  97. Paging,
  98. },
  99. data() {
  100. return {
  101. moveLike: null,
  102. };
  103. },
  104. mounted() {},
  105. watch: {},
  106. methods: {
  107. clickItem(e, item) {
  108. if (
  109. e.path[0] &&
  110. (e.path[0].className === "like_img" || e.path[0].className === "like")
  111. )
  112. return;
  113. if (item.link) return window.open(item.link);
  114. this.$showBroadcast({
  115. item,
  116. zhuti: this.theme,
  117. });
  118. },
  119. // 点击点赞
  120. async praise(id) {
  121. let res = await goodsLikeApi({
  122. goodsId: id,
  123. goodsModuleId: this.likeOFF.id,
  124. });
  125. if (res.code === 0) {
  126. this.infoTitle("点赞成功", "success");
  127. this.$emit("upLike");
  128. }
  129. },
  130. //点击取消点赞
  131. async praiseNo(id) {
  132. let res = await goodsLikeDelApi(id);
  133. if (res.code === 0) {
  134. this.infoTitle("取消点赞成功", "success");
  135. this.$emit("upLike");
  136. }
  137. },
  138. // 点击投票
  139. async vote(id) {
  140. let res = await goodsVoteApi({
  141. goodsId: id,
  142. goodsModuleId: this.likeOFF.id,
  143. });
  144. if (res.code === 0) {
  145. this.infoTitle("投票成功", "success");
  146. this.$emit("upLike");
  147. }
  148. },
  149. // 点击取消投票
  150. async voteNo(id) {
  151. let res = await goodsVoteDelApi(id);
  152. if (res.code === 0) {
  153. this.infoTitle("取消投票成功", "success");
  154. this.$emit("upLike");
  155. }
  156. },
  157. // 封装消息提示信息
  158. infoTitle(title, type) {
  159. Notification({
  160. title,
  161. type,
  162. position: "bottom-right",
  163. });
  164. },
  165. },
  166. };
  167. </script>
  168. <style lang="less" scoped>
  169. .collection {
  170. position: relative;
  171. margin: 0 auto;
  172. width: 100%;
  173. display: flex;
  174. justify-content: space-between;
  175. align-items: flex-start;
  176. min-height: 30vh;
  177. .d-body {
  178. width: 100%;
  179. text-align: center;
  180. position: relative;
  181. padding-bottom: 30px;
  182. > ul {
  183. width: 100%;
  184. min-height: 70vh;
  185. text-align: left;
  186. > li {
  187. font-size: 0;
  188. display: inline-block;
  189. width: 310px;
  190. margin-right: 18px;
  191. text-align: center;
  192. margin-bottom: 18px;
  193. cursor: pointer;
  194. &:nth-child(3n) {
  195. margin-right: 0;
  196. }
  197. > div {
  198. background: linear-gradient(180deg, #a2a2a2 0%, #606060 100%);
  199. &:first-child {
  200. height: 200px;
  201. position: relative;
  202. overflow: hidden;
  203. > img {
  204. position: absolute;
  205. top: 50%;
  206. left: 50%;
  207. transform: translate(-50%, -50%);
  208. width: 100%;
  209. }
  210. }
  211. &:last-child {
  212. height: 50px;
  213. padding: 0 12px;
  214. display: flex;
  215. justify-content: space-between;
  216. align-items: center;
  217. background: #fff;
  218. color: #333;
  219. box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.16);
  220. > span {
  221. width: calc(100% - 40px);
  222. white-space: nowrap;
  223. text-overflow: ellipsis;
  224. overflow: hidden;
  225. word-break: break-all;
  226. font-weight: bold;
  227. text-align: left;
  228. }
  229. > img {
  230. width: 30px;
  231. height: 30px;
  232. }
  233. }
  234. }
  235. &:hover {
  236. > div {
  237. &:last-child {
  238. > span {
  239. color: #fff;
  240. }
  241. }
  242. }
  243. }
  244. }
  245. }
  246. .paging {
  247. margin-top: 40px;
  248. font-weight: normal;
  249. }
  250. }
  251. .norecord {
  252. position: absolute;
  253. top: 50%;
  254. left: 50%;
  255. transform: translate(-50%, -50%);
  256. font-size: 16px;
  257. color: #000;
  258. }
  259. .collectionHover {
  260. position: relative;
  261. .like {
  262. padding: 5px;
  263. z-index: 999;
  264. position: absolute;
  265. right: 0;
  266. top: 0px;
  267. & > img {
  268. width: 24px;
  269. height: 24px;
  270. margin-right: 5px;
  271. }
  272. }
  273. }
  274. }
  275. </style>