goods-log.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <s-layout :title="$t('user.goods.log.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. {{$t('user.goods.collect.total')}}
  8. <text class="goods-number ui-TC-Main ss-flex">
  9. {{ state.pagination.total }}
  10. </text>
  11. {{$t('user.goods.collect.unitgoods')}}
  12. </view>
  13. <view class="header-right">
  14. <button
  15. v-if="state.editMode && state.pagination.total"
  16. class="ss-reset-button"
  17. @tap="state.editMode = false"
  18. >
  19. {{$t('user.goods.collect.cancle')}}
  20. </button>
  21. <button
  22. v-if="!state.editMode && state.pagination.total"
  23. class="ss-reset-button ui-TC-Main"
  24. @tap="state.editMode = true"
  25. >
  26. {{$t('user.goods.collect.edit')}}
  27. </button>
  28. </view>
  29. </view>
  30. <!-- 内容 -->
  31. <view class="cart-content">
  32. <view
  33. class="goods-box ss-r-10 ss-m-b-14"
  34. v-for="item in state.pagination.data"
  35. :key="item.id"
  36. >
  37. <view class="ss-flex ss-col-center">
  38. <label
  39. class="check-box ss-flex ss-col-center ss-p-l-10"
  40. v-if="state.editMode"
  41. @tap="onSelect(item.goods_id)"
  42. >
  43. <radio
  44. :checked="state.selectedCollectList.includes(item.goods_id)"
  45. color="var(--ui-BG-Main)"
  46. style="transform: scale(0.8)"
  47. @tap.stop="onSelect(item.goods_id)"
  48. />
  49. </label>
  50. <s-goods-item
  51. :title="item.goods.title"
  52. :img="item.goods.image"
  53. :price="item.goods.price[0]"
  54. :skuText="item.goods.subtitle"
  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. <label class="check-box ss-flex ss-col-center ss-p-r-30" @tap="onSelectAll">
  72. <radio
  73. :checked="state.selectAll"
  74. color="var(--ui-BG-Main)"
  75. style="transform: scale(0.7)"
  76. @tap.stop="onSelectAll"
  77. />
  78. <view>{{$t('user.goods.collect.chooseAll')}}</view>
  79. </label>
  80. </view>
  81. <view class="footer-right">
  82. <button
  83. class="ss-reset-button ui-BG-Main-Gradient pay-btn ss-font-28 ui-Shadow-Main"
  84. @tap="onCancel"
  85. >
  86. {{$t('user.goods.log.delete')}}
  87. </button>
  88. </view>
  89. </view>
  90. </su-fixed>
  91. </view>
  92. <uni-load-more
  93. v-if="state.pagination.total > 0"
  94. :status="state.loadStatus"
  95. :content-text="{
  96. contentdown: $t('activity.index.uploadMore'),
  97. }"
  98. @tap="loadmore"
  99. />
  100. <s-empty
  101. v-if="state.pagination.total === 0"
  102. :text="$t('user.goods.log.noData')"
  103. icon="/static/collect-empty.png"
  104. />
  105. </s-layout>
  106. </template>
  107. <script setup>
  108. import sheep from '@/sheep';
  109. import { reactive } from 'vue';
  110. import { onLoad, onReachBottom } from '@dcloudio/uni-app';
  111. import _ from 'lodash';
  112. const sys_navBar = sheep.$platform.navbar;
  113. const pagination = {
  114. data: [],
  115. current_page: 1,
  116. total: 1,
  117. last_page: 1,
  118. };
  119. const state = reactive({
  120. pagination: {
  121. data: [],
  122. current_page: 1,
  123. total: 1,
  124. last_page: 1,
  125. },
  126. loadStatus: '',
  127. editMode: false,
  128. selectedCollectList: [],
  129. selectAll: false,
  130. });
  131. async function getData(page = 1, list_rows = 10) {
  132. state.loadStatus = 'loading';
  133. let res = await sheep.$api.user.goodsLog.list({
  134. type: 'views',
  135. list_rows,
  136. page,
  137. });
  138. if (res.code === 1) {
  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 { code } = await sheep.$api.user.view.delete({
  182. goods_id: state.selectedCollectList,
  183. });
  184. if (code === 1) {
  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>