You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

428 lines
10 KiB

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