index.vue 10 KB

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