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.

recharge-weixin.vue 25KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. <template>
  2. <view class="wrapper">
  3. <view class="account">
  4. <image :src="`${$imgUrl}common/bg-recharge.png`" class="head-bg" mode="aspectFill"></image>
  5. <view class="account-text">
  6. <view class="balance">
  7. <text class="balance-tit">账户余额</text>
  8. <text class="balance-val">{{card.money/100}}元</text>
  9. </view>
  10. <view class="right-box">
  11. <view class="no">账户编号:000100</view>
  12. <view class="btn btn-record" @click="goRecord()">账户充值记录</view>
  13. </view>
  14. </view>
  15. </view>
  16. <view class="input-box">
  17. <input v-model="state.money" placeholder="请输入金额" class="input" />
  18. <view class="tips">最低充值金额不小于10元</view>
  19. </view>
  20. <view class="tabs">
  21. <!-- <view class="tab-tit as-gravity-center-start">充值方式
  22. <u-input @click="state.transWayTypeShow = true" inputAlign="center" v-model="state.transWayName"
  23. type="select" />
  24. </view> -->
  25. <view class="tab-tit">在线充值</view>
  26. <view class="tab">
  27. <view v-for="(item,index) in state.moneryArray" @click="tableIndexAction(index)" :key="index"
  28. :class="{'item':state.moneryArray,'active':state.tableIndex===index}">{{item.name}}</view>
  29. </view>
  30. </view>
  31. <view class="btn btn-primary" @click="rechargeAction">立即充值</view>
  32. </view>
  33. <u-select v-model="state.transWayTypeShow" :list="state.transWayTypeList" @confirm="selectConfirm"></u-select>
  34. </template>
  35. <script setup lang="ts">
  36. import {
  37. stringToJson
  38. } from "@/utils/network/encryption";
  39. import {
  40. onLoad,
  41. onShow
  42. } from "@dcloudio/uni-app";
  43. import {
  44. quanCheck,
  45. quanApply,
  46. quanXf,
  47. cardCzPayResultCheck,
  48. cardCzApply,
  49. cardCzPay,
  50. cardCzPayResult,
  51. cardCzXFCheck,
  52. quanConfirm,
  53. wechatAppID,
  54. wechatPayConfigId,
  55. wechatSecret,
  56. aliPayConfigId,
  57. obtainUserId,
  58. getOpenidApi
  59. } from "@/utils/network/api.js";
  60. import {
  61. request
  62. } from "@/utils/network/request.js";
  63. import {
  64. reactive
  65. } from "vue";
  66. import {
  67. navTo
  68. } from "@/utils/utils"
  69. import {
  70. msg
  71. } from "@/utils/utils";
  72. import {
  73. getItem,
  74. StorageKeys,
  75. setItem
  76. } from "@/utils/storage";
  77. const datas = require("../../static/etcUtil/datas.js");
  78. const bluetoothUtil = require("../../static/etcUtil/index.js");
  79. const cmd = require("../../static/etcUtil/cmdConfig.js");
  80. const tools = require("../../static/etcUtil/tools.js");
  81. const NFCAPI = require('../../static/nfc/NFCAPI.js');
  82. const state = reactive({
  83. transWayTypeShow: false,
  84. transWayTypeList: [{
  85. label: "蓝牙",
  86. value: "blu",
  87. }, {
  88. label: "NFC",
  89. value: "nfc",
  90. }
  91. ],
  92. isShowBlue: false,
  93. moneryArray: [{
  94. name: '50元',
  95. value: 50
  96. }, {
  97. name: '100元',
  98. value: 100
  99. }, {
  100. name: '200元',
  101. value: 200
  102. }, {
  103. name: '300元',
  104. value: 300
  105. }, {
  106. name: '500元',
  107. value: 500
  108. }, {
  109. name: '1000元',
  110. value: 1000
  111. }],
  112. tableIndex: 0,
  113. openid: "",
  114. connectSuccess: undefined,
  115. fee: 5000,
  116. money: 50,
  117. orderNum: "",
  118. transWayName: "蓝牙",
  119. transWay: "blu", //“blu”为蓝牙充值方式、“nfc”为NFC充值方式
  120. cardId: "", //卡号 需要传参
  121. mockpreBalance: 2000, //fix:模拟余额 目前没有检测状态接口,第一次会模拟圈层检测来检测状态
  122. show: false,
  123. items: [{
  124. value: '0',
  125. name: '微信',
  126. checked: 'true'
  127. },
  128. {
  129. value: '1',
  130. name: '对公账户'
  131. }
  132. ],
  133. current: 0
  134. });
  135. const selectConfirm = (item : any) => {
  136. state.transWayName = item[0].label
  137. state.transWay = item[0].value
  138. };
  139. //读卡信息
  140. const card : any = reactive({
  141. cardId: "",
  142. netId: "",
  143. cardType: "",
  144. startTime: "",
  145. endTime: "",
  146. userName: "",
  147. idNum: "",
  148. vehiclePlate: "",
  149. vehiclePlateColor: "",
  150. color: "",
  151. version: "",
  152. type: "",
  153. favourable: "",
  154. money: undefined,
  155. v_userType: "",
  156. });
  157. onLoad((option) => {
  158. /*获取openId 用途:(用户支付)*/
  159. // #ifdef MP-WEIXIN
  160. getOpenID();/*传参*/
  161. // #endif
  162. console.log("开始option", option)
  163. state.transWay = option.transWay == 'nfc' ? "nfc" : "blu"
  164. // state.cardId = option.cardId;
  165. state.connectSuccess = option.connectSuccess;
  166. state.orderNum = getItem("orderNum");
  167. // 金额回填,本来是好的,但是他跳转了,跳转过来就得刷新页面,所以就是默认的5000
  168. if (option.fee) {
  169. state.fee = option.fee
  170. state.money = option.fee / 100
  171. } else {
  172. state.fee = state.money * 100; //元换成分
  173. }
  174. console.log("state.fee", option, state.fee)
  175. //跳转过来走圈存流程
  176. // connectSuccess 2 从选择方式进来去圈存检测 1 只读卡
  177. if (state.connectSuccess === "1") {
  178. /*读卡*/
  179. getCardId(1);
  180. } else {
  181. quanCheckActionTrue().then((val : any) => {
  182. console.log("圈层检测val", val)
  183. //如果 圈层检测正常
  184. if (val.chargeStatus === 1) {
  185. console.log(`进行充值检测`);
  186. czCheckAction().then((checkResult : any) => {
  187. //判断订单逻辑如果有订单充值 则直接拿到订单去链接蓝牙
  188. if (checkResult.orders && checkResult.orders.length > 0) {
  189. //拿到订单,存起来
  190. state.orderNum = checkResult.orders[0].orderNum;
  191. setItem("orderNum", state.orderNum);
  192. // 检测用户是否存在有半条流水
  193. } else {
  194. console.log('没有可修复的流水')
  195. }
  196. });
  197. } else {
  198. // 检测用户是否存在有半条流水
  199. }
  200. });
  201. }
  202. });
  203. function radioChange(evt) {
  204. console.log('输出内容', evt)
  205. state.transWay = evt.detail.value; //“blu”为蓝牙充值方式、“nfc”为NFC充值方式
  206. }
  207. function go(money) {
  208. let content = ""
  209. if (money) {
  210. content = '待消费订单' + money + '元'
  211. } else {
  212. content = '待消费订单'
  213. }
  214. uni.showModal({
  215. title: '提示',
  216. content: content,
  217. showCancel: false,
  218. success: (res) => {
  219. if (res.confirm) {
  220. //走蓝牙进行修复
  221. // quanCheckActionTrue().then((val : any) => {
  222. // console.log("圈层检测val", val)
  223. // //如果 圈层检测正常
  224. // if (val.chargeStatus === 1) {
  225. console.log(`进行充值检测`);
  226. czCheckAction().then((checkResult : any) => {
  227. //判断订单逻辑如果有订单充值 则直接拿到订单去链接蓝牙
  228. if (checkResult.orders && checkResult.orders.length > 0) {
  229. //拿到订单,存起来
  230. state.orderNum = checkResult.orders[0].orderNum;
  231. setItem("orderNum", state.orderNum);
  232. // 检测用户是否存在有半条流水
  233. getCardId()
  234. } else {
  235. console.log('没有可修复的流水')
  236. }
  237. });
  238. // } else {
  239. // // 检测用户是否存在有半条流水
  240. // let fixFee = val.fixFee / 100
  241. // console.log("fixFee", fixFee)
  242. // go(fixFee)
  243. // }
  244. // });
  245. } else if (res.cancel) {
  246. console.log('用户点击取消');
  247. }
  248. console.log("state.isShowBlue", state.isShowBlue)
  249. },
  250. fail: () => {
  251. }
  252. })
  253. }
  254. const tableIndexAction = (val : any) => {
  255. state.tableIndex = val
  256. state.money = state.moneryArray[val].value
  257. }
  258. /*点击充值按钮*/
  259. const rechargeAction = () => {
  260. state.fee = state.money * 100; //元换成分
  261. uni.showModal({
  262. title: '圈存确认',
  263. content: '您确定要充值圈存吗',
  264. success: function (res) {
  265. if (res.confirm) {
  266. /*进行圈层检测,此处检测仅为校验圈层状态来决定去哪里*/
  267. console.log("进行圈层检测");
  268. quanCheckActionTrue().then((val : any) => {
  269. console.log("圈存检测接口返回", val)
  270. //如果 圈层检测正常
  271. if (val.chargeStatus === 1) {
  272. console.log(`进行充值检测`);
  273. czCheckAction().then((checkResult : any) => {
  274. console.log("进行充值检测", checkResult)
  275. //判断订单逻辑如果有订单充值 则直接拿到订单去链接蓝牙
  276. if (checkResult.orders && checkResult.orders.length > 0) {
  277. state.fee = checkResult.orders[0]['rechargeMoney']
  278. state.money = checkResult.orders[0]['rechargeMoney'] / 100
  279. //拿到订单,存起来
  280. state.orderNum = checkResult.orders[0].orderNum;
  281. setItem("orderNum", state.orderNum);
  282. //链接蓝牙
  283. go(state.money)
  284. } else {
  285. cardCzApplyAction().then((applyResult : any) => {
  286. //拿到订单 存起来
  287. state.orderNum = applyResult.orderNum;
  288. setItem("orderNum", state.orderNum);
  289. //如果订单没有支付 走支付
  290. if (applyResult.orderStatus === "ORDER_NOT_PAY") {
  291. //走支付
  292. console.log("走支付");
  293. // #ifdef MP-WEIXIN
  294. wxPayment();
  295. // #endif
  296. // #ifdef MP-ALIPAY
  297. aliPayment()
  298. // #endif
  299. }
  300. });
  301. }
  302. });
  303. } else {
  304. //走蓝牙进行修复
  305. // 圈存检测异常,继续上次圈存 chargeStatus==2
  306. let fixFee = val.fixFee / 100
  307. console.log("fixFee", fixFee)
  308. go(fixFee)
  309. }
  310. });
  311. }
  312. }
  313. });
  314. };
  315. /*读卡*/
  316. const getCardId = (readCard) => {
  317. console.log("======获取卡信息======");
  318. let cmdArr = [
  319. cmd.HOME_DIRECTORY,
  320. //选择主目
  321. cmd.APPLICATION_DIRECTORY,
  322. //选择文件1001--DF01联网收费应用目录
  323. cmd.CMD_READBINARY,
  324. //15文件--卡片发行基本数据文件
  325. cmd.CMD_GETBALANCE,
  326. //钱包
  327. ];
  328. tools.showLoadingAlert("正在执行指令");
  329. transCmd(cmdArr, function (res : any) {
  330. if (readCard == 1) {
  331. // 只读卡号
  332. getCardIdReturnReadCard(res)
  333. } else {
  334. getCardIdReturn(res);
  335. }
  336. })
  337. };
  338. function getCardIdReturnReadCard(res : any) {
  339. tools.hideLoadingAlert();
  340. //10:写卡 20:写OBU
  341. let str = res[2].substring(res[2].length - 4, res[2].length);
  342. let str3 = res[3].substring(res[3].length - 4, res[3].length);
  343. if (str == "9000" || str3 == "9000") {
  344. if (res[2].length > 86 || res[3] >= 12) {
  345. state.cardId = res[2].substring(20, 40); //卡号
  346. card.cardId = res[2].substring(20, 40); //卡号
  347. card.money = parseInt(parseInt(res[3].substring(0, 8), 16), 10)
  348. console.log("======卡信息======", card, state.cardId);
  349. } else {
  350. console.error("CMD_READBINARY指令长度不符" + res[2]);
  351. tools.hideLoadingAlert();
  352. }
  353. }
  354. console.error("CMD_READBINARY指令长度不符" + res[2]);
  355. tools.hideLoadingAlert();
  356. }
  357. function getCardIdReturn(res : any) {
  358. tools.hideLoadingAlert();
  359. //10:写卡 20:写OBU
  360. let str = res[2].substring(res[2].length - 4, res[2].length);
  361. let str3 = res[3].substring(res[3].length - 4, res[3].length);
  362. if (str == "9000" || str3 == "9000") {
  363. if (res[2].length > 86 || res[3] >= 12) {
  364. state.cardId = res[2].substring(20, 40); //卡号
  365. card.cardId = res[2].substring(20, 40); //卡号
  366. card.startTime = res[2].substring(40, 48);
  367. card.endTime = res[2].substring(48, 56);
  368. card.version = res[2].substring(18, 19) >= 4 ? "4x" : "2x";
  369. card.netId = res[2].substring(20, 24);
  370. card.cardType = res[2].substring(28, 29) == 23 ? 1 : 2;
  371. card.vehiclePlateColor = parseInt(res[2].substring(82, 84), 16);
  372. (card.money = parseInt(parseInt(res[3].substring(0, 8), 16), 10)),
  373. console.log("======卡信息======", card, card.money);
  374. // if (card.cardId !== state.cardId) {
  375. // msg("设备卡信息与当前充值卡号不匹配,请核对卡号");
  376. // return;
  377. // }
  378. quanCheckActionTrue().then((val) => {
  379. checkQuanCengEvent(val);
  380. });
  381. } else {
  382. console.error("CMD_READBINARY指令长度不符" + res[2]);
  383. tools.hideLoadingAlert();
  384. }
  385. }
  386. console.error("CMD_READBINARY指令长度不符" + res[2]);
  387. tools.hideLoadingAlert();
  388. }
  389. const checkQuanCengEvent = (val : any) => {
  390. if (val.chargeStatus === 1) {
  391. let cmdArr = val.command.split(",");
  392. uni.showLoading({
  393. title: "写入中",
  394. });
  395. transCmd(cmdArr, function (res : any) {
  396. let response = res.toString();
  397. var dic = {
  398. command: val.command,
  399. cosResponse: response,
  400. };
  401. uni.hideLoading();
  402. cardCzXFCheckAction().then((xfRes) => {
  403. quanApplyAction(dic).then((value : any) => {
  404. console.log("圈层申请完后的结果");
  405. console.log(value.commandType, value);
  406. //圈存初始化验证通过 , 进行圈存
  407. if (value.commandType === 2) {
  408. uanConfirmAction(value);
  409. } else {
  410. quanApplyAction(value).then((values) => {
  411. console.log("圈层申请完后的结果");
  412. uanConfirmAction(values);
  413. });
  414. // msg("圈存初始化指令验证失败, 重新初始化");
  415. }
  416. });
  417. });
  418. });
  419. } else {
  420. let cmdArr = val.command.split(",");
  421. uni.showLoading({
  422. title: "写入中",
  423. });
  424. transCmd(cmdArr, function (res : any) {
  425. var status = res[1].substring(res[1].length - 4, res[1].length);
  426. console.log("打印状态");
  427. console.log(status);
  428. if (status === "9000") {
  429. console.log("修复指令入参");
  430. let response = res.toString();
  431. var dic = {
  432. command: val.command,
  433. cosResponse: response,
  434. rechargeId: val.rechargeId,
  435. };
  436. quanFixAction(dic).then((value : any) => {
  437. console.log(value);
  438. console.log("修复结果返回");
  439. var fixStatus = value.fixStatus;
  440. //圈存修复COS指令Response信息不足,重新进行修复初始化
  441. if (fixStatus === 3) {
  442. let xfcmdArr = value.command.split(",");
  443. bluetoothUtil.transCmd(xfcmdArr, "10", function (resValueData) {
  444. var status = resValueData[1].substring(
  445. resValueData[1].length - 4,
  446. resValueData[1].length
  447. );
  448. console.log("打印状态");
  449. console.log(status);
  450. if (status === "9000") {
  451. console.log(resValueData);
  452. var valueResponse = resValueData.toString();
  453. console.log(response);
  454. var applyDic = {
  455. command: value.command,
  456. cosResponse: valueResponse,
  457. rechargeId: value.rechargeId,
  458. };
  459. console.log("消费成功");
  460. quanApplyAction(applyDic).then((applyValue) => {
  461. uanConfirmAction(applyValue);
  462. });
  463. }
  464. });
  465. } else if (fixStatus === 2) {
  466. uanConfirmSucessAction(value).then((confirmResult) => {
  467. console.log("充值成功")
  468. getCardId(1)
  469. setTimeout(() => {
  470. msg("充值成功");
  471. navTo(`/pages/recharge/result`)
  472. }, 2000)
  473. });
  474. } else if (fixStatus === 1) {
  475. quanCheckActionTrue().then((val) => {
  476. checkQuanCengEvent(val);
  477. });
  478. }
  479. });
  480. uni.hideLoading();
  481. }
  482. });
  483. }
  484. };
  485. /*透传*/
  486. const transCmd = (cmd : any, click : any) => {
  487. if (state.transWay == 'blu') {
  488. bluetoothUtil.transCmd(cmd, "10", function (res : any) {
  489. click(res);
  490. });
  491. } else {
  492. //nfc透传
  493. NFCAPI.transCmd(cmd, function (res : any) {
  494. tools.hideLoadingAlert();
  495. if (res.code == 0) {
  496. click(res.data);
  497. } else {
  498. //透传失败返回
  499. tools.alertF(res.msg);
  500. }
  501. });
  502. }
  503. };
  504. const quanCheckActionTrue = () => {
  505. console.log("进行真实圈层检测");
  506. var data = {
  507. cardId: card.cardId,
  508. fee: state.fee,
  509. preBalance: card.money,
  510. tradeType: 14,
  511. };
  512. const options = {
  513. type: 2,
  514. data: data,
  515. method: "POST",
  516. showLoading: true,
  517. };
  518. return new Promise(async (resolve, reject) => {
  519. const res = await request(quanCheck, options);
  520. const data = stringToJson(res.bizContent);
  521. resolve(data);
  522. }).catch((error) => {
  523. reject(error);
  524. });
  525. };
  526. /*充值消费*/
  527. const cardCzXFCheckAction = () => {
  528. var data = {
  529. cardId: card.cardId, //修复初始化的指令
  530. openId: getItem(StorageKeys.OpenId), //修复初始化结果
  531. orderNum: state.orderNum, //充值流水号
  532. };
  533. const options = {
  534. type: 2,
  535. data: data,
  536. method: "POST",
  537. showLoading: true,
  538. };
  539. return new Promise(async (resolve, reject) => {
  540. const res = await request(cardCzXFCheck, options);
  541. const data = stringToJson(res.bizContent);
  542. resolve(data);
  543. }).catch((error) => {
  544. reject(error);
  545. });
  546. };
  547. /*圈存修复*/
  548. const quanFixAction = (val) => {
  549. var data = {
  550. command: val.command, //修复初始化的指令
  551. cosResponse: val.cosResponse, //修复初始化结果
  552. rechargeId: val.rechargeId, //充值流水号
  553. };
  554. const options = {
  555. type: 2,
  556. data: data,
  557. method: "POST",
  558. showLoading: true,
  559. };
  560. return new Promise(async (resolve, reject) => {
  561. const res = await request(quanXf, options);
  562. const data = stringToJson(res.bizContent);
  563. resolve(data);
  564. }).catch((error) => {
  565. reject(error);
  566. });
  567. };
  568. /*圈层申请*/
  569. const quanApplyAction = (data) => {
  570. console.log("圈层申请data====", data, data.rechargeId)
  571. var form = {
  572. cardId: card.cardId,
  573. fee: state.fee,
  574. preBalance: card.money,
  575. tradeType: 14,
  576. command: data.command,
  577. cosResponse: data.cosResponse,
  578. orderId: state.orderNum,
  579. rechargeId: data.rechargeId,
  580. openId: getItem(StorageKeys.OpenId)
  581. };
  582. const options = {
  583. type: 2,
  584. data: form,
  585. method: "POST",
  586. showLoading: true,
  587. };
  588. return new Promise(async (resolve, reject) => {
  589. const res = await request(quanApply, options);
  590. const data = stringToJson(res.bizContent);
  591. resolve(data);
  592. }).catch((error) => {
  593. reject(error);
  594. });
  595. };
  596. /*圈层确认*/
  597. const uanConfirmAction = (data : any) => {
  598. console.log("圈层确认进入");
  599. let cmdArr = data.command.split(",");
  600. console.log(cmdArr);
  601. transCmd(cmdArr, function (res : any) {
  602. console.log("圈层透传");
  603. console.log(res);
  604. var arraylenth = res.length;
  605. var status = res[arraylenth - 1].substring(
  606. res[arraylenth - 1].length - 4,
  607. res[arraylenth - 1].length
  608. );
  609. console.log("打印圈层确认指令状态");
  610. if (status === "9000") {
  611. var form = {
  612. command: data.command,
  613. cosResponse: res.toString(),
  614. rechargeId: data.rechargeId,
  615. paidAmount: state.fee,
  616. giftAmount: 0,
  617. };
  618. const options = {
  619. type: 2,
  620. data: form,
  621. method: "POST",
  622. showLoading: true,
  623. };
  624. return new Promise(async () => {
  625. const res = await request(quanConfirm, options);
  626. const data = stringToJson(res.bizContent);
  627. console.log("data充值成功", data);
  628. getCardId(1)
  629. setTimeout(() => {
  630. msg("充值成功");
  631. navTo(`/pages/recharge/result`)
  632. }, 2000)
  633. }).catch((error) => {
  634. console.log('输出内容', error)
  635. });
  636. }
  637. });
  638. };
  639. const uanConfirmSucessAction = (data) => {
  640. var form = {
  641. command: data.command,
  642. cosResponse: "9000",
  643. rechargeId: data.rechargeId,
  644. paidAmount: state.fee,
  645. giftAmount: 0,
  646. };
  647. const options = {
  648. type: 2,
  649. data: form,
  650. method: "POST",
  651. showLoading: true,
  652. };
  653. return new Promise(async (resolve, reject) => {
  654. const res = await request(quanConfirm, options);
  655. const data = stringToJson(res.bizContent);
  656. resolve(data);
  657. console.log("uanConfirmSucessAction", data)
  658. }).catch((error) => {
  659. reject(error);
  660. });
  661. };
  662. /*充值检测*/
  663. const czCheckAction = () => {
  664. var form = {
  665. cardId: state.cardId,
  666. openId: getItem(StorageKeys.OpenId),
  667. };
  668. const options = {
  669. type: 2,
  670. data: form,
  671. method: "POST",
  672. showLoading: true,
  673. };
  674. return new Promise(async (resolve, reject) => {
  675. const res = await request(cardCzPayResultCheck, options);
  676. const data = stringToJson(res.bizContent);
  677. console.log("充值检测", data)
  678. resolve(data);
  679. }).catch((error) => {
  680. reject(error);
  681. });
  682. };
  683. /*充值申请*/
  684. const cardCzApplyAction = () => {
  685. var data = {
  686. cardId: state.cardId,
  687. openId: getItem(StorageKeys.OpenId),
  688. rechargeMoney: state.fee,
  689. };
  690. const options = {
  691. type: 2,
  692. data: data,
  693. method: "POST",
  694. showLoading: true,
  695. };
  696. return new Promise(async (resolve, reject) => {
  697. const res = await request(cardCzApply, options);
  698. const data = stringToJson(res.bizContent);
  699. resolve(data);
  700. }).catch((error) => {
  701. reject(error);
  702. });
  703. };
  704. //获取微信小程序openid
  705. const getOpenID = () => {
  706. uni.login({
  707. provider: "weixin",
  708. success: function (e) {
  709. getOpenid(e.code);
  710. },
  711. fail: function () {
  712. msg("获取不到oppenId,请检查AppID和Secret是否争取");
  713. },
  714. });
  715. };
  716. const getOpenid = (code) => {
  717. const options = {
  718. type: 2,
  719. data: {
  720. "jsCode": code
  721. },
  722. method: "POST",
  723. showLoading: true,
  724. };
  725. // #ifdef MP-WEIXIN
  726. request(getOpenidApi, options).then((res) => {
  727. const result = stringToJson(res.bizContent);
  728. console.log("获取微信小程序openid", result);
  729. const openidData = stringToJson(result.data);
  730. // setItem("QYorder", result.data);
  731. state.openid = openidData.openid
  732. });
  733. // #endif
  734. }
  735. //掉起微信支付
  736. const wxPayment = () => {
  737. // #ifdef MP-WEIXIN
  738. const options = {
  739. type: 2,
  740. data: {
  741. openId: getItem(StorageKeys.OpenId),
  742. wxOpenId: state.openid,
  743. cardId: state.cardId,
  744. orderNum: state.orderNum,
  745. payConfigId: wechatPayConfigId,
  746. body: "储值卡充值",
  747. },
  748. method: "POST",
  749. showLoading: true,
  750. };
  751. request(cardCzPay, options).then((res) => {
  752. const data = stringToJson(res.bizContent);
  753. uni.requestPayment({
  754. provider: "wxpay",
  755. orderInfo: "",
  756. timeStamp: data.timestamp,
  757. nonceStr: data.noncestr,
  758. package: data.wxPackage ? data.wxPackage : "",
  759. signType: data.signType,
  760. paySign: data.sign,
  761. success: function () {
  762. //回调订单状态
  763. console.log("回调订单状态");
  764. checkOrder();
  765. },
  766. fail: function (err) {
  767. confirm(err, () => { }, "支付失败", false);
  768. },
  769. });
  770. });
  771. // #endif
  772. };
  773. //掉起支付宝支付
  774. const aliPayment = () => {
  775. // #ifdef MP-ALIPAY
  776. my.getAuthCode({
  777. scopes: 'auth_base',
  778. success: res => {
  779. const optionsUser = {
  780. type: 2,
  781. data: {
  782. payConfigId: aliPayConfigId,
  783. code: res.authCode
  784. },
  785. method: "POST",
  786. showLoading: true,
  787. };
  788. request(obtainUserId, optionsUser).then((res) => {
  789. const data = stringToJson(res.bizContent);
  790. const optionsali = {
  791. type: 2,
  792. data: {
  793. openId: getItem(StorageKeys.OpenId),
  794. wxOpenId: data.openId,
  795. cardId: state.cardId,
  796. orderNum: state.orderNum,
  797. payConfigId: "6a9a54123456578934edfre132b1234",
  798. body: "储值卡充值",
  799. },
  800. method: "POST",
  801. showLoading: true,
  802. };
  803. request(cardCzPay, optionsali).then((res) => {
  804. const data = stringToJson(res.bizContent);
  805. my.tradePay({
  806. // 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号 trade_no
  807. tradeNO: data.tranPackage,
  808. success: res => {
  809. console.log("支付成功", res);
  810. checkOrder();
  811. },
  812. fail: res => {
  813. confirm(res, () => { }, "支付失败", false);
  814. },
  815. });
  816. });
  817. });
  818. },
  819. fail: err => {
  820. console.log('my.getAuthCode 调用失败', err)
  821. }
  822. });
  823. // #endif
  824. };
  825. //支付成功改变订单状态
  826. const checkOrder = () => {
  827. const options = {
  828. type: 2,
  829. data: {
  830. cardId: state.cardId,
  831. openId: getItem(StorageKeys.OpenId),
  832. orderNum: state.orderNum,
  833. },
  834. method: "POST",
  835. showLoading: true,
  836. };
  837. request(cardCzPayResult, options).then((res) => {
  838. const data = stringToJson(res.bizContent);
  839. if (data.tradeState === "SUCCESS") {
  840. getCardId();
  841. }
  842. console.log(data);
  843. });
  844. };
  845. const goRecord = () => {
  846. uni.navigateTo({
  847. url: `/subpackage/personal-center/consumption-record?cardId=${state.cardId}`
  848. })
  849. }
  850. </script>
  851. <style>
  852. .account {
  853. height: 224rpx;
  854. width: 690rpx;
  855. margin: 30rpx;
  856. position: relative;
  857. }
  858. .account .account-text {
  859. display: flex;
  860. justify-content: space-between;
  861. padding: 20rpx 50rpx;
  862. height: 100%;
  863. }
  864. .account .balance {
  865. display: flex;
  866. flex-direction: column;
  867. justify-content: center;
  868. align-items: flex-start;
  869. color: #ffffff;
  870. }
  871. .account .balance-tit {
  872. font-size: 26rpx;
  873. margin-bottom: 10rpx;
  874. }
  875. .account .balance-val {
  876. font-size: 56rpx;
  877. }
  878. .account .right-box {
  879. display: flex;
  880. flex-direction: column;
  881. justify-content: flex-start;
  882. align-items: flex-end;
  883. }
  884. .account .right-box .no {
  885. font-size: 26rpx;
  886. color: #ffffff;
  887. }
  888. .account .right-box .btn {
  889. font-size: 26rpx;
  890. padding: 0 20rpx;
  891. box-sizing: border-box;
  892. height: 42rpx;
  893. line-height: 42rpx;
  894. color: #28d20f;
  895. background: #ffffff;
  896. border-radius: 21rpx;
  897. display: inline-block;
  898. margin-top: 18rpx;
  899. }
  900. .account .head-bg {
  901. width: 690rpx;
  902. height: 224rpx;
  903. position: absolute;
  904. left: 0;
  905. top: 0;
  906. z-index: -99;
  907. }
  908. .input-box {
  909. display: flex;
  910. flex-direction: column;
  911. justify-content: center;
  912. align-items: center;
  913. padding: 20rpx 0;
  914. }
  915. .input-box .input {
  916. width: 430rpx;
  917. height: 98rpx;
  918. line-height: 98rpx;
  919. background: #f8f8f8;
  920. border: 1px solid #999999;
  921. border-radius: 6rpx;
  922. font-size: 30rpx;
  923. text-align: center;
  924. }
  925. .input-box .tips {
  926. color: #666666;
  927. font-size: 26rpx;
  928. margin-top: 18rpx;
  929. }
  930. .tabs {}
  931. .tabs .tab-tit {
  932. font-size: 30rpx;
  933. color: #333;
  934. padding: 45rpx 0 22rpx 30rpx;
  935. }
  936. .tabs .tab {
  937. display: flex;
  938. flex-wrap: wrap;
  939. justify-content: space-evenly;
  940. }
  941. .tabs .tab .item {
  942. width: 210rpx;
  943. height: 100rpx;
  944. background: #f6fff7;
  945. border: 1px solid #dcdde1;
  946. box-sizing: border-box;
  947. line-height: 100rpx;
  948. border-radius: 6rpx;
  949. text-align: center;
  950. margin-bottom: 24rpx;
  951. color: #333333;
  952. font-size: 32rpx;
  953. }
  954. .tabs .tab .item.active {
  955. border: 1px solid #24cc49;
  956. color: #24cc49;
  957. }
  958. .btn-primary {
  959. width: 670rpx;
  960. height: 80rpx;
  961. line-height: 80rpx;
  962. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  963. border-radius: 40rpx;
  964. font-size: 32rpx;
  965. color: #ffffff;
  966. margin: 200rpx 40rpx 0;
  967. text-align: center;
  968. }
  969. .uni-list {
  970. padding: 120rpx 10rpx 0 10rpx;
  971. font-size: 34rpx;
  972. }
  973. label {
  974. display: flex;
  975. justify-content: space-between;
  976. margin-top: 30rpx;
  977. }
  978. </style>