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.

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