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

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