metalExchangeList.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. <template>
  2. <view class="container">
  3. <view class="tabs-container">
  4. <view
  5. class="tab-item"
  6. :class="{ active: currentTab === 0 }"
  7. @click="switchTab(0)"
  8. >
  9. 预约订单
  10. </view>
  11. <view
  12. class="tab-item"
  13. :class="{ active: currentTab === 1 }"
  14. @click="switchTab(1)"
  15. >
  16. 提料订单
  17. </view>
  18. </view>
  19. <z-paging
  20. class="paging-box"
  21. ref="pagingRef"
  22. use-page-scroll
  23. v-model="currentList"
  24. @query="handleQuery"
  25. @refresherTouchend="refresherTouchend"
  26. :fixed="false"
  27. :empty-view-text="getEmptyText()"
  28. >
  29. <view
  30. class="list-item"
  31. v-for="(item, index) in combineList"
  32. :key="index"
  33. :class="{ 'reservation-item': currentTab === 0 }"
  34. >
  35. <view class="item-top">
  36. <view class="item-left">
  37. <view class="item-detail">
  38. <text class="detail-label">
  39. 金属类型:<span class="detail-value">{{
  40. item.metalTypeMsg
  41. }}</span>
  42. </text>
  43. <text class="detail-label" style="margin-left: 20rpx">
  44. 克重:{{ item.weight }}g
  45. </text>
  46. </view>
  47. <view v-if="currentTab === 0" class="item-time">
  48. 预约日期:{{ item.reservationDate }}
  49. </view>
  50. <view
  51. v-if="currentTab === 1"
  52. class="item-time"
  53. @click="copy(item.expressNo)"
  54. >
  55. 快递单号:{{ item.expressNo || "发货后将在此处显示快递单号" }}
  56. </view>
  57. <view class="item-time">创建时间:{{ item.createTime }}</view>
  58. </view>
  59. <view v-if="currentTab === 0" class="item-status-tag">
  60. <view class="status-tag" :class="getStatusClass(item.status)">
  61. {{ getStatusText(item.status) }}
  62. </view>
  63. </view>
  64. <view v-if="currentTab === 1" class="item-amount">
  65. 金价¥{{ item.realTimePrice }}/g
  66. </view>
  67. </view>
  68. <!-- 预约订单底部操作栏:取消订单(始终显示)+ 前往提料 -->
  69. <view v-if="currentTab === 0" class="item-operation">
  70. <!-- 取消订单:根据status控制可点击和颜色 -->
  71. <button
  72. class="cancel-btn"
  73. :class="{ 'cancel-btn--disabled': item.status !== 1 }"
  74. :disabled="item.status !== 1"
  75. @click="handleCancelReservation(item.reservationId)"
  76. >
  77. 取消订单
  78. </button>
  79. <!-- 前往提料:根据status + 时间控制可点击和颜色 -->
  80. <button
  81. class="withdraw-btn"
  82. :class="{
  83. 'withdraw-btn--disabled':
  84. item.status !== 1 || !canGoToWithdraw(item.reservationDate),
  85. }"
  86. :disabled="
  87. item.status !== 1 || !canGoToWithdraw(item.reservationDate)
  88. "
  89. @click="gotoWithdraw(item)"
  90. >
  91. 前往提料
  92. </button>
  93. </view>
  94. </view>
  95. </z-paging>
  96. </view>
  97. </template>
  98. <script setup>
  99. import { ref, computed } from "vue";
  100. import { onLoad } from "@dcloudio/uni-app";
  101. import useZPaging from "@/uni_modules/z-paging/components/z-paging/js/hooks/useZPaging.js";
  102. import { useAppStore } from "@/stores/app";
  103. import { useToast } from "@/hooks/useToast";
  104. import { getUserInfo } from "@/api/user";
  105. import {
  106. getMetalOrderList,
  107. getMyReservations,
  108. cancelReservation,
  109. } from "@/api/vault";
  110. const appStore = useAppStore();
  111. const { Toast } = useToast();
  112. const pagingRef = ref(null);
  113. useZPaging(pagingRef);
  114. // tabs状态
  115. const currentTab = ref(0); // 0-预约订单 1-提料订单
  116. const reservationList = ref([]); // 预约订单数据
  117. const recordList = ref([]); // 提料订单原始数据
  118. // 金属类型映射
  119. const metalTypeMap = {
  120. 1: "黄金",
  121. 2: "铂金",
  122. 3: "白银",
  123. };
  124. // 根据当前tab返回对应的数据列表
  125. const currentList = computed(() => {
  126. return currentTab.value === 0 ? reservationList.value : recordList.value;
  127. });
  128. // 处理列表数据格式化
  129. const combineList = computed(() => {
  130. if (currentTab.value === 0) {
  131. return reservationList.value.map((item) => ({
  132. ...item,
  133. orderNo: item.reservationNo || item.id,
  134. weight: item.reservedWeight,
  135. metalTypeMsg: metalTypeMap[item.metalType] || "未知金属",
  136. reservationDate: item.reservationDate,
  137. createTime: item.createTime,
  138. status: item.status,
  139. reservationId: item.id || item.reservationId,
  140. metalType: item.metalType,
  141. }));
  142. } else {
  143. return recordList.value.map((item) => ({
  144. ...item,
  145. orderNo: item.orderNo,
  146. amount: item.totalAmount,
  147. weight: item.plateWeight,
  148. metalTypeMsg:
  149. item.metalTypeName || metalTypeMap[item.metalType] || "未知金属",
  150. expressName: item.expressCompanyName || "未选择",
  151. createTime: item.createTime,
  152. realTimePrice: item.realTimePrice,
  153. expressNo: item.expressNo,
  154. }));
  155. }
  156. });
  157. // 切换tabs
  158. const switchTab = (tabIndex) => {
  159. currentTab.value = tabIndex;
  160. pagingRef.value?.reload();
  161. };
  162. // 空状态文本
  163. const getEmptyText = () => {
  164. return currentTab.value === 0 ? "暂无预约订单" : "暂无提料兑换订单";
  165. };
  166. // 预约状态文本映射
  167. const getStatusText = (status) => {
  168. const statusMap = {
  169. 1: "已预约",
  170. 2: "已完成",
  171. 3: "已取消",
  172. };
  173. return statusMap[status] || "未知状态";
  174. };
  175. // 预约状态标签样式
  176. const getStatusClass = (status) => {
  177. const classMap = {
  178. 1: "status-reserved", // 已预约-绿色
  179. 2: "status-completed", // 已完成-蓝色
  180. 3: "status-canceled", // 已取消-灰色
  181. };
  182. return classMap[status] || "";
  183. };
  184. // 判断是否可点击「前往提料」(仅status=1时判断时间)
  185. const canGoToWithdraw = (reservationDate) => {
  186. if (!reservationDate) return false;
  187. const reserveDate = new Date(reservationDate).getTime();
  188. const endTime = reserveDate + 24 * 60 * 60 * 1000;
  189. const now = new Date().getTime();
  190. return now > reserveDate && now < endTime;
  191. };
  192. // 前往提料页面
  193. const gotoWithdraw = (item) => {
  194. uni.redirectTo({
  195. url: `/pages/users/vault/storeMetal/metalExchangeWithdraw?metalType=${item.metalType}&weight=${item.weight}&reservationId=${item.reservationId}`,
  196. });
  197. };
  198. // 统一查询入口
  199. const handleQuery = async (page, pageSize) => {
  200. if (currentTab.value === 0) {
  201. await queryReservationList(page, pageSize);
  202. } else {
  203. await queryMaterialOrderList(page, pageSize);
  204. }
  205. };
  206. // 查询预约订单列表
  207. const queryReservationList = async (page, pageSize) => {
  208. try {
  209. const params = { page, pageSize, uid: appStore.uid };
  210. const res = await getMyReservations(params);
  211. const newList = res?.data?.list || [];
  212. reservationList.value =
  213. page === 1 ? newList : [...reservationList.value, ...newList];
  214. const total = res?.data?.total || 0;
  215. pagingRef.value?.complete(reservationList.value, total);
  216. } catch (error) {
  217. console.error("预约订单查询失败:", error);
  218. pagingRef.value?.complete(false);
  219. Toast({ title: "查询失败,请稍后重试" });
  220. }
  221. };
  222. // 查询提料订单列表
  223. const queryMaterialOrderList = async (page, pageSize) => {
  224. try {
  225. const params = { page, pageSize, uid: appStore.uid, userId: appStore.uid };
  226. const res = await getMetalOrderList(params);
  227. const newList = res?.data?.list || [];
  228. recordList.value = page === 1 ? newList : [...recordList.value, ...newList];
  229. const total = res?.data?.total || 0;
  230. pagingRef.value?.complete(recordList.value, total);
  231. } catch (error) {
  232. console.error("提料兑换订单查询失败:", error);
  233. pagingRef.value?.complete(false);
  234. Toast({ title: "查询失败,请稍后重试" });
  235. }
  236. };
  237. // 取消预约操作(仅status=1时触发,已通过按钮disabled控制)
  238. const handleCancelReservation = async (reservationId) => {
  239. uni.showModal({
  240. title: "提示",
  241. content: "确定要取消该预约吗?取消后将无法恢复",
  242. confirmText: "确认取消",
  243. cancelText: "取消",
  244. success: async (res) => {
  245. if (res.confirm) {
  246. try {
  247. uni.showLoading({ title: "处理中...", mask: true });
  248. await cancelReservation(reservationId);
  249. uni.showToast({ title: "取消成功", icon: "success" });
  250. pagingRef.value?.reload();
  251. } catch (error) {
  252. console.error("取消预约失败:", error);
  253. uni.showToast({ title: "取消失败,请稍后重试", icon: "none" });
  254. } finally {
  255. uni.hideLoading();
  256. }
  257. }
  258. },
  259. });
  260. };
  261. onLoad(() => {
  262. pagingRef.value?.reload();
  263. });
  264. // 复制快递单号
  265. const copy = (expressNo) => {
  266. if (!expressNo) return;
  267. uni.setClipboardData({
  268. data: expressNo,
  269. success: () => uni.showToast({ title: "复制成功", icon: "success" }),
  270. fail: (err) => {
  271. uni.showToast({ title: "复制失败", icon: "none" });
  272. console.error("复制失败:", err);
  273. },
  274. });
  275. };
  276. </script>
  277. <style lang="scss" scoped>
  278. $primary-color: #e9c279;
  279. $text-color: #333;
  280. $text-secondary: #666;
  281. $text-light: #999;
  282. $bg-color: #f5f5f5;
  283. $white: #fff;
  284. $cancel-color: #ff1e0f; // 取消按钮-启用色
  285. $cancel-disabled-color: #ccc; // 取消按钮-禁用色
  286. $withdraw-color: #007aff; // 提料按钮-启用色
  287. $withdraw-disabled-color: #ccc; // 提料按钮-禁用色
  288. // tabs样式
  289. .tabs-container {
  290. display: flex;
  291. height: 80rpx;
  292. background-color: $white;
  293. border-radius: 10rpx;
  294. margin-bottom: 20rpx;
  295. overflow: hidden;
  296. .tab-item {
  297. flex: 1;
  298. display: flex;
  299. align-items: center;
  300. justify-content: center;
  301. font-size: 30rpx;
  302. color: $text-secondary;
  303. position: relative;
  304. &.active {
  305. color: $primary-color;
  306. font-weight: 500;
  307. &::after {
  308. content: "";
  309. position: absolute;
  310. bottom: 0;
  311. left: 0;
  312. width: 100%;
  313. height: 4rpx;
  314. background-color: $primary-color;
  315. }
  316. }
  317. }
  318. }
  319. // 页面容器
  320. .container {
  321. min-height: 100vh;
  322. overflow: hidden;
  323. background: $bg-color;
  324. padding: 20rpx;
  325. }
  326. // 分页列表容器
  327. .paging-box {
  328. min-height: 60vh;
  329. }
  330. // 通用列表项样式
  331. .list-item {
  332. background: $white;
  333. margin-bottom: 20rpx;
  334. border-radius: 16rpx;
  335. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  336. }
  337. // 预约订单卡片专用样式
  338. .reservation-item {
  339. display: flex;
  340. flex-direction: column;
  341. gap: 20rpx;
  342. }
  343. // 卡片顶部区域
  344. .item-top {
  345. display: flex;
  346. padding: 30rpx 25rpx;
  347. padding-bottom: 0;
  348. justify-content: space-between;
  349. align-items: flex-start;
  350. }
  351. // 左侧信息区域
  352. .item-left {
  353. flex: 1;
  354. .item-detail {
  355. margin-bottom: 15rpx;
  356. font-size: 26rpx;
  357. .detail-label {
  358. color: $text-secondary;
  359. }
  360. .detail-value {
  361. color: $primary-color !important;
  362. }
  363. }
  364. .item-time {
  365. font-size: 22rpx;
  366. color: $text-light;
  367. margin-bottom: 8rpx;
  368. }
  369. }
  370. // 预约订单右上角状态标签
  371. .item-status-tag {
  372. display: flex;
  373. align-items: flex-start;
  374. }
  375. // 提料订单右上角金价
  376. .item-amount {
  377. font-size: 26rpx;
  378. font-weight: 500;
  379. color: $primary-color;
  380. }
  381. // 预约状态标签样式
  382. .status-tag {
  383. width: 120rpx;
  384. text-align: center;
  385. padding: 4rpx 0;
  386. border-radius: 20rpx;
  387. font-size: 22rpx;
  388. color: $white;
  389. &.status-reserved {
  390. background-color: #4cd964;
  391. }
  392. &.status-completed {
  393. background-color: #007aff;
  394. }
  395. &.status-canceled {
  396. background-color: $text-light;
  397. }
  398. }
  399. // 预约订单底部操作栏
  400. .item-operation {
  401. display: flex;
  402. justify-content: space-between;
  403. align-items: center;
  404. height: 50rpx;
  405. border-top: 1px solid #f5f5f5;
  406. }
  407. // 取消订单按钮-基础样式
  408. .cancel-btn {
  409. flex: 1;
  410. height: 100%;
  411. background-color: $cancel-color;
  412. color: $white;
  413. font-size: 24rpx;
  414. display: flex;
  415. align-items: center;
  416. justify-content: center;
  417. border: none;
  418. padding: 0;
  419. cursor: pointer;
  420. &::after {
  421. border: none;
  422. }
  423. }
  424. // 取消订单按钮-禁用样式
  425. .cancel-btn--disabled {
  426. background-color: $cancel-disabled-color;
  427. color: #fff;
  428. cursor: not-allowed; // 鼠标禁用样式
  429. opacity: 0.8;
  430. }
  431. // 前往提料按钮-基础样式
  432. .withdraw-btn {
  433. flex: 1;
  434. height: 100%;
  435. background-color: $withdraw-color;
  436. color: $white;
  437. font-size: 24rpx;
  438. display: flex;
  439. align-items: center;
  440. justify-content: center;
  441. border: none;
  442. padding: 0;
  443. cursor: pointer;
  444. &::after {
  445. border: none;
  446. }
  447. }
  448. // 前往提料按钮-禁用样式
  449. .withdraw-btn--disabled {
  450. background-color: $withdraw-disabled-color;
  451. color: #fff;
  452. cursor: not-allowed;
  453. opacity: 0.8;
  454. }
  455. </style>