goods-collect.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <s-layout :title="$t('user.goods.collect.title')">
  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">{{ state.pagination.total }}</text>
  9. {{$t('user.goods.collect.unitgoods')}}
  10. </view>
  11. <view class="header-right">
  12. <button
  13. v-if="state.editMode && state.pagination.total"
  14. class="ss-reset-button"
  15. @tap="state.editMode = false"
  16. >
  17. {{$t('user.goods.collect.cancle')}}
  18. </button>
  19. <button
  20. v-if="!state.editMode && state.pagination.total"
  21. class="ss-reset-button ui-TC-Main"
  22. @tap="state.editMode = true"
  23. >{{$t('user.goods.collect.edit')}}</button
  24. >
  25. </view>
  26. </view>
  27. <!-- 内容 -->
  28. <view class="cart-content">
  29. <view
  30. class="goods-box ss-r-10 ss-m-b-14"
  31. v-for="item in state.pagination.data"
  32. :key="item.id"
  33. >
  34. <view class="ss-flex ss-col-center">
  35. <label
  36. class="check-box ss-flex ss-col-center ss-p-l-10"
  37. v-if="state.editMode"
  38. @tap="onSelect(item.goods_id)"
  39. >
  40. <radio
  41. :checked="state.selectedCollectList.includes(item.goods_id)"
  42. color="var(--ui-BG-Main)"
  43. style="transform: scale(0.8)"
  44. @tap.stop="onSelect(item.goods_id)"
  45. />
  46. </label>
  47. <s-goods-item
  48. :title="item.goods.title"
  49. :img="item.goods.image"
  50. :price="item.goods.price[0]"
  51. :skuText="item.goods.subtitle"
  52. priceColor="#FF3000"
  53. :titleWidth="400"
  54. @tap="
  55. sheep.$router.go('/pages/goods/index', {
  56. id: item.goods_id,
  57. })
  58. "
  59. >
  60. </s-goods-item>
  61. </view>
  62. </view>
  63. </view>
  64. <!-- 底部 -->
  65. <su-fixed bottom :val="0" placeholder v-show="state.editMode">
  66. <view class="cart-footer ss-flex ss-col-center ss-row-between ss-p-x-30 border-bottom">
  67. <view class="footer-left ss-flex ss-col-center">
  68. <label class="check-box ss-flex ss-col-center ss-p-r-30" @tap="onSelectAll">
  69. <radio
  70. :checked="state.selectAll"
  71. color="var(--ui-BG-Main)"
  72. style="transform: scale(0.7)"
  73. @tap.stop="onSelectAll"
  74. />
  75. <view> {{$t('user.goods.collect.chooseAll')}} </view>
  76. </label>
  77. </view>
  78. <view class="footer-right">
  79. <button
  80. class="ss-reset-button ui-BG-Main-Gradient pay-btn ss-font-28 ui-Shadow-Main"
  81. @tap="onCancel"
  82. >{{$t('user.goods.collect.cancleCollect')}}</button
  83. >
  84. </view>
  85. </view>
  86. </su-fixed>
  87. </view>
  88. <uni-load-more
  89. v-if="state.pagination.total > 0"
  90. :status="state.loadStatus"
  91. :content-text="{
  92. contentdown: $t('activity.index.uploadMore'),
  93. }"
  94. @tap="loadmore"
  95. />
  96. <s-empty v-if="state.pagination.total === 0" :text="$t('user.goods.collect.noData')" icon="/static/collect-empty.png" />
  97. </s-layout>
  98. </template>
  99. <script setup>
  100. import sheep from '@/sheep';
  101. import { reactive } from 'vue';
  102. import { onLoad, onReachBottom } from '@dcloudio/uni-app';
  103. import _ from 'lodash';
  104. const sys_navBar = sheep.$platform.navbar;
  105. const pagination = {
  106. data: [],
  107. current_page: 1,
  108. total: 1,
  109. last_page: 1,
  110. };
  111. const state = reactive({
  112. pagination: {
  113. data: [],
  114. current_page: 1,
  115. total: 1,
  116. last_page: 1,
  117. },
  118. loadStatus: '',
  119. editMode: false,
  120. selectedCollectList: [],
  121. selectAll: false,
  122. });
  123. async function getData(page = 1, list_rows = 10) {
  124. state.loadStatus = 'loading';
  125. let res = await sheep.$api.user.goodsLog.list({
  126. type: 'favorite',
  127. list_rows,
  128. page,
  129. });
  130. if (res.code === 1) {
  131. let orderList = _.concat(state.pagination.data, res.data.data);
  132. state.pagination = {
  133. ...res.data,
  134. data: orderList,
  135. };
  136. if (state.pagination.current_page < state.pagination.last_page) {
  137. state.loadStatus = 'more';
  138. } else {
  139. state.loadStatus = 'noMore';
  140. }
  141. }
  142. }
  143. // 格式化价格
  144. function formatPrice(e) {
  145. return e.length === 1 ? e[0] : e.join('~');
  146. }
  147. // 单选选中
  148. const onSelect = (id) => {
  149. if (!state.selectedCollectList.includes(id)) {
  150. state.selectedCollectList.push(id);
  151. } else {
  152. state.selectedCollectList.splice(state.selectedCollectList.indexOf(id), 1);
  153. }
  154. state.selectAll = state.selectedCollectList.length === state.pagination.data.length;
  155. };
  156. // 全选
  157. const onSelectAll = () => {
  158. state.selectAll = !state.selectAll;
  159. if (!state.selectAll) {
  160. state.selectedCollectList = [];
  161. } else {
  162. state.pagination.data.forEach((item) => {
  163. if (state.selectedCollectList.includes(item.goods_id)) {
  164. state.selectedCollectList.splice(state.selectedCollectList.indexOf(item.goods_id), 1);
  165. }
  166. state.selectedCollectList.push(item.goods_id);
  167. });
  168. }
  169. };
  170. async function onCancel() {
  171. if (state.selectedCollectList) {
  172. state.selectedCollectList = state.selectedCollectList.toString();
  173. const { code } = await sheep.$api.user.favorite.cancel(state.selectedCollectList);
  174. if (code === 1) {
  175. state.editMode = false;
  176. state.selectedCollectList = [];
  177. state.selectAll = false;
  178. state.pagination = pagination;
  179. getData();
  180. }
  181. }
  182. }
  183. // 加载更多
  184. function loadmore() {
  185. if (state.loadStatus !== 'noMore') {
  186. getData(state.pagination.current_page + 1);
  187. }
  188. }
  189. onReachBottom(() => {
  190. loadmore();
  191. });
  192. onLoad(() => {
  193. getData();
  194. });
  195. </script>
  196. <style lang="scss" scoped>
  197. .cart-box {
  198. .cart-header {
  199. height: 70rpx;
  200. background-color: #f6f6f6;
  201. width: 100%;
  202. position: fixed;
  203. left: 0;
  204. top: v-bind('sys_navBar') rpx;
  205. z-index: 1000;
  206. box-sizing: border-box;
  207. }
  208. .cart-footer {
  209. height: 100rpx;
  210. background-color: #fff;
  211. .pay-btn {
  212. height: 80rpx;
  213. line-height: 80rpx;
  214. border-radius: 40rpx;
  215. padding: 0 40rpx;
  216. min-width: 200rpx;
  217. }
  218. }
  219. .cart-content {
  220. width: 100%;
  221. margin-top: 70rpx;
  222. padding: 0 20rpx;
  223. box-sizing: border-box;
  224. .goods-box {
  225. background-color: #fff;
  226. &:last-child {
  227. margin-bottom: 40rpx;
  228. }
  229. }
  230. }
  231. }
  232. </style>