rechargeGold.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. <template>
  2. <view class="withdraw">
  3. <view class="recharge-header">
  4. <view class="title">账户余额</view>
  5. <view class="price">
  6. <view class="fh">¥</view>
  7. <view class="price-fh">{{
  8. formatNumber(appStore?.userInfo?.nowMoney) || 0
  9. }}</view>
  10. </view>
  11. </view>
  12. <view class="tabs">
  13. <view
  14. v-for="item in tabsList"
  15. :key="item.key"
  16. class="tabs-item"
  17. :class="[tabsIndex === item.key ? 'active' : '']"
  18. @click="tabsChange(item)"
  19. >
  20. {{ item.title }}
  21. </view>
  22. </view>
  23. <view class="contanier">
  24. <view class="contaniner-top">
  25. <view class="box-title">克重</view>
  26. <view class="price-box">
  27. <view class="price">
  28. 实时金价
  29. <span class="tit">{{ realprice.toFixed(2) }}</span>
  30. </view>
  31. <view class="equity">权益 -{{ rightsStore.userBenefits.buy || 0 }}</view>
  32. </view>
  33. </view>
  34. <view class="input-box">
  35. <input
  36. type="text"
  37. placeholder="请输入克重"
  38. v-model.number="weight"
  39. @input="inputHandle"
  40. />
  41. <view class="g">g</view>
  42. </view>
  43. <view class="buy-price">
  44. <view class="buy-txt">买料价格</view>
  45. <view class="buy-num">{{ buyGoldPrice }}</view>
  46. <view class="t"> 元 </view>
  47. </view>
  48. <view class="btn-box" @click="submitHandle">
  49. <view class="btn">确认</view>
  50. </view>
  51. <view class="aggregate" @click="aggregate = !aggregate">
  52. <image
  53. class="choose"
  54. :src="
  55. aggregate
  56. ? '/static/recycle/choose.png'
  57. : '/static/recycle/nochoose.png'
  58. "
  59. mode="scaleToFill"
  60. ></image>
  61. <view class="aggre">
  62. 阅读并同意
  63. <span class="aggre-text" @click.stop="showAggre">《买金协议》</span>
  64. </view>
  65. </view>
  66. <view class="white"></view>
  67. </view>
  68. <uni-popup
  69. ref="singPopup"
  70. type="bottom"
  71. borderRadius="10px 10px 0 0"
  72. maskBackgroundColor="rgba(0,0,0,0)"
  73. >
  74. <view class="signContent">
  75. <scroll-view scrollY class="scroll">
  76. <up-parse :content="content"></up-parse>
  77. </scroll-view>
  78. <view
  79. class="comfireBtn footer"
  80. @click="
  81. aggregate = true;
  82. $refs.singPopup.close();
  83. "
  84. >
  85. 我已详细知悉
  86. </view>
  87. </view>
  88. </uni-popup>
  89. </view>
  90. </template>
  91. <script setup>
  92. import { ref, computed, watch, onMounted } from "vue";
  93. import { useAppStore } from "@/stores/app";
  94. import useRealGoldPrice from "@/hooks/useRealGoldPrice";
  95. import { rechargeGoldAPI } from "@/api/functions";
  96. import { agreementGetoneApi } from "@/api/user";
  97. const appStore = useAppStore();
  98. // 响应式数据
  99. const type = ref("余额");
  100. const weight = ref("");
  101. const buyGoldPrice = ref(0);
  102. const aggregate = ref(false);
  103. const content = ref("");
  104. const tabsIndex = ref(1);
  105. const selectedGender = ref("gold");
  106. const tabsList = ref([
  107. { key: 1, label: "gold", title: "黄金" },
  108. { key: 2, label: "platinum", title: "铂金" },
  109. { key: 3, label: "silver", title: "白银" },
  110. ]);
  111. // 实时价格处理
  112. const {
  113. realGoldprice, // 黄金实时销售价(基础)
  114. realPtprice, // 铂金实时销售价(基础)
  115. realAgprice, // 白银实时销售价(基础)
  116. } = useRealGoldPrice({});
  117. import { useStoreRights } from "@/stores/rights";
  118. const rightsStore = useStoreRights();
  119. // 黄金调整价
  120. const adjustGoldprice = computed(() => {
  121. const res = rightsStore.userBenefits.nobleMeta.find(
  122. (gold) => gold.name == "黄金"
  123. );
  124. return res;
  125. });
  126. // 铂金调整价
  127. const adjustPtprice = computed(() => {
  128. const res = rightsStore.userBenefits.nobleMeta.find(
  129. (gold) => gold.name == "铂金"
  130. );
  131. return res;
  132. });
  133. // 白银调整价
  134. const adjustAgprice = computed(() => {
  135. const res = rightsStore.userBenefits.nobleMeta.find(
  136. (gold) => gold.name == "白银"
  137. );
  138. return res;
  139. });
  140. const viprealGoldprice = computed(
  141. () =>
  142. Number(realGoldprice.value) -
  143. Number(rightsStore.userBenefits.buy) +
  144. Number(adjustGoldprice.value.sellPriceAdjust)
  145. );
  146. const viprealPtprice = computed(
  147. () =>
  148. Number(realPtprice.value) -
  149. Number(rightsStore.userBenefits.buy) +
  150. Number(adjustPtprice.value.sellPriceAdjust)
  151. );
  152. const viprealAgprice = computed(
  153. () =>
  154. Number(realAgprice.value) -
  155. Number(rightsStore.userBenefits.buy) +
  156. Number(adjustAgprice.value.sellPriceAdjust)
  157. );
  158. const realprice = computed(() => {
  159. if (tabsIndex.value == 1) {
  160. return viprealGoldprice.value;
  161. }
  162. if (tabsIndex.value == 2) {
  163. return viprealPtprice.value;
  164. }
  165. if (tabsIndex.value == 3) {
  166. return viprealAgprice.value;
  167. }
  168. });
  169. // 监听器
  170. watch(realprice, (newData) => {
  171. buyGoldPrice.value = (weight.value * realprice.value).toFixed(2);
  172. });
  173. // 获取协议
  174. function agreementGetoneFn() {
  175. // 资产说明
  176. agreementGetoneApi({ name: "buyGold" }).then((res) => {
  177. content.value = res.data?.content;
  178. });
  179. }
  180. // 生命周期钩子 - 替代onLoad
  181. onMounted(() => {
  182. // 页面加载时执行的逻辑]
  183. agreementGetoneFn();
  184. });
  185. const inputHandle = () => {
  186. // buyGoldPrice.value = vk.myfn.accMulDecimal(this.weight, this.realprice, 2);
  187. buyGoldPrice.value = (weight.value * realprice.value).toFixed(2);
  188. };
  189. // 提交
  190. const submitHandle = async () => {
  191. if (checkInfo()) {
  192. uni.showLoading({
  193. title: "买料中",
  194. });
  195. const res = await rechargeGoldAPI({
  196. metalType: tabsIndex.value,
  197. weight: weight.value,
  198. });
  199. // console.log(res);
  200. if (res.code == 200) {
  201. uni.showToast({ title: "买料成功" });
  202. setTimeout(() => {
  203. uni.navigateTo({
  204. url: "/pages/users/vault/index",
  205. });
  206. }, 1500);
  207. }
  208. uni.hideLoading();
  209. }
  210. };
  211. const formatNumber = (num) => {
  212. if (isNaN(num)) return "0.00";
  213. const parts = num.toString().split(".");
  214. parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  215. if (parts.length > 1) {
  216. return parts[0] + "." + parts[1].padEnd(2, "0").slice(0, 2);
  217. }
  218. return parts[0] + ".00";
  219. };
  220. const checkInfo = () => {
  221. if (!weight.value) {
  222. uni.showToast({
  223. title: "请输入克重",
  224. duration: 1000,
  225. icon: "none",
  226. });
  227. return false;
  228. }
  229. if (!aggregate.value) {
  230. uni.showToast({
  231. title: "请阅读并同意协议",
  232. duration: 1000,
  233. icon: "none",
  234. });
  235. return false;
  236. }
  237. return true;
  238. };
  239. // 假设$refs.singPopup在模板中存在
  240. const singPopup = ref(null);
  241. const showAggre = () => {
  242. singPopup.value.open();
  243. };
  244. const tabsChange = (item) => {
  245. tabsIndex.value = item.key;
  246. weight.value = "";
  247. buyGoldPrice.value = 0;
  248. };
  249. const toDecimalP2 = (arg) => {};
  250. </script>
  251. <style lang="scss" scoped>
  252. .withdraw {
  253. width: 750rpx;
  254. height: 100%;
  255. // background-image: linear-gradient(180deg, #b7ad94 0%, #fcfcfc 100%);
  256. background: $uni-bg-primary !important;
  257. display: flex;
  258. flex-direction: column;
  259. // align-items: center;
  260. .recharge-header {
  261. margin-left: 103rpx;
  262. margin-bottom: 50rpx;
  263. padding-top: 80rpx;
  264. .title {
  265. font-size: 29rpx;
  266. color: #ffffff;
  267. }
  268. .price {
  269. font-size: 56rpx;
  270. color: #ffffff;
  271. margin-top: 15rpx;
  272. display: flex;
  273. // height: ;
  274. align-items: flex-end;
  275. .fh {
  276. font-size: 36rpx;
  277. // color: #cc9933;
  278. margin-bottom: 8rpx;
  279. }
  280. .price-fh {
  281. margin-left: 15rpx;
  282. }
  283. }
  284. }
  285. .tabs {
  286. display: flex;
  287. height: 80rpx;
  288. border-radius: 40rpx;
  289. padding: 0 20rpx;
  290. color: #fff;
  291. font-size: 32rpx;
  292. font-weight: 300;
  293. // margin-bottom: 10rpx;
  294. .tabs-item {
  295. width: 50%;
  296. height: 100%;
  297. display: flex;
  298. justify-content: center;
  299. // align-items:;
  300. position: relative;
  301. }
  302. .active::after {
  303. position: absolute;
  304. bottom: -10rpx;
  305. left: 50%;
  306. transform: translateX(-50%);
  307. content: "";
  308. z-index: 100;
  309. border-style: solid;
  310. border-width: 0 25rpx 25rpx 25rpx;
  311. border-color: transparent transparent #ffffff transparent;
  312. width: 0;
  313. height: 0;
  314. transform-origin: center top;
  315. animation: showTriangle 0.3s ease-out forwards;
  316. }
  317. }
  318. .contanier {
  319. box-sizing: border-box;
  320. padding: 70rpx 70rpx;
  321. background-color: #ffffff;
  322. border-radius: 40rpx;
  323. .contaniner-top {
  324. display: flex;
  325. justify-content: space-between;
  326. align-items: center;
  327. .price-box {
  328. // flex: 3;
  329. display: flex;
  330. align-items: center;
  331. position: relative;
  332. .price {
  333. font-size: 31rpx;
  334. color: #000000;
  335. .tit {
  336. color: #d8a235;
  337. font-size: 36rpx;
  338. margin-left: 10rpx;
  339. }
  340. }
  341. .equity {
  342. position: absolute;
  343. top: -35rpx;
  344. right: 0;
  345. padding: 2rpx 12rpx;
  346. font-size: 16rpx;
  347. color: #fff;
  348. background: #cd9933;
  349. // border-radius: 10rpx;
  350. border-top-left-radius: 30rpx;
  351. border-bottom-right-radius: 30rpx;
  352. &::after {
  353. position: absolute;
  354. bottom: -15rpx;
  355. left: 50%;
  356. width: 0;
  357. height: 0;
  358. z-index: 0;
  359. transform: translateX(-50%);
  360. content: "";
  361. // background: red;
  362. border-style: solid;
  363. border-width: 0 10px 10px 10px;
  364. border-color: transparent transparent transparent #cd9933;
  365. }
  366. }
  367. }
  368. }
  369. .input-box {
  370. width: 610rpx;
  371. height: 89rpx;
  372. background-color: #ededed;
  373. border-radius: 10rpx;
  374. padding: 0 30rpx;
  375. box-sizing: border-box;
  376. display: flex;
  377. justify-content: space-between;
  378. align-items: center;
  379. margin: 20rpx 0;
  380. font-size: 25rpx;
  381. color: #999999;
  382. input {
  383. color: #000000;
  384. width: 99%;
  385. }
  386. .g {
  387. font-size: 32rpx;
  388. color: #cc9933;
  389. }
  390. }
  391. .buy-price {
  392. display: flex;
  393. justify-content: center;
  394. font-size: 25rpx;
  395. color: #000000;
  396. align-items: center;
  397. .buy-num {
  398. color: #cc9933;
  399. font-size: 28rpx;
  400. margin: 0 5rpx;
  401. }
  402. }
  403. .payment-method {
  404. margin-top: 120rpx;
  405. .method-box {
  406. display: flex;
  407. justify-content: space-between;
  408. align-items: center;
  409. margin: 50rpx 0;
  410. .box-left {
  411. display: flex;
  412. justify-content: center;
  413. image {
  414. height: 48rpx;
  415. }
  416. text {
  417. margin-left: 15rpx;
  418. }
  419. }
  420. }
  421. }
  422. .btn-box {
  423. display: flex;
  424. justify-content: center;
  425. width: 100%;
  426. margin-top: 200rpx;
  427. .btn {
  428. width: 300rpx;
  429. height: 71rpx;
  430. background-color: #cc9933;
  431. border-radius: 34rpx;
  432. display: flex;
  433. justify-content: center;
  434. align-items: center;
  435. font-size: 33rpx;
  436. color: #ffffff;
  437. }
  438. }
  439. .aggregate {
  440. display: flex;
  441. align-items: center;
  442. justify-content: center;
  443. padding: 10px;
  444. .aggre {
  445. font-size: 14px;
  446. margin-left: 10px;
  447. .aggre-text {
  448. color: #cc9933;
  449. }
  450. }
  451. .choose {
  452. width: 16px;
  453. height: 16px;
  454. }
  455. }
  456. .white {
  457. height: 100rpx;
  458. background-color: #ffffff;
  459. }
  460. .box-title {
  461. height: 50rpx;
  462. padding-left: 19rpx;
  463. font-size: 31rpx;
  464. color: #000000;
  465. position: relative;
  466. display: flex;
  467. align-items: center;
  468. &::after {
  469. position: absolute;
  470. bottom: -10rpx;
  471. left: 5rpx;
  472. top: 23%;
  473. transform: translateX(-50%);
  474. content: "";
  475. background-color: #cc9933;
  476. width: 4rpx;
  477. height: 28rpx;
  478. }
  479. }
  480. }
  481. .signContent {
  482. background-color: #f8f8f8;
  483. padding: 20px;
  484. box-sizing: border-box;
  485. display: flex;
  486. justify-content: center;
  487. align-items: center;
  488. flex-direction: column;
  489. border-radius: 20px 20px 0 0;
  490. .scroll {
  491. background-color: #fff;
  492. padding: 4px;
  493. height: 300px;
  494. overflow-y: hidden;
  495. border: 1px solid #dfdfdf;
  496. }
  497. .footer {
  498. margin-top: 10px;
  499. color: #fff;
  500. padding: 4px 20px;
  501. border-radius: 20px;
  502. background: linear-gradient(to right, #8ed187, #5dd665);
  503. }
  504. }
  505. }
  506. </style>