payorder.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  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. if (this.orderType == "bond" && this.bondBalance < this.sum) {
  419. uni.showToast({
  420. title: "保证金余额不足以缴纳保证金,请先充值保证金。",
  421. icon: "none",
  422. });
  423. return;
  424. }
  425. // console.log(new Date().getTime());
  426. if (this.orderType == "difference") {
  427. //补差额
  428. uni.$u.http
  429. .post(`/api/order/fill`, {
  430. order_id: this.orderid,
  431. pay_type: this.pay_type,
  432. })
  433. .then((res) => {
  434. if (this.pay_type == "wechat") {
  435. uni.requestPayment({
  436. provider: "wxpay",
  437. timeStamp: String(res.timeStamp),
  438. nonceStr: res.nonceStr,
  439. package: res.package,
  440. signType: res.signType,
  441. paySign: res.paySign,
  442. success: function (res) {
  443. this.$u.toast(this.i18n.Paymentsuccess);
  444. console.log("success:" + JSON.stringify(res));
  445. setTimeout(() => {
  446. uni.navigateTo({
  447. url: "confirm",
  448. });
  449. }, 800);
  450. },
  451. fail: function (err) {
  452. console.log("fail:" + JSON.stringify(err));
  453. },
  454. // success: (result) => {
  455. //
  456. // // console.log(result);
  457. // },
  458. // fail: (error) => {
  459. // console.log(error);
  460. // },
  461. });
  462. }
  463. uni.showToast({
  464. title: this.i18n.Paymentsuccess,
  465. icon: "none",
  466. });
  467. //一秒钟之后返回上一页
  468. let timer = setTimeout(() => {
  469. uni.navigateBack({
  470. delta: 1,
  471. });
  472. clearTimeout(timer);
  473. }, 1000);
  474. });
  475. return;
  476. } else if (this.orderType == "bond") {
  477. //支付保证金
  478. uni.$u.http
  479. .post(`/api/order/earnest_pay`, {
  480. order_id: this.orderid,
  481. })
  482. .then((res) => {
  483. if (this.pay_type == "wechat") {
  484. uni.requestPayment({
  485. provider: "wxpay",
  486. timeStamp: String(res.timeStamp),
  487. nonceStr: res.nonceStr,
  488. package: res.package,
  489. signType: res.signType,
  490. paySign: res.paySign,
  491. success: function (res) {
  492. this.$u.toast("支付成功");
  493. console.log("success:" + JSON.stringify(res));
  494. setTimeout(() => {
  495. uni.navigateTo({
  496. url: "confirm",
  497. });
  498. }, 800);
  499. },
  500. fail: function (err) {
  501. console.log("fail:" + JSON.stringify(err));
  502. },
  503. });
  504. }
  505. //提示支付成功
  506. uni.showToast({
  507. title: "支付成功",
  508. icon: "none",
  509. });
  510. //一秒钟之后返回上一页
  511. let timer = setTimeout(() => {
  512. uni.navigateBack({
  513. delta: 1,
  514. });
  515. clearTimeout(timer);
  516. }, 1000);
  517. });
  518. return;
  519. }
  520. if (this.type == "") {
  521. uni.$u.http
  522. .post("/api/order/payment", {
  523. order_id: this.orderid,
  524. pay_type: this.pay_type,
  525. customer_currency: "RMB",
  526. })
  527. .then((res) => {
  528. console.log(res);
  529. if (this.pay_type == "wechat") {
  530. uni.requestPayment({
  531. provider: "wxpay",
  532. timeStamp: String(res.timeStamp),
  533. nonceStr: res.nonceStr,
  534. package: res.package,
  535. signType: res.signType,
  536. paySign: res.paySign,
  537. success: function (res) {
  538. this.$u.toast(this.i18n.Paymentsuccess);
  539. console.log("success:" + JSON.stringify(res));
  540. setTimeout(() => {
  541. uni.navigateTo({
  542. url: "/pageA/confirm",
  543. });
  544. }, 800);
  545. },
  546. fail: function (err) {
  547. console.log("fail:" + JSON.stringify(err));
  548. },
  549. // success: (result) => {
  550. //
  551. // // console.log(result);
  552. // },
  553. // fail: (error) => {
  554. // console.log(error);
  555. // },
  556. });
  557. } else {
  558. this.$u.toast(this.i18n.Paymentsuccess);
  559. setTimeout(() => {
  560. uni.navigateTo({
  561. url: "/pageA/confirm",
  562. });
  563. }, 800);
  564. }
  565. uni.showToast({
  566. title: this.i18n.Paymentsuccess,
  567. icon: "none",
  568. });
  569. uni.navigateBack({
  570. delta: 1,
  571. });
  572. })
  573. .catch(() => {});
  574. } else {
  575. uni.$u.http
  576. .post("/api/pay", {
  577. order_id: this.orderid,
  578. pay_type: this.mode == 2 ? "customer_service" : this.pay_type,
  579. type: this.type,
  580. exchange_rate_id: this.exchange_rate_id,
  581. })
  582. .then((res) => {
  583. if (this.pay_type == "wechat") {
  584. uni.requestPayment({
  585. provider: "wxpay",
  586. timeStamp: String(res.timeStamp),
  587. nonceStr: res.nonceStr,
  588. package: res.package,
  589. signType: res.signType,
  590. paySign: res.paySign,
  591. success: function (res) {
  592. console.log("success:" + JSON.stringify(res));
  593. setTimeout(() => {
  594. uni.switchTab({
  595. url: "/pages/express/express",
  596. });
  597. }, 800);
  598. },
  599. fail: function (err) {
  600. console.log("fail:" + JSON.stringify(err));
  601. },
  602. });
  603. } else {
  604. this.$u.toast(this.i18n.Paymentsuccess);
  605. setTimeout(() => {
  606. uni.switchTab({
  607. url: "/pages/express/express",
  608. });
  609. }, 800);
  610. }
  611. // uni.navigateTo({
  612. // url: 'confirm'
  613. // })
  614. })
  615. .catch(() => {});
  616. }
  617. },
  618. },
  619. };
  620. </script>
  621. <style lang="scss" scoped>
  622. .payment {
  623. font-family: PingFangSC, PingFang SC;
  624. font-weight: 500;
  625. font-size: 24rpx;
  626. color: #222222;
  627. line-height: 34rpx;
  628. text-align: left;
  629. font-style: normal;
  630. }
  631. .content {
  632. font-family: PingFangSC, PingFang SC;
  633. font-weight: 400;
  634. font-size: 20rpx;
  635. color: #777777;
  636. line-height: 28rpx;
  637. text-align: left;
  638. font-style: normal;
  639. }
  640. .stateac {
  641. font-family: PingFangSC, PingFang SC;
  642. font-weight: 400;
  643. font-size: 24rpx;
  644. color: #ff1515;
  645. line-height: 34rpx;
  646. text-align: left;
  647. font-style: normal;
  648. }
  649. .unstate {
  650. font-family: PingFangSC, PingFang SC;
  651. font-weight: 400;
  652. font-size: 24rpx;
  653. color: #222222;
  654. line-height: 34rpx;
  655. text-align: left;
  656. font-style: normal;
  657. }
  658. .confirm {
  659. position: fixed;
  660. bottom: 66rpx;
  661. width: 702rpx;
  662. height: 84rpx;
  663. background: #f83224;
  664. border-radius: 44rpx;
  665. font-family: PingFangSC, PingFang SC;
  666. font-weight: 500;
  667. font-size: 32rpx;
  668. color: #ffffff;
  669. line-height: 84rpx;
  670. text-align: center;
  671. font-style: normal;
  672. }
  673. .payitem {
  674. width: 702rpx;
  675. height: 140rpx;
  676. background: #ffffff;
  677. border-radius: 12rpx;
  678. padding: 34rpx 24rpx;
  679. box-sizing: border-box;
  680. }
  681. .back {
  682. padding: 20rpx 24rpx;
  683. box-sizing: border-box;
  684. .topbox {
  685. position: relative;
  686. .state {
  687. // width: 128rpx;
  688. // height: 56rpx;
  689. background: #ffffff;
  690. border-radius: 6rpx;
  691. padding: 12rpx;
  692. box-sizing: border-box;
  693. }
  694. .paysum {
  695. font-family: PingFangSC, PingFang SC;
  696. font-weight: 400;
  697. font-size: 28rpx;
  698. color: #222222;
  699. line-height: 40rpx;
  700. text-align: left;
  701. font-style: normal;
  702. }
  703. .numbe {
  704. font-family: HarmonyOS_Sans_Medium;
  705. font-size: 28rpx;
  706. color: #000000;
  707. line-height: 38rpx;
  708. text-align: left;
  709. font-style: normal;
  710. margin-top: 20rpx;
  711. }
  712. }
  713. }
  714. </style>