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 17KB

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