index.vue 11 KB

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