index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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. toLogin()
  125. }
  126. },
  127. onShow() {
  128. uni.removeStorageSync('form_type_cart');
  129. this.times = [];
  130. this.loadend = false;
  131. this.page = 1;
  132. this.visitList = [];
  133. this.get_user_visit_list();
  134. },
  135. methods: {
  136. goDetails(item){
  137. if(this.isShowChecked || !item.is_show) return false;
  138. uni.navigateTo({
  139. url: '/pages/goods_details/index?id=' + item.product_id
  140. })
  141. },
  142. switchTap(){
  143. this.isShowChecked = !this.isShowChecked;
  144. },
  145. collect(){
  146. let ids = [];
  147. this.visitList.forEach(item=>{
  148. item.picList.forEach(j=>{
  149. if(j.checked){
  150. ids.push(j.product_id)
  151. }
  152. })
  153. })
  154. if(!ids.length){
  155. return this.$util.Tips({
  156. title: '请选择收藏商品'
  157. });
  158. }
  159. collectAdd(ids).then(res=>{
  160. return this.$util.Tips({
  161. title: res.msg
  162. });
  163. })
  164. },
  165. del(){
  166. let ids = [];
  167. this.visitList.forEach(item=>{
  168. item.picList.forEach(j=>{
  169. if(j.checked){
  170. ids.push(j.product_id)
  171. }
  172. })
  173. })
  174. if(!ids.length){
  175. return this.$util.Tips({
  176. title: '请选择删除商品'
  177. });
  178. }
  179. deleteVisitList({ids}).then(res=>{
  180. this.times = [];
  181. this.loadend = false;
  182. this.page = 1;
  183. this.$set(this, 'visitList', []);
  184. this.get_user_visit_list();
  185. return this.$util.Tips({
  186. title: res.msg
  187. });
  188. })
  189. },
  190. picCheckbox(event, index) {
  191. let that = this,
  192. picTime = event.detail.value;
  193. that.visitList[index].picList.forEach(j => {
  194. if (picTime.indexOf(j.id + '') !== -1) {
  195. j.checked = true;
  196. } else {
  197. j.checked = false;
  198. }
  199. })
  200. if(that.visitList[index].picList.length == picTime.length){
  201. that.visitList[index].checked = true;
  202. }else{
  203. that.visitList[index].checked = false;
  204. }
  205. let visitObj = [];
  206. that.visitList.forEach(item=>{
  207. if(item.checked){
  208. visitObj.push(item.time)
  209. }else{
  210. if(visitObj.indexOf(item.time) !== -1){
  211. visitObj.remove(item.time);
  212. }
  213. }
  214. })
  215. if(visitObj.length == that.visitList.length){
  216. that.isAllSelect = true;
  217. }else{
  218. that.isAllSelect = false;
  219. }
  220. },
  221. checkboxChange(event) {
  222. let that = this,
  223. timeList = event.detail.value;
  224. that.isItemAll = timeList;
  225. that.visitList.forEach((item, index) => {
  226. if (timeList.indexOf(item.time) !== -1) {
  227. item.checked = true;
  228. } else {
  229. item.checked = false;
  230. }
  231. item.picList.forEach(j => {
  232. if (item.checked) {
  233. j.checked = true;
  234. } else {
  235. j.checked = false;
  236. }
  237. })
  238. })
  239. if (timeList.length === that.visitList.length) {
  240. that.isAllSelect = true;
  241. } else {
  242. that.isAllSelect = false;
  243. }
  244. },
  245. forGoods(val) {
  246. let that = this;
  247. if (!that.visitList.length) return
  248. that.visitList.forEach((item) => {
  249. if (val) {
  250. item.checked = true;
  251. } else {
  252. item.checked = false;
  253. }
  254. item.picList.forEach(j => {
  255. if (val) {
  256. j.checked = true;
  257. } else {
  258. j.checked = false;
  259. }
  260. })
  261. })
  262. },
  263. checkboxAllChange(event) {
  264. let value = event.detail.value;
  265. if (value.length) {
  266. this.isAllSelect = true;
  267. this.forGoods(1)
  268. } else {
  269. this.isAllSelect = false;
  270. this.forGoods(0)
  271. }
  272. },
  273. // 授权关闭
  274. authColse: function(e) {
  275. this.isShowAuth = e
  276. },
  277. onLoadFun(){
  278. this.get_user_visit_list();
  279. this.isShowAuth = false
  280. },
  281. /**
  282. * 获取记录产品
  283. */
  284. get_user_visit_list: function() {
  285. let that = this;
  286. if (this.loading) return;
  287. if (this.loadend) return;
  288. that.loading = true;
  289. that.loadTitle = "";
  290. getVisitList({
  291. page: that.page,
  292. limit: that.limit
  293. }).then(res => {
  294. this.count = res.data.count;
  295. for (let i = 0; i < res.data.time.length; i++) {
  296. if (this.times.indexOf(res.data.time[i]) == -1) {
  297. this.times.push(res.data.time[i])
  298. this.visitList.push({
  299. time: res.data.time[i],
  300. picList: []
  301. })
  302. }
  303. }
  304. for (let x = 0; x < this.times.length; x++) {
  305. this.visitList[x].checked = this.isAllSelect ? true : false;
  306. for (let j = 0; j < res.data.list.length; j++) {
  307. if (this.times[x] === res.data.list[j].time_key) {
  308. if (this.isAllSelect) {
  309. res.data.list[j].checked = true;
  310. } else {
  311. res.data.list[j].checked = false;
  312. }
  313. this.visitList[x].picList.push(res.data.list[j])
  314. }
  315. }
  316. }
  317. let loadend = res.data.list.length < that.limit;
  318. that.loadend = loadend;
  319. that.loadTitle = loadend ? '没有更多内容啦~' : '加载更多';
  320. that.page = that.page + 1;
  321. that.loading = false;
  322. }).catch(err => {
  323. that.loading = false;
  324. that.loadTitle = "加载更多";
  325. });
  326. },
  327. /**
  328. * 获取我的推荐
  329. */
  330. get_host_product: function() {
  331. let that = this;
  332. if (that.hotScroll) return
  333. getProductHot(
  334. that.hotPage,
  335. that.hotLimit,
  336. ).then(res => {
  337. that.hotPage++
  338. that.hotScroll = res.data.length < that.hotLimit
  339. that.hostProduct = that.hostProduct.concat(res.data)
  340. });
  341. }
  342. },
  343. onReachBottom() {
  344. if (this.visitList.length) {
  345. this.get_user_visit_list();
  346. } else {
  347. this.get_host_product();
  348. }
  349. }
  350. }
  351. </script>
  352. <style lang="scss">
  353. page {
  354. background-color: #fff;
  355. }
  356. .noCommodity .pictrue{
  357. width: 414rpx;
  358. height: 304rpx;
  359. margin: 30rpx auto 0 auto;
  360. .tip{
  361. color: #bbb;
  362. font-size: 25rpx;
  363. }
  364. }
  365. .record .pictrue /deep/checkbox .uni-checkbox-input {
  366. background-color: rgba(0, 0, 0, 0.16);
  367. }
  368. .record .pictrue /deep/checkbox .wx-checkbox-input {
  369. background-color: rgba(0, 0, 0, 0.16);
  370. }
  371. .record {
  372. .footer {
  373. box-sizing: border-box;
  374. padding: 0 30rpx;
  375. width: 100%;
  376. height: 96rpx;
  377. box-shadow: 0px -4px 20px 0px rgba(0, 0, 0, 0.06);
  378. background-color: #fff;
  379. position: fixed;
  380. bottom: 0;
  381. z-index: 30;
  382. height: calc(96rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  383. height: calc(96rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  384. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  385. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  386. .bnt {
  387. width: 160rpx;
  388. height: 60rpx;
  389. border-radius: 30rpx;
  390. border: 1rpx solid #ccc;
  391. color: #666666;
  392. &.on {
  393. border: 1rpx solid var(--view-theme);
  394. margin-left: 16rpx;
  395. color: var(--view-theme);
  396. }
  397. }
  398. }
  399. .nav {
  400. border-bottom: 1rpx solid #eee;
  401. color: #999999;
  402. font-size: 28rpx;
  403. height: 74rpx;
  404. padding: 0 30rpx;
  405. .left {
  406. color: #333;
  407. .num {
  408. color: var(--view-theme);
  409. margin: 0 10rpx;
  410. }
  411. }
  412. }
  413. .list {
  414. padding-top: 32rpx;
  415. padding-bottom: 96rpx;
  416. .item {
  417. .title {
  418. padding: 0 30rpx;
  419. margin-bottom: 34rpx;
  420. font-size: 34rpx;
  421. font-weight: 600;
  422. }
  423. .picList {
  424. padding: 0 30rpx 0 12rpx;
  425. .picTxt {
  426. margin-left: 18rpx;
  427. margin-bottom: 48rpx;
  428. .pictrue {
  429. width: 218rpx;
  430. height: 218rpx;
  431. border-radius: 10rpx;
  432. position: relative;
  433. image {
  434. width: 100%;
  435. height: 100%;
  436. border-radius: 10rpx;
  437. }
  438. .masks {
  439. position: absolute;
  440. top: 0;
  441. left: 0;
  442. right: 0;
  443. bottom: 0;
  444. background: rgba(0, 0, 0, 0.2);
  445. border-radius: 10rpx;
  446. .bg {
  447. width: 110rpx;
  448. height: 110rpx;
  449. background: #000000;
  450. opacity: 0.6;
  451. color: #fff;
  452. font-size: 22rpx;
  453. border-radius: 50%;
  454. padding: 22rpx 0;
  455. text-align: center;
  456. }
  457. }
  458. .checkbox {
  459. position: absolute;
  460. right: 10rpx;
  461. top: 14rpx;
  462. }
  463. }
  464. .money {
  465. font-size: 24rpx;
  466. color: var(--view-priceColor);
  467. font-weight: 600;
  468. margin-top: 15rpx;
  469. .num {
  470. font-size: 32rpx;
  471. margin-left: 6rpx;
  472. }
  473. }
  474. }
  475. }
  476. }
  477. }
  478. }
  479. </style>