index.vue 12 KB

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