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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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. // #endif
  191. var data = {
  192. orderId: state.orderId,
  193. source: source //请求方来源
  194. };
  195. const options = {
  196. type: 2,
  197. data: data,
  198. method: "POST",
  199. showLoading: true,
  200. };
  201. console.log("输出内容", options);
  202. request(PAYDETECTION, options).then((res) => {
  203. const data = stringToJson(res.bizContent);
  204. console.log(data);
  205. if (data.paymentStatus == 'ALLSUCCESS') {
  206. gotoEditUserOrUnitInfo()
  207. }
  208. state.dataArray = data.datas;
  209. for (let i = 0; i < state.dataArray.length; i++) {
  210. if (state.dataArray[i].payType === 'HANDLE') {
  211. state.dataArray[i].payName = '权益金'
  212. } else if (state.dataArray[i].payType === 'MARGIN') {
  213. state.dataArray[i].payName = '保证金'
  214. } else if (state.dataArray[i].payType === 'PRESTORE') {
  215. state.dataArray[i].payName = '预存金'
  216. } else if (state.dataArray[i].payType === 'EQUITY') {
  217. state.dataArray[i].payName = '权益费'
  218. } else if (state.dataArray[i].payType === 'REPAIROBU') {
  219. state.dataArray[i].payName = '增补obu'
  220. } else if (state.dataArray[i].payType === 'CHANGECARD') {
  221. state.dataArray[i].payName = '更换卡'
  222. } else if (state.dataArray[i].payType === 'CHANGEOBU') {
  223. state.dataArray[i].payName = '更换签'
  224. } else if (state.dataArray[i].payType === 'CHANGEALL') {
  225. state.dataArray[i].payName = '更换卡签'
  226. } else {
  227. state.dataArray[i].payName = '未知费'
  228. }
  229. if (state.dataArray[i].payStatus === 'SUCCESS') {
  230. state.dataArray[i].payStatusName = '已支付'
  231. } else if (state.dataArray[i].payStatus === 'PAYING') {
  232. state.dataArray[i].payStatusName = '支付中'
  233. } else if (state.dataArray[i].payStatus === 'FAILED') {
  234. state.dataArray[i].payStatusName = '支付失败'
  235. } else if (state.dataArray[i].payStatus === 'UNPAY') {
  236. state.dataArray[i].payStatusName = '未支付'
  237. } else if (state.dataArray[i].payStatus === 'CLOSED') {
  238. state.dataArray[i].payStatusName = '已关闭'
  239. } else if (state.dataArray[i].payStatus === 'CANCELED') {
  240. state.dataArray[i].payStatusName = '已撤销'
  241. } else if (state.dataArray[i].payStatus === 'REFUND') {
  242. state.dataArray[i].payStatusName = '转入退费'
  243. } else {
  244. state.dataArray[i].payStatusName = '未知'
  245. }
  246. }
  247. console.log("state.dataArray", state.dataArray)
  248. });
  249. }
  250. onLoad((option : any) => {
  251. console.log("传递过来的到支付页面", option)
  252. state.orderId = option.orderId;
  253. state.isValueCard = option.isValueCard;
  254. let source = ""
  255. // #ifdef MP-ALIPAY
  256. imageUrl = imgURL + "applyCard/alibaba.png";
  257. source = "ALI"
  258. // #endif
  259. // #ifdef MP-WEIXIN
  260. imageUrl = imgURL + "applyCard/wechat.png";
  261. source = "WECHAT"
  262. // #endif
  263. var data = {
  264. orderId: state.orderId,
  265. source: source //请求方来源
  266. };
  267. const options = {
  268. type: 2,
  269. data: data,
  270. method: "POST",
  271. showLoading: true,
  272. };
  273. console.log("输出内容", options);
  274. request(PAYDETECTION, options).then((res) => {
  275. // console.log(res.bizContent);
  276. const data = stringToJson(res.bizContent);
  277. console.log(data);
  278. if (data.paymentStatus == 'ALLSUCCESS') {
  279. // isValueCard 1 储值卡 2 记账卡
  280. if (state.isValueCard == 1) {
  281. uni.switchTab({
  282. url: "/pages/order/order"
  283. })
  284. } else {
  285. uni.redirectTo({
  286. url: `/subpackage/orders/release-products?orderId=${state.orderId}`,
  287. });
  288. }
  289. }
  290. state.dataArray = data.datas;
  291. for (let i = 0; i < state.dataArray.length; i++) {
  292. if (state.dataArray[i].payType === 'HANDLE') {
  293. state.dataArray[i].payName = '权益金'
  294. } else if (state.dataArray[i].payType === 'MARGIN') {
  295. state.dataArray[i].payName = '保证金'
  296. } else if (state.dataArray[i].payType === 'PRESTORE') {
  297. state.dataArray[i].payName = '预存金'
  298. } else if (state.dataArray[i].payType === 'EQUITY') {
  299. state.dataArray[i].payName = '权益费'
  300. } else if (state.dataArray[i].payType === 'REPAIROBU') {
  301. state.dataArray[i].payName = '增补obu'
  302. } else if (state.dataArray[i].payType === 'CHANGECARD') {
  303. state.dataArray[i].payName = '更换卡'
  304. } else if (state.dataArray[i].payType === 'CHANGEOBU') {
  305. state.dataArray[i].payName = '更换签'
  306. } else if (state.dataArray[i].payType === 'CHANGEALL') {
  307. state.dataArray[i].payName = '更换卡签'
  308. } else {
  309. state.dataArray[i].payName = '未知费'
  310. }
  311. if (state.dataArray[i].payStatus === 'SUCCESS') {
  312. state.dataArray[i].payStatusName = '已支付'
  313. } else if (state.dataArray[i].payStatus === 'PAYING') {
  314. state.dataArray[i].payStatusName = '支付中'
  315. } else if (state.dataArray[i].payStatus === 'FAILED') {
  316. state.dataArray[i].payStatusName = '支付失败'
  317. } else if (state.dataArray[i].payStatus === 'UNPAY') {
  318. state.dataArray[i].payStatusName = '未支付'
  319. } else if (state.dataArray[i].payStatus === 'CLOSED') {
  320. state.dataArray[i].payStatusName = '已关闭'
  321. } else if (state.dataArray[i].payStatus === 'CANCELED') {
  322. state.dataArray[i].payStatusName = '已撤销'
  323. } else if (state.dataArray[i].payStatus === 'REFUND') {
  324. state.dataArray[i].payStatusName = '转入退费'
  325. } else {
  326. state.dataArray[i].payStatusName = '未知'
  327. }
  328. }
  329. console.log("state.dataArray", state.dataArray)
  330. });
  331. });
  332. //解析URL获取参数
  333. const getRequest = (urlStr) => {
  334. if (typeof urlStr == "undefined") {
  335. // 获取url中"?"符后的字符串
  336. var url = decodeURI(location.search);
  337. } else {
  338. var url = "?" + urlStr.split("?")[1];
  339. }
  340. var theRequest = new Object();
  341. if (url.indexOf("?") != -1) {
  342. var str = url.substr(1);
  343. var strs = str.split("&");
  344. for (var i = 0; i < strs.length; i++) {
  345. theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
  346. }
  347. }
  348. return theRequest;
  349. };
  350. //监听页面滚动
  351. onPageScroll((e) => {
  352. scrollTop.value = e.scrollTop;
  353. });
  354. // isValueCard 1 储值卡 2 记账卡
  355. const gotoEditUserOrUnitInfo = () => {
  356. if (state.isValueCard == 1) {
  357. uni.switchTab({
  358. url: "/pages/order/order"
  359. })
  360. } else {
  361. uni.redirectTo({
  362. url: `/subpackage/orders/release-products?orderId=${state.orderId}`,
  363. });
  364. }
  365. }
  366. const state = reactive({
  367. isValueCard: 1, //卡的类型
  368. radiolist1: [], //选择卡的数据列表
  369. choiceCardShow: false, //选择卡的弹出框
  370. isSign: '',
  371. id: "",
  372. orderId: "",
  373. userType: 1, //1 个人 2单位
  374. type: 0, //0 客车 1货车
  375. vehiclePlateColor: "",
  376. data: {
  377. show: false,
  378. src: imgURL + "applyCard/edit.png",
  379. },
  380. dataArray: [],
  381. list: [
  382. {
  383. bg: imgURL + "applyCard/product-bg.png",
  384. icon: imgURL + "applyCard/wechat.png",
  385. title: "【货车】微信车主服务",
  386. tip: "绑定微信支付,无需绑定银行卡",
  387. },
  388. ],
  389. openid: ""
  390. });
  391. </script>
  392. <style lang="scss" scoped>
  393. ::v-deep .u-radio {
  394. display: flex !important;
  395. align-items: center !important;
  396. float: none !important;
  397. }
  398. ::v-deep .u-icon__icon {
  399. top: -4px !important;
  400. }
  401. .bottomTip {
  402. margin-top: 100rpx;
  403. text-align: center;
  404. font-size: 28rpx;
  405. font-family: Microsoft YaHei;
  406. font-weight: 400;
  407. color: #b3b3b3;
  408. }
  409. .content-value {
  410. position: relative;
  411. // margin-top: -50rpx;
  412. padding: 0rpx 30rpx;
  413. position: relative;
  414. .img-pos {
  415. position: absolute;
  416. left: 500rpx;
  417. top: -38rpx;
  418. right: 50rpx;
  419. .img-flex {
  420. display: flex;
  421. justify-content: space-between;
  422. align-items: center;
  423. .car-img {
  424. width: 86rpx;
  425. height: 42rpx;
  426. }
  427. .flag-img {
  428. width: 30rpx;
  429. height: 35rpx;
  430. }
  431. }
  432. }
  433. }
  434. .flex {
  435. display: flex;
  436. align-items: center;
  437. }
  438. .action {
  439. margin-top: 30rpx;
  440. padding-left: 20rpx;
  441. padding-right: 20rpx;
  442. padding-bottom: 30rpx;
  443. .button {
  444. height: 80rpx;
  445. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  446. border-radius: 40rpx;
  447. font-size: 32rpx;
  448. font-weight: 400;
  449. color: #ffffff;
  450. line-height: 80rpx;
  451. }
  452. }
  453. .action-btn {
  454. margin-left: 45rpx;
  455. width: 121rpx;
  456. height: 61rpx;
  457. border: 1px solid rgba(255, 255, 255, 1);
  458. border-radius: 30rpx;
  459. background: rgba(255, 255, 255, 0.2);
  460. text-align: center;
  461. font-size: 30rpx;
  462. font-family: Microsoft YaHei;
  463. font-weight: 400;
  464. color: #ffffff;
  465. line-height: 61rpx;
  466. }
  467. .tag1 {
  468. padding: 5rpx;
  469. background: rgba(0, 179, 139, 0.5);
  470. border-radius: 6rpx;
  471. font-size: 22rpx;
  472. font-family: Microsoft YaHei;
  473. font-weight: 400;
  474. color: #ffffff;
  475. }
  476. .tag3 {
  477. padding: 5rpx;
  478. background: rgba(139, 112, 228, 0.5);
  479. border-radius: 6rpx;
  480. font-size: 22rpx;
  481. font-family: Microsoft YaHei;
  482. font-weight: 400;
  483. color: #ffffff;
  484. }
  485. .tag2 {
  486. padding: 5rpx;
  487. background: rgba(249, 97, 60, 0.5);
  488. border-radius: 6rpx;
  489. font-size: 22rpx;
  490. font-family: Microsoft YaHei;
  491. font-weight: 400;
  492. color: #ffffff;
  493. }
  494. .ul-item {
  495. padding: 5px 20rpx;
  496. display: flex;
  497. align-items: center;
  498. .item-value {
  499. padding: 20rpx;
  500. position: absolute;
  501. display: flex;
  502. align-items: center;
  503. // justify-content: space-around;
  504. width: 80%;
  505. .content {
  506. width: 51%;
  507. .title {
  508. font-size: 32rpx;
  509. font-family: Microsoft YaHei;
  510. font-weight: 400;
  511. color: #ffffff;
  512. }
  513. .tip {
  514. font-size: 24rpx;
  515. font-family: Microsoft YaHei;
  516. font-weight: 400;
  517. color: #ffffff;
  518. }
  519. }
  520. }
  521. .icon-tip {
  522. width: 100rpx;
  523. height: 100rpx;
  524. }
  525. .content {
  526. margin-left: 40rpx;
  527. }
  528. }
  529. .money {
  530. color: white;
  531. // float: right;
  532. }
  533. ::v-deep .u-mode-center-box {
  534. border-radius: 10rpx;
  535. }
  536. .squire {
  537. padding: 30rpx 30rpx 50rpx 50rpx;
  538. }
  539. .mask-close {
  540. text-align: right;
  541. }
  542. .icon-closed {
  543. width: 48rpx;
  544. height: 48rpx;
  545. }
  546. .mask-title {
  547. text-align: center;
  548. font-size: 32rpx;
  549. color: $uni-text-color-black;
  550. margin-bottom: 50rpx;
  551. }
  552. </style>