您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

order_payment.vue 15KB

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