goods-log.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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.data"
  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.goods_id)"
  41. >
  42. <radio
  43. :checked="state.selectedCollectList.includes(item.goods_id)"
  44. color="var(--ui-BG-Main)"
  45. style="transform: scale(0.8)"
  46. @tap.stop="onSelect(item.goods_id)"
  47. />
  48. </label>
  49. <s-goods-item
  50. :title="item.goods.title"
  51. :img="item.goods.image"
  52. :price="item.goods.price[0]"
  53. :skuText="item.goods.subtitle"
  54. priceColor="#FF3000"
  55. :titleWidth="400"
  56. @tap="
  57. sheep.$router.go('/pages/goods/index', {
  58. id: item.goods_id,
  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">
  81. <button
  82. class="ss-reset-button ui-BG-Main-Gradient pay-btn ss-font-28 ui-Shadow-Main"
  83. @tap="onCancel"
  84. >
  85. 删除足迹
  86. </button>
  87. </view>
  88. </view>
  89. </su-fixed>
  90. </view>
  91. <uni-load-more
  92. v-if="state.pagination.total > 0"
  93. :status="state.loadStatus"
  94. :content-text="{
  95. contentdown: '上拉加载更多',
  96. }"
  97. @tap="loadmore"
  98. />
  99. <s-empty
  100. v-if="state.pagination.total === 0"
  101. text="暂无浏览记录"
  102. icon="/static/collect-empty.png"
  103. />
  104. </s-layout>
  105. </template>
  106. <script setup>
  107. import sheep from '@/sheep';
  108. import { reactive } from 'vue';
  109. import { onLoad, onReachBottom } from '@dcloudio/uni-app';
  110. import _ from 'lodash';
  111. const sys_navBar = sheep.$platform.navbar;
  112. const pagination = {
  113. data: [],
  114. current_page: 1,
  115. total: 1,
  116. last_page: 1,
  117. };
  118. const state = reactive({
  119. pagination: {
  120. data: [],
  121. current_page: 1,
  122. total: 1,
  123. last_page: 1,
  124. },
  125. loadStatus: '',
  126. editMode: false,
  127. selectedCollectList: [],
  128. selectAll: false,
  129. });
  130. async function getData(page = 1, list_rows = 10) {
  131. state.loadStatus = 'loading';
  132. let res = await sheep.$api.user.view.list({
  133. list_rows,
  134. page,
  135. });
  136. if (res.error === 0) {
  137. let orderList = _.concat(state.pagination.data, res.data.data);
  138. state.pagination = {
  139. ...res.data,
  140. data: orderList,
  141. };
  142. if (state.pagination.current_page < state.pagination.last_page) {
  143. state.loadStatus = 'more';
  144. } else {
  145. state.loadStatus = 'noMore';
  146. }
  147. }
  148. }
  149. // 格式化价格
  150. function formatPrice(e) {
  151. return e.length === 1 ? e[0] : e.join('~');
  152. }
  153. // 单选选中
  154. const onSelect = (id) => {
  155. if (!state.selectedCollectList.includes(id)) {
  156. state.selectedCollectList.push(id);
  157. } else {
  158. state.selectedCollectList.splice(state.selectedCollectList.indexOf(id), 1);
  159. }
  160. state.selectAll = state.selectedCollectList.length === state.pagination.data.length;
  161. };
  162. // 全选
  163. const onSelectAll = () => {
  164. state.selectAll = !state.selectAll;
  165. if (!state.selectAll) {
  166. state.selectedCollectList = [];
  167. } else {
  168. state.pagination.data.forEach((item) => {
  169. if (state.selectedCollectList.includes(item.goods_id)) {
  170. state.selectedCollectList.splice(state.selectedCollectList.indexOf(item.goods_id), 1);
  171. }
  172. state.selectedCollectList.push(item.goods_id);
  173. });
  174. }
  175. };
  176. async function onCancel() {
  177. if (state.selectedCollectList) {
  178. state.selectedCollectList = state.selectedCollectList.toString();
  179. const { error } = await sheep.$api.user.view.delete({
  180. goods_id: state.selectedCollectList,
  181. });
  182. if (error === 0) {
  183. state.editMode = false;
  184. state.selectedCollectList = [];
  185. state.selectAll = false;
  186. state.pagination = pagination;
  187. getData();
  188. }
  189. }
  190. }
  191. // 加载更多
  192. function loadmore() {
  193. if (state.loadStatus !== 'noMore') {
  194. getData(state.pagination.current_page + 1);
  195. }
  196. }
  197. onReachBottom(() => {
  198. loadmore();
  199. });
  200. onLoad(() => {
  201. getData();
  202. });
  203. </script>
  204. <style lang="scss" scoped>
  205. .cart-box {
  206. .cart-header {
  207. height: 70rpx;
  208. background-color: #f6f6f6;
  209. width: 100%;
  210. position: fixed;
  211. left: 0;
  212. top: v-bind('sys_navBar') rpx;
  213. z-index: 1000;
  214. box-sizing: border-box;
  215. }
  216. .cart-footer {
  217. height: 100rpx;
  218. background-color: #fff;
  219. .pay-btn {
  220. height: 80rpx;
  221. line-height: 80rpx;
  222. border-radius: 40rpx;
  223. padding: 0 40rpx;
  224. min-width: 200rpx;
  225. }
  226. }
  227. .cart-content {
  228. width: 100%;
  229. padding: 0 20rpx;
  230. box-sizing: border-box;
  231. margin-top: 70rpx;
  232. .goods-box {
  233. background-color: #fff;
  234. &:last-child {
  235. margin-bottom: 40rpx;
  236. }
  237. }
  238. }
  239. }
  240. .title-card {
  241. padding: 36rpx 0 46rpx 20rpx;
  242. .img-box {
  243. width: 164rpx;
  244. height: 164rpx;
  245. .order-img {
  246. width: 164rpx;
  247. height: 164rpx;
  248. }
  249. }
  250. .check-box {
  251. height: 100%;
  252. }
  253. .title-text {
  254. font-size: 28rpx;
  255. font-weight: 500;
  256. color: #333333;
  257. }
  258. .params-box {
  259. .params-title {
  260. height: 38rpx;
  261. background: #f4f4f4;
  262. border-radius: 2rpx;
  263. font-size: 24rpx;
  264. font-weight: 400;
  265. color: #666666;
  266. }
  267. }
  268. .price-text {
  269. color: $red;
  270. font-family: OPPOSANS;
  271. }
  272. }
  273. </style>