index.vue 13 KB

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