You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

order_payment.vue 15KB

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