metalExchangeWithdraw.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <template>
  2. <view class="withdraw">
  3. <view class="withdrawContent">
  4. <!-- 金属类型 -->
  5. <view class="metal-type">
  6. <view class="info-label">金属类型</view>
  7. <view class="info-value">{{ metalTypeName }}</view>
  8. </view>
  9. <!-- 收货地址模块 -->
  10. <view class="address" @click="onAddress">
  11. <view class="addressCon" v-if="addressInfo.realName">
  12. <view class="name">
  13. {{ addressInfo.realName }}
  14. <text class="phone">{{ addressInfo.phone }}</text>
  15. </view>
  16. <view class="address-detail">
  17. <text class="default" v-if="addressInfo.isDefault">[默认]</text>
  18. <text class="address-text"
  19. >{{ addressInfo.province }}{{ addressInfo.city
  20. }}{{ addressInfo.district }}{{ addressInfo.detail }}</text
  21. >
  22. </view>
  23. </view>
  24. <view class="addressCon" v-else>
  25. <view class="setaddress">设置收货地址</view>
  26. </view>
  27. </view>
  28. <!-- 快递公司选择 -->
  29. <view class="courier-section">
  30. <view class="section-title">选择快递公司</view>
  31. <view class="courier-list">
  32. <view
  33. class="courier-item"
  34. :class="{ active: item.isSelected }"
  35. v-for="(item, index) in courierList"
  36. :key="index"
  37. @click="handleSelectCourier(index)"
  38. >
  39. <image class="courier-logo" :src="item.logo"></image>
  40. <view class="courier-price" v-if="isSvip && item.price > 0">
  41. <text class="original-price">¥{{ item.price }}</text>
  42. <text class="svip-price">¥{{ (item.price / 2).toFixed(2) }}</text>
  43. </view>
  44. <view class="courier-price" v-else-if="item.price > 0">
  45. ¥{{ item.price }}
  46. </view>
  47. <view class="courier-price" v-else> 到付 </view>
  48. <image
  49. v-show="item.isSelected"
  50. class="courier-checked"
  51. src="https://mp-ad17e5cd-05c1-4df9-b060-556e25dac130.cdn.bspapp.com/mini/courier/dui.png"
  52. ></image>
  53. </view>
  54. </view>
  55. </view>
  56. <!-- 详情 -->
  57. <view class="detail-card">
  58. <view class="detail-item">
  59. <view class="detail-label">预约提料克重</view>
  60. <view class="detail-value">{{ extract }}g</view>
  61. </view>
  62. <view class="detail-item">
  63. <view class="detail-label">预约日期</view>
  64. <view class="detail-value">
  65. {{ reservationDetail.reservationDate || "未知" }}
  66. </view>
  67. </view>
  68. <view class="detail-item">
  69. <view class="detail-label">手续费</view>
  70. <view class="detail-value">
  71. {{ totalFee }}元({{ feePerGram }}元/g)
  72. </view>
  73. </view>
  74. <view class="detail-item">
  75. <view class="detail-label">运费</view>
  76. <view class="detail-value">
  77. <span class="svip-discount-tag" v-if="isSvip">SVIP减半</span>
  78. {{ courierPrice }}元
  79. </view>
  80. </view>
  81. <view class="detail-item">
  82. <view class="detail-label">总费用</view>
  83. <view class="detail-value">
  84. {{ (Number(totalFee) + Number(courierPrice)).toFixed(2) }}元
  85. </view>
  86. </view>
  87. </view>
  88. <!-- 提示信息 -->
  89. <view class="tips">
  90. <view class="tips-item">* 提料克重以预约信息为准,不可修改</view>
  91. <view class="tips-item">* 提料预计1-5个工作日送达</view>
  92. <view class="tips-item" v-if="reservationDetail.remark">
  93. * 备注:{{ reservationDetail.remark }}
  94. </view>
  95. <view class="tips-item" v-if="isSvip">* SVIP用户享运费5折优惠</view>
  96. </view>
  97. <!-- 操作按钮区 -->
  98. <view class="operation-area">
  99. <button class="cancel-btn" @click="gotoOrderList">返回列表</button>
  100. <button
  101. class="submit-btn"
  102. @click="handleSubmit"
  103. :disabled="isSubmitting || isDetailLoading"
  104. :loading="isSubmitting"
  105. >
  106. 确认提交提料并支付
  107. </button>
  108. </view>
  109. </view>
  110. <!-- 收货地址组件 -->
  111. <addressWindow
  112. ref="addressWindowRef"
  113. :address="address"
  114. :pagesUrl="pagesUrl"
  115. @OnDefaultAddress="OnDefaultAddress"
  116. @OnChangeAddress="OnChangeAddress"
  117. @changeClose="changeClose"
  118. />
  119. </view>
  120. </template>
  121. <script setup>
  122. import { ref, computed, nextTick, watch } from "vue";
  123. import { onLoad } from "@dcloudio/uni-app";
  124. import { storeToRefs } from "pinia";
  125. import { useAppStore } from "@/stores/app";
  126. import { nest_exchangeMetalOrder, getReservationDetail } from "@/api/vault";
  127. import addressWindow from "@/components/addressWindow";
  128. import { getAddressDetail, getAddressDefault } from "@/api/user.js";
  129. const appStore = useAppStore();
  130. const { wxConfig, userInfo, isWxConfigReady } = storeToRefs(appStore);
  131. const isSvip = computed(() => {
  132. return appStore.isLogin && !!appStore?.userInfo?.svip;
  133. });
  134. const reservationId = ref("");
  135. const reservationDetail = ref({});
  136. const isDetailLoading = ref(true);
  137. const detailError = ref("");
  138. const isSubmitting = ref(false);
  139. const metalTypeMap = { 1: "黄金", 2: "铂金", 3: "白银" };
  140. const metalConfigs = ref([]);
  141. const extract = ref(0);
  142. // 地址相关数据
  143. const pagesUrl = ref("/pages/users/user_address_list/index");
  144. const addressWindowRef = ref(null);
  145. const address = ref({ address: false, addressId: 0 });
  146. const addressInfo = ref({});
  147. // 快递公司数据
  148. const courierList = ref([
  149. {
  150. type: 2,
  151. name: "顺丰陆运",
  152. logo: "https://my-go-easy-im.oss-cn-shenzhen.aliyuncs.com/goeasy-im-%E6%B0%B4%E8%B4%9D%E5%95%86%E5%9F%8E/luyun_20251011172420_906_6.png",
  153. isSelected: true,
  154. price: 15,
  155. },
  156. {
  157. type: 3,
  158. name: "顺丰空运",
  159. logo: "https://my-go-easy-im.oss-cn-shenzhen.aliyuncs.com/goeasy-im-%E6%B0%B4%E8%B4%9D%E5%95%86%E5%9F%8E/kongyun_20251011172421_908_6.png",
  160. isSelected: false,
  161. price: 24,
  162. },
  163. {
  164. type: 4,
  165. name: "顺丰到付",
  166. logo: "https://my-go-easy-im.oss-cn-shenzhen.aliyuncs.com/goeasy-im-%E6%B0%B4%E8%B4%9D%E5%95%86%E5%9F%8E/daofu_20251011172420_907_6.png",
  167. isSelected: false,
  168. price: 0,
  169. },
  170. ]);
  171. const selectedCourierType = ref(2);
  172. const courierPrice = computed(() => {
  173. const selectedCourier =
  174. courierList.value.find((item) => item.isSelected) || courierList.value[0];
  175. const originalPrice = selectedCourier.price;
  176. const finalPrice = isSvip.value ? originalPrice / 2 : originalPrice;
  177. return finalPrice.toFixed(2);
  178. });
  179. // 原有计算属性
  180. const metalTypeName = computed(() => {
  181. return metalTypeMap[reservationDetail.value.metalType] || "未知金属";
  182. });
  183. const feePerGram = computed(() => {
  184. if (!metalConfigs.value.length || !reservationDetail.value.metalType)
  185. return "0.00";
  186. const typeMap = { 1: "au", 2: "pt", 3: "ag" };
  187. const currentType = typeMap[reservationDetail.value.metalType];
  188. const config = metalConfigs.value.find(
  189. (item) => item.metalType === currentType
  190. );
  191. return config?.feePerGram ? Number(config.feePerGram).toFixed(2) : "0.00";
  192. });
  193. const totalFee = computed(() => {
  194. return (Number(feePerGram.value) * Number(extract.value)).toFixed(2);
  195. });
  196. const accountWeight = computed(() => {
  197. const weightMap = {
  198. 1: userInfo.value.goldBalance || 0,
  199. 2: userInfo.value.ptBalance || 0,
  200. 3: userInfo.value.agBalance || 0,
  201. };
  202. return Number(weightMap[reservationDetail.value.metalType || 1]).toFixed(2);
  203. });
  204. // 页面加载
  205. onLoad((options) => {
  206. if (!options.reservationId) {
  207. detailError.value = "未获取到预约信息,请返回重新选择";
  208. isDetailLoading.value = false;
  209. return;
  210. }
  211. reservationId.value = options.reservationId;
  212. metalConfigs.value = wxConfig.value?.metalConfigs || [];
  213. fetchReservationDetail();
  214. if (appStore.isLogin) {
  215. getAddressInfo();
  216. nextTick(() => {
  217. addressWindowRef.value?.fetchAddressList();
  218. });
  219. }
  220. });
  221. // 监听wxConfig
  222. watch(
  223. isWxConfigReady,
  224. (isReady) => {
  225. if (isReady) {
  226. metalConfigs.value = appStore.wxConfig?.metalConfigs || [];
  227. }
  228. },
  229. { immediate: true }
  230. );
  231. const fetchReservationDetail = async () => {
  232. try {
  233. isDetailLoading.value = true;
  234. const res = await getReservationDetail(reservationId.value);
  235. if (!res.data) throw new Error("预约详情为空");
  236. reservationDetail.value = res.data;
  237. extract.value = reservationDetail.value.reservedWeight || 0;
  238. detailError.value = "";
  239. } catch (err) {
  240. detailError.value = "获取预约详情失败:" + (err.message || "未知错误");
  241. console.error("查询预约详情失败:", err);
  242. } finally {
  243. isDetailLoading.value = false;
  244. }
  245. };
  246. const gotoOrderList = () => {
  247. uni.redirectTo({
  248. url: "/pages/users/vault/storeMetal/metalExchangeList",
  249. });
  250. };
  251. const getAddressInfo = () => {
  252. const fetchFn = address.value.addressId
  253. ? getAddressDetail(address.value.addressId)
  254. : getAddressDefault();
  255. fetchFn
  256. .then((res) => {
  257. if (res.data) {
  258. res.data.isDefault = parseInt(res.data.isDefault);
  259. addressInfo.value = res.data;
  260. address.value.addressId = res.data.id || 0;
  261. }
  262. })
  263. .catch((err) => console.error("获取地址失败:", err));
  264. };
  265. const OnDefaultAddress = (e) => {
  266. addressInfo.value = e;
  267. address.value.addressId = e.id || 0;
  268. };
  269. const onAddress = () => {
  270. address.value.address = true;
  271. nextTick(() => addressWindowRef.value?.fetchAddressList());
  272. };
  273. const OnChangeAddress = (e) => {
  274. addressInfo.value = e;
  275. address.value.addressId = e.id || 0;
  276. address.value.address = false;
  277. };
  278. const changeClose = () => {
  279. address.value.address = false;
  280. };
  281. const handleSelectCourier = (index) => {
  282. courierList.value.forEach((item, i) => (item.isSelected = i === index));
  283. selectedCourierType.value = courierList.value[index].type;
  284. };
  285. // 提交校验
  286. const validateSubmit = () => {
  287. if (!appStore.isLogin) return { valid: false, msg: "请先登录" };
  288. if (!reservationId.value) return { valid: false, msg: "预约ID异常" };
  289. if (Number(extract.value) <= 0) return { valid: false, msg: "预约克重异常" };
  290. if (!address.value.addressId) return { valid: false, msg: "请选择收货地址" };
  291. if (!selectedCourierType.value)
  292. return { valid: false, msg: "请选择快递公司" };
  293. return { valid: true };
  294. };
  295. // 提交方法
  296. const handleSubmit = async () => {
  297. const check = validateSubmit();
  298. if (!check.valid) {
  299. uni.showToast({ title: check.msg, icon: "none", duration: 2000 });
  300. return;
  301. }
  302. const params = {
  303. metalType: reservationDetail.value.metalType,
  304. plateWeight: extract.value,
  305. reservationId: reservationId.value,
  306. addressId: address.value.addressId,
  307. expressCompany: selectedCourierType.value,
  308. freightAmount: Number(courierPrice.value),
  309. };
  310. try {
  311. isSubmitting.value = true;
  312. uni.showLoading({ title: "提交中...", mask: true });
  313. const res = await nest_exchangeMetalOrder(params);
  314. uni.hideLoading();
  315. uni.showToast({ title: "提料订单提交成功", icon: "success" });
  316. setTimeout(gotoOrderList, 1000);
  317. } catch (err) {
  318. uni.hideLoading();
  319. uni.showToast({ title: "网络异常,请重试", icon: "none" });
  320. console.error("提料下单失败:", err);
  321. } finally {
  322. isSubmitting.value = false;
  323. }
  324. };
  325. </script>
  326. <style lang="scss" scoped>
  327. $primary: #dca12b;
  328. $text-main: #333;
  329. $text-secondary: #666;
  330. $text-light: #999;
  331. $bg-gray: #f7f7f7;
  332. $border-gray: #eee;
  333. $svip-color: #ff4500;
  334. page {
  335. background-color: #f5f5f5;
  336. min-height: 100vh;
  337. }
  338. // 原有样式(不变)
  339. .page-title {
  340. padding: 30rpx 40rpx;
  341. font-size: 36rpx;
  342. font-weight: bold;
  343. color: $text-main;
  344. background-color: #fff;
  345. border-bottom: 1px solid $border-gray;
  346. }
  347. .withdrawContent {
  348. padding: 40rpx;
  349. background-color: #fff;
  350. margin-top: 20rpx;
  351. border-radius: 20rpx;
  352. margin: 20rpx 20rpx 0;
  353. }
  354. .metal-type {
  355. display: flex;
  356. align-items: center;
  357. padding: 20rpx 0;
  358. border-bottom: 1px solid $border-gray;
  359. margin-bottom: 30rpx;
  360. .info-label {
  361. font-size: 30rpx;
  362. color: $text-secondary;
  363. width: 180rpx;
  364. }
  365. .info-value {
  366. font-size: 32rpx;
  367. color: $primary;
  368. font-weight: bold;
  369. }
  370. }
  371. .address {
  372. display: flex;
  373. justify-content: space-between;
  374. align-items: flex-start;
  375. padding: 25rpx 20rpx;
  376. background-color: $bg-gray;
  377. border-radius: 16rpx;
  378. margin-bottom: 30rpx;
  379. .addressCon {
  380. flex: 1;
  381. margin-right: 20rpx;
  382. .name {
  383. font-size: 28rpx;
  384. color: $text-main;
  385. font-weight: 500;
  386. margin-bottom: 10rpx;
  387. .phone {
  388. margin-left: 30rpx;
  389. color: $text-secondary;
  390. font-weight: normal;
  391. }
  392. }
  393. .address-detail {
  394. font-size: 26rpx;
  395. color: $text-secondary;
  396. line-height: 1.4;
  397. .default {
  398. color: $primary;
  399. margin-right: 10rpx;
  400. }
  401. .address-text {
  402. display: -webkit-box;
  403. -webkit-line-clamp: 2;
  404. -webkit-box-orient: vertical;
  405. overflow: hidden;
  406. }
  407. }
  408. .setaddress {
  409. font-size: 28rpx;
  410. color: $text-secondary;
  411. }
  412. }
  413. .icon-arrow-right {
  414. width: 24rpx;
  415. height: 40rpx;
  416. margin-top: 5rpx;
  417. background: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iNDAiIHZpZXdCb3g9IjAgMCAyNCA0MCIgZmlsbD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AuOTU3IDIwIDIwIDIwIDIwLjk0NiAyMCAyMSAyMCAyMSIgc3Ryb2tlPSIjNjY2IiBzdHJva2Utd2lkdGg9IjIiLz48L3N2Zz4=")
  418. no-repeat center;
  419. background-size: contain;
  420. }
  421. }
  422. .courier-item {
  423. flex: 1;
  424. display: flex;
  425. flex-direction: column;
  426. align-items: center;
  427. padding: 20rpx 10rpx;
  428. border: 2rpx solid $border-gray;
  429. border-radius: 16rpx;
  430. position: relative;
  431. &.active {
  432. border-color: $primary;
  433. }
  434. .courier-logo {
  435. width: 120rpx;
  436. height: 120rpx;
  437. margin-bottom: 10rpx;
  438. }
  439. // 新增:快递价格显示(区分原价/折后价)
  440. .courier-price {
  441. font-size: 24rpx;
  442. color: $text-main;
  443. margin-top: 8rpx;
  444. }
  445. .original-price {
  446. text-decoration: line-through;
  447. color: $text-light;
  448. font-size: 20rpx;
  449. margin-right: 8rpx;
  450. }
  451. .svip-price {
  452. color: $svip-color;
  453. font-weight: 500;
  454. }
  455. .courier-checked {
  456. position: absolute;
  457. right: 10rpx;
  458. bottom: 10rpx;
  459. width: 36rpx;
  460. height: 36rpx;
  461. }
  462. }
  463. // 新增:详情卡片中的SVIP优惠标签
  464. .svip-discount-tag {
  465. background-color: rgba(255, 69, 0, 0.1);
  466. color: $svip-color;
  467. font-size: 20rpx;
  468. padding: 2rpx 10rpx;
  469. border-radius: 8rpx;
  470. margin-left: 10rpx;
  471. }
  472. // 原有样式(不变)
  473. .courier-section {
  474. margin-bottom: 30rpx;
  475. .section-title {
  476. font-size: 28rpx;
  477. color: $text-secondary;
  478. margin-bottom: 20rpx;
  479. padding-left: 10rpx;
  480. border-left: 4rpx solid $primary;
  481. }
  482. .courier-list {
  483. display: flex;
  484. justify-content: space-between;
  485. gap: 20rpx;
  486. }
  487. }
  488. .detail-card {
  489. background-color: $bg-gray;
  490. border-radius: 16rpx;
  491. padding: 30rpx;
  492. margin-bottom: 30rpx;
  493. .detail-item {
  494. display: flex;
  495. justify-content: space-between;
  496. padding: 15rpx 0;
  497. border-bottom: 1px dashed $border-gray;
  498. &:last-child {
  499. border-bottom: none;
  500. }
  501. .detail-label {
  502. font-size: 28rpx;
  503. color: $text-secondary;
  504. }
  505. .detail-value {
  506. font-size: 28rpx;
  507. color: $text-main;
  508. font-weight: 500;
  509. }
  510. }
  511. }
  512. .tips {
  513. margin-bottom: 40rpx;
  514. padding: 20rpx;
  515. background-color: rgba(220, 161, 43, 0.1);
  516. border-radius: 12rpx;
  517. .tips-item {
  518. font-size: 24rpx;
  519. color: $primary;
  520. margin-bottom: 10rpx;
  521. &:last-child {
  522. margin-bottom: 0;
  523. }
  524. }
  525. }
  526. .operation-area {
  527. display: flex;
  528. gap: 20rpx;
  529. margin-top: 20rpx;
  530. .cancel-btn,
  531. .submit-btn {
  532. flex: 1;
  533. height: 90rpx;
  534. border-radius: 45rpx;
  535. font-size: 24rpx;
  536. display: flex;
  537. align-items: center;
  538. justify-content: center;
  539. }
  540. .cancel-btn {
  541. background-color: #fff;
  542. color: $text-secondary;
  543. border: 1px solid $border-gray;
  544. }
  545. .submit-btn {
  546. background-color: $primary;
  547. color: #fff;
  548. border: none;
  549. &:disabled {
  550. background-color: #c4bba6;
  551. opacity: 0.8;
  552. }
  553. }
  554. }
  555. .error-view {
  556. padding: 40rpx;
  557. text-align: center;
  558. color: #ff1e0f;
  559. font-size: 28rpx;
  560. }
  561. .loading-view {
  562. padding: 40rpx;
  563. text-align: center;
  564. color: $text-light;
  565. font-size: 28rpx;
  566. }
  567. </style>