goods-log.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. <view
  38. v-show="state.editMode"
  39. class="check-box ss-flex ss-col-center ss-p-l-10"
  40. @tap="onSelect(item.goods_id)"
  41. >
  42. <label class="radio">
  43. <radio
  44. :checked="state.selectedCollectList.includes(item.goods_id)"
  45. color="var(--ui-BG-Main)"
  46. style="transform: scale(0.8)"
  47. />
  48. </label>
  49. </view>
  50. <s-goods-item
  51. :title="item.goods.title"
  52. :img="item.goods.image"
  53. price="666"
  54. skuText="123"
  55. priceColor="#FF3000"
  56. :titleWidth="400"
  57. @tap="
  58. sheep.$router.go('/pages/goods/index', {
  59. id: item.goods_id,
  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. <view class="check-box ss-flex ss-col-center ss-p-r-30" @tap="onSelectAll">
  72. <label class="radio">
  73. <radio
  74. :checked="state.selectAll"
  75. color="var(--ui-BG-Main)"
  76. style="transform: scale(0.7)"
  77. />
  78. </label>
  79. <view>全选</view>
  80. </view>
  81. </view>
  82. <view class="footer-right">
  83. <button
  84. class="ss-reset-button ui-BG-Main-Gradient pay-btn ss-font-28 ui-Shadow-Main"
  85. @tap="onCancel"
  86. >
  87. 取消收藏
  88. </button>
  89. </view>
  90. </view>
  91. </su-fixed>
  92. </view>
  93. <uni-load-more
  94. v-if="state.pagination.total > 0"
  95. :status="state.loadStatus"
  96. :content-text="{
  97. contentdown: '上拉加载更多',
  98. }"
  99. @tap="loadmore"
  100. />
  101. <s-empty
  102. v-if="state.pagination.total === 0"
  103. text="暂无浏览记录"
  104. icon="/static/collect-empty.png"
  105. />
  106. </s-layout>
  107. </template>
  108. <script setup>
  109. import sheep from '@/sheep';
  110. import { reactive } from 'vue';
  111. import { onLoad, onReachBottom } from '@dcloudio/uni-app';
  112. import _ from 'lodash';
  113. const sys_navBar = sheep.$platform.navbar;
  114. const state = reactive({
  115. pagination: {
  116. data: [],
  117. current_page: 1,
  118. total: 1,
  119. last_page: 1,
  120. },
  121. loadStatus: '',
  122. editMode: false,
  123. selectedCollectList: [],
  124. selectAll: false,
  125. });
  126. async function getData(page = 1, list_rows = 6) {
  127. state.loadStatus = 'loading';
  128. let res = await sheep.$api.user.view.list({
  129. list_rows,
  130. page,
  131. });
  132. if (res.error === 0) {
  133. if (page >= 2) {
  134. let orderList = _.concat(state.pagination.data, res.data.data);
  135. state.pagination = {
  136. ...res.data,
  137. data: orderList,
  138. };
  139. } else {
  140. state.pagination = res.data;
  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. getData();
  187. }
  188. }
  189. }
  190. // 加载更多
  191. function loadmore() {
  192. if (state.loadStatus !== 'noMore') {
  193. getData(state.pagination.current_page + 1);
  194. }
  195. }
  196. onReachBottom(() => {
  197. loadmore();
  198. });
  199. onLoad(() => {
  200. getData();
  201. });
  202. </script>
  203. <style lang="scss" scoped>
  204. .cart-box {
  205. .cart-header {
  206. height: 70rpx;
  207. background-color: #f6f6f6;
  208. width: 100%;
  209. position: fixed;
  210. left: 0;
  211. top: v-bind('sys_navBar') rpx;
  212. z-index: 1000;
  213. box-sizing: border-box;
  214. }
  215. .cart-footer {
  216. height: 100rpx;
  217. background-color: #fff;
  218. .pay-btn {
  219. height: 80rpx;
  220. line-height: 80rpx;
  221. border-radius: 40rpx;
  222. padding: 0 40rpx;
  223. min-width: 200rpx;
  224. }
  225. }
  226. .cart-content {
  227. width: 100%;
  228. padding: 0 20rpx;
  229. box-sizing: border-box;
  230. margin-top: 70rpx;
  231. .goods-box {
  232. background-color: #fff;
  233. &:last-child {
  234. margin-bottom: 40rpx;
  235. }
  236. }
  237. }
  238. }
  239. .title-card {
  240. padding: 36rpx 0 46rpx 20rpx;
  241. .img-box {
  242. width: 164rpx;
  243. height: 164rpx;
  244. .order-img {
  245. width: 164rpx;
  246. height: 164rpx;
  247. }
  248. }
  249. .check-box {
  250. height: 100%;
  251. }
  252. .title-text {
  253. font-size: 28rpx;
  254. font-weight: 500;
  255. color: #333333;
  256. }
  257. .params-box {
  258. .params-title {
  259. height: 38rpx;
  260. background: #f4f4f4;
  261. border-radius: 2rpx;
  262. font-size: 24rpx;
  263. font-weight: 400;
  264. color: #666666;
  265. }
  266. }
  267. .price-text {
  268. color: $red;
  269. font-family: OPPOSANS;
  270. }
  271. }
  272. </style>