collection.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. <template>
  2. <div class="box">
  3. <div class="null-page" v-show="yes"></div>
  4. <div class="collection" v-loading="loading">
  5. <el-tabs v-model="activeName" @tab-click="handleClick">
  6. <el-tab-pane label="宝贝" name="goods">
  7. <div v-if="goodsList.length > 0">
  8. <div class="goods">
  9. <div class="goods-wrap" v-for="(item, index) in goodsList" :key="item.goods_id">
  10. <div class="goods-item">
  11. <div class="img" @click="$util.pushToTab({ path: '/sku/' + item.sku_id })">
  12. <img :src="$img(item.goods_image.split(',')[0], { size: 'mid' })" @error="imageError(index)" />
  13. <i class="del el-icon-delete" @click.stop="deleteGoods(item.goods_id)"></i>
  14. </div>
  15. <div class="goods-name">{{ item.goods_name }}</div>
  16. <div class="price">¥{{ item.price }}</div>
  17. </div>
  18. </div>
  19. </div>
  20. <div class="pager">
  21. <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
  22. :current-page="goodsInfo.page" :page-size="goodsInfo.page_size" background :pager-count="5"
  23. prev-text="上一页" next-text="下一页" hide-on-single-page :total="goodsTotal"></el-pagination>
  24. </div>
  25. </div>
  26. <div v-else-if="!loading && !goodsList.length" class="empty">您还没有关注商品哦</div>
  27. </el-tab-pane>
  28. </el-tabs>
  29. </div>
  30. <div class="goods-recommended">
  31. <div class="youLike">
  32. <span>猜你喜欢</span>
  33. </div>
  34. <div class="body-wrap">
  35. <ul class="goods-list">
  36. <li v-for="(item, index) in list" :key="index" :title="item.goods_name"
  37. @click="$util.pushToTab({ path: '/sku/' + item.sku_id })">
  38. <div class="img-wrap"><img alt="商品图片" :src="$img(item.goods_image.split(',')[0], {size: 'mid'})"
  39. @error="imageImgError(index)" /></div>
  40. <h3>{{ item.goods_name }}</h3>
  41. <p class="price">
  42. <span class="num">{{ item.discount_price }}元</span>
  43. <del>{{ item.market_price }}元</del>
  44. </p>
  45. </li>
  46. </ul>
  47. </div>
  48. </div>
  49. </div>
  50. </template>
  51. <script>
  52. import {
  53. goodsCollect,
  54. deleteGoods
  55. } from "@/api/member/collection"
  56. import {
  57. mapGetters
  58. } from "vuex"
  59. import {
  60. goodsRecommend
  61. } from '@/api/goods/goods';
  62. export default {
  63. name: "collection",
  64. layout: "member",
  65. components: {},
  66. layout: 'member',
  67. data() {
  68. return {
  69. goodsInfo: {
  70. page: 1,
  71. page_size: 10
  72. },
  73. shopInfo: {
  74. page: 1,
  75. page_size: 10
  76. },
  77. activeName: "goods",
  78. goodsTotal: 0,
  79. goodsList: [],
  80. loading: true,
  81. yes: true,
  82. list: [],
  83. page: 1,
  84. pageSize: 5
  85. }
  86. },
  87. created() {
  88. this.getGoodsCollect()
  89. this.getGoodsRecommend()
  90. },
  91. computed: {
  92. ...mapGetters(["defaultGoodsImage"])
  93. },
  94. mounted() {
  95. let self = this;
  96. setTimeout(function() {
  97. self.yes = false
  98. }, 300)
  99. },
  100. methods: {
  101. // 获取推荐商品列列表
  102. getGoodsRecommend() {
  103. goodsRecommend({
  104. page: this.page,
  105. page_size: this.pageSize
  106. })
  107. .then(res => {
  108. if (res.code == 0) this.list = res.data.list;
  109. this.loading = false;
  110. })
  111. .catch(res => {
  112. this.loading = false;
  113. });
  114. },
  115. //获取关注商品
  116. getGoodsCollect() {
  117. goodsCollect(this.goodsInfo)
  118. .then(res => {
  119. this.goodsTotal = res.data.count
  120. this.goodsList = res.data.list
  121. this.loading = false
  122. })
  123. .catch(err => {
  124. this.loading = false
  125. this.$message.error(err.message)
  126. })
  127. },
  128. //删除关注商品
  129. deleteGoods(id) {
  130. deleteGoods({
  131. goods_id: id
  132. })
  133. .then(res => {
  134. if (res.code == 0) {
  135. this.$message({
  136. message: "取消关注成功",
  137. type: "success"
  138. })
  139. this.getGoodsCollect()
  140. }
  141. })
  142. .catch(err => {
  143. this.$message.error(err.message)
  144. })
  145. },
  146. handleClick(tab, event) {
  147. if (tab.index == "0") {
  148. this.loading = true
  149. this.getGoodsCollect()
  150. }
  151. },
  152. handleSizeChange(size) {
  153. this.goodsInfo.page_size = size
  154. this.loading = true
  155. this.getGoodsCollect()
  156. },
  157. handleCurrentChange(page) {
  158. this.goodsInfo.page = page
  159. this.loading = true
  160. this.getGoodsCollect()
  161. },
  162. imageError(index) {
  163. this.goodsList[index].sku_image = this.defaultGoodsImage
  164. },
  165. imageImgError(index) {
  166. this.list[index].sku_image = this.defaultGoodsImage;
  167. }
  168. }
  169. }
  170. </script>
  171. <style lang="scss" scoped>
  172. .goods-recommended {
  173. width: 100%;
  174. margin-top: 15px;
  175. background-color: #fff;
  176. .youLike {
  177. width: 955px;
  178. box-sizing: border-box;
  179. border-bottom: 2px solid #dedede;
  180. margin: 0 20px 20px;
  181. span {
  182. display: inline-block;
  183. font-size: 14px;
  184. padding: 10px 0;
  185. }
  186. }
  187. .body-wrap {
  188. .goods-list {
  189. display: flex;
  190. flex-wrap: wrap;
  191. li {
  192. width: 23%;
  193. margin-left: 19px;
  194. margin-bottom: 20px;
  195. background: #fff;
  196. cursor: pointer;
  197. padding: 10px 0;
  198. transition: all 0.2s linear;
  199. &:hover {
  200. z-index: 2;
  201. -webkit-box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
  202. box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
  203. -webkit-transform: translate3d(0, -2px, 0);
  204. transform: translate3d(0, -2px, 0);
  205. }
  206. .img-wrap {
  207. width: 160px;
  208. height: 160px;
  209. margin: 0 auto 18px;
  210. text-align: center;
  211. line-height: 160px;
  212. img {
  213. max-width: 100%;
  214. max-height: 100%;
  215. }
  216. }
  217. h3 {
  218. font-size: 14px;
  219. text-align: center;
  220. text-overflow: ellipsis;
  221. white-space: nowrap;
  222. overflow: hidden;
  223. margin: 5px 15px;
  224. }
  225. .desc {
  226. margin: 0 30px 10px;
  227. height: 20px;
  228. font-size: 12px;
  229. color: #b0b0b0;
  230. text-align: center;
  231. text-overflow: ellipsis;
  232. white-space: nowrap;
  233. overflow: hidden;
  234. }
  235. .price {
  236. margin: 0 10px 14px;
  237. text-align: center;
  238. color: $base-color;
  239. del {
  240. margin-left: 0.5em;
  241. color: #b0b0b0;
  242. }
  243. }
  244. }
  245. }
  246. }
  247. .bottom-wrap {
  248. margin-top: 10px;
  249. width: $width;
  250. height: 118px;
  251. cursor: pointer;
  252. overflow: hidden;
  253. img {
  254. max-width: 100%;
  255. }
  256. }
  257. }
  258. .box {
  259. width: 100%;
  260. position: relative;
  261. }
  262. .null-page {
  263. width: 100%;
  264. height: 730px;
  265. background-color: #FFFFFF;
  266. position: absolute;
  267. top: 0;
  268. left: 0;
  269. z-index: 9;
  270. }
  271. .collection {
  272. background: #ffffff;
  273. padding: 10px 20px;
  274. .goods {
  275. display: flex;
  276. flex-wrap: wrap;
  277. .goods-wrap {
  278. width: 19%;
  279. margin-right: 1.25%;
  280. margin-bottom: 20px;
  281. &:nth-child(5n) {
  282. margin-right: 0;
  283. }
  284. .goods-item {
  285. border: 1px solid #f1f1f1;
  286. box-sizing: border-box;
  287. padding: 10px;
  288. .img {
  289. width: 100%;
  290. height: 160px;
  291. cursor: pointer;
  292. position: relative;
  293. img {
  294. width: 100%;
  295. height: 100%;
  296. }
  297. .del {
  298. font-size: 20px;
  299. position: absolute;
  300. top: 2px;
  301. right: 2px;
  302. padding: 3px;
  303. background: rgba($color: #000000, $alpha: 0.3);
  304. display: none;
  305. color: #ffffff;
  306. }
  307. &:hover {
  308. .del {
  309. display: block;
  310. }
  311. }
  312. }
  313. .goods-name {
  314. width: 100%;
  315. margin-top: 10px;
  316. overflow: hidden;
  317. display: -webkit-box;
  318. -webkit-line-clamp: 2;
  319. -webkit-box-orient: vertical;
  320. height: 55px;
  321. }
  322. .price {
  323. color: $base-color;
  324. }
  325. }
  326. }
  327. }
  328. .shop {
  329. display: flex;
  330. flex-wrap: wrap;
  331. .shop-wrap {
  332. margin: 0 15px 20px 0;
  333. &:nth-child(5n) {
  334. margin-right: 0;
  335. }
  336. .shop-item {
  337. width: 156px;
  338. height: 227px;
  339. border: 1px solid #eeeeee;
  340. padding: 0 10px;
  341. cursor: pointer;
  342. .head-wrap {
  343. text-align: center;
  344. padding: 10px 0;
  345. border-bottom: 1px solid #eeeeee;
  346. position: relative;
  347. .del {
  348. font-size: 20px;
  349. position: absolute;
  350. top: 0px;
  351. right: 0px;
  352. padding: 3px;
  353. background: rgba($color: #000000, $alpha: 0.3);
  354. display: none;
  355. color: #ffffff;
  356. cursor: pointer;
  357. }
  358. &:hover {
  359. .del {
  360. display: block;
  361. }
  362. }
  363. .img-wrap {
  364. width: 60px;
  365. height: 60px;
  366. line-height: 60px;
  367. display: inline-block;
  368. }
  369. .name {
  370. display: block;
  371. width: 100%;
  372. height: 24px;
  373. line-height: 24px;
  374. overflow: hidden;
  375. text-overflow: ellipsis;
  376. white-space: nowrap;
  377. }
  378. .tag {
  379. margin-left: 5px;
  380. }
  381. }
  382. .info-wrap {
  383. padding: 10px 0;
  384. }
  385. }
  386. }
  387. }
  388. .empty {
  389. text-align: center;
  390. }
  391. .page {
  392. text-align: center;
  393. }
  394. }
  395. </style>