goods-log.vue 7.7 KB

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