index.vue 9.5 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. console.log(this.ids.length,'ids')
  132. console.log(e.detail.value)
  133. if (e.detail.value.length < this.ids.length) {
  134. this.$set(this, 'isAllSelect', false);
  135. } else if (e.detail.value.length === this.collectProductList.length) {
  136. this.$set(this, 'isAllSelect', true);
  137. }
  138. console.log(this.isAllSelect)
  139. this.$set(this, 'ids', e.detail.value);
  140. },
  141. subDel() {
  142. let that = this
  143. if (this.ids.length) {
  144. collectDel(that.ids).then(res => {
  145. that.loadend = false;
  146. that.$util.Tips({
  147. title: res.msg
  148. });
  149. that.page = 1;
  150. that.collectProductList = [];
  151. this.getUserCollectProduct();
  152. this.ids.length = '';
  153. });
  154. } else {
  155. return that.$util.Tips({
  156. title: that.$t(`请选择商品`)
  157. });
  158. }
  159. },
  160. checkboxAllChange(event) {
  161. console.log(event.detail.value)
  162. let value = event.detail.value;
  163. if (value.length > 0) {
  164. this.setAllSelectValue(1)
  165. } else {
  166. this.setAllSelectValue(0)
  167. }
  168. },
  169. setAllSelectValue(status) {
  170. let that = this;
  171. let selectValue = [];
  172. let valid = that.collectProductList;
  173. if (valid.length > 0) {
  174. let newValid = valid.map(item => {
  175. if (status) {
  176. item.checked = true;
  177. selectValue.push(item.pid);
  178. that.isAllSelect = true;
  179. } else {
  180. item.checked = false;
  181. that.isAllSelect = false;
  182. }
  183. return item;
  184. });
  185. that.$set(that, 'collectProductList', newValid);
  186. console.log(selectValue)
  187. that.$set(that, 'ids', selectValue);
  188. }
  189. },
  190. jump(item) {
  191. uni.navigateTo({
  192. url: "/pages/goods_details/index?id=" + item.pid
  193. })
  194. },
  195. /**
  196. * 授权回调
  197. */
  198. onLoadFun: function() {
  199. this.loadend = false;
  200. this.page = 1;
  201. this.$set(this, 'collectProductList', []);
  202. this.getUserCollectProduct();
  203. // this.get_host_product();
  204. },
  205. // 授权关闭
  206. authColse(e) {
  207. this.isShowAuth = e
  208. },
  209. /**
  210. * 获取收藏产品
  211. */
  212. getUserCollectProduct() {
  213. let that = this;
  214. if (this.loading) return;
  215. if (this.loadend) return;
  216. that.loading = true;
  217. that.loadTitle = "";
  218. getCollectUserList({
  219. page: that.page,
  220. limit: that.limit
  221. }).then(res => {
  222. this.count = res.data.count;
  223. let collectProductList = res.data.list;
  224. collectProductList.map(e => {
  225. e.checked = false
  226. })
  227. let loadend = collectProductList.length < that.limit;
  228. that.collectProductList = that.$util.SplitArray(collectProductList, that
  229. .collectProductList);
  230. that.$set(that, 'collectProductList', that.collectProductList);
  231. that.loadend = loadend;
  232. that.loadTitle = loadend ? that.$t(`我也是有底线的`) : that.$t(`加载更多`);
  233. if (!that.collectProductList.length && that.page == 1) this.get_host_product();
  234. that.page = that.page + 1;
  235. that.loading = false;
  236. }).catch(err => {
  237. that.loading = false;
  238. that.loadTitle = that.$t(`加载更多`);
  239. });
  240. },
  241. /**
  242. * 获取我的推荐
  243. */
  244. get_host_product() {
  245. let that = this;
  246. if (that.hotScroll) return
  247. getProductHot(
  248. that.hotPage,
  249. that.hotLimit,
  250. ).then(res => {
  251. that.hotPage++
  252. that.hotScroll = res.data.length < that.hotLimit
  253. that.hostProduct = that.hostProduct.concat(res.data)
  254. });
  255. }
  256. },
  257. onReachBottom() {
  258. this.getUserCollectProduct();
  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>