GoldMailForm.vue 17 KB

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