goods-log.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <!-- 产品浏览记录 -->
  2. <template>
  3. <s-layout :bgStyle="{ color: '#f2f2f2' }" tabbar="/pages/user/goods-log" title="我的足迹">
  4. <view class="cart-box ss-flex ss-flex-col ss-row-between">
  5. <!-- 头部 -->
  6. <view class="cart-header ss-flex ss-col-center ss-row-between ss-p-x-30">
  7. <view class="header-left ss-flex ss-col-center ss-font-26">
  8. <text class="goods-number ui-TC-Main ss-flex">
  9. {{ state.pagination.total }}
  10. </text>
  11. 件产品
  12. </view>
  13. <view class="header-right">
  14. <button v-if="state.editMode && state.pagination.total" class="ss-reset-button" @tap="state.editMode = false">
  15. 取消
  16. </button>
  17. <button v-if="!state.editMode && state.pagination.total" class="ss-reset-button ui-TC-Main"
  18. @tap="state.editMode = true">
  19. 编辑
  20. </button>
  21. </view>
  22. </view>
  23. <!-- 内容 -->
  24. <view class="cart-content">
  25. <view class="goods-box ss-r-10 ss-m-b-14" v-for="item in state.pagination.list" :key="item.id">
  26. <view class="ss-flex ss-col-center">
  27. <label class="check-box ss-flex ss-col-center ss-p-l-10" v-if="state.editMode" @tap="onSelect(item.spuId)">
  28. <radio :checked="state.selectedSpuIdList.includes(item.spuId)" color="var(--ui-BG-Main)"
  29. style="transform: scale(0.8)" @tap.stop="onSelect(item.spuId)" />
  30. </label>
  31. <s-goods-item :title="item.spuName" :img="item.picUrl" :price="item.price" :skuText="item.introduction"
  32. priceColor="#FF3000" :titleWidth="400" @tap="
  33. sheep.$router.go('/pages/goods/index', {
  34. id: item.spuId,
  35. })
  36. ">
  37. </s-goods-item>
  38. </view>
  39. </view>
  40. </view>
  41. <!-- 底部 -->
  42. <su-fixed bottom :val="0" placeholder v-show="state.editMode">
  43. <view class="cart-footer ss-flex ss-col-center ss-row-between ss-p-x-30 border-bottom">
  44. <view class="footer-left ss-flex ss-col-center">
  45. <label class="check-box ss-flex ss-col-center ss-p-r-30" @tap="onSelectAll">
  46. <radio :checked="state.selectAll" color="var(--ui-BG-Main)" style="transform: scale(0.7)"
  47. @tap.stop="onSelectAll" />
  48. <view>全选</view>
  49. </label>
  50. </view>
  51. <view class="footer-right ss-flex">
  52. <button :class="[
  53. 'ss-reset-button pay-btn ss-font-28 ',
  54. {
  55. 'ui-BG-Main-Gradient': state.selectedSpuIdList.length > 0,
  56. 'ui-Shadow-Main': state.selectedSpuIdList.length > 0,
  57. },
  58. ]" @tap="onDelete">
  59. 删除足迹
  60. </button>
  61. <button class="ss-reset-button ui-BG-Main-Gradient pay-btn ss-font-28 ui-Shadow-Main ml-2" @tap="onClean">
  62. 清空
  63. </button>
  64. </view>
  65. </view>
  66. </su-fixed>
  67. </view>
  68. <uni-load-more v-if="state.pagination.total > 0" :status="state.loadStatus" :content-text="{
  69. contentdown: '上拉加载更多',
  70. }" @tap="loadMore" />
  71. <s-empty v-if="state.pagination.total === 0" text="暂无浏览记录" icon="/static/collect-empty.png" />
  72. </s-layout>
  73. </template>
  74. <script setup>
  75. import sheep from '@/sheep';
  76. import { reactive } from 'vue';
  77. import { onLoad, onReachBottom } from '@dcloudio/uni-app';
  78. import _ from 'lodash-es';
  79. import SpuHistoryApi from '@/sheep/api/product/history';
  80. import { cloneDeep } from '@/sheep/helper/utils';
  81. const sys_navBar = sheep.$platform.navbar;
  82. const pagination = {
  83. list: [],
  84. pageNo: 1,
  85. total: 1,
  86. pageSize: 10,
  87. };
  88. const state = reactive({
  89. pagination: cloneDeep(pagination),
  90. loadStatus: '',
  91. editMode: false,
  92. selectedSpuIdList: [],
  93. selectAll: false,
  94. });
  95. async function getList() {
  96. state.loadStatus = 'loading';
  97. const { code, data } = await SpuHistoryApi.getBrowseHistoryPage({
  98. pageNo: state.pagination.pageNo,
  99. pageSize: state.pagination.pageSize,
  100. });
  101. if (code !== 0) {
  102. return;
  103. }
  104. state.pagination.list = _.concat(state.pagination.list, data.list);
  105. state.pagination.total = data.total;
  106. state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
  107. }
  108. // 单选选中
  109. const onSelect = (id) => {
  110. if (!state.selectedSpuIdList.includes(id)) {
  111. state.selectedSpuIdList.push(id);
  112. } else {
  113. state.selectedSpuIdList.splice(state.selectedSpuIdList.indexOf(id), 1);
  114. }
  115. state.selectAll = state.selectedSpuIdList.length === state.pagination.list.length;
  116. };
  117. // 全选
  118. const onSelectAll = () => {
  119. state.selectAll = !state.selectAll;
  120. if (!state.selectAll) {
  121. state.selectedSpuIdList = [];
  122. } else {
  123. state.pagination.list.forEach((item) => {
  124. if (state.selectedSpuIdList.includes(item.spuId)) {
  125. state.selectedSpuIdList.splice(state.selectedSpuIdList.indexOf(item.spuId), 1);
  126. }
  127. state.selectedSpuIdList.push(item.spuId);
  128. });
  129. }
  130. };
  131. // 删除足迹
  132. async function onDelete() {
  133. if (state.selectedSpuIdList.length <= 0) {
  134. return;
  135. }
  136. const { code } = await SpuHistoryApi.deleteBrowseHistory(state.selectedSpuIdList);
  137. if (code === 0) {
  138. reload();
  139. }
  140. }
  141. // 清空
  142. async function onClean() {
  143. const { code } = await SpuHistoryApi.cleanBrowseHistory();
  144. if (code === 0) {
  145. reload();
  146. }
  147. }
  148. function reload() {
  149. state.editMode = false;
  150. state.selectedSpuIdList = [];
  151. state.selectAll = false;
  152. state.pagination = pagination;
  153. getList();
  154. }
  155. // 加载更多
  156. function loadMore() {
  157. if (state.loadStatus !== 'noMore') {
  158. state.pagination.pageNo += 1;
  159. getList();
  160. }
  161. }
  162. onReachBottom(() => {
  163. loadMore();
  164. });
  165. onLoad(() => {
  166. getList();
  167. });
  168. </script>
  169. <style lang="scss" scoped>
  170. .cart-box {
  171. .cart-header {
  172. height: 70rpx;
  173. background-color: #f6f6f6;
  174. width: 100%;
  175. position: fixed;
  176. left: 0;
  177. top: v-bind('sys_navBar') rpx;
  178. z-index: 1000;
  179. box-sizing: border-box;
  180. }
  181. .cart-footer {
  182. height: 100rpx;
  183. background-color: #fff;
  184. .pay-btn {
  185. height: 80rpx;
  186. line-height: 80rpx;
  187. border-radius: 40rpx;
  188. padding: 0 40rpx;
  189. min-width: 200rpx;
  190. }
  191. }
  192. .cart-content {
  193. width: 100%;
  194. padding: 0 20rpx;
  195. box-sizing: border-box;
  196. margin-top: 70rpx;
  197. .goods-box {
  198. background-color: #fff;
  199. &:last-child {
  200. margin-bottom: 40rpx;
  201. }
  202. }
  203. }
  204. }
  205. .title-card {
  206. padding: 36rpx 0 46rpx 20rpx;
  207. .img-box {
  208. width: 164rpx;
  209. height: 164rpx;
  210. .order-img {
  211. width: 164rpx;
  212. height: 164rpx;
  213. }
  214. }
  215. .check-box {
  216. height: 100%;
  217. }
  218. .title-text {
  219. font-size: 28rpx;
  220. font-weight: 500;
  221. color: #333333;
  222. }
  223. .params-box {
  224. .params-title {
  225. height: 38rpx;
  226. background: #f4f4f4;
  227. border-radius: 2rpx;
  228. font-size: 24rpx;
  229. font-weight: 400;
  230. color: #666666;
  231. }
  232. }
  233. .price-text {
  234. color: $red;
  235. font-family: OPPOSANS;
  236. }
  237. }
  238. </style>