goods-log.vue 7.1 KB

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