選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

order_payment.vue 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  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 gotoEditUserOrUnitInfo = () => {
  369. if (state.isValueCard == 1) {
  370. uni.switchTab({
  371. url: "/pages/order/order"
  372. })
  373. } else {
  374. uni.redirectTo({
  375. url: `/subpackage/orders/release-products?orderId=${state.orderId}`,
  376. });
  377. }
  378. }
  379. const state = reactive({
  380. isValueCard: 1, //卡的类型
  381. radiolist1: [], //选择卡的数据列表
  382. choiceCardShow: false, //选择卡的弹出框
  383. isSign: '',
  384. id: "",
  385. orderId: "",
  386. userType: 1, //1 个人 2单位
  387. type: 0, //0 客车 1货车
  388. vehiclePlateColor: "",
  389. data: {
  390. show: false,
  391. src: imgURL + "applyCard/edit.png",
  392. },
  393. dataArray: [],
  394. list: [
  395. {
  396. bg: imgURL + "applyCard/product-bg.png",
  397. icon: imgURL + "applyCard/wechat.png",
  398. title: "【货车】微信车主服务",
  399. tip: "绑定微信支付,无需绑定银行卡",
  400. },
  401. ],
  402. openid: ""
  403. });
  404. </script>
  405. <style lang="scss" scoped>
  406. ::v-deep .u-radio {
  407. display: flex !important;
  408. align-items: center !important;
  409. float: none !important;
  410. }
  411. ::v-deep .u-icon__icon {
  412. top: -4px !important;
  413. }
  414. .bottomTip {
  415. margin-top: 100rpx;
  416. text-align: center;
  417. font-size: 28rpx;
  418. font-family: Microsoft YaHei;
  419. font-weight: 400;
  420. color: #b3b3b3;
  421. }
  422. .content-value {
  423. position: relative;
  424. // margin-top: -50rpx;
  425. padding: 0rpx 30rpx;
  426. position: relative;
  427. .img-pos {
  428. position: absolute;
  429. left: 500rpx;
  430. top: -38rpx;
  431. right: 50rpx;
  432. .img-flex {
  433. display: flex;
  434. justify-content: space-between;
  435. align-items: center;
  436. .car-img {
  437. width: 86rpx;
  438. height: 42rpx;
  439. }
  440. .flag-img {
  441. width: 30rpx;
  442. height: 35rpx;
  443. }
  444. }
  445. }
  446. }
  447. .flex {
  448. display: flex;
  449. align-items: center;
  450. }
  451. .action {
  452. margin-top: 30rpx;
  453. padding-left: 20rpx;
  454. padding-right: 20rpx;
  455. padding-bottom: 30rpx;
  456. .button {
  457. height: 80rpx;
  458. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  459. border-radius: 40rpx;
  460. font-size: 32rpx;
  461. font-weight: 400;
  462. color: #ffffff;
  463. line-height: 80rpx;
  464. }
  465. }
  466. .action-btn {
  467. margin-left: 45rpx;
  468. width: 121rpx;
  469. height: 61rpx;
  470. border: 1px solid rgba(255, 255, 255, 1);
  471. border-radius: 30rpx;
  472. background: rgba(255, 255, 255, 0.2);
  473. text-align: center;
  474. font-size: 30rpx;
  475. font-family: Microsoft YaHei;
  476. font-weight: 400;
  477. color: #ffffff;
  478. line-height: 61rpx;
  479. }
  480. .tag1 {
  481. padding: 5rpx;
  482. background: rgba(0, 179, 139, 0.5);
  483. border-radius: 6rpx;
  484. font-size: 22rpx;
  485. font-family: Microsoft YaHei;
  486. font-weight: 400;
  487. color: #ffffff;
  488. }
  489. .tag3 {
  490. padding: 5rpx;
  491. background: rgba(139, 112, 228, 0.5);
  492. border-radius: 6rpx;
  493. font-size: 22rpx;
  494. font-family: Microsoft YaHei;
  495. font-weight: 400;
  496. color: #ffffff;
  497. }
  498. .tag2 {
  499. padding: 5rpx;
  500. background: rgba(249, 97, 60, 0.5);
  501. border-radius: 6rpx;
  502. font-size: 22rpx;
  503. font-family: Microsoft YaHei;
  504. font-weight: 400;
  505. color: #ffffff;
  506. }
  507. .ul-item {
  508. padding: 5px 20rpx;
  509. display: flex;
  510. align-items: center;
  511. .item-value {
  512. padding: 20rpx;
  513. position: absolute;
  514. display: flex;
  515. align-items: center;
  516. // justify-content: space-around;
  517. width: 80%;
  518. .content {
  519. width: 51%;
  520. .title {
  521. font-size: 32rpx;
  522. font-family: Microsoft YaHei;
  523. font-weight: 400;
  524. color: #ffffff;
  525. }
  526. .tip {
  527. font-size: 24rpx;
  528. font-family: Microsoft YaHei;
  529. font-weight: 400;
  530. color: #ffffff;
  531. }
  532. }
  533. }
  534. .icon-tip {
  535. width: 100rpx;
  536. height: 100rpx;
  537. }
  538. .content {
  539. margin-left: 40rpx;
  540. }
  541. }
  542. .money {
  543. color: white;
  544. // float: right;
  545. }
  546. ::v-deep .u-mode-center-box {
  547. border-radius: 10rpx;
  548. }
  549. .squire {
  550. padding: 30rpx 30rpx 50rpx 50rpx;
  551. }
  552. .mask-close {
  553. text-align: right;
  554. }
  555. .icon-closed {
  556. width: 48rpx;
  557. height: 48rpx;
  558. }
  559. .mask-title {
  560. text-align: center;
  561. font-size: 32rpx;
  562. color: $uni-text-color-black;
  563. margin-bottom: 50rpx;
  564. }
  565. </style>