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.

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