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

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