goods-log.vue 7.7 KB

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