Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

order_payment.vue 15KB

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