index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <template>
  2. <view class="collection" :style="colorStyle">
  3. <view class="nav acea-row row-center-wrapper">
  4. <view class="item" :class="active == index?'on':''" v-for="(item,index) in navList" :key="index" @click="navTap(index)">{{item.name}}</view>
  5. </view>
  6. <view class="manage acea-row row-between-wrapper" v-if="collectProductList.length">
  7. <view>当前共 <text class="num">{{count}}</text> 件{{!active ? '商品':'视频'}}</view>
  8. <view class="close" @click="manageTap" v-if="administer">取消</view>
  9. <view class="font-color" @click="manageTap" v-else>管理</view>
  10. </view>
  11. <view class="collectList" v-if="collectProductList.length && !active">
  12. <checkbox-group @change="checkboxChange">
  13. <view class="item acea-row row-between-wrapper" v-for="(item,index) in collectProductList" :key="index" @click="goGoods(item.product_id)">
  14. <view class="pictrue">
  15. <!-- #ifndef MP -->
  16. <checkbox class="checkbox" v-if="administer" :value="(item.id).toString()" :checked="item.checked" />
  17. <!-- #endif -->
  18. <!-- #ifdef MP -->
  19. <checkbox class="checkbox" v-if="administer" :value="item.id" :checked="item.checked" />
  20. <!-- #endif -->
  21. <!-- <image :src="item.image"></image> -->
  22. <lazyLoad :src="item.image" width="100%" height="100%"></lazyLoad>
  23. </view>
  24. <view class="text">
  25. <view class="top">
  26. <view class="name line2">{{item.store_name}}</view>
  27. <view class="label acea-row" v-if="item.promotions.title">
  28. <text class="labelCon">{{item.promotions.title}}</text>
  29. </view>
  30. </view>
  31. <view class="money">¥<text class="num">{{item.price}}</text></view>
  32. </view>
  33. </view>
  34. </checkbox-group>
  35. <view class='loadingicon acea-row row-center-wrapper'>
  36. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  37. </view>
  38. <view class="footer acea-row row-between-wrapper" v-if="administer">
  39. <checkbox-group @change="checkboxAllChange">
  40. <checkbox value="all" :checked="isAllSelect" />
  41. <text class='checkAll'>全选</text>
  42. </checkbox-group>
  43. <view class="acea-row row-middle">
  44. <view class="bnt on acea-row row-center-wrapper" @click="del('product')">取消收藏</view>
  45. </view>
  46. </view>
  47. </view>
  48. <view class="videoList" v-if="collectProductList.length && active">
  49. <checkbox-group @change="checkboxChange">
  50. <view class="acea-row row-middle">
  51. <view class="item" v-for="(item,index) in collectProductList" :key="index" @click="goVideo">
  52. <!-- #ifndef MP -->
  53. <checkbox class="checkbox" v-if="administer" :value="(item.id).toString()" :checked="item.checked" />
  54. <!-- #endif -->
  55. <!-- #ifdef MP -->
  56. <checkbox class="checkbox" v-if="administer" :value="item.id" :checked="item.checked" />
  57. <!-- #endif -->
  58. <!-- <image :src="item.image"></image> -->
  59. <lazyLoad :src="item.image" width="100%" height="100%"></lazyLoad>
  60. <view class="like">
  61. <text class="iconfont icon-shipindianzan-weidian1"></text>{{item.like_num}}
  62. </view>
  63. </view>
  64. </view>
  65. </checkbox-group>
  66. <view class='loadingicon acea-row row-center-wrapper'>
  67. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  68. </view>
  69. <view class="footer acea-row row-between-wrapper" v-if="administer">
  70. <checkbox-group @change="checkboxAllChange">
  71. <checkbox value="all" :checked="isAllSelect" />
  72. <text class='checkAll'>全选</text>
  73. </checkbox-group>
  74. <view class="acea-row row-middle">
  75. <view class="bnt on acea-row row-center-wrapper" @click="del('video')">取消收藏</view>
  76. </view>
  77. </view>
  78. </view>
  79. <view class='noCommodity' v-else-if="!collectProductList.length && page > 1">
  80. <view class='pictrue'>
  81. <image :src="imgHost + '/statics/images/noCollection.png'"></image>
  82. </view>
  83. <recommend :hostProduct="hostProduct"></recommend>
  84. </view>
  85. <view></view>
  86. <home v-if="navigation"></home>
  87. </view>
  88. </template>
  89. <script>
  90. import lazyLoad from '@/components/muqian-lazyLoad/muqian-lazyLoad.vue'
  91. import colors from '@/mixins/color.js';
  92. import {HTTP_REQUEST_URL} from '@/config/app';
  93. import {
  94. getCollectUserList,
  95. getProductHot,
  96. collectDel
  97. } from '@/api/store.js';
  98. import {
  99. mapGetters
  100. } from "vuex";
  101. import {
  102. toLogin
  103. } from '@/libs/login.js';
  104. import recommend from '@/components/recommend';
  105. import home from '@/components/home';
  106. export default{
  107. mixins:[colors],
  108. computed: mapGetters(['isLogin']),
  109. components: {
  110. recommend,
  111. home,
  112. lazyLoad
  113. },
  114. data(){
  115. return{
  116. navList:[
  117. {
  118. name:'商品'
  119. },
  120. {
  121. name:'视频'
  122. }
  123. ],
  124. active:0,
  125. hostProduct: [],
  126. loadTitle: '加载更多',
  127. loading: false,
  128. loadend: false,
  129. collectProductList: [],
  130. limit: 4,
  131. page: 1,
  132. hotScroll:false,
  133. hotPage:1,
  134. hotLimit:10,
  135. imgHost:HTTP_REQUEST_URL,
  136. administer:0,
  137. isAllSelect: false,
  138. count:0
  139. }
  140. },
  141. onLoad() {
  142. if (this.isLogin) {
  143. this.loadend = false;
  144. this.page = 1;
  145. this.collectProductList = [];
  146. this.get_user_collect_product('product');
  147. this.get_host_product();
  148. } else {
  149. toLogin();
  150. }
  151. },
  152. onShow(){
  153. uni.removeStorageSync('form_type_cart');
  154. this.loadend = false;
  155. this.page = 1;
  156. this.$set(this,'collectProductList',[]);
  157. this.get_user_collect_product('product');
  158. },
  159. methods:{
  160. goGoods(id){
  161. if(this.administer) return false
  162. uni.navigateTo({
  163. url: `/pages/goods_details/index?id=${id}`
  164. });
  165. },
  166. goVideo(){
  167. if(this.administer) return false
  168. uni.navigateTo({
  169. //#ifdef APP
  170. url: '/pages/short_video/appSwiper/index',
  171. //#endif
  172. //#ifndef APP
  173. url: '/pages/short_video/nvueSwiper/index',
  174. //#endif
  175. })
  176. },
  177. del(type){
  178. let ids = [];
  179. this.collectProductList.forEach(item=>{
  180. if(item.checked){
  181. ids.push(item.id);
  182. }
  183. })
  184. if(!ids.length){
  185. return this.$util.Tips({
  186. title: '请选择收藏商品或视频'
  187. });
  188. }
  189. collectDel(ids,type).then(res=>{
  190. this.loadend = false;
  191. this.page = 1;
  192. this.$set(this,'collectProductList',[]);
  193. this.get_user_collect_product(type);
  194. return this.$util.Tips({
  195. title: res.msg
  196. });
  197. }).catch(err=>{
  198. return this.$util.Tips({
  199. title: err
  200. });
  201. })
  202. },
  203. checkboxChange(event){
  204. let idList = event.detail.value;
  205. this.collectProductList.forEach((item)=>{
  206. if(idList.indexOf(item.id + '') !== -1){
  207. item.checked = true;
  208. }else{
  209. item.checked = false;
  210. }
  211. })
  212. if(idList.length == this.collectProductList.length){
  213. this.isAllSelect = true;
  214. }else{
  215. this.isAllSelect = false;
  216. }
  217. },
  218. forGoods(val){
  219. let that = this;
  220. if(!that.collectProductList.length) return
  221. that.collectProductList.forEach((item)=>{
  222. if(val){
  223. item.checked = true;
  224. }else{
  225. item.checked = false;
  226. }
  227. })
  228. },
  229. checkboxAllChange(event){
  230. let value = event.detail.value;
  231. if(value.length){
  232. this.forGoods(1)
  233. }else{
  234. this.forGoods(0)
  235. }
  236. },
  237. manageTap(){
  238. this.administer = !this.administer;
  239. },
  240. navTap(index){
  241. this.active = index;
  242. let type = 'product'
  243. if(index){
  244. type = 'video'
  245. }else{
  246. type = 'product'
  247. }
  248. this.isAllSelect = false;
  249. this.forGoods(0);
  250. this.loadend = false;
  251. this.page = 1;
  252. this.$set(this,'collectProductList',[]);
  253. this.get_user_collect_product(type);
  254. },
  255. /**
  256. * 获取收藏产品
  257. */
  258. get_user_collect_product: function(type) {
  259. let that = this;
  260. if (this.loading) return;
  261. if (this.loadend) return;
  262. that.loading = true;
  263. that.loadTitle = "";
  264. getCollectUserList({
  265. page: that.page,
  266. limit: that.limit,
  267. category:type
  268. }).then(res => {
  269. let collectProductList = res.data.list;
  270. collectProductList.forEach(item=>{
  271. item.checked = false;
  272. })
  273. this.count = res.data.count;
  274. let loadend = collectProductList.length < that.limit;
  275. that.collectProductList = that.$util.SplitArray(collectProductList, that.collectProductList);
  276. that.$set(that, 'collectProductList', that.collectProductList);
  277. console.log(that.collectProductList);
  278. that.loadend = loadend;
  279. that.loadTitle = loadend ? '没有更多内容啦~' : '加载更多';
  280. that.page = that.page + 1;
  281. that.loading = false;
  282. }).catch(err => {
  283. that.loading = false;
  284. that.loadTitle = "加载更多";
  285. });
  286. },
  287. /**
  288. * 获取我的推荐
  289. */
  290. get_host_product: function() {
  291. let that = this;
  292. if(that.hotScroll) return
  293. getProductHot(
  294. that.hotPage,
  295. that.hotLimit,
  296. ).then(res => {
  297. that.hotPage++
  298. that.hotScroll = res.data.length<that.hotLimit
  299. that.hostProduct = that.hostProduct.concat(res.data)
  300. });
  301. }
  302. },
  303. onReachBottom() {
  304. if(this.collectProductList.length){
  305. this.get_user_collect_product('product');
  306. }else{
  307. // this.get_host_product();
  308. }
  309. }
  310. }
  311. </script>
  312. <style lang="scss">
  313. .collection{
  314. .nav{
  315. background-color: #fff;
  316. height: 88rpx;
  317. .item{
  318. margin: 0 48rpx;
  319. font-weight: 400;
  320. color: #282828;
  321. font-size: 30rpx;
  322. position: relative;
  323. &.on{
  324. font-weight: 500;
  325. color: var(--view-theme);
  326. &:before{
  327. content: '';
  328. position: absolute;
  329. width: 60rpx;
  330. height: 3rpx;
  331. background: var(--view-theme);
  332. bottom: -28rpx;
  333. }
  334. }
  335. }
  336. }
  337. .manage{
  338. padding: 0 30rpx;
  339. font-weight: 400;
  340. color: #333333;
  341. font-size: 28rpx;
  342. background-color: #fff;
  343. height: 74rpx;
  344. .close{
  345. color: #999999;
  346. }
  347. .num{
  348. color: var(--view-theme);
  349. margin: 0 5rpx;
  350. }
  351. }
  352. .collectList{
  353. padding: 0 20rpx 100rpx 20rpx;
  354. .item{
  355. margin-top: 20rpx;
  356. background-color: #fff;
  357. border-radius: 14rpx;
  358. padding: 20rpx;
  359. .pictrue{
  360. width: 220rpx;
  361. height: 220rpx;
  362. border-radius: 10rpx;
  363. position: relative;
  364. image{
  365. border-radius: 10rpx;
  366. width:100%;
  367. height: 100%;
  368. }
  369. .checkbox{
  370. position: absolute;
  371. top:10rpx;
  372. left:10rpx;
  373. z-index: 9;
  374. }
  375. /deep/checkbox .uni-checkbox-input {
  376. background-color: rgba(0, 0, 0, 0.16);
  377. }
  378. /deep/checkbox .wx-checkbox-input {
  379. background-color: rgba(0, 0, 0, 0.16);
  380. }
  381. }
  382. .text{
  383. width:420rpx;
  384. .top{
  385. height: 128rpx;
  386. }
  387. .name{
  388. font-weight: 400;
  389. color: #333333;
  390. font-size: 28rpx;
  391. }
  392. .label{
  393. margin-top: 16rpx;
  394. .labelCon{
  395. border: 1px solid var(--view-theme);
  396. padding: 2rpx 4rpx;
  397. color: var(--view-theme);
  398. font-weight: 400;
  399. font-size: 20rpx;
  400. border-radius: 10rpx;
  401. }
  402. }
  403. .money{
  404. margin-top: 62rpx;
  405. font-size: 24rpx;
  406. font-weight: 600;
  407. color: var(--view-theme);
  408. .num{
  409. font-size: 30rpx;
  410. }
  411. }
  412. }
  413. }
  414. }
  415. .videoList{
  416. padding: 0 4rpx 100rpx 4rpx;
  417. .item{
  418. width: 226rpx;
  419. height: 300rpx;
  420. border-radius: 8rpx;
  421. position: relative;
  422. margin-left: 16rpx;
  423. margin-top: 20rpx;
  424. position: relative;
  425. image{
  426. width: 100%;
  427. height: 100%;
  428. }
  429. .checkbox{
  430. position: absolute;
  431. top:10rpx;
  432. left:10rpx;
  433. z-index: 9;
  434. }
  435. /deep/checkbox .uni-checkbox-input {
  436. background-color: rgba(0, 0, 0, 0.16);
  437. }
  438. /deep/checkbox .wx-checkbox-input {
  439. background-color: rgba(0, 0, 0, 0.16);
  440. }
  441. .like{
  442. position: absolute;
  443. color: #fff;
  444. bottom: 14rpx;
  445. font-weight: 400;
  446. font-size: 20rpx;
  447. left: 14rpx;
  448. .iconfont{
  449. font-size: 24rpx;
  450. margin-right: 6rpx;
  451. }
  452. }
  453. }
  454. }
  455. .footer {
  456. box-sizing: border-box;
  457. padding: 0 30rpx;
  458. width: 100%;
  459. height: 96rpx;
  460. box-shadow: 0px -4px 20px 0px rgba(0, 0, 0, 0.06);
  461. background-color: #fff;
  462. position: fixed;
  463. bottom: 0;
  464. z-index: 30;
  465. height: calc(96rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  466. height: calc(96rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  467. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  468. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  469. width: 100%;
  470. left: 0;
  471. .bnt {
  472. width: 160rpx;
  473. height: 60rpx;
  474. border-radius: 30rpx;
  475. border: 1rpx solid #ccc;
  476. color: #666666;
  477. &.on {
  478. border: 1rpx solid var(--view-theme);
  479. margin-left: 16rpx;
  480. color: var(--view-theme);
  481. }
  482. }
  483. }
  484. }
  485. </style>