index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <template>
  2. <view :data-theme="theme">
  3. <view class='collectionGoods' v-if="collectProductList.length">
  4. <view class="placeholders"></view>
  5. <view class="borderPad navbox">
  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. </view>
  12. <view class="list">
  13. <checkbox-group @change="checkboxChange" class="centent">
  14. <!-- #ifndef APP-PLUS-->
  15. <view v-for="(item,index) in collectProductList" :key="index" class='item acea-row row-middle'>
  16. <checkbox :value="item.productId.toString()" :checked="item.checked" v-if="!footerswitch"
  17. style="margin-right: 10rpx;" />
  18. <view @click="handleProductDetail(item)" class="acea-row">
  19. <view class='pictrue'>
  20. <image :src="item.image"></image>
  21. <view v-if="item.activityStyle" :style="{ backgroundImage: `url(${item.activityStyle})` }" class="border-picture"></view>
  22. </view>
  23. <view>
  24. <view class='name line1 text-28rpx' :class="item.isShow?'':'text--w111-ccc'">{{item.name}}</view>
  25. <view class='money text-26rpx' v-if="item.isShow">¥{{item.price}}</view>
  26. <view v-else class="text--w111-ccc text-24rpx">该商品已下架</view>
  27. </view>
  28. </view>
  29. </view>
  30. <!-- #endif -->
  31. <!-- #ifdef APP-PLUS -->
  32. <view v-for="(item,index) in collectProductList" :key="index" :data-index="index"
  33. class='item acea-row row-middle order-item'>
  34. <view @click="handleProductDetail(item)" class="acea-row">
  35. <view class='pictrue m-30'>
  36. <image :src="item.image"></image>
  37. <view v-if="item.activityStyle" :style="{ backgroundImage: `url(${item.activityStyle})` }" class="border-picture"></view>
  38. </view>
  39. <view>
  40. <view class='name line1 text-28rpx' :class="item.isShow?'':'text--w111-ccc'">{{item.name}}</view>
  41. <view v-if="item.isShow" class='money text-26rpx'>¥{{item.price}}</view>
  42. <view v-else class="text--w111-ccc text-24rpx">该商品已下架</view>
  43. </view>
  44. </view>
  45. <view class="remove borRadius14" @tap="delCollection(item.productId)">删除</view>
  46. </view>
  47. <!-- #endif -->
  48. </checkbox-group>
  49. </view>
  50. <view class='loadingicon acea-row row-center-wrapper'>
  51. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  52. </view>
  53. <view v-if="!footerswitch" class='footer acea-row row-between-wrapper'>
  54. <view>
  55. <checkbox-group @change="checkboxAllChange">
  56. <checkbox value="all" :checked="!!isAllSelect" />
  57. <text class='checkAll'>全选</text>
  58. </checkbox-group>
  59. </view>
  60. <view class='button acea-row row-middle'>
  61. <form @submit="delCollectionAll" report-submit='true'>
  62. <button class='bnt cart-color' formType="submit">取消收藏</button>
  63. </form>
  64. </view>
  65. </view>
  66. </view>
  67. <view class='noCommodity' v-else-if="!collectProductList.length && page > 1">
  68. <view class='pictrue'>
  69. <image :src="urlDomain+'crmebimage/presets/noguanzhu.png'"></image>
  70. <view class="text-ccc">收藏列表为空哦~</view>
  71. </view>
  72. <recommend ref="recommendIndex"></recommend>
  73. </view>
  74. </view>
  75. </template>
  76. <script>
  77. // +----------------------------------------------------------------------
  78. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  79. // +----------------------------------------------------------------------
  80. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  81. // +----------------------------------------------------------------------
  82. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  83. // +----------------------------------------------------------------------
  84. // | Author: CRMEB Team <admin@crmeb.com>
  85. // +----------------------------------------------------------------------
  86. import {
  87. getCollectUserList,
  88. getProductHot,
  89. collectCancel
  90. } from '@/api/product.js';
  91. import {
  92. mapGetters
  93. } from "vuex";
  94. import {
  95. toLogin
  96. } from '@/libs/login.js';
  97. import recommend from "@/components/base/recommend.vue";
  98. import {
  99. goProductDetail
  100. } from '@/libs/order.js'
  101. let app = getApp();
  102. export default {
  103. components: {
  104. recommend
  105. },
  106. data() {
  107. return {
  108. urlDomain: this.$Cache.get("imgHost"),
  109. footerswitch: true,
  110. hostProduct: [],
  111. loadTitle: '加载更多',
  112. loading: false,
  113. loadend: false,
  114. collectProductList: [],
  115. limit: 20,
  116. page: 1,
  117. hotScroll: false,
  118. hotPage: 1,
  119. hotLimit: 10,
  120. isAllSelect: false, //全选
  121. selectValue: [], //选中的数据
  122. delBtnWidth: 80, //左滑默认宽度
  123. totals: 0,
  124. theme:app.globalData.theme,
  125. };
  126. },
  127. computed: mapGetters(['isLogin']),
  128. onLoad() {
  129. let that = this;
  130. if (this.isLogin) {
  131. this.loadend = false;
  132. this.page = 1;
  133. this.collectProductList = [];
  134. this.get_user_collect_product();
  135. } else {
  136. toLogin();
  137. }
  138. },
  139. onShow() {
  140. this.loadend = false;
  141. this.page = 1;
  142. this.collectProductList = [];
  143. this.get_user_collect_product();
  144. },
  145. methods: {
  146. //去商品详情
  147. handleProductDetail(item){
  148. if(item.isShow)goProductDetail(item.productId, 0, '');
  149. },
  150. manage: function() {
  151. this.footerswitch = !this.footerswitch;
  152. },
  153. checkboxChange: function(event) {
  154. var items = this.collectProductList,
  155. values = event.detail.value;
  156. for (var i = 0, lenI = items.length; i < lenI; ++i) {
  157. const item = items[i]
  158. if (values.includes(item.productId.toString())) {
  159. this.$set(item, 'checked', true)
  160. } else {
  161. this.$set(item, 'checked', false)
  162. }
  163. }
  164. this.selectValue = values.toString();
  165. this.isAllSelect = items.length === values.length;
  166. },
  167. checkboxAllChange: function(event) {
  168. let value = event.detail.value;
  169. if (value.length > 0) {
  170. this.setAllSelectValue(1)
  171. } else {
  172. this.setAllSelectValue(0)
  173. }
  174. },
  175. setAllSelectValue: function(status) {
  176. let selectValue = [];
  177. if (this.collectProductList.length > 0) {
  178. this.collectProductList.map(item => {
  179. if (status) {
  180. this.$set(item, 'checked', true)
  181. selectValue.push(item.productId);
  182. this.isAllSelect = true;
  183. } else {
  184. this.$set(item, 'checked', false)
  185. this.isAllSelect = false;
  186. }
  187. });
  188. this.selectValue = selectValue.toString();
  189. }
  190. },
  191. /**
  192. * 获取收藏产品
  193. */
  194. get_user_collect_product: function() {
  195. let that = this;
  196. if (this.loading) return;
  197. if (this.loadend) return;
  198. that.loading = true;
  199. that.loadTitle = "";
  200. getCollectUserList({
  201. page: that.page,
  202. limit: that.limit
  203. }).then(res => {
  204. res.data.list.map(item => {
  205. that.$set(item, 'right', 0);
  206. });
  207. that.totals = res.data.total;
  208. let collectProductList = res.data.list;
  209. let loadend = collectProductList.length < that.limit;
  210. that.collectProductList = that.$util.SplitArray(collectProductList, that
  211. .collectProductList);
  212. that.$set(that, 'collectProductList', that.collectProductList);
  213. that.loadend = loadend;
  214. that.loadTitle = loadend ? '我也是有底线的' : '加载更多';
  215. that.page = that.page + 1;
  216. that.loading = false;
  217. }).catch(err => {
  218. that.loading = false;
  219. that.loadTitle = "加载更多";
  220. });
  221. },
  222. /**
  223. * 取消收藏
  224. */
  225. delCollection: function(id, index) {
  226. this.selectValue = id;
  227. this.del({
  228. ids: this.selectValue.toString()
  229. });
  230. },
  231. delCollectionAll: function() {
  232. if (!this.selectValue || this.selectValue.length == 0) return this.$util.Tips({
  233. title: '请选择商品'
  234. });
  235. this.del({
  236. ids: this.selectValue
  237. });
  238. },
  239. del: function(data) {
  240. collectCancel(data).then(res => {
  241. this.$util.Tips({
  242. title: '取消收藏成功',
  243. icon: 'success'
  244. });
  245. this.selectValue = [];
  246. // this.collectProductList = this.collectProductList.filter(item=>item!==this.selectValue)
  247. this.collectProductList = [];
  248. this.loadend = false;
  249. this.page = 1;
  250. this.get_user_collect_product();
  251. }).catch(err => {
  252. return this.$util.Tips({
  253. title: err
  254. })
  255. });
  256. }
  257. },
  258. /**
  259. * 页面上拉触底事件的处理函数
  260. */
  261. onReachBottom() {
  262. this.get_user_collect_product();
  263. if(!this.collectProductList.length && this.page > 1){
  264. this.$refs.recommendIndex.get_host_product();
  265. }
  266. },
  267. // 滚动监听
  268. onPageScroll(e) {
  269. // 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
  270. uni.$emit('scroll');
  271. }
  272. }
  273. </script>
  274. <style scoped lang="scss">
  275. .placeholders{
  276. height: 30rpx;
  277. background-color: #f5f5f5;
  278. width: 100%;
  279. position: fixed;
  280. z-index: 111;
  281. }
  282. .money{
  283. font-size: 26rpx;
  284. @include price_color(theme);
  285. }
  286. .order-item {
  287. width: 100%;
  288. display: flex;
  289. position: relative;
  290. align-items: right;
  291. flex-direction: row;
  292. }
  293. .remove {
  294. width: 120rpx;
  295. height: 40rpx;
  296. @include main_bg_color(theme);
  297. color: #fff;
  298. position: absolute;
  299. bottom: 30rpx;
  300. right: 60rpx;
  301. display: flex;
  302. justify-content: center;
  303. align-items: center;
  304. font-size: 24rpx;
  305. }
  306. .collectionGoods {
  307. .navbox{
  308. width: 100%;
  309. height: 90rpx;
  310. }
  311. .nav {
  312. width: 93.5%;
  313. height: 90rpx;
  314. background-color: #fff;
  315. padding: 0 24rpx;
  316. -webkit-box-sizing: border-box;
  317. box-sizing: border-box;
  318. font-size: 28rpx;
  319. color: #282828;
  320. position: fixed;
  321. z-index: 5;
  322. top: 30rpx;
  323. border-bottom: 1px solid #EEEEEE;
  324. border-top-left-radius: 14rpx;
  325. border-top-right-radius: 14rpx;
  326. }
  327. .list {
  328. padding: 0 24rpx;
  329. .name {
  330. width: 434rpx;
  331. /* #ifdef APP-PLUS */
  332. width: 486rpx;
  333. /* #endif */
  334. margin-bottom: 56rpx;
  335. }
  336. }
  337. .centent {
  338. /* #ifdef H5 || MP */
  339. background-color: #fff;
  340. /* #endif */
  341. border-bottom-left-radius: 14rpx;
  342. border-bottom-right-radius: 14rpx;
  343. padding: 24rpx 0;
  344. }
  345. }
  346. .collectionGoods .item {
  347. background-color: #fff;
  348. padding-left: 24rpx;
  349. padding-top: 24rpx;
  350. border-radius: 14rpx;
  351. margin-bottom: 30rpx;
  352. }
  353. .collectionGoods .item:nth-last-child(1){
  354. margin-bottom: 0;
  355. }
  356. .collectionGoods .item .pictrue {
  357. width: 130rpx;
  358. height: 130rpx;
  359. margin-right: 20rpx;
  360. position: relative;
  361. }
  362. .collectionGoods .item .pictrue image {
  363. width: 100%;
  364. height: 100%;
  365. border-radius: 14rpx;
  366. }
  367. .collectionGoods .item .text {
  368. width: 535rpx;
  369. height: 130rpx;
  370. font-size: 28rpx;
  371. color: #282828;
  372. }
  373. .collectionGoods .item .text .name {
  374. width: 100%;
  375. }
  376. .collectionGoods .item .text .delete {
  377. font-size: 26rpx;
  378. color: #282828;
  379. width: 144rpx;
  380. height: 46rpx;
  381. border: 1px solid #bbb;
  382. border-radius: 4rpx;
  383. text-align: center;
  384. line-height: 46rpx;
  385. }
  386. .footer {
  387. z-index: 9;
  388. width: 100%;
  389. height: 96rpx;
  390. background-color: #fff;
  391. position: fixed;
  392. padding: 0 30rpx;
  393. box-sizing: border-box;
  394. border-top: 1rpx solid #eee;
  395. border-bottom: 1px solid #EEEEEE;
  396. /* #ifdef H5 || MP */
  397. bottom: 0rpx;
  398. /* #endif */
  399. /* #ifdef APP-PLUS */
  400. bottom: 0;
  401. /* #endif */
  402. /* #ifndef MP || APP-PLUS */
  403. // bottom: 98rpx;
  404. // bottom: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  405. // bottom: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  406. /* #endif */
  407. .checkAll {
  408. font-size: 28rpx;
  409. color: #282828;
  410. margin-left: 16rpx;
  411. }
  412. .button .bnt {
  413. font-size: 28rpx;
  414. color: #999;
  415. border-radius: 30rpx;
  416. border: 1px solid #999;
  417. width: 160rpx;
  418. height: 60rpx;
  419. text-align: center;
  420. line-height: 60rpx;
  421. }
  422. }
  423. .font_color{
  424. @include main_color(theme);
  425. }
  426. /deep/ checkbox .uni-checkbox-input.uni-checkbox-input-checked {
  427. @include main_bg_color(theme);
  428. @include coupons_border_color(theme);
  429. color: #fff!important
  430. }
  431. /deep/ checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  432. @include main_bg_color(theme);
  433. @include coupons_border_color(theme);
  434. color: #fff!important;
  435. margin-right: 0 !important;
  436. }
  437. .default_txt {
  438. font-size: 26rpx;
  439. color: #999;
  440. text-align: center;
  441. }
  442. .m-30 {
  443. margin-bottom: 24rpx;
  444. }
  445. </style>