index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <template>
  2. <view :style="colorStyle">
  3. <view class='collectionGoods' v-if="collectProductList.length">
  4. <view class="title-admin">
  5. <view>{{$t(`当前共`)}} <text class="text"> {{count}} </text> {{$t(`件商品`)}}</view>
  6. <view class="admin" @click="showRadio">{{checkbox_show?$t(`取消`):$t(`管理`)}}</view>
  7. </view>
  8. <checkbox-group @change.stop="checkboxChange">
  9. <view class='item acea-row' v-for="(item,index) in collectProductList" :key="index">
  10. <view class="left">
  11. <checkbox v-show="checkbox_show" :value="item.pid.toString()" :checked="item.checked" />
  12. <view class='pictrue' @click="jump(item)">
  13. <image :src="item.image"></image>
  14. <view class="invalid acea-row row-center-wrapper" v-if="!item.is_show">
  15. 已下架
  16. </view>
  17. </view>
  18. </view>
  19. <view class='text acea-row row-column-between' @click="jump(item)">
  20. <view class='name line2'>{{item.store_name}}</view>
  21. <view class='acea-row row-between-wrapper'>
  22. <view class='money font-color'>{{$t(`¥`)}}{{item.price}}</view>
  23. <!-- <view class='delete' @click.stop='delCollection(item.pid,index)'>删除</view> -->
  24. </view>
  25. </view>
  26. </view>
  27. <view class='loadingicon acea-row row-center-wrapper'>
  28. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  29. </view>
  30. </checkbox-group>
  31. </view>
  32. <view class='noCommodity' v-else-if="!collectProductList.length && page > 1">
  33. <view class='pictrue'>
  34. <image :src="imgHost + '/statics/images/noCollection.png'"></image>
  35. </view>
  36. <recommend :hostProduct="hostProduct"></recommend>
  37. </view>
  38. <view class='footer acea-row row-between-wrapper' v-if="checkbox_show && collectProductList.length">
  39. <view>
  40. <checkbox-group @change="checkboxAllChange">
  41. <checkbox value="all" :checked="!!isAllSelect" />
  42. <text class='checkAll'>{{$t(`全选`)}}({{ids.length}})</text>
  43. </checkbox-group>
  44. </view>
  45. <view class='button acea-row row-middle'>
  46. <button class='bnt' formType="submit" @click="subDel">{{$t(`取关`)}}</button>
  47. </view>
  48. </view>
  49. <!-- #ifdef MP -->
  50. <!-- <authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize> -->
  51. <!-- #endif -->
  52. <!-- #ifndef MP -->
  53. <home></home>
  54. <!-- #endif -->
  55. </view>
  56. </template>
  57. <script>
  58. import {
  59. getCollectUserList,
  60. getProductHot,
  61. collectDel
  62. } from '@/api/store.js';
  63. import {
  64. mapGetters
  65. } from "vuex";
  66. import {
  67. toLogin
  68. } from '@/libs/login.js';
  69. import recommend from '@/components/recommend';
  70. // #ifdef MP
  71. import authorize from '@/components/Authorize';
  72. // #endif
  73. import home from '@/components/home';
  74. import colors from '@/mixins/color.js';
  75. import {
  76. HTTP_REQUEST_URL
  77. } from '@/config/app';
  78. export default {
  79. components: {
  80. recommend,
  81. // #ifdef MP
  82. authorize,
  83. // #endif
  84. home
  85. },
  86. mixins: [colors],
  87. data() {
  88. return {
  89. imgHost: HTTP_REQUEST_URL,
  90. ids: [],
  91. hostProduct: [],
  92. checkbox_show: false,
  93. loadTitle: this.$t(`加载更多`),
  94. loading: false,
  95. loadend: false,
  96. collectProductList: [],
  97. count: 0,
  98. limit: 15,
  99. page: 1,
  100. isAuto: false, //没有授权的不会自动授权
  101. isShowAuth: false, //是否隐藏授权
  102. hotScroll: false,
  103. hotPage: 1,
  104. hotLimit: 10,
  105. isAllSelect: false, //全选
  106. };
  107. },
  108. computed: mapGetters(['isLogin']),
  109. onLoad() {
  110. if (this.isLogin) {
  111. this.loadend = false;
  112. this.page = 1;
  113. this.collectProductList = [];
  114. this.getUserCollectProduct();
  115. } else {
  116. toLogin();
  117. }
  118. },
  119. onShow() {
  120. this.loadend = false;
  121. this.page = 1;
  122. this.$set(this, 'collectProductList', []);
  123. this.getUserCollectProduct();
  124. },
  125. /**
  126. * 页面上拉触底事件的处理函数
  127. */
  128. onReachBottom: function() {
  129. this.getUserCollectProduct();
  130. },
  131. methods: {
  132. showRadio() {
  133. this.checkbox_show = !this.checkbox_show
  134. },
  135. checkboxChange(e) {
  136. if (e.detail.value.length < this.ids.length) {
  137. this.$set(this, 'isAllSelect', false);
  138. } else if (e.detail.value.length === this.collectProductList.length) {
  139. this.$set(this, 'isAllSelect', true);
  140. }
  141. this.$set(this, 'ids', e.detail.value);
  142. },
  143. subDel() {
  144. let that = this
  145. if (this.ids.length) {
  146. collectDel(that.ids).then(res => {
  147. that.loadend = false;
  148. that.$util.Tips({
  149. title: res.msg
  150. });
  151. that.page = 1;
  152. that.collectProductList = [];
  153. this.getUserCollectProduct();
  154. this.ids.length = '';
  155. });
  156. } else {
  157. return that.$util.Tips({
  158. title: that.$t(`请选择商品`)
  159. });
  160. }
  161. },
  162. checkboxAllChange(event) {
  163. let value = event.detail.value;
  164. if (value.length > 0) {
  165. this.setAllSelectValue(1)
  166. } else {
  167. this.setAllSelectValue(0)
  168. }
  169. },
  170. setAllSelectValue(status) {
  171. let that = this;
  172. let selectValue = [];
  173. let valid = that.collectProductList;
  174. if (valid.length > 0) {
  175. let newValid = valid.map(item => {
  176. if (status) {
  177. item.checked = true;
  178. selectValue.push(item.pid);
  179. that.isAllSelect = true;
  180. } else {
  181. item.checked = false;
  182. that.isAllSelect = false;
  183. }
  184. return item;
  185. });
  186. that.$set(that, 'collectProductList', newValid);
  187. that.$set(that, 'ids', selectValue);
  188. }
  189. },
  190. jump(item) {
  191. if (item.is_show) {
  192. uni.navigateTo({
  193. url: "/pages/goods_details/index?id=" + item.pid
  194. })
  195. } else {
  196. this.$util.Tips({
  197. title: that.$t(`该商品已下架`)
  198. })
  199. }
  200. },
  201. /**
  202. * 授权回调
  203. */
  204. onLoadFun: function() {
  205. this.loadend = false;
  206. this.page = 1;
  207. this.$set(this, 'collectProductList', []);
  208. this.getUserCollectProduct();
  209. // this.get_host_product();
  210. },
  211. // 授权关闭
  212. authColse(e) {
  213. this.isShowAuth = e
  214. },
  215. /**
  216. * 获取收藏产品
  217. */
  218. getUserCollectProduct() {
  219. let that = this;
  220. if (this.loading) return;
  221. if (this.loadend) return;
  222. that.loading = true;
  223. that.loadTitle = "";
  224. getCollectUserList({
  225. page: that.page,
  226. limit: that.limit
  227. }).then(res => {
  228. this.count = res.data.count;
  229. let collectProductList = res.data.list;
  230. collectProductList.map(e => {
  231. e.checked = false
  232. })
  233. let loadend = collectProductList.length < that.limit;
  234. that.collectProductList = that.$util.SplitArray(collectProductList, that
  235. .collectProductList);
  236. that.$set(that, 'collectProductList', that.collectProductList);
  237. that.loadend = loadend;
  238. that.loadTitle = loadend ? that.$t(`我也是有底线的`) : that.$t(`加载更多`);
  239. if (!that.collectProductList.length && that.page == 1) this.get_host_product();
  240. that.page = that.page + 1;
  241. that.loading = false;
  242. }).catch(err => {
  243. that.loading = false;
  244. that.loadTitle = that.$t(`加载更多`);
  245. });
  246. },
  247. /**
  248. * 获取我的推荐
  249. */
  250. get_host_product() {
  251. let that = this;
  252. if (that.hotScroll) return
  253. getProductHot(
  254. that.hotPage,
  255. that.hotLimit,
  256. ).then(res => {
  257. that.hotPage++
  258. that.hotScroll = res.data.length < that.hotLimit
  259. that.hostProduct = that.hostProduct.concat(res.data)
  260. });
  261. }
  262. },
  263. onReachBottom() {
  264. this.getUserCollectProduct();
  265. },
  266. // 滚动监听
  267. onPageScroll(e) {
  268. // 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
  269. uni.$emit('scroll');
  270. },
  271. }
  272. </script>
  273. <style scoped lang="scss">
  274. .collectionGoods {
  275. background-color: #fff;
  276. border-top: 1rpx solid #eee;
  277. }
  278. .collectionGoods .item {
  279. margin-left: 30rpx;
  280. border-bottom: 1rpx solid #eee;
  281. height: 180rpx;
  282. display: flex;
  283. align-items: center;
  284. flex-wrap: nowrap;
  285. }
  286. .left {
  287. display: flex;
  288. align-items: center;
  289. margin-right: 20rpx;
  290. }
  291. .collectionGoods .item .pictrue {
  292. width: 130rpx;
  293. height: 130rpx;
  294. margin-left: 20rpx;
  295. position: relative;
  296. .invalid {
  297. position: absolute;
  298. width: 100%;
  299. height: 100%;
  300. top: 0;
  301. left: 0;
  302. background-color: rgba(0, 0, 0, 0.4);
  303. backdrop-filter: blur(3px);
  304. color: #fff;
  305. }
  306. }
  307. .collectionGoods .item .pictrue image {
  308. width: 100%;
  309. height: 100%;
  310. border-radius: 6rpx;
  311. }
  312. .collectionGoods .item .text {
  313. height: 130rpx;
  314. flex: 1;
  315. font-size: 28rpx;
  316. color: #282828;
  317. padding-right: 20rpx;
  318. }
  319. .collectionGoods .item .text .name {
  320. width: max-contnet;
  321. }
  322. .collectionGoods .item .text .money {
  323. font-size: 26rpx;
  324. }
  325. .collectionGoods .item .text .delete {
  326. font-size: 26rpx;
  327. color: #282828;
  328. width: 144rpx;
  329. height: 46rpx;
  330. border: 1px solid #bbb;
  331. border-radius: 4rpx;
  332. text-align: center;
  333. line-height: 46rpx;
  334. }
  335. .noCommodity {
  336. background-color: #fff;
  337. padding-top: 1rpx;
  338. border-top: 0;
  339. }
  340. .title-admin {
  341. display: flex;
  342. justify-content: space-between;
  343. align-items: center;
  344. padding: 20rpx;
  345. border-bottom: 1px solid #f2f2f2;
  346. .text {
  347. color: var(--view-theme);
  348. }
  349. .admin {
  350. color: var(--view-theme);
  351. }
  352. }
  353. .footer {
  354. z-index: 999;
  355. width: 100%;
  356. height: 96rpx;
  357. background-color: #fafafa;
  358. position: fixed;
  359. padding: 0 30rpx;
  360. box-sizing: border-box;
  361. border-top: 1rpx solid #eee;
  362. bottom: 0;
  363. }
  364. .footer.on {
  365. // #ifndef H5
  366. bottom: 0rpx;
  367. // #endif
  368. // #ifdef MP || APP-PLUS
  369. bottom: 100rpx;
  370. bottom: calc(100rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  371. bottom: calc(100rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  372. // #endif
  373. }
  374. .footer .checkAll {
  375. font-size: 28rpx;
  376. color: #282828;
  377. margin-left: 16rpx;
  378. }
  379. // .shoppingCart .footer checkbox .wx-checkbox-input{background-color:#fafafa;}
  380. .footer .money {
  381. font-size: 30rpx;
  382. }
  383. .footer .placeOrder {
  384. color: #fff;
  385. font-size: 30rpx;
  386. width: 226rpx;
  387. height: 70rpx;
  388. border-radius: 50rpx;
  389. text-align: center;
  390. line-height: 70rpx;
  391. margin-left: 22rpx;
  392. }
  393. .footer .button .bnt {
  394. font-size: 28rpx;
  395. color: #999;
  396. border-radius: 50rpx;
  397. border: 1px solid #999;
  398. width: 160rpx;
  399. height: 60rpx;
  400. text-align: center;
  401. line-height: 60rpx;
  402. }
  403. .footer .button form~form {
  404. margin-left: 17rpx;
  405. }
  406. </style>