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-weixin.vue 25KB

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