選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

order_payment.vue 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. <template>
  2. <navBar title="订单支付" :scrollTop="scrollTop" :orderId="state.orderId"></navBar>
  3. <navBgCar></navBgCar>
  4. <view class="content-value">
  5. <view @click="savaHandle(item)" class="ul-item" v-for="(item, index) in state.dataArray" :key="index">
  6. <image style="width: 100%; height: 170rpx; border-radius: 20rpx"
  7. :src="`${$imgUrl}applyCard/product-bg.png`"></image>
  8. <view class="item-value">
  9. <image class="icon-tip" :src="imageUrl"></image>
  10. <view class="content">
  11. <view class="title">
  12. {{ item.payName }}
  13. </view>
  14. <view style="margin-top: 15rpx" class="tip">
  15. {{ item.payStatusName }}
  16. </view>
  17. </view>
  18. <view class="money">
  19. ¥:{{ item.fee * 0.01 }}
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script setup lang="ts">
  26. import { onLoad, onPageScroll } from "@dcloudio/uni-app";
  27. import { reactive, ref } from "vue";
  28. import {
  29. PAYDETECTION,
  30. PAYMENTORDERAPPLY,
  31. wechatAppID,
  32. wechatSecret,
  33. CardBillQuery,
  34. CardBillPlaceOrder,
  35. CardBillPayStatus,
  36. wechatPayConfigId,
  37. aliPayConfigIdTwo,
  38. obtainUserId,
  39. getOpenidApi,
  40. orderDetail
  41. } from "@/utils/network/api.js";
  42. import { request } from "@/utils/network/request.js";
  43. import { stringToJson } from "@/utils/network/encryption";
  44. import { fileURL } from "@/datas/fileURL.js";
  45. import navBgCar from "./components/nav-bg-car5";
  46. import navBar from "@/components/nav-bar/nav-bar2.vue";
  47. import { getItem, StorageKeys, setItem } from "@/utils/storage.ts";
  48. import { msg } from "@/utils/utils";
  49. const imgURL = `${fileURL}image/`;
  50. import { confirm } from "@/utils/utils";
  51. let imageUrl = ""
  52. let logo
  53. const scrollTop = ref(0); //滚动距离
  54. const savaHandle = (val) => {
  55. if (state.isclick) {
  56. if (val.payStatus == "SUCCESS") {
  57. return;
  58. }
  59. state.isclick = false
  60. console.log("state.isclick", state.isclick, val.payStatus)
  61. if (val.payStatus === 'UNPAY') {
  62. // #ifdef MP-ALIPAY
  63. my.getAuthCode({
  64. scopes: 'auth_base',
  65. success: res => {
  66. const optionsUser = {
  67. type: 2,
  68. data: {
  69. payConfigId: aliPayConfigIdTwo,
  70. code: res.authCode
  71. },
  72. method: "POST",
  73. showLoading: true,
  74. };
  75. console.log('支付宝用户编号请求:', optionsUser)
  76. request(obtainUserId, optionsUser).then((res) => {
  77. console.log('支付宝用户编号返回:', res)
  78. const data = stringToJson(res.bizContent);
  79. const optionsali = {
  80. type: 2,
  81. data: {
  82. orderId: state.orderId,
  83. wxOpenid: data.openId,
  84. payType: val.payType
  85. },
  86. method: "POST",
  87. showLoading: true,
  88. };
  89. console.log('支付下单请求:', optionsali)
  90. request(PAYMENTORDERAPPLY, optionsali).then((res) => {
  91. const data = stringToJson(res.bizContent);
  92. console.log('支付下单返回:', data)
  93. my.tradePay({
  94. // 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号 trade_no
  95. tradeNO: data.tranPackage,
  96. success: res => {
  97. console.log("支付成功", res);
  98. refresh();
  99. },
  100. fail: res => {
  101. console.log("支付失败", res);
  102. },
  103. });
  104. });
  105. });
  106. },
  107. fail: err => {
  108. console.log('my.getAuthCode 调用失败', err)
  109. state.isclick = true
  110. }
  111. });
  112. // #endif
  113. // #ifdef MP-WEIXIN
  114. uni.login({
  115. provider: "weixin",
  116. success: function (e) {
  117. const options1 = {
  118. type: 2,
  119. data: {
  120. "jsCode": e.code
  121. },
  122. method: "POST",
  123. showLoading: true,
  124. };
  125. request(getOpenidApi, options1).then((res) => {
  126. const result = stringToJson(res.bizContent);
  127. const openidData = stringToJson(result.data);
  128. console.log("获取openId", openidData)
  129. const options = {
  130. type: 2,
  131. data: {
  132. orderId: state.orderId,
  133. wxOpenid: openidData.openid,
  134. payType: val.payType
  135. },
  136. method: "POST",
  137. showLoading: true,
  138. };
  139. request(PAYMENTORDERAPPLY, options).then((res) => {
  140. console.log("stringToJson(res.bizContent)", stringToJson(res.bizContent))
  141. const data = stringToJson(res.bizContent);
  142. uni.requestPayment({
  143. provider: "wxpay",
  144. orderInfo: "",
  145. timeStamp: data.timestamp,
  146. nonceStr: data.noncestr,
  147. package: data.wxPackage ? data.wxPackage : "",
  148. signType: data.signType,
  149. paySign: data.sign,
  150. success: function (e) {
  151. console.log("支付成功", res);
  152. refresh();
  153. },
  154. fail: function (err) {
  155. state.isclick = true
  156. confirm(err, () => { }, "支付失败", false);
  157. },
  158. });
  159. });
  160. });
  161. },
  162. });
  163. // #endif
  164. }
  165. }
  166. };
  167. const getOpenID = () => {
  168. uni.login({
  169. provider: "weixin",
  170. success: function (e) {
  171. getOpenid(e.code);
  172. },
  173. });
  174. };
  175. const getOpenid = (code) => {
  176. const options = {
  177. type: 2,
  178. data: {
  179. "jsCode": code
  180. },
  181. method: "POST",
  182. showLoading: true,
  183. };
  184. // #ifdef MP-WEIXIN
  185. request(getOpenidApi, options).then((res) => {
  186. const result = stringToJson(res.bizContent);
  187. console.log("获取微信小程序openid", result);
  188. const openidData = stringToJson(result.data);
  189. state.openid = openidData.openid;
  190. });
  191. // #endif
  192. }
  193. const refresh = () => {
  194. state.isclick = true
  195. let source = ""
  196. // #ifdef MP-ALIPAY
  197. source = "ALI"
  198. // #endif
  199. // #ifdef MP-WEIXIN
  200. source = "WECHAT"
  201. // #endif
  202. var data = {
  203. orderId: state.orderId,
  204. source: source //请求方来源
  205. };
  206. const options = {
  207. type: 2,
  208. data: data,
  209. method: "POST",
  210. showLoading: true,
  211. };
  212. console.log("输出内容", options);
  213. request(PAYDETECTION, options).then((res) => {
  214. const data = stringToJson(res.bizContent);
  215. console.log(data);
  216. if (data.paymentStatus == 'ALLSUCCESS') {
  217. gotoEditUserOrUnitInfo()
  218. }
  219. state.dataArray = data.datas;
  220. for (let i = 0; i < state.dataArray.length; i++) {
  221. if (state.dataArray[i].payType === 'HANDLE') {
  222. state.dataArray[i].payName = '权益金'
  223. } else if (state.dataArray[i].payType === 'MARGIN') {
  224. state.dataArray[i].payName = '保证金'
  225. } else if (state.dataArray[i].payType === 'PRESTORE') {
  226. state.dataArray[i].payName = '预存金'
  227. } else if (state.dataArray[i].payType === 'EQUITY') {
  228. state.dataArray[i].payName = '权益费'
  229. } else if (state.dataArray[i].payType === 'REPAIROBU') {
  230. state.dataArray[i].payName = '增补obu'
  231. } else if (state.dataArray[i].payType === 'CHANGECARD') {
  232. state.dataArray[i].payName = '更换卡'
  233. } else if (state.dataArray[i].payType === 'CHANGEOBU') {
  234. state.dataArray[i].payName = '更换签'
  235. } else if (state.dataArray[i].payType === 'CHANGEALL') {
  236. state.dataArray[i].payName = '更换卡签'
  237. } else {
  238. state.dataArray[i].payName = '未知费'
  239. }
  240. if (state.dataArray[i].payStatus === 'SUCCESS') {
  241. state.dataArray[i].payStatusName = '已支付'
  242. } else if (state.dataArray[i].payStatus === 'PAYING') {
  243. state.dataArray[i].payStatusName = '支付中'
  244. } else if (state.dataArray[i].payStatus === 'FAILED') {
  245. state.dataArray[i].payStatusName = '支付失败'
  246. } else if (state.dataArray[i].payStatus === 'UNPAY') {
  247. state.dataArray[i].payStatusName = '未支付'
  248. } else if (state.dataArray[i].payStatus === 'CLOSED') {
  249. state.dataArray[i].payStatusName = '已关闭'
  250. } else if (state.dataArray[i].payStatus === 'CANCELED') {
  251. state.dataArray[i].payStatusName = '已撤销'
  252. } else if (state.dataArray[i].payStatus === 'REFUND') {
  253. state.dataArray[i].payStatusName = '转入退费'
  254. } else {
  255. state.dataArray[i].payStatusName = '未知'
  256. }
  257. }
  258. console.log("state.dataArray", state.dataArray)
  259. });
  260. }
  261. onLoad((option : any) => {
  262. console.log("传递过来的到支付页面", option)
  263. state.orderId = option.orderId;
  264. state.isValueCard = option.isValueCard;
  265. let source = ""
  266. // #ifdef MP-ALIPAY
  267. imageUrl = imgURL + "applyCard/alibaba.png";
  268. source = "ALI"
  269. // #endif
  270. // #ifdef MP-WEIXIN
  271. imageUrl = imgURL + "applyCard/wechat.png";
  272. source = "WECHAT"
  273. // #endif
  274. var data = {
  275. orderId: state.orderId,
  276. source: source //请求方来源
  277. };
  278. const options = {
  279. type: 2,
  280. data: data,
  281. method: "POST",
  282. showLoading: true,
  283. };
  284. console.log("输出内容", options);
  285. request(PAYDETECTION, options).then((res) => {
  286. const data = stringToJson(res.bizContent);
  287. console.log(data);
  288. if (data.paymentStatus == 'ALLSUCCESS') {
  289. // isValueCard 1 储值卡 2 记账卡
  290. if (state.isValueCard == 1) {
  291. uni.switchTab({
  292. url: "/pages/order/order"
  293. })
  294. } else {
  295. uni.redirectTo({
  296. url: `/subpackage/orders/release-products?orderId=${state.orderId}`,
  297. });
  298. }
  299. }
  300. state.dataArray = data.datas;
  301. for (let i = 0; i < state.dataArray.length; i++) {
  302. if (state.dataArray[i].payType === 'HANDLE') {
  303. state.dataArray[i].payName = '权益金'
  304. } else if (state.dataArray[i].payType === 'MARGIN') {
  305. state.dataArray[i].payName = '保证金'
  306. } else if (state.dataArray[i].payType === 'PRESTORE') {
  307. state.dataArray[i].payName = '预存金'
  308. } else if (state.dataArray[i].payType === 'EQUITY') {
  309. state.dataArray[i].payName = '权益费'
  310. } else if (state.dataArray[i].payType === 'REPAIROBU') {
  311. state.dataArray[i].payName = '增补obu'
  312. } else if (state.dataArray[i].payType === 'CHANGECARD') {
  313. state.dataArray[i].payName = '更换卡'
  314. } else if (state.dataArray[i].payType === 'CHANGEOBU') {
  315. state.dataArray[i].payName = '更换签'
  316. } else if (state.dataArray[i].payType === 'CHANGEALL') {
  317. state.dataArray[i].payName = '更换卡签'
  318. } else {
  319. state.dataArray[i].payName = '未知费'
  320. }
  321. if (state.dataArray[i].payStatus === 'SUCCESS') {
  322. state.dataArray[i].payStatusName = '已支付'
  323. } else if (state.dataArray[i].payStatus === 'PAYING') {
  324. state.dataArray[i].payStatusName = '支付中'
  325. } else if (state.dataArray[i].payStatus === 'FAILED') {
  326. state.dataArray[i].payStatusName = '支付失败'
  327. } else if (state.dataArray[i].payStatus === 'UNPAY') {
  328. state.dataArray[i].payStatusName = '未支付'
  329. } else if (state.dataArray[i].payStatus === 'CLOSED') {
  330. state.dataArray[i].payStatusName = '已关闭'
  331. } else if (state.dataArray[i].payStatus === 'CANCELED') {
  332. state.dataArray[i].payStatusName = '已撤销'
  333. } else if (state.dataArray[i].payStatus === 'REFUND') {
  334. state.dataArray[i].payStatusName = '转入退费'
  335. } else {
  336. state.dataArray[i].payStatusName = '未知'
  337. }
  338. }
  339. console.log("state.dataArray", state.dataArray)
  340. });
  341. });
  342. //解析URL获取参数
  343. const getRequest = (urlStr) => {
  344. if (typeof urlStr == "undefined") {
  345. // 获取url中"?"符后的字符串
  346. var url = decodeURI(location.search);
  347. } else {
  348. var url = "?" + urlStr.split("?")[1];
  349. }
  350. var theRequest = new Object();
  351. if (url.indexOf("?") != -1) {
  352. var str = url.substr(1);
  353. var strs = str.split("&");
  354. for (var i = 0; i < strs.length; i++) {
  355. theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
  356. }
  357. }
  358. return theRequest;
  359. };
  360. //监听页面滚动
  361. onPageScroll((e) => {
  362. scrollTop.value = e.scrollTop;
  363. });
  364. // isValueCard 1 储值卡 2 记账卡
  365. const gotoEditUserOrUnitInfo = () => {
  366. if (state.isValueCard == 1) {
  367. uni.switchTab({
  368. url: "/pages/order/order"
  369. })
  370. } else {
  371. uni.redirectTo({
  372. url: `/subpackage/orders/release-products?orderId=${state.orderId}`,
  373. });
  374. }
  375. }
  376. const state = reactive({
  377. isValueCard: 1, //卡的类型
  378. radiolist1: [], //选择卡的数据列表
  379. choiceCardShow: false, //选择卡的弹出框
  380. isSign: '',
  381. id: "",
  382. orderId: "",
  383. userType: 1, //1 个人 2单位
  384. type: 0, //0 客车 1货车
  385. vehiclePlateColor: "",
  386. data: {
  387. show: false,
  388. src: imgURL + "applyCard/edit.png",
  389. },
  390. dataArray: [],
  391. list: [
  392. {
  393. bg: imgURL + "applyCard/product-bg.png",
  394. icon: imgURL + "applyCard/wechat.png",
  395. title: "【货车】微信车主服务",
  396. tip: "绑定微信支付,无需绑定银行卡",
  397. },
  398. ],
  399. openid: "",
  400. isclick: true,//防止重复点击
  401. });
  402. </script>
  403. <style lang="scss" scoped>
  404. ::v-deep .u-radio {
  405. display: flex !important;
  406. align-items: center !important;
  407. float: none !important;
  408. }
  409. ::v-deep .u-icon__icon {
  410. top: -4px !important;
  411. }
  412. .bottomTip {
  413. margin-top: 100rpx;
  414. text-align: center;
  415. font-size: 28rpx;
  416. font-family: Microsoft YaHei;
  417. font-weight: 400;
  418. color: #b3b3b3;
  419. }
  420. .content-value {
  421. position: relative;
  422. // margin-top: -50rpx;
  423. padding: 0rpx 30rpx;
  424. position: relative;
  425. .img-pos {
  426. position: absolute;
  427. left: 500rpx;
  428. top: -38rpx;
  429. right: 50rpx;
  430. .img-flex {
  431. display: flex;
  432. justify-content: space-between;
  433. align-items: center;
  434. .car-img {
  435. width: 86rpx;
  436. height: 42rpx;
  437. }
  438. .flag-img {
  439. width: 30rpx;
  440. height: 35rpx;
  441. }
  442. }
  443. }
  444. }
  445. .flex {
  446. display: flex;
  447. align-items: center;
  448. }
  449. .action {
  450. margin-top: 30rpx;
  451. padding-left: 20rpx;
  452. padding-right: 20rpx;
  453. padding-bottom: 30rpx;
  454. .button {
  455. height: 80rpx;
  456. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  457. border-radius: 40rpx;
  458. font-size: 32rpx;
  459. font-weight: 400;
  460. color: #ffffff;
  461. line-height: 80rpx;
  462. }
  463. }
  464. .action-btn {
  465. margin-left: 45rpx;
  466. width: 121rpx;
  467. height: 61rpx;
  468. border: 1px solid rgba(255, 255, 255, 1);
  469. border-radius: 30rpx;
  470. background: rgba(255, 255, 255, 0.2);
  471. text-align: center;
  472. font-size: 30rpx;
  473. font-family: Microsoft YaHei;
  474. font-weight: 400;
  475. color: #ffffff;
  476. line-height: 61rpx;
  477. }
  478. .tag1 {
  479. padding: 5rpx;
  480. background: rgba(0, 179, 139, 0.5);
  481. border-radius: 6rpx;
  482. font-size: 22rpx;
  483. font-family: Microsoft YaHei;
  484. font-weight: 400;
  485. color: #ffffff;
  486. }
  487. .tag3 {
  488. padding: 5rpx;
  489. background: rgba(139, 112, 228, 0.5);
  490. border-radius: 6rpx;
  491. font-size: 22rpx;
  492. font-family: Microsoft YaHei;
  493. font-weight: 400;
  494. color: #ffffff;
  495. }
  496. .tag2 {
  497. padding: 5rpx;
  498. background: rgba(249, 97, 60, 0.5);
  499. border-radius: 6rpx;
  500. font-size: 22rpx;
  501. font-family: Microsoft YaHei;
  502. font-weight: 400;
  503. color: #ffffff;
  504. }
  505. .ul-item {
  506. padding: 5px 20rpx;
  507. display: flex;
  508. align-items: center;
  509. .item-value {
  510. padding: 20rpx;
  511. position: absolute;
  512. display: flex;
  513. align-items: center;
  514. // justify-content: space-around;
  515. width: 80%;
  516. .content {
  517. width: 51%;
  518. .title {
  519. font-size: 32rpx;
  520. font-family: Microsoft YaHei;
  521. font-weight: 400;
  522. color: #ffffff;
  523. }
  524. .tip {
  525. font-size: 24rpx;
  526. font-family: Microsoft YaHei;
  527. font-weight: 400;
  528. color: #ffffff;
  529. }
  530. }
  531. }
  532. .icon-tip {
  533. width: 100rpx;
  534. height: 100rpx;
  535. }
  536. .content {
  537. margin-left: 40rpx;
  538. }
  539. }
  540. .money {
  541. color: white;
  542. // float: right;
  543. }
  544. ::v-deep .u-mode-center-box {
  545. border-radius: 10rpx;
  546. }
  547. .squire {
  548. padding: 30rpx 30rpx 50rpx 50rpx;
  549. }
  550. .mask-close {
  551. text-align: right;
  552. }
  553. .icon-closed {
  554. width: 48rpx;
  555. height: 48rpx;
  556. }
  557. .mask-title {
  558. text-align: center;
  559. font-size: 32rpx;
  560. color: $uni-text-color-black;
  561. margin-bottom: 50rpx;
  562. }
  563. </style>