index.vue 9.4 KB

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