payorder.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. <template>
  2. <view class="back">
  3. <view class="topbox">
  4. <view
  5. class=""
  6. style="position: absolute; top: -30rpx; right: 0"
  7. v-if="pay_type == 'customer'"
  8. >
  9. <view
  10. class="state u-flex u-row-between"
  11. @click="stateshow = !stateshow"
  12. >
  13. <text>{{ state }}</text>
  14. <image
  15. src="static/images/pull_down.png"
  16. style="width: 24rpx; height: 24rpx"
  17. mode=""
  18. ></image>
  19. </view>
  20. <view class="state" v-if="stateshow">
  21. <view
  22. @click="statechange(item, idx)"
  23. :class="state_id == idx ? 'stateac' : 'unstate'"
  24. style="margin-bottom: 20rpx; font-size: 24rpx"
  25. v-for="(item, idx) in array"
  26. >
  27. <text v-if="language == 'zh-CN'">
  28. {{ item.name_cn }}
  29. </text>
  30. <text v-if="language == 'en-US'">
  31. {{ item.name_en }}
  32. </text>
  33. <text v-if="language == 'es-ES'">
  34. {{ item.name_es }}
  35. </text>
  36. <text v-if="language == 'it-IT'">
  37. {{ item.name_ita }}
  38. </text>
  39. </view>
  40. </view>
  41. </view>
  42. <view
  43. class="u-row-center"
  44. style="
  45. display: flex;
  46. flex-direction: column;
  47. align-items: center;
  48. margin-top: 56rpx;
  49. "
  50. >
  51. <view class="paysum">{{ i18n.Actual }}</view>
  52. <view class="numbe" style="margin-top: 40rpx">
  53. <text v-if="state_id == 0 && mode == 2">¥</text>
  54. <text v-if="state_id == 1 && mode == 2">$</text>
  55. <text v-if="state_id == 2 && mode == 2">€</text>
  56. <text v-if="state_id == 3 && mode == 2">¥</text>
  57. <text v-if="mode != 2">¥</text>
  58. <text style="font-size: 60rpx; font-weight: 600" v-if="mode == 2">{{
  59. sum
  60. }}</text>
  61. <text style="font-size: 60rpx; font-weight: 600" v-else>{{
  62. sum1
  63. }}</text>
  64. </view>
  65. <!-- <view class="">
  66. <text>支付剩余时间 13:50</text>
  67. </view> -->
  68. </view>
  69. <!-- 缴纳保证金 -->
  70. <view
  71. v-if="orderType == 'bond'"
  72. class="payitem"
  73. style="margin-top: 100rpx; display: flex"
  74. @click="change(0)"
  75. >
  76. <image
  77. src="static/images/yuer.png"
  78. mode=""
  79. style="width: 40rpx; height: 40rpx"
  80. ></image>
  81. <view class="u-flex u-row-between" style="margin-left: 20rpx; flex: 1">
  82. <view class="">
  83. <view class="">{{ i18n.Marginpayment }}</view>
  84. <view
  85. class=""
  86. style="
  87. margin-top: 10rpx;
  88. color: rgba(248, 50, 36, 1);
  89. font-size: 24rpx;
  90. "
  91. >
  92. {{ i18n.Currentbalance }}:
  93. {{ bondBalance }}
  94. </view>
  95. </view>
  96. <image
  97. v-if="mode == 0"
  98. src="static/images/active.png"
  99. mode=""
  100. style="width: 36rpx; height: 36rpx"
  101. >
  102. </image>
  103. <image
  104. v-else
  105. src="static/images/unactive.png"
  106. mode=""
  107. style="width: 36rpx; height: 36rpx"
  108. ></image>
  109. </view>
  110. </view>
  111. <!-- 余额支付 -->
  112. <view
  113. v-else
  114. class="payitem"
  115. style="margin-top: 100rpx; display: flex"
  116. @click="change(0)"
  117. >
  118. <image
  119. src="static/images/yuer.png"
  120. mode=""
  121. style="width: 40rpx; height: 40rpx"
  122. ></image>
  123. <view class="u-flex u-row-between" style="margin-left: 20rpx; flex: 1">
  124. <view class="">
  125. <view class="">{{ i18n.Balancepayment }}</view>
  126. <view
  127. v-if="mode == 2"
  128. class=""
  129. style="
  130. margin-top: 10rpx;
  131. color: rgba(248, 50, 36, 1);
  132. font-size: 24rpx;
  133. "
  134. >
  135. {{ i18n.Currentbalance }}:{{ balance }}
  136. </view>
  137. <view
  138. v-else
  139. class=""
  140. style="
  141. margin-top: 10rpx;
  142. color: rgba(248, 50, 36, 1);
  143. font-size: 24rpx;
  144. "
  145. >
  146. {{ i18n.Currentbalance }}:{{ balance1 }}
  147. </view>
  148. </view>
  149. <image
  150. v-if="mode == 0"
  151. src="static/images/active.png"
  152. mode=""
  153. style="width: 36rpx; height: 36rpx"
  154. >
  155. </image>
  156. <image
  157. v-else
  158. src="static/images/unactive.png"
  159. mode=""
  160. style="width: 36rpx; height: 36rpx"
  161. ></image>
  162. </view>
  163. </view>
  164. <!-- 微信支付 -->
  165. <view
  166. v-if="orderType != 'bond'"
  167. class="payitem"
  168. style="margin-top: 20rpx; display: flex"
  169. @click="change(1)"
  170. >
  171. <image
  172. src="static/images/wx.png"
  173. mode=""
  174. style="width: 40rpx; height: 40rpx"
  175. ></image>
  176. <view class="u-flex u-row-between" style="margin-left: 20rpx; flex: 1">
  177. <view class="">
  178. <view class="">{{ i18n.WechatPay }}</view>
  179. <view
  180. class=""
  181. style="
  182. margin-top: 10rpx;
  183. color: rgba(121, 121, 121, 1);
  184. font-size: 24rpx;
  185. "
  186. >
  187. {{ i18n.applicable }}
  188. </view>
  189. </view>
  190. <image
  191. v-if="mode == 1"
  192. src="static/images/active.png"
  193. mode=""
  194. style="width: 36rpx; height: 36rpx"
  195. >
  196. </image>
  197. <image
  198. v-else
  199. src="static/images/unactive.png"
  200. mode=""
  201. style="width: 36rpx; height: 36rpx"
  202. ></image>
  203. </view>
  204. </view>
  205. <!-- 客服支付 -->
  206. <view
  207. v-if="orderType != 'bond'"
  208. class="payitem"
  209. style="margin-top: 20rpx; display: flex"
  210. @click="change(2)"
  211. >
  212. <image
  213. src="static/images/kefu2.png"
  214. mode=""
  215. style="width: 40rpx; height: 40rpx"
  216. ></image>
  217. <view class="u-flex u-row-between" style="margin-left: 20rpx; flex: 1">
  218. <view class="">
  219. <view class="">{{ i18n.Customerservicepayment }}</view>
  220. <view
  221. class=""
  222. style="
  223. margin-top: 10rpx;
  224. color: rgba(121, 121, 121, 1);
  225. font-size: 24rpx;
  226. "
  227. >
  228. {{ i18n.Contactpayment }}
  229. </view>
  230. </view>
  231. <image
  232. v-if="mode == 2"
  233. src="static/images/active.png"
  234. mode=""
  235. style="width: 36rpx; height: 36rpx"
  236. >
  237. </image>
  238. <image
  239. v-else
  240. src="static/images/unactive.png"
  241. mode=""
  242. style="width: 36rpx; height: 36rpx"
  243. ></image>
  244. </view>
  245. </view>
  246. </view>
  247. <!-- 付款须知 -->
  248. <view class="" v-if="pay_type == 'customer'">
  249. <view
  250. class="payment"
  251. style="margin-top: 24rpx; margin-bottom: 18rpx; font-size: 32rpx"
  252. >{{ i18n.Paymentinstructions }}</view
  253. >
  254. <!-- <view class="content" style="margin-top: 18rpx">1.联系客服付款需走线下支付通道,付款成</view> -->
  255. <u-parse :content="content" style="margin-top: 18rpx"></u-parse>
  256. </view>
  257. <view class="confirm" @click="confirm">
  258. {{ i18n.Confirmpayment }}
  259. </view>
  260. </view>
  261. </template>
  262. <script>
  263. export default {
  264. data() {
  265. return {
  266. mode: 0,
  267. stateshow: false,
  268. state: "人民币",
  269. state_id: 0,
  270. array: [],
  271. sum: "",
  272. pay_type: "balance",
  273. orderid: "",
  274. balance: "",
  275. type: "",
  276. exchange_rate_id: "",
  277. balance1: 0,
  278. sum1: "",
  279. language: "zh-CN",
  280. orderType: "",
  281. bondBalance: "",
  282. content: "",
  283. };
  284. },
  285. onLoad(options) {
  286. this.sum1 = options.sum;
  287. this.sum = options.sum;
  288. this.orderid = options.orderid;
  289. this.orderType = options.orderType;
  290. if (options.type) {
  291. this.type = options.type;
  292. }
  293. },
  294. onShow() {
  295. this.ratelist();
  296. // this.userinfo()
  297. if (uni.getStorageSync("language") != "") {
  298. this.language = uni.getStorageSync("language");
  299. }
  300. this.reminder();
  301. },
  302. computed: {
  303. i18n() {
  304. return this.$t("index");
  305. },
  306. },
  307. methods: {
  308. //协议
  309. reminder() {
  310. uni.$u.http
  311. .get(`/api/agreement?code=Payment instructions`)
  312. .then((res) => {
  313. console.log(res);
  314. if (this.language == "zh-CN") {
  315. // this.name = res.name_cn
  316. this.content = res.content_cn;
  317. } else if (this.language == "en-US") {
  318. // this.name = res.name_en
  319. this.content = res.content_en;
  320. } else if (this.language == "es-ES") {
  321. // this.name = res.name_es
  322. this.content = res.content_es;
  323. } else if (this.language == "it-IT") {
  324. // this.name = res.name_ita
  325. this.content = res.content_ita;
  326. }
  327. });
  328. },
  329. //用户信息
  330. userinfo() {
  331. uni.$u.http
  332. .get("/api/member/info", {})
  333. .then((res) => {
  334. this.balance = res.balance;
  335. this.balance1 = this.balance;
  336. this.bondBalance = res.deposit;
  337. this.calculate1(this.balance1);
  338. })
  339. .catch(() => {});
  340. },
  341. //汇率列表
  342. ratelist() {
  343. uni.$u.http
  344. .get("/api/exchange-rate", {})
  345. .then((res) => {
  346. this.array = res.reverse();
  347. this.exchange_rate_id = this.array[0].id;
  348. if (this.language == "zh-CN") {
  349. this.state = this.array[0].name_cn;
  350. }
  351. if (this.language == "en-US") {
  352. this.state = this.array[0].name_en;
  353. }
  354. if (this.language == "es-ES") {
  355. this.state = this.array[0].name_es;
  356. }
  357. if (this.language == "it-IT") {
  358. this.state = this.array[0].name_ita;
  359. }
  360. this.userinfo();
  361. this.calculate();
  362. })
  363. .catch(() => {});
  364. },
  365. //汇率价格
  366. calculate() {
  367. uni.$u.http
  368. .post("/api/exchange-rate/calculate/" + this.exchange_rate_id, {
  369. price: this.sum1,
  370. })
  371. .then((res) => {
  372. this.sum = res.amount;
  373. })
  374. .catch(() => {});
  375. },
  376. calculate1(balance) {
  377. uni.$u.http
  378. .post("/api/exchange-rate/calculate/" + this.exchange_rate_id, {
  379. price: balance,
  380. })
  381. .then((res) => {
  382. this.balance = res.amount;
  383. })
  384. .catch(() => {});
  385. },
  386. change(idx) {
  387. this.mode = idx;
  388. if (idx == 0) {
  389. this.pay_type = "balance";
  390. }
  391. if (idx == 1) {
  392. this.pay_type = "wechat";
  393. }
  394. if (idx == 2) {
  395. this.pay_type = "customer";
  396. }
  397. },
  398. statechange(item, idx) {
  399. if (this.language == "zh-CN") {
  400. this.state = item.name_cn;
  401. }
  402. if (this.language == "en-US") {
  403. this.state = item.name_en;
  404. }
  405. if (this.language == "es-ES") {
  406. this.state = item.name_es;
  407. }
  408. if (this.language == "it-IT") {
  409. this.state = item.name_ita;
  410. }
  411. this.state_id = idx;
  412. this.exchange_rate_id = item.id;
  413. this.stateshow = !this.stateshow;
  414. this.calculate();
  415. this.calculate1(this.balance1);
  416. },
  417. confirm() {
  418. console.log(this.bondBalance);
  419. console.log(this.sum);
  420. if (
  421. this.orderType == "bond" &&
  422. Number(this.bondBalance) < Number(this.sum)
  423. ) {
  424. uni.showToast({
  425. title: "保证金余额不足以缴纳保证金,请先充值保证金。",
  426. icon: "none",
  427. });
  428. return;
  429. }
  430. // console.log(new Date().getTime());
  431. if (this.orderType == "difference") {
  432. //补差额
  433. uni.$u.http
  434. .post(`/api/order/fill`, {
  435. order_id: this.orderid,
  436. pay_type: this.pay_type,
  437. })
  438. .then((res) => {
  439. if (this.pay_type == "wechat") {
  440. uni.requestPayment({
  441. provider: "wxpay",
  442. timeStamp: String(res.timeStamp),
  443. nonceStr: res.nonceStr,
  444. package: res.package,
  445. signType: res.signType,
  446. paySign: res.paySign,
  447. success: function (res) {
  448. this.$u.toast(this.i18n.Paymentsuccess);
  449. console.log("success:" + JSON.stringify(res));
  450. setTimeout(() => {
  451. uni.navigateTo({
  452. url: "confirm",
  453. });
  454. }, 800);
  455. },
  456. fail: function (err) {
  457. console.log("fail:" + JSON.stringify(err));
  458. },
  459. // success: (result) => {
  460. //
  461. // // console.log(result);
  462. // },
  463. // fail: (error) => {
  464. // console.log(error);
  465. // },
  466. });
  467. }
  468. uni.showToast({
  469. title: this.i18n.Paymentsuccess,
  470. icon: "none",
  471. });
  472. //一秒钟之后返回上一页
  473. let timer = setTimeout(() => {
  474. uni.navigateBack({
  475. delta: 1,
  476. });
  477. clearTimeout(timer);
  478. }, 1000);
  479. });
  480. return;
  481. } else if (this.orderType == "bond") {
  482. //支付保证金
  483. uni.$u.http
  484. .post(`/api/order/earnest_pay`, {
  485. order_id: this.orderid,
  486. })
  487. .then((res) => {
  488. if (this.pay_type == "wechat") {
  489. uni.requestPayment({
  490. provider: "wxpay",
  491. timeStamp: String(res.timeStamp),
  492. nonceStr: res.nonceStr,
  493. package: res.package,
  494. signType: res.signType,
  495. paySign: res.paySign,
  496. success: function (res) {
  497. this.$u.toast("支付成功");
  498. console.log("success:" + JSON.stringify(res));
  499. setTimeout(() => {
  500. uni.navigateTo({
  501. url: "confirm",
  502. });
  503. }, 800);
  504. },
  505. fail: function (err) {
  506. console.log("fail:" + JSON.stringify(err));
  507. },
  508. });
  509. }
  510. //提示支付成功
  511. uni.showToast({
  512. title: "支付成功",
  513. icon: "none",
  514. });
  515. //一秒钟之后返回上一页
  516. let timer = setTimeout(() => {
  517. uni.navigateBack({
  518. delta: 1,
  519. });
  520. clearTimeout(timer);
  521. }, 1000);
  522. });
  523. return;
  524. }
  525. if (this.type == "") {
  526. console.log(3333333333);
  527. uni.$u.http
  528. .post("/api/order/payment", {
  529. order_id: this.orderid,
  530. pay_type: this.pay_type,
  531. customer_currency: "RMB",
  532. })
  533. .then((res) => {
  534. if (this.pay_type == "wechat") {
  535. uni.requestPayment({
  536. provider: "wxpay",
  537. timeStamp: String(res.timeStamp),
  538. nonceStr: res.nonceStr,
  539. package: res.package,
  540. signType: res.signType,
  541. paySign: res.paySign,
  542. success: function (res) {
  543. // this.$u.toast(this.i18n.Paymentsuccess);
  544. console.log("success:" + JSON.stringify(res));
  545. setTimeout(() => {
  546. uni.reLaunch({
  547. url: "/pageA/confirm",
  548. });
  549. }, 800);
  550. },
  551. fail: function (err) {
  552. console.log("fail:" + JSON.stringify(err));
  553. },
  554. // success: (result) => {
  555. //
  556. // // console.log(result);
  557. // },
  558. // fail: (error) => {
  559. // console.log(error);
  560. // },
  561. });
  562. } else {
  563. setTimeout(() => {
  564. uni.reLaunch({
  565. url: "/pageA/confirm",
  566. });
  567. }, 800);
  568. }
  569. })
  570. .catch(() => {});
  571. } else {
  572. uni.$u.http
  573. .post("/api/pay", {
  574. order_id: this.orderid,
  575. pay_type: this.mode == 2 ? "customer_service" : this.pay_type,
  576. type: this.type,
  577. exchange_rate_id: this.exchange_rate_id,
  578. })
  579. .then((res) => {
  580. if (this.pay_type == "wechat") {
  581. uni.requestPayment({
  582. provider: "wxpay",
  583. timeStamp: String(res.timeStamp),
  584. nonceStr: res.nonceStr,
  585. package: res.package,
  586. signType: res.signType,
  587. paySign: res.paySign,
  588. success: function (res) {
  589. console.log("success:" + JSON.stringify(res));
  590. setTimeout(() => {
  591. uni.switchTab({
  592. url: "/pages/express/express",
  593. });
  594. }, 800);
  595. },
  596. fail: function (err) {
  597. console.log("fail:" + JSON.stringify(err));
  598. },
  599. });
  600. } else {
  601. this.$u.toast(this.i18n.Paymentsuccess);
  602. setTimeout(() => {
  603. uni.switchTab({
  604. url: "/pages/express/express",
  605. });
  606. }, 800);
  607. }
  608. // uni.navigateTo({
  609. // url: 'confirm'
  610. // })
  611. })
  612. .catch(() => {});
  613. }
  614. },
  615. },
  616. };
  617. </script>
  618. <style lang="scss" scoped>
  619. .payment {
  620. font-family: PingFangSC, PingFang SC;
  621. font-weight: 500;
  622. font-size: 24rpx;
  623. color: #222222;
  624. line-height: 34rpx;
  625. text-align: left;
  626. font-style: normal;
  627. }
  628. .content {
  629. font-family: PingFangSC, PingFang SC;
  630. font-weight: 400;
  631. font-size: 20rpx;
  632. color: #777777;
  633. line-height: 28rpx;
  634. text-align: left;
  635. font-style: normal;
  636. }
  637. .stateac {
  638. font-family: PingFangSC, PingFang SC;
  639. font-weight: 400;
  640. font-size: 24rpx;
  641. color: #ff1515;
  642. line-height: 34rpx;
  643. text-align: left;
  644. font-style: normal;
  645. }
  646. .unstate {
  647. font-family: PingFangSC, PingFang SC;
  648. font-weight: 400;
  649. font-size: 24rpx;
  650. color: #222222;
  651. line-height: 34rpx;
  652. text-align: left;
  653. font-style: normal;
  654. }
  655. .confirm {
  656. position: fixed;
  657. bottom: 66rpx;
  658. width: 702rpx;
  659. height: 84rpx;
  660. background: #f83224;
  661. border-radius: 44rpx;
  662. font-family: PingFangSC, PingFang SC;
  663. font-weight: 500;
  664. font-size: 32rpx;
  665. color: #ffffff;
  666. line-height: 84rpx;
  667. text-align: center;
  668. font-style: normal;
  669. }
  670. .payitem {
  671. width: 702rpx;
  672. height: 140rpx;
  673. background: #ffffff;
  674. border-radius: 12rpx;
  675. padding: 34rpx 24rpx;
  676. box-sizing: border-box;
  677. }
  678. .back {
  679. padding: 20rpx 24rpx;
  680. box-sizing: border-box;
  681. .topbox {
  682. position: relative;
  683. .state {
  684. // width: 128rpx;
  685. // height: 56rpx;
  686. background: #ffffff;
  687. border-radius: 6rpx;
  688. padding: 12rpx;
  689. box-sizing: border-box;
  690. }
  691. .paysum {
  692. font-family: PingFangSC, PingFang SC;
  693. font-weight: 400;
  694. font-size: 28rpx;
  695. color: #222222;
  696. line-height: 40rpx;
  697. text-align: left;
  698. font-style: normal;
  699. }
  700. .numbe {
  701. font-family: HarmonyOS_Sans_Medium;
  702. font-size: 28rpx;
  703. color: #000000;
  704. line-height: 38rpx;
  705. text-align: left;
  706. font-style: normal;
  707. margin-top: 20rpx;
  708. }
  709. }
  710. }
  711. </style>