index.vue 13 KB

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