goods-log.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. <radio-group
  38. v-show="state.editMode"
  39. class="check-box ss-flex ss-col-center ss-p-l-10"
  40. @change="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. </radio-group>
  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. <radio-group @change="onSelectAll">
  72. <label class="check-box ss-flex ss-col-center ss-p-r-30">
  73. <radio
  74. :checked="state.selectAll"
  75. color="var(--ui-BG-Main)"
  76. style="transform: scale(0.7)"
  77. />
  78. <view>全选</view>
  79. </label>
  80. </radio-group>
  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 pagination = {
  115. data: [],
  116. current_page: 1,
  117. total: 1,
  118. last_page: 1,
  119. };
  120. const state = reactive({
  121. pagination: {
  122. data: [],
  123. current_page: 1,
  124. total: 1,
  125. last_page: 1,
  126. },
  127. loadStatus: '',
  128. editMode: false,
  129. selectedCollectList: [],
  130. selectAll: false,
  131. });
  132. async function getData(page = 1, list_rows = 10) {
  133. state.loadStatus = 'loading';
  134. let res = await sheep.$api.user.view.list({
  135. list_rows,
  136. page,
  137. });
  138. if (res.error === 0) {
  139. let orderList = _.concat(state.pagination.data, res.data.data);
  140. state.pagination = {
  141. ...res.data,
  142. data: orderList,
  143. };
  144. if (state.pagination.current_page < state.pagination.last_page) {
  145. state.loadStatus = 'more';
  146. } else {
  147. state.loadStatus = 'noMore';
  148. }
  149. }
  150. }
  151. // 格式化价格
  152. function formatPrice(e) {
  153. return e.length === 1 ? e[0] : e.join('~');
  154. }
  155. // 单选选中
  156. const onSelect = (id) => {
  157. if (!state.selectedCollectList.includes(id)) {
  158. state.selectedCollectList.push(id);
  159. } else {
  160. state.selectedCollectList.splice(state.selectedCollectList.indexOf(id), 1);
  161. }
  162. state.selectAll = state.selectedCollectList.length === state.pagination.data.length;
  163. };
  164. // 全选
  165. const onSelectAll = () => {
  166. state.selectAll = !state.selectAll;
  167. if (!state.selectAll) {
  168. state.selectedCollectList = [];
  169. } else {
  170. state.pagination.data.forEach((item) => {
  171. if (state.selectedCollectList.includes(item.goods_id)) {
  172. state.selectedCollectList.splice(state.selectedCollectList.indexOf(item.goods_id), 1);
  173. }
  174. state.selectedCollectList.push(item.goods_id);
  175. });
  176. }
  177. };
  178. async function onCancel() {
  179. if (state.selectedCollectList) {
  180. state.selectedCollectList = state.selectedCollectList.toString();
  181. const { error } = await sheep.$api.user.view.delete({
  182. goods_id: state.selectedCollectList,
  183. });
  184. if (error === 0) {
  185. state.editMode = false;
  186. state.selectedCollectList = [];
  187. state.selectAll = false;
  188. state.pagination = pagination
  189. getData();
  190. }
  191. }
  192. }
  193. // 加载更多
  194. function loadmore() {
  195. if (state.loadStatus !== 'noMore') {
  196. getData(state.pagination.current_page + 1);
  197. }
  198. }
  199. onReachBottom(() => {
  200. loadmore();
  201. });
  202. onLoad(() => {
  203. getData();
  204. });
  205. </script>
  206. <style lang="scss" scoped>
  207. .cart-box {
  208. .cart-header {
  209. height: 70rpx;
  210. background-color: #f6f6f6;
  211. width: 100%;
  212. position: fixed;
  213. left: 0;
  214. top: v-bind('sys_navBar') rpx;
  215. z-index: 1000;
  216. box-sizing: border-box;
  217. }
  218. .cart-footer {
  219. height: 100rpx;
  220. background-color: #fff;
  221. .pay-btn {
  222. height: 80rpx;
  223. line-height: 80rpx;
  224. border-radius: 40rpx;
  225. padding: 0 40rpx;
  226. min-width: 200rpx;
  227. }
  228. }
  229. .cart-content {
  230. width: 100%;
  231. padding: 0 20rpx;
  232. box-sizing: border-box;
  233. margin-top: 70rpx;
  234. .goods-box {
  235. background-color: #fff;
  236. &:last-child {
  237. margin-bottom: 40rpx;
  238. }
  239. }
  240. }
  241. }
  242. .title-card {
  243. padding: 36rpx 0 46rpx 20rpx;
  244. .img-box {
  245. width: 164rpx;
  246. height: 164rpx;
  247. .order-img {
  248. width: 164rpx;
  249. height: 164rpx;
  250. }
  251. }
  252. .check-box {
  253. height: 100%;
  254. }
  255. .title-text {
  256. font-size: 28rpx;
  257. font-weight: 500;
  258. color: #333333;
  259. }
  260. .params-box {
  261. .params-title {
  262. height: 38rpx;
  263. background: #f4f4f4;
  264. border-radius: 2rpx;
  265. font-size: 24rpx;
  266. font-weight: 400;
  267. color: #666666;
  268. }
  269. }
  270. .price-text {
  271. color: $red;
  272. font-family: OPPOSANS;
  273. }
  274. }
  275. </style>