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-two.vue 26KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049
  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. // setItem("QYorder", result.data);
  701. state.openid = openidData.openid
  702. /*读卡*/
  703. getCardId(1);
  704. });
  705. // #endif
  706. }
  707. //掉起微信支付
  708. const wxPayment = () => {
  709. // #ifdef MP-WEIXIN
  710. const options = {
  711. type: 2,
  712. data: {
  713. openId: getItem(StorageKeys.OpenId),
  714. wxOpenId: state.openid,
  715. cardId: state.cardId,
  716. orderNum: state.orderNum,
  717. payConfigId: wechatPayConfigId,
  718. body: "储值卡充值",
  719. },
  720. method: "POST",
  721. showLoading: true,
  722. };
  723. request(cardCzPay, options).then((res) => {
  724. const data = stringToJson(res.bizContent);
  725. uni.requestPayment({
  726. provider: "wxpay",
  727. orderInfo: "",
  728. timeStamp: data.timestamp,
  729. nonceStr: data.noncestr,
  730. package: data.wxPackage ? data.wxPackage : "",
  731. signType: data.signType,
  732. paySign: data.sign,
  733. success: function () {
  734. //回调订单状态
  735. console.log("回调订单状态");
  736. checkOrder();
  737. },
  738. fail: function (err) {
  739. confirm(err, () => { }, "支付失败", false);
  740. },
  741. });
  742. });
  743. // #endif
  744. };
  745. //掉起支付宝支付
  746. const aliPayment = () => {
  747. // #ifdef MP-ALIPAY
  748. my.getAuthCode({
  749. scopes: 'auth_base',
  750. success: res => {
  751. const optionsUser = {
  752. type: 2,
  753. data: {
  754. payConfigId: aliPayConfigId,
  755. code: res.authCode
  756. },
  757. method: "POST",
  758. showLoading: true,
  759. };
  760. request(obtainUserId, optionsUser).then((res) => {
  761. const data = stringToJson(res.bizContent);
  762. const optionsali = {
  763. type: 2,
  764. data: {
  765. openId: getItem(StorageKeys.OpenId),
  766. wxOpenId: data.openId,
  767. cardId: state.cardId,
  768. orderNum: state.orderNum,
  769. payConfigId: "6a9a54123456578934edfre132b1234",
  770. body: "储值卡充值",
  771. },
  772. method: "POST",
  773. showLoading: true,
  774. };
  775. request(cardCzPay, optionsali).then((res) => {
  776. const data = stringToJson(res.bizContent);
  777. my.tradePay({
  778. // 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号 trade_no
  779. tradeNO: data.tranPackage,
  780. success: res => {
  781. console.log("支付成功", res);
  782. checkOrder();
  783. },
  784. fail: res => {
  785. confirm(res, () => { }, "支付失败", false);
  786. },
  787. });
  788. });
  789. });
  790. },
  791. fail: err => {
  792. console.log('my.getAuthCode 调用失败', err)
  793. }
  794. });
  795. // #endif
  796. };
  797. //支付成功改变订单状态
  798. const checkOrder = () => {
  799. const options = {
  800. type: 2,
  801. data: {
  802. cardId: state.cardId,
  803. openId: getItem(StorageKeys.OpenId),
  804. orderNum: state.orderNum,
  805. },
  806. method: "POST",
  807. showLoading: true,
  808. };
  809. request(cardCzPayResult, options).then((res) => {
  810. const data = stringToJson(res.bizContent);
  811. if (data.tradeState === "SUCCESS") {
  812. getCardId();
  813. }
  814. console.log(data);
  815. });
  816. };
  817. const goRecord = () => {
  818. uni.navigateTo({
  819. url: `/subpackage/personal-center/consumption-record?cardId=${state.cardId}`
  820. })
  821. }
  822. // 校验金额输入框
  823. const checkNum = (event) => {
  824. let sNum = event.target.value.toString(); //先转换成字符串类
  825. if (sNum.indexOf('.') == 0) {//第一位就是 .
  826. console.log('first str is .')
  827. sNum = '0' + sNum
  828. }
  829. sNum = sNum.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
  830. sNum = sNum.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
  831. sNum = sNum.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
  832. sNum = sNum.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');//只能输入两个小数
  833. //以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额
  834. if (sNum.indexOf(".") < 0 && sNum != "") {
  835. sNum = parseFloat(sNum);
  836. }
  837. console.log('输入的值1', sNum)
  838. setTimeout(() => {
  839. state.money = sNum
  840. }, 20)
  841. }
  842. const readCard = () => {
  843. let cmdArr = [
  844. cmd.HOME_DIRECTORY,
  845. //选择主目
  846. cmd.APPLICATION_DIRECTORY,
  847. //选择文件1001--DF01联网收费应用目录
  848. cmd.CMD_READBINARY,
  849. //15文件--卡片发行基本数据文件
  850. cmd.CMD_GETBALANCE,
  851. //钱包
  852. ];
  853. tools.showLoadingAlert("正在执行指令");
  854. transCmd(cmdArr, function (res : any) {
  855. tools.hideLoadingAlert();
  856. //10:写卡 20:写OBU
  857. let str = res[2].substring(res[2].length - 4, res[2].length);
  858. let str3 = res[3].substring(res[3].length - 4, res[3].length);
  859. if (str == "9000" || str3 == "9000") {
  860. if (res[2].length > 86 || res[3] >= 12) {
  861. state.cardId = res[2].substring(20, 40); //卡号
  862. card.cardId = res[2].substring(20, 40); //卡号
  863. card.money = parseInt(parseInt(res[3].substring(0, 8), 16), 10)
  864. }
  865. }
  866. })
  867. }
  868. </script>
  869. <style>
  870. .account {
  871. height: 224rpx;
  872. width: 690rpx;
  873. margin: 30rpx;
  874. position: relative;
  875. }
  876. .account .account-text {
  877. display: flex;
  878. justify-content: space-between;
  879. padding: 20rpx 50rpx;
  880. height: 100%;
  881. }
  882. .account .balance {
  883. display: flex;
  884. flex-direction: column;
  885. justify-content: center;
  886. align-items: flex-start;
  887. color: #ffffff;
  888. }
  889. .account .balance-tit {
  890. font-size: 26rpx;
  891. margin-bottom: 10rpx;
  892. }
  893. .account .balance-val {
  894. font-size: 56rpx;
  895. }
  896. .account .right-box {
  897. display: flex;
  898. flex-direction: column;
  899. justify-content: flex-start;
  900. align-items: flex-end;
  901. }
  902. .account .right-box .no {
  903. font-size: 26rpx;
  904. color: #ffffff;
  905. }
  906. .account .right-box .btn {
  907. font-size: 26rpx;
  908. padding: 0 20rpx;
  909. box-sizing: border-box;
  910. height: 42rpx;
  911. line-height: 42rpx;
  912. color: #28d20f;
  913. background: #ffffff;
  914. border-radius: 21rpx;
  915. display: inline-block;
  916. margin-top: 18rpx;
  917. }
  918. .account .head-bg {
  919. width: 690rpx;
  920. height: 224rpx;
  921. position: absolute;
  922. left: 0;
  923. top: 0;
  924. z-index: -99;
  925. }
  926. .input-box {
  927. display: flex;
  928. flex-direction: column;
  929. justify-content: center;
  930. align-items: center;
  931. padding: 20rpx 0;
  932. }
  933. .input-box .input {
  934. width: 430rpx;
  935. height: 98rpx;
  936. line-height: 98rpx;
  937. background: #f8f8f8;
  938. border: 1px solid #999999;
  939. border-radius: 6rpx;
  940. font-size: 30rpx;
  941. text-align: center;
  942. }
  943. .input-box .tips {
  944. color: #666666;
  945. font-size: 26rpx;
  946. margin-top: 18rpx;
  947. }
  948. .tabs {}
  949. .tabs .tab-tit {
  950. font-size: 30rpx;
  951. color: #333;
  952. padding: 45rpx 0 22rpx 30rpx;
  953. }
  954. .tabs .tab {
  955. display: flex;
  956. flex-wrap: wrap;
  957. justify-content: space-evenly;
  958. }
  959. .tabs .tab .item {
  960. width: 210rpx;
  961. height: 100rpx;
  962. background: #f6fff7;
  963. border: 1px solid #dcdde1;
  964. box-sizing: border-box;
  965. line-height: 100rpx;
  966. border-radius: 6rpx;
  967. text-align: center;
  968. margin-bottom: 24rpx;
  969. color: #333333;
  970. font-size: 32rpx;
  971. }
  972. .tabs .tab .item.active {
  973. border: 1px solid #24cc49;
  974. color: #24cc49;
  975. }
  976. .btn-primary {
  977. width: 670rpx;
  978. height: 80rpx;
  979. line-height: 80rpx;
  980. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  981. border-radius: 40rpx;
  982. font-size: 32rpx;
  983. color: #ffffff;
  984. margin: 200rpx 40rpx 0;
  985. text-align: center;
  986. }
  987. .uni-list {
  988. padding: 120rpx 10rpx 0 10rpx;
  989. font-size: 34rpx;
  990. }
  991. label {
  992. display: flex;
  993. justify-content: space-between;
  994. margin-top: 30rpx;
  995. }
  996. </style>