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

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