payorder.vue 17 KB

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