GoldMailForm.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. <template>
  2. <view class="withdraw">
  3. <view class="content">
  4. <view class="withdraw-express">
  5. <view class="header">
  6. <span class="title">自主邮寄</span>
  7. </view>
  8. <view class="item">
  9. <view class="targe">收</view>
  10. <view class="address">
  11. <view
  12. >{{ appStore.$wxConfig.mailerName }} :{{
  13. appStore.$wxConfig.mailerPhone
  14. }}</view
  15. >
  16. <view class="address-detail" style="margin-top: 4px">
  17. <text class="receive-address">地址:</text>
  18. {{ appStore.$wxConfig.mailingAddress }}
  19. </view>
  20. </view>
  21. <view class="end">
  22. <view
  23. class="copy"
  24. @click="
  25. copy(
  26. `${appStore.$wxConfig.mailerName}:${appStore.$wxConfig.mailerPhone} 地址: ${appStore.$wxConfig.mailingAddress}`
  27. )
  28. "
  29. >复制</view
  30. >
  31. </view>
  32. </view>
  33. </view>
  34. <view>
  35. <view style="padding: 0rpx 10px">
  36. <view class="gold-item">
  37. <view class="header">
  38. <span class="title">快递单号</span>
  39. </view>
  40. <view class="input-box">
  41. <input
  42. type="text"
  43. class="inpu-box-ds"
  44. placeholder="请输入快递单号"
  45. v-model="expressNum"
  46. placeholder-style="color: #999999; font-size: 28rpx;"
  47. />
  48. <text class="iconfont icon-iconfontscan" @click="scanCode"></text>
  49. </view>
  50. </view>
  51. <view class="gold-item">
  52. <view class="header">
  53. <span class="title">快递图片</span>
  54. </view>
  55. <view style="margin-top: 10px">
  56. <view class="upload-box">
  57. <up-upload
  58. :fileList="imageList"
  59. uploadIcon="plus"
  60. @afterRead="afterRead"
  61. @delete="deletePic"
  62. name="1"
  63. multiple
  64. :maxCount="3"
  65. >
  66. <template #trigger>
  67. <view class="upload-block">
  68. <uni-icons
  69. size="38"
  70. color="#ccc"
  71. type="plusempty"
  72. ></uni-icons>
  73. </view>
  74. </template>
  75. </up-upload>
  76. </view>
  77. </view>
  78. </view>
  79. <view class="gold-item">
  80. <view class="form-body">
  81. <view class="weight-input">
  82. <view class="input-label">黄金金重</view>
  83. <view class="form-body-box">
  84. <input
  85. v-model="auExtract"
  86. type="digit"
  87. class="weight-value"
  88. />
  89. <text>g</text>
  90. </view>
  91. </view>
  92. <view class="weight-input">
  93. <view class="input-label">K金金重</view>
  94. <view class="form-body-box">
  95. <input
  96. v-model="kauExtract"
  97. type="digit"
  98. class="weight-value"
  99. />
  100. <text>g</text>
  101. </view>
  102. </view>
  103. <view class="weight-input">
  104. <view class="input-label">铂金金重</view>
  105. <view class="form-body-box">
  106. <input
  107. v-model="ptExtract"
  108. type="digit"
  109. class="weight-value"
  110. />
  111. <text>g</text>
  112. </view>
  113. </view>
  114. <view class="weight-input">
  115. <view class="input-label">白银金重</view>
  116. <view class="form-body-box">
  117. <input
  118. v-model="agExtract"
  119. type="digit"
  120. class="weight-value"
  121. />
  122. <text>g</text>
  123. </view>
  124. </view>
  125. <view class="tips">* 若无相关产品,可不用填写</view>
  126. </view>
  127. </view>
  128. </view>
  129. <view class="withdraw-body">
  130. <view
  131. class="tx-active"
  132. style="margin-top: 10px"
  133. @click="submitGoldOrder"
  134. >
  135. <!-- <button @click="submitGoldOrder">点击提交</button> -->
  136. <image class="btn" src="/static/images/sb_btn.png"></image>
  137. <text class="btn-text">点击提交</text>
  138. </view>
  139. <view class="aggregate" @click="aggregate = !aggregate">
  140. <image
  141. class="choose"
  142. :src="
  143. aggregate
  144. ? '/static/recycle/choose.png'
  145. : '/static/recycle/nochoose.png'
  146. "
  147. mode="scaleToFill"
  148. ></image>
  149. <view class="aggre">
  150. 阅读并同意
  151. <span class="aggre-text" @click="showAggre">《存金协议》</span>
  152. </view>
  153. </view>
  154. <view style="margin-top: 20px">
  155. <up-parse :content="content"></up-parse>
  156. </view>
  157. </view>
  158. </view>
  159. </view>
  160. <uni-popup
  161. background-color="#fff"
  162. ref="singPopup"
  163. type="bottom"
  164. :safeArea="false"
  165. borderRadius="10px 10px 0 0"
  166. maskBackgroundColor="rgba(0, 0, 0,0)"
  167. >
  168. <view class="signContent">
  169. <scroll-view scrollY class="scroll">
  170. <up-parse :content="agreement"></up-parse>
  171. </scroll-view>
  172. <view
  173. class="comfireBtn footer"
  174. @click="
  175. aggregate = true;
  176. $refs.singPopup.close();
  177. "
  178. >
  179. 我已详细知悉
  180. </view>
  181. </view>
  182. </uni-popup>
  183. </view>
  184. </template>
  185. <script setup>
  186. // 1. 导入依赖(保持不变)
  187. import { ref } from "vue";
  188. import { onLoad } from "@dcloudio/uni-app";
  189. import { depositCreateAPI } from "@/api/functions";
  190. import { useImageUpload } from "@/hooks/useImageUpload";
  191. import { useAppStore } from "@/stores/app";
  192. const appStore = useAppStore();
  193. console.log("appStore.$wxConfig", appStore.$wxConfig);
  194. // 2. 响应式变量(保持不变,明确金属类型对应关系)
  195. const { imageList, afterRead, deletePic, uploadLoading } = useImageUpload({
  196. pid: 9,
  197. model: "gold",
  198. });
  199. const extract = ref([]);
  200. const auExtract = ref(null); // 黄金重量 → type:1
  201. const ptExtract = ref(null); // 铂金重量 → type:2
  202. const agExtract = ref(null); // 白银重量 → type:3
  203. const kauExtract = ref(null); // K金重量 → type:4
  204. const aggregate = ref(false);
  205. const expressNum = ref("");
  206. const cust_img = ref([]);
  207. const singPopup = ref(null);
  208. const props = defineProps(["agreement", "content"]);
  209. onLoad(() => {});
  210. const showAggre = () => {
  211. singPopup.value?.open();
  212. };
  213. // 3. 扫码方法(保持不变)
  214. const scanCode = () => {
  215. uni.scanCode({
  216. success: (res) => {
  217. expressNum.value = res.result;
  218. console.log("赋值后:", expressNum.value);
  219. },
  220. fail: (err) => {
  221. console.error("扫码失败:", err);
  222. uni.showToast({ title: "扫码失败,请重试", icon: "none" });
  223. },
  224. });
  225. };
  226. const copy = (item) => {
  227. uni.setClipboardData({
  228. data: item,
  229. success: () => {
  230. uni.showToast({
  231. title: "复制成功",
  232. icon: "success",
  233. });
  234. },
  235. fail: (err) => {
  236. uni.showToast({
  237. title: "复制失败",
  238. icon: "none",
  239. });
  240. console.error("复制失败:", err);
  241. },
  242. });
  243. };
  244. /**
  245. * 转换金属重量为目标格式:[{type:1,weight:1}, ...]
  246. * 改用直接引用ref变量的映射表,避免eval
  247. */
  248. const buildMetalWeightList = () => {
  249. // 优化:金属映射表直接包含ref变量,无需通过字符串动态获取
  250. const metalConfigList = [
  251. { metalVar: auExtract, type: 1, label: "黄金" }, // 直接传auExtract(ref变量)
  252. { metalVar: ptExtract, type: 2, label: "铂金" },
  253. { metalVar: agExtract, type: 3, label: "白银" },
  254. { metalVar: kauExtract, type: 4, label: "K金" },
  255. ];
  256. // 循环收集有效重量(逻辑与之前一致,仅获取重量的方式变化)
  257. const metalList = [];
  258. metalConfigList.forEach(({ metalVar, type }) => {
  259. // 直接访问ref变量的.value获取重量值
  260. const weightValue = metalVar.value;
  261. // 处理重量:去空格、排除空值、转为数字
  262. const trimmedWeight = weightValue ? String(weightValue).trim() : "";
  263. const validWeight = Number(trimmedWeight);
  264. // 仅保留「非空、非NaN、正数」的重量
  265. if (trimmedWeight !== "" && !isNaN(validWeight) && validWeight > 0) {
  266. metalList.push({
  267. type: type,
  268. weight: validWeight, // 转为数字格式,符合接口要求
  269. });
  270. }
  271. });
  272. return metalList;
  273. };
  274. // 5. 提交方法(逻辑不变,依赖优化后的buildMetalWeightList)
  275. const submitGoldOrder = async () => {
  276. // 步骤1:基础校验(图片+重量+快递单号)
  277. const isCheckPass = checkHandle();
  278. if (!isCheckPass) return;
  279. // 步骤2:构建目标格式的金属重量数组
  280. const metalWeightList = buildMetalWeightList();
  281. if (metalWeightList.length === 0) {
  282. uni.showToast({ title: "请至少填写一个有效金属重量!", icon: "none" });
  283. return;
  284. }
  285. if (!aggregate.value) {
  286. uni.showToast({ title: "请阅读并同意《存金协议》!", icon: "none" });
  287. return;
  288. }
  289. // 步骤3:整合提交数据
  290. const submitData = {
  291. metalInfos: metalWeightList, // 核心目标数组
  292. expressNo: expressNum.value.trim(),
  293. expressImages: imageList.value.map((v) => v.info.url),
  294. };
  295. // 步骤4:执行提交(示例接口调用)
  296. try {
  297. const res = await depositCreateAPI(submitData);
  298. uni.showToast({ title: "提交成功!" });
  299. setTimeout(() => {
  300. uni.navigateTo({
  301. url: "/pages/users/vault/storeMetal/order",
  302. });
  303. }, 1000);
  304. } catch (error) {
  305. console.error("提交失败:", error);
  306. uni.showToast({ title: "提交失败,请重试", icon: "none" });
  307. }
  308. };
  309. // 6. 校验方法(逻辑不变,依赖优化后的buildMetalWeightList)
  310. const checkHandle = () => {
  311. // 校验1:快递图片
  312. if (imageList.value.length === 0) {
  313. uni.showToast({ title: "请上传快递图片!", icon: "none" });
  314. return false;
  315. }
  316. // 校验2:至少一个有效金属重量
  317. const metalWeightList = buildMetalWeightList();
  318. if (metalWeightList.length === 0) {
  319. uni.showToast({
  320. title: "请至少填写一个金属重量(黄金/铂金/白银/K金)!",
  321. icon: "none",
  322. });
  323. return false;
  324. }
  325. // 校验3:快递单号(可选,根据需求保留)
  326. if (!expressNum.value.trim()) {
  327. uni.showToast({ title: "请填写或扫码获取快递单号!", icon: "none" });
  328. return false;
  329. }
  330. return true;
  331. };
  332. </script>
  333. <style lang="scss" scoped>
  334. page {
  335. height: 100%;
  336. }
  337. .icon-iconfontscan {
  338. font-size: 24px;
  339. color: #f8c007;
  340. }
  341. .upload-box {
  342. .upload-block {
  343. width: 160rpx;
  344. height: 160rpx;
  345. border: 1px solid #ccc;
  346. border-radius: 10rpx;
  347. display: flex;
  348. flex-direction: column;
  349. justify-content: center;
  350. align-items: center;
  351. color: #ccc;
  352. font-weight: 700;
  353. font-size: 26rpx;
  354. }
  355. }
  356. .tips {
  357. text-align: center;
  358. color: #bdbdbd;
  359. font-size: 24rpx;
  360. margin: 20rpx auto;
  361. }
  362. .form-body {
  363. // background-color: #fff;
  364. // padding: 20px 30px;
  365. font-size: 14px;
  366. margin-top: 90rpx;
  367. .weight-input {
  368. display: flex;
  369. align-items: center;
  370. // justify-content: space-around;
  371. margin: 30rpx 0;
  372. .form-body-box {
  373. display: flex;
  374. align-items: center;
  375. background-color: #ededed;
  376. margin-left: 30rpx;
  377. height: 72rpx;
  378. border-radius: 10rpx;
  379. font-size: 30rpx;
  380. text {
  381. color: #000;
  382. padding-right: 20rpx;
  383. font-size: 25rpx;
  384. }
  385. input {
  386. // font-size: 18rpx;
  387. padding-left: 10rpx;
  388. }
  389. }
  390. .input-label {
  391. font-size: 32rpx;
  392. font-weight: 500;
  393. width: 170rpx;
  394. }
  395. .weight-value {
  396. height: 1.9em;
  397. font-size: 1.5em;
  398. border: none;
  399. outline: none;
  400. }
  401. }
  402. .submit-btn-area {
  403. button {
  404. color: #fff;
  405. background: #c4bba6;
  406. }
  407. }
  408. .agreement-section {
  409. display: flex;
  410. align-items: center;
  411. justify-content: center;
  412. padding: 20rpx;
  413. margin-top: 30rpx;
  414. .agreement-checkbox {
  415. width: 32rpx;
  416. height: 16px;
  417. }
  418. .agreement-text {
  419. font-size: 14px;
  420. margin-left: 10px;
  421. .agreement-link {
  422. color: #3ab0ff;
  423. }
  424. }
  425. }
  426. }
  427. .input-box {
  428. display: flex;
  429. background-color: #ededed;
  430. border-radius: 5px;
  431. height: 90rpx;
  432. align-items: center;
  433. justify-content: space-around;
  434. font-size: 28rpx;
  435. // paddingft: ;
  436. padding-left: 20rpx;
  437. // color:#c7c7c7 ;
  438. input {
  439. // background-color: ;
  440. width: 80%;
  441. // color: #c7c7c7;
  442. }
  443. }
  444. .inpu-box-zl {
  445. justify-content: space-between;
  446. padding-left: 47rpx;
  447. }
  448. .gold-item {
  449. margin: 50rpx 0;
  450. }
  451. // .gold-input{
  452. // background-color: red !important;
  453. // }
  454. .address-detail {
  455. line-height: 2.2;
  456. }
  457. .header {
  458. padding-left: 5px;
  459. position: relative;
  460. display: flex;
  461. align-items: center;
  462. justify-content: space-between;
  463. padding: 10px 10px;
  464. border-radius: 5px;
  465. // background-color: #fff;
  466. font-weight: bold;
  467. font-size: 18px;
  468. &::before {
  469. position: absolute;
  470. /*绝对定位*/
  471. top: 50%;
  472. /*Y轴方向偏移自身高度的50%*/
  473. transform: translatey(-50%);
  474. /*Y轴方向偏移微调*/
  475. left: 0;
  476. /*紧靠容器左边缘*/
  477. content: "";
  478. /*伪元素需要有内容才能显示*/
  479. width: 2px;
  480. /*伪元素宽度*/
  481. height: 15px;
  482. /*伪元素高度*/
  483. background-color: #f8c007;
  484. /*伪元素颜色*/
  485. }
  486. .title {
  487. font-weight: 500;
  488. font-size: 32rpx;
  489. font-family: "黑体";
  490. }
  491. }
  492. .withdraw {
  493. height: 100%;
  494. background-color: #f7f7f7;
  495. border-radius: 40rpx 40rpx 0 0;
  496. position: relative;
  497. // top: -20rpx;
  498. padding: 0 25rpx;
  499. top: -67rpx;
  500. .withdraw-express {
  501. display: flex;
  502. flex-direction: column;
  503. align-items: flex-start;
  504. justify-content: center;
  505. padding: 28rpx;
  506. margin-bottom: 30rpx;
  507. border-radius: 30rpx;
  508. padding-right: 0;
  509. .head {
  510. font-size: 14px;
  511. }
  512. .item {
  513. display: flex;
  514. align-items: center;
  515. margin-top: 15px;
  516. .targe {
  517. display: flex;
  518. justify-content: center;
  519. align-items: center;
  520. color: #fff;
  521. width: 35px;
  522. height: 35px;
  523. border-radius: 50%;
  524. // background-color: #cc9933;
  525. background-color: #ffd034;
  526. }
  527. .address {
  528. width: 430rpx;
  529. margin: 0 10px;
  530. font-size: 28rpx;
  531. .receive-address {
  532. letter-spacing: 9px;
  533. }
  534. }
  535. .end {
  536. display: flex;
  537. justify-content: center;
  538. align-items: center;
  539. .copy {
  540. color: #888888;
  541. border-radius: 3px;
  542. border: 1px solid #888888;
  543. font-size: 24rpx;
  544. padding: 6rpx 23rpx;
  545. }
  546. }
  547. }
  548. }
  549. .withdraw-body {
  550. // background-color: #fff;
  551. padding: 20px 30px;
  552. font-size: 14px;
  553. .input-money {
  554. display: flex;
  555. align-items: center;
  556. justify-content: center;
  557. font-weight: 600;
  558. border-bottom: 1px solid #eaeef1;
  559. .rmb {
  560. font-size: 16px;
  561. }
  562. .t-input {
  563. height: 1.9em;
  564. font-size: 1.5em;
  565. border: none;
  566. outline: none;
  567. }
  568. }
  569. .aggregate {
  570. display: flex;
  571. align-items: center;
  572. justify-content: center;
  573. padding: 10px;
  574. color: #ababab;
  575. font-size: 12px;
  576. .aggre {
  577. font-size: 30rpx;
  578. margin-left: 10px;
  579. .aggre-text {
  580. color: #cc9933;
  581. }
  582. }
  583. }
  584. .choose {
  585. width: 28rpx;
  586. height: 28rpx;
  587. }
  588. }
  589. }
  590. .tx {
  591. button {
  592. color: #b2b2b2;
  593. }
  594. }
  595. .tx-active {
  596. margin: 0 auto;
  597. position: relative;
  598. display: flex;
  599. justify-content: center;
  600. align-items: center;
  601. .btn {
  602. width: 267rpx;
  603. height: 71rpx;
  604. }
  605. .btn-text {
  606. font-size: 30rpx;
  607. color: #000;
  608. position: absolute;
  609. top: 50%;
  610. left: 50%;
  611. transform: translate(-50%, -50%);
  612. }
  613. }
  614. .signContent {
  615. // background-color: #f8f8f8;
  616. padding: 20px;
  617. box-sizing: border-box;
  618. display: flex;
  619. justify-content: center;
  620. align-items: center;
  621. flex-direction: column;
  622. border-radius: 20px 20px 0 0;
  623. .scroll {
  624. // background-color: #fff;
  625. padding: 4px;
  626. height: 300px;
  627. overflow-y: hidden;
  628. border: 1px solid #dfdfdf;
  629. }
  630. .footer {
  631. margin-top: 10px;
  632. color: #fff;
  633. padding: 4px 20px;
  634. border-radius: 20px;
  635. background: linear-gradient(to right, #8ed187, #5dd665);
  636. }
  637. }
  638. .express-input {
  639. &:nth-child(1) {
  640. padding: 0;
  641. }
  642. }
  643. </style>