Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

recharge-two.vue 26KB

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