index.vue 12 KB

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