goods-log.vue 7.9 KB

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