index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template>
  2. <view>
  3. <view class="hdbj"></view>
  4. <!-- 收藏列表 -->
  5. <view class='collectionGoods' v-if="collectProductList.length">
  6. <!-- #ifdef H5 || MP-->
  7. <view class='nav acea-row row-between-wrapper'>
  8. <view>当前共 <text class='num font-color'>{{ totals }}</text>件商品</view>
  9. <view class='administrate acea-row row-center-wrapper' @click='manage'>{{ footerswitch ? '管理' : '取消'}}
  10. </view>
  11. </view>
  12. <!-- #endif -->
  13. <view class="list">
  14. <checkbox-group @change="checkboxChange" class="centent">
  15. <view v-for="(item,index) in collectProductList" :key="index" class='item acea-row row-middle'>
  16. <checkbox :value="item.id.toString()" :checked="item.checked" v-if="!footerswitch"
  17. style="margin-right: 10rpx;" />
  18. <navigator :url='"/pages/goods_details/index?id="+item.spuId' hover-class='none'
  19. class="acea-row">
  20. <view class='pictrue'>
  21. <image :src="item.picUrl" />
  22. </view>
  23. <view>
  24. <view class='name line1'>{{ item.spuName }}</view>
  25. <view class='money font-color'>¥{{ item.price }}</view>
  26. </view>
  27. </navigator>
  28. </view>
  29. </checkbox-group>
  30. </view>
  31. <view class='loadingicon acea-row row-center-wrapper'>
  32. <text class='loading iconfont icon-jiazai' :hidden='!loading' />{{loadTitle}}
  33. </view>
  34. <view v-if="!footerswitch" class='footer acea-row row-between-wrapper'>
  35. <view>
  36. <checkbox-group @change="checkboxAllChange">
  37. <checkbox value="all" :checked="!!isAllSelect" />
  38. <text class='checkAll'>全选</text>
  39. </checkbox-group>
  40. </view>
  41. <view class='button acea-row row-middle'>
  42. <form @submit="delCollectionAll" report-submit='true'>
  43. <button class='bnt cart-color' formType="submit">取消收藏</button>
  44. </form>
  45. </view>
  46. </view>
  47. </view>
  48. <!-- 热门商品 -->
  49. <view class='noCommodity' v-else-if="!collectProductList.length && page > 1">
  50. <view class='pictrue'>
  51. <image src='../static/noCollection.png'></image>
  52. </view>
  53. <recommend :hostProduct="hostProduct"></recommend>
  54. </view>
  55. <home></home>
  56. </view>
  57. </template>
  58. <script>
  59. import { mapGetters } from "vuex";
  60. import { toLogin } from '@/libs/login.js';
  61. import recommend from '@/components/recommend';
  62. import home from '@/components/home';
  63. import * as ProductSpuApi from '@/api/product/spu.js';
  64. import * as ProductFavoriteApi from '@/api/product/favorite.js';
  65. import * as PromotionActivityApi from '@/api/promotion/activity.js';
  66. import * as ProductUtil from '@/utils/product.js';
  67. export default {
  68. components: {
  69. recommend,
  70. home
  71. },
  72. data() {
  73. return {
  74. footerswitch: true,
  75. loadTitle: '加载更多',
  76. loading: false,
  77. loadend: false,
  78. collectProductList: [], // 收藏列表
  79. limit: 8,
  80. page: 1,
  81. isAllSelect: false, // 全选
  82. selectValue: [], // 选中的数据
  83. totals: 0,
  84. // ========== 热门推荐 ==========
  85. hostProduct: [],
  86. hotPage: 1,
  87. hotLimit: 10,
  88. hotScroll: false,
  89. };
  90. },
  91. computed: mapGetters(['isLogin']),
  92. onLoad() {
  93. if (!this.isLogin) {
  94. toLogin();
  95. return
  96. }
  97. this.loadend = false;
  98. this.page = 1;
  99. this.collectProductList = [];
  100. this.get_user_collect_product();
  101. },
  102. onShow() {
  103. this.loadend = false;
  104. this.page = 1;
  105. this.collectProductList = [];
  106. this.get_user_collect_product();
  107. },
  108. methods: {
  109. /**
  110. * 获取收藏产品
  111. */
  112. get_user_collect_product: function() {
  113. let that = this;
  114. if (this.loading || this.loadend) {
  115. return;
  116. }
  117. this.loading = true;
  118. this.loadTitle = "";
  119. ProductFavoriteApi.getFavoritePage({
  120. pageNo: this.page,
  121. pageSize: this.limit
  122. }).then(res => {
  123. this.totals = res.data.total;
  124. const collectProductList = res.data.list;
  125. const loadend = collectProductList.length < this.limit;
  126. this.collectProductList = this.$util.SplitArray(collectProductList, this.collectProductList);
  127. this.$set(that, 'collectProductList', this.collectProductList);
  128. this.loadend = loadend;
  129. this.loadTitle = loadend ? '我也是有底线的' : '加载更多';
  130. this.page = this.page + 1;
  131. this.loading = false;
  132. // 如果没有收藏,加载热门商品
  133. if (this.totals === 0) {
  134. this.get_host_product();
  135. }
  136. }).catch(err => {
  137. this.loading = false;
  138. this.loadTitle = "加载更多";
  139. });
  140. },
  141. /**
  142. * 删除多个收藏
  143. */
  144. delCollectionAll: function() {
  145. // 取消收藏
  146. if (!this.selectValue || this.selectValue.length === 0) {
  147. return this.$util.Tips({
  148. title: '请选择商品'
  149. });
  150. }
  151. ProductFavoriteApi.deleteFavoriteList(this.selectValue).then(res => {
  152. this.$util.Tips({
  153. title: '取消收藏成功',
  154. icon: 'success'
  155. });
  156. // 重新获得收藏列表
  157. this.collectProductList = [];
  158. this.loadend = false;
  159. this.page = 1;
  160. this.get_user_collect_product();
  161. }).catch(err => {
  162. return this.$util.Tips({
  163. title: err
  164. })
  165. });
  166. },
  167. /**
  168. * 进入【管理】
  169. */
  170. manage: function() {
  171. this.footerswitch = !this.footerswitch;
  172. },
  173. /**
  174. * 选中某个收藏
  175. */
  176. checkboxChange: function(event) {
  177. const items = this.collectProductList;
  178. const values = event.detail.value;
  179. for (let i = 0; i < items.length; ++i) {
  180. const item = items[i]
  181. if (values.includes(item.spuId)) {
  182. this.$set(item, 'checked', true)
  183. } else {
  184. this.$set(item, 'checked', false)
  185. }
  186. }
  187. this.selectValue = values;
  188. this.isAllSelect = items.length === values.length;
  189. },
  190. /**
  191. * 全选收藏
  192. */
  193. checkboxAllChange: function(event) {
  194. let value = event.detail.value;
  195. if (value.length > 0) {
  196. this.setAllSelectValue(1)
  197. } else {
  198. this.setAllSelectValue(0)
  199. }
  200. },
  201. /**
  202. * 全选收藏
  203. */
  204. setAllSelectValue: function(status) {
  205. const selectValue = [];
  206. if (this.collectProductList.length > 0) {
  207. this.collectProductList.map(item => {
  208. if (status) {
  209. this.$set(item, 'checked', true)
  210. selectValue.push(item.spuId);
  211. this.isAllSelect = true;
  212. } else {
  213. this.$set(item, 'checked', false)
  214. this.isAllSelect = false;
  215. }
  216. });
  217. this.selectValue = selectValue.toString();
  218. }
  219. },
  220. /**
  221. * 获取我的推荐
  222. */
  223. get_host_product: function() {
  224. if (this.hotScroll) {
  225. return
  226. }
  227. ProductSpuApi.getSpuPage({
  228. recommendType: 'hot',
  229. pageNo: this.hotPage,
  230. pageSize: this.hotLimit
  231. }).then(res => {
  232. const good_list = res.data.list;
  233. this.hotPage++
  234. this.hotScroll = good_list.length < this.hotLimit
  235. // 设置营销活动
  236. const spuIds = good_list.map(item => item.id);
  237. if (spuIds.length > 0) {
  238. PromotionActivityApi.getActivityListBySpuIds(spuIds).then(res => {
  239. ProductUtil.setActivityList(good_list, res.data);
  240. this.hostProduct = this.hostProduct.concat(good_list) // 放在此处,避免 Vue 监控不到数组里的元素变化
  241. });
  242. }
  243. });
  244. }
  245. },
  246. /**
  247. * 页面上拉触底事件的处理函数
  248. */
  249. onReachBottom() {
  250. this.get_user_collect_product();
  251. this.get_host_product();
  252. }
  253. }
  254. </script>
  255. <style scoped lang="scss">
  256. .hdbj {
  257. width: 100%;
  258. height: 30rpx;
  259. background-color: #f5f5f5;
  260. z-index: 999999;
  261. position: fixed;
  262. top: 0;
  263. }
  264. .order-item {
  265. width: 100%;
  266. display: flex;
  267. position: relative;
  268. align-items: right;
  269. flex-direction: row;
  270. }
  271. .remove {
  272. width: 120rpx;
  273. height: 100%;
  274. background-color: $theme-color;
  275. color: white;
  276. position: absolute;
  277. top: 0;
  278. right: -160rpx;
  279. display: flex;
  280. justify-content: center;
  281. align-items: center;
  282. font-size: 24rpx;
  283. }
  284. .collectionGoods {
  285. .nav {
  286. width: 92%;
  287. height: 90rpx;
  288. background-color: #fff;
  289. padding: 0 24rpx;
  290. -webkit-box-sizing: border-box;
  291. box-sizing: border-box;
  292. font-size: 28rpx;
  293. color: #282828;
  294. position: fixed;
  295. left: 30rpx;
  296. z-index: 5;
  297. top: 30rpx;
  298. border-bottom: 1px solid #EEEEEE;
  299. border-top-left-radius: 14rpx;
  300. border-top-right-radius: 14rpx;
  301. }
  302. .list {
  303. padding: 30rpx;
  304. margin-top: 90rpx;
  305. .name {
  306. width: 434rpx;
  307. margin-bottom: 56rpx;
  308. }
  309. }
  310. .centent {
  311. /* #ifdef H5 || MP */
  312. background-color: #fff;
  313. /* #endif */
  314. border-bottom-left-radius: 14rpx;
  315. border-bottom-right-radius: 14rpx;
  316. }
  317. }
  318. .collectionGoods .item {
  319. background-color: #fff;
  320. padding-left: 24rpx;
  321. height: 180rpx;
  322. margin-bottom: 15rpx;
  323. border-radius: 14rpx;
  324. }
  325. .collectionGoods .item .pictrue {
  326. width: 130rpx;
  327. height: 130rpx;
  328. margin-right: 20rpx;
  329. }
  330. .collectionGoods .item .pictrue image {
  331. width: 100%;
  332. height: 100%;
  333. border-radius: 14rpx;
  334. }
  335. .collectionGoods .item .text {
  336. width: 535rpx;
  337. height: 130rpx;
  338. font-size: 28rpx;
  339. color: #282828;
  340. }
  341. .collectionGoods .item .text .name {
  342. width: 100%;
  343. }
  344. .collectionGoods .item .text .money {
  345. font-size: 26rpx;
  346. }
  347. .collectionGoods .item .text .delete {
  348. font-size: 26rpx;
  349. color: #282828;
  350. width: 144rpx;
  351. height: 46rpx;
  352. border: 1px solid #bbb;
  353. border-radius: 4rpx;
  354. text-align: center;
  355. line-height: 46rpx;
  356. }
  357. .noCommodity {
  358. background-color: #fff;
  359. padding-top: 1rpx;
  360. border-top: 0;
  361. }
  362. .footer {
  363. z-index: 9;
  364. width: 100%;
  365. height: 96rpx;
  366. background-color: #fff;
  367. position: fixed;
  368. padding: 0 30rpx;
  369. box-sizing: border-box;
  370. border-top: 1rpx solid #eee;
  371. border-bottom: 1px solid #EEEEEE;
  372. /* #ifdef H5 || MP */
  373. bottom: 0rpx;
  374. /* #endif */
  375. /* #ifndef MP */
  376. // bottom: 98rpx;
  377. // bottom: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  378. // bottom: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  379. /* #endif */
  380. .checkAll {
  381. font-size: 28rpx;
  382. color: #282828;
  383. margin-left: 16rpx;
  384. }
  385. .button .bnt {
  386. font-size: 28rpx;
  387. color: #999;
  388. border-radius: 30rpx;
  389. border: 1px solid #999;
  390. width: 160rpx;
  391. height: 60rpx;
  392. text-align: center;
  393. line-height: 60rpx;
  394. }
  395. }
  396. </style>