選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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. 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. tradeType: 14
  131. });
  132. const selectConfirm = (item : any) => {
  133. state.transWayName = item[0].label
  134. state.transWay = item[0].value
  135. };
  136. //读卡信息
  137. const card : any = reactive({
  138. cardId: "",
  139. netId: "",
  140. cardType: "",
  141. startTime: "",
  142. endTime: "",
  143. userName: "",
  144. idNum: "",
  145. vehiclePlate: "",
  146. vehiclePlateColor: "",
  147. color: "",
  148. version: "",
  149. type: "",
  150. favourable: "",
  151. money: 0,
  152. v_userType: "",
  153. });
  154. onLoad((option) => {
  155. /*获取openId 用途:(用户支付)*/
  156. // #ifdef MP-WEIXIN
  157. getOpenID();/*传参*/
  158. // #endif
  159. console.log("开始option", option)
  160. state.transWay = option.transWay == 'nfc' ? "nfc" : "blu"
  161. // state.cardId = option.cardId;
  162. state.connectSuccess = option.connectSuccess;
  163. // state.orderNum = getItem("orderNum");
  164. // 金额回填,本来是好的,但是他跳转了,跳转过来就得刷新页面,所以就是默认的5000
  165. if (option.fee) {
  166. state.fee = option.fee
  167. state.money = option.fee / 100
  168. } else {
  169. state.fee = state.money * 100; //元换成分
  170. }
  171. console.log("state.fee", option, state.fee)
  172. //跳转过来走圈存流程
  173. // connectSuccess 2 从选择方式进来去圈存检测 1 只读卡
  174. if (state.connectSuccess === "1") {
  175. /*读卡*/
  176. getCardId(1);
  177. } else {
  178. //进行真实圈层检测
  179. quanCheckActionTrue().then((val : any) => {
  180. console.log("圈存检测val", val)
  181. //如果 圈存检测正常
  182. if (val.chargeStatus === 1) {
  183. console.log(`进行充值检测`);
  184. //充值检测
  185. czCheckAction().then((checkResult : any) => {
  186. //判断订单逻辑如果有订单充值 则直接拿到订单去链接蓝牙
  187. if (checkResult.orders && checkResult.orders.length > 0) {
  188. //拿到订单,存起来
  189. state.orderNum = checkResult.orders[0].orderNum;
  190. // setItem("orderNum", state.orderNum);
  191. // 检测用户是否存在有半条流水
  192. } else {
  193. console.log('没有可修复的流水')
  194. }
  195. });
  196. } else {
  197. // 检测用户是否存在有半条流水
  198. }
  199. });
  200. }
  201. });
  202. function radioChange(evt) {
  203. console.log('输出内容', evt)
  204. state.transWay = evt.detail.value; //“blu”为蓝牙充值方式、“nfc”为NFC充值方式
  205. }
  206. function go(money) {
  207. let content = ""
  208. if (money) {
  209. state.fee = money * 100
  210. content = '待消费订单' + money + '元'
  211. } else {
  212. content = '待消费订单'
  213. }
  214. uni.showModal({
  215. title: '提示',
  216. content: content,
  217. showCancel: false,
  218. success: (res) => {
  219. if (res.confirm) {
  220. //走蓝牙进行修复
  221. quanCheckActionTrue().then((val : any) => {
  222. console.log("圈存检测val", val)
  223. //如果 圈存检测正常
  224. if (val.chargeStatus === 1) {
  225. console.log(`进行充值检测`);
  226. czCheckAction().then((checkResult : any) => {
  227. //判断订单逻辑如果有订单充值 则直接拿到订单去链接蓝牙
  228. if (checkResult.orders && checkResult.orders.length > 0) {
  229. //拿到订单,存起来
  230. state.orderNum = checkResult.orders[0].orderNum;
  231. // 检测用户是否存在有半条流水
  232. getCardId()
  233. } else {
  234. console.log('没有可修复的流水')
  235. }
  236. });
  237. } else {
  238. // 检测用户是否存在有半条流水
  239. getCardId()
  240. }
  241. });
  242. } else if (res.cancel) {
  243. console.log('用户点击取消');
  244. }
  245. console.log("state.isShowBlue", state.isShowBlue)
  246. },
  247. fail: () => {
  248. }
  249. })
  250. }
  251. const tableIndexAction = (val : any) => {
  252. state.tableIndex = val
  253. state.money = state.moneryArray[val].value
  254. }
  255. /*点击充值按钮*/
  256. const rechargeAction = () => {
  257. state.fee = state.money * 100; //元换成分
  258. uni.showModal({
  259. title: '圈存确认',
  260. content: '您确定要充值圈存吗',
  261. success: function (res) {
  262. if (res.confirm) {
  263. /*进行圈存检测,此处检测仅为校验圈存状态来决定去哪里*/
  264. console.log("进行圈存检测");
  265. quanCheckActionTrue().then((val : any) => {
  266. console.log("圈存检测接口返回", val)
  267. //如果 圈存检测正常
  268. if (val.chargeStatus === 1) {
  269. console.log(`进行充值检测`);
  270. czCheckAction().then((checkResult : any) => {
  271. console.log("进行充值检测", checkResult)
  272. //判断订单逻辑如果有订单充值 则直接拿到订单去链接蓝牙
  273. if (checkResult.orders && checkResult.orders.length > 0) {
  274. state.fee = checkResult.orders[0]['rechargeMoney']
  275. state.money = checkResult.orders[0]['rechargeMoney'] / 100
  276. //拿到订单,存起来
  277. state.orderNum = checkResult.orders[0].orderNum;
  278. //链接蓝牙
  279. go(state.money)
  280. } else {
  281. cardCzApplyAction().then((applyResult : any) => {
  282. //拿到订单 存起来
  283. state.orderNum = applyResult.orderNum;
  284. //如果订单没有支付 走支付
  285. if (applyResult.orderStatus === "ORDER_NOT_PAY") {
  286. //走支付
  287. console.log("走支付");
  288. // #ifdef MP-WEIXIN
  289. wxPayment();
  290. // #endif
  291. // #ifdef MP-ALIPAY
  292. aliPayment()
  293. // #endif
  294. }
  295. });
  296. }
  297. });
  298. } else {
  299. //走蓝牙进行修复
  300. // 圈存检测异常,继续上次圈存 chargeStatus==2
  301. let fixFee = val.fixFee / 100
  302. console.log("fixFee", fixFee)
  303. go(fixFee)
  304. }
  305. });
  306. }
  307. }
  308. });
  309. };
  310. /*读卡*/
  311. const getCardId = (readCard : number) => {
  312. console.log("======获取卡信息======");
  313. let cmdArr = [
  314. cmd.HOME_DIRECTORY,
  315. //选择主目
  316. cmd.APPLICATION_DIRECTORY,
  317. //选择文件1001--DF01联网收费应用目录
  318. cmd.CMD_READBINARY,
  319. //15文件--卡片发行基本数据文件
  320. cmd.CMD_GETBALANCE,
  321. //钱包
  322. ];
  323. tools.showLoadingAlert("正在执行指令");
  324. transCmd(cmdArr, function (res : any) {
  325. if (readCard == 1) {
  326. // 只读卡号
  327. getCardIdReturnReadCard(res)
  328. } else {
  329. getCardIdReturn(res);
  330. }
  331. })
  332. };
  333. function getCardIdReturnReadCard(res : any) {
  334. tools.hideLoadingAlert();
  335. //10:写卡 20:写OBU
  336. let str = res[2].substring(res[2].length - 4, res[2].length);
  337. let str3 = res[3].substring(res[3].length - 4, res[3].length);
  338. if (str == "9000" || str3 == "9000") {
  339. if (res[2].length > 86 || res[3] >= 12) {
  340. state.cardId = res[2].substring(20, 40); //卡号
  341. card.cardId = res[2].substring(20, 40); //卡号
  342. card.money = parseInt(parseInt(res[3].substring(0, 8), 16), 10)
  343. console.log("======卡信息======", card, state.cardId);
  344. } else {
  345. console.error("CMD_READBINARY指令长度不符" + res[2]);
  346. tools.hideLoadingAlert();
  347. }
  348. }
  349. console.error("CMD_READBINARY指令长度不符" + res[2]);
  350. tools.hideLoadingAlert();
  351. }
  352. function getCardIdReturn(res : any) {
  353. tools.hideLoadingAlert();
  354. //10:写卡 20:写OBU
  355. let str = res[2].substring(res[2].length - 4, res[2].length);
  356. let str3 = res[3].substring(res[3].length - 4, res[3].length);
  357. if (str == "9000" || str3 == "9000") {
  358. if (res[2].length > 86 || res[3] >= 12) {
  359. state.cardId = res[2].substring(20, 40); //卡号
  360. card.cardId = res[2].substring(20, 40); //卡号
  361. card.startTime = res[2].substring(40, 48);
  362. card.endTime = res[2].substring(48, 56);
  363. card.version = res[2].substring(18, 19) >= 4 ? "4x" : "2x";
  364. card.netId = res[2].substring(20, 24);
  365. card.cardType = res[2].substring(28, 29) == 23 ? 1 : 2;
  366. card.vehiclePlateColor = parseInt(res[2].substring(82, 84), 16);
  367. (card.money = parseInt(parseInt(res[3].substring(0, 8), 16), 10)),
  368. console.log("======卡信息======", card, card.money);
  369. quanCheckActionTrue().then((val) => {
  370. checkQuanCengEvent(val);
  371. });
  372. } else {
  373. console.error("CMD_READBINARY指令长度不符" + res[2]);
  374. tools.hideLoadingAlert();
  375. }
  376. }
  377. console.error("CMD_READBINARY指令长度不符" + res[2]);
  378. tools.hideLoadingAlert();
  379. }
  380. const checkQuanCengEvent = (val : any) => {
  381. if (val.chargeStatus === 1) {
  382. let cmdArr = val.command.split(",");
  383. uni.showLoading({
  384. title: "写入中",
  385. });
  386. transCmd(cmdArr, function (res : any) {
  387. let response = res.toString();
  388. var dic = {
  389. command: val.command,
  390. cosResponse: response,
  391. };
  392. uni.hideLoading();
  393. quanApplyAction(dic).then((value : any) => {
  394. console.log("圈存申请完后的结果");
  395. console.log(value.commandType, value);
  396. //圈存初始化验证通过 , 进行圈存
  397. if (value.commandType === 2) {
  398. uanConfirmAction(value);
  399. } else {
  400. console.log("第二次70", value)
  401. let cmdArr = value.command.split(",");
  402. uni.showLoading({
  403. title: "写入中",
  404. });
  405. transCmd(cmdArr, function (res : any) {
  406. let response = res.toString();
  407. var dic = {
  408. command: val.command,
  409. cosResponse: response,
  410. };
  411. uni.hideLoading();
  412. quanApplyAction(dic).then((values) => {
  413. console.log("圈存申请完后的结果");
  414. uanConfirmAction(values);
  415. });
  416. })
  417. }
  418. });
  419. });
  420. } else {
  421. let cmdArr = val.command.split(",");
  422. uni.showLoading({
  423. title: "写入中",
  424. });
  425. transCmd(cmdArr, function (res : any) {
  426. var status = res[1].substring(res[1].length - 4, res[1].length);
  427. console.log("打印状态");
  428. console.log(status);
  429. if (status === "9000") {
  430. console.log("修复指令入参");
  431. let response = res.toString();
  432. var dic = {
  433. command: val.command,
  434. cosResponse: response,
  435. rechargeId: val.rechargeId,
  436. };
  437. quanFixAction(dic).then((value : any) => {
  438. state.orderNum = value.orderId
  439. state.tradeType = value.tradeType
  440. console.log(value);
  441. console.log("修复结果返回");
  442. var fixStatus = value.fixStatus;
  443. //圈存修复COS指令Response信息不足,重新进行修复初始化
  444. if (fixStatus === 3) {
  445. let xfcmdArr = value.command.split(",");
  446. bluetoothUtil.transCmd(xfcmdArr, "10", function (resValueData) {
  447. var status = resValueData[1].substring(
  448. resValueData[1].length - 4,
  449. resValueData[1].length
  450. );
  451. console.log("打印状态");
  452. console.log(status);
  453. if (status === "9000") {
  454. console.log(resValueData);
  455. var valueResponse = resValueData.toString();
  456. console.log(response);
  457. var applyDic = {
  458. command: value.command,
  459. cosResponse: valueResponse,
  460. rechargeId: value.rechargeId,
  461. };
  462. console.log("消费成功");
  463. quanApplyAction(applyDic).then((applyValue) => {
  464. uanConfirmAction(applyValue);
  465. });
  466. }
  467. });
  468. } else if (fixStatus === 2) {
  469. uanConfirmSucessAction(value).then((confirmResult) => {
  470. console.log("充值成功")
  471. getCardId(1)
  472. setTimeout(() => {
  473. msg("充值成功");
  474. navTo(`/pages/recharge/result?cardId=${card.cardId}`)
  475. }, 2000)
  476. });
  477. } else if (fixStatus === 1) {
  478. quanCheckActionTrue().then((val) => {
  479. checkQuanCengEvent(val);
  480. });
  481. }
  482. });
  483. uni.hideLoading();
  484. }
  485. });
  486. }
  487. };
  488. /*透传*/
  489. const transCmd = (cmd : any, click : any) => {
  490. if (state.transWay == 'blu') {
  491. bluetoothUtil.transCmd(cmd, "10", function (res : any) {
  492. click(res);
  493. });
  494. } else {
  495. //nfc透传
  496. NFCAPI.transCmd(cmd, function (res : any) {
  497. tools.hideLoadingAlert();
  498. if (res.code == 0) {
  499. click(res.data);
  500. } else {
  501. //透传失败返回
  502. tools.alertF(res.msg);
  503. }
  504. });
  505. }
  506. };
  507. const quanCheckActionTrue = () => {
  508. console.log("进行真实圈存检测");
  509. var data = {
  510. cardId: card.cardId,
  511. fee: state.fee,
  512. preBalance: card.money,
  513. tradeType: 14,
  514. };
  515. const options = {
  516. type: 2,
  517. data: data,
  518. method: "POST",
  519. showLoading: true,
  520. };
  521. return new Promise(async (resolve, reject) => {
  522. const res = await request(quanCheck, options);
  523. const data = stringToJson(res.bizContent);
  524. resolve(data);
  525. }).catch((error) => {
  526. reject(error);
  527. });
  528. };
  529. /*圈存修复*/
  530. const quanFixAction = (val) => {
  531. var data = {
  532. command: val.command, //修复初始化的指令
  533. cosResponse: val.cosResponse, //修复初始化结果
  534. rechargeId: val.rechargeId, //充值流水号
  535. };
  536. const options = {
  537. type: 2,
  538. data: data,
  539. method: "POST",
  540. showLoading: true,
  541. };
  542. return new Promise(async (resolve, reject) => {
  543. const res = await request(quanXf, options);
  544. const data = stringToJson(res.bizContent);
  545. resolve(data);
  546. }).catch((error) => {
  547. reject(error);
  548. });
  549. };
  550. /*圈存申请*/
  551. const quanApplyAction = (data) => {
  552. console.log("圈存申请data====", data, data.rechargeId)
  553. var form = {
  554. cardId: card.cardId,
  555. fee: state.fee,
  556. preBalance: card.money,
  557. tradeType: state.tradeType,
  558. command: data.command,
  559. cosResponse: data.cosResponse,
  560. orderId: state.orderNum,
  561. rechargeId: data.rechargeId,
  562. openId: getItem(StorageKeys.OpenId)
  563. };
  564. const options = {
  565. type: 2,
  566. data: form,
  567. method: "POST",
  568. showLoading: true,
  569. };
  570. return new Promise(async (resolve, reject) => {
  571. const res = await request(quanApply, options);
  572. const data = stringToJson(res.bizContent);
  573. resolve(data);
  574. }).catch((error) => {
  575. reject(error);
  576. });
  577. };
  578. /*圈存确认*/
  579. const uanConfirmAction = (data : any) => {
  580. console.log("圈存确认进入");
  581. let cmdArr = data.command.split(",");
  582. console.log(cmdArr);
  583. transCmd(cmdArr, function (res : any) {
  584. console.log("圈存透传");
  585. console.log(res);
  586. var arraylenth = res.length;
  587. var status = res[arraylenth - 1].substring(
  588. res[arraylenth - 1].length - 4,
  589. res[arraylenth - 1].length
  590. );
  591. console.log("打印圈存确认指令状态");
  592. if (status === "9000") {
  593. var form = {
  594. command: data.command,
  595. cosResponse: res.toString(),
  596. rechargeId: data.rechargeId,
  597. paidAmount: state.fee,
  598. giftAmount: 0,
  599. };
  600. const options = {
  601. type: 2,
  602. data: form,
  603. method: "POST",
  604. showLoading: true,
  605. };
  606. return new Promise(async () => {
  607. const res = await request(quanConfirm, options);
  608. const data = stringToJson(res.bizContent);
  609. console.log("data充值成功", data);
  610. getCardId(1)
  611. setTimeout(() => {
  612. msg("充值成功");
  613. navTo(`/pages/recharge/result?cardId=${card.cardId}`)
  614. }, 2000)
  615. }).catch((error) => {
  616. console.log('输出内容', error)
  617. });
  618. }
  619. });
  620. };
  621. const uanConfirmSucessAction = (data) => {
  622. var form = {
  623. command: data.command,
  624. cosResponse: "9000",
  625. rechargeId: data.rechargeId,
  626. paidAmount: state.fee,
  627. giftAmount: 0,
  628. };
  629. const options = {
  630. type: 2,
  631. data: form,
  632. method: "POST",
  633. showLoading: true,
  634. };
  635. return new Promise(async (resolve, reject) => {
  636. const res = await request(quanConfirm, options);
  637. const data = stringToJson(res.bizContent);
  638. resolve(data);
  639. console.log("uanConfirmSucessAction", data)
  640. }).catch((error) => {
  641. reject(error);
  642. });
  643. };
  644. /*充值检测*/
  645. const czCheckAction = () => {
  646. var form = {
  647. cardId: state.cardId,
  648. openId: getItem(StorageKeys.OpenId),
  649. };
  650. const options = {
  651. type: 2,
  652. data: form,
  653. method: "POST",
  654. showLoading: true,
  655. };
  656. return new Promise(async (resolve, reject) => {
  657. const res = await request(cardCzPayResultCheck, options);
  658. const data = stringToJson(res.bizContent);
  659. console.log("充值检测", data)
  660. resolve(data);
  661. }).catch((error) => {
  662. reject(error);
  663. });
  664. };
  665. /*充值申请*/
  666. const cardCzApplyAction = () => {
  667. var data = {
  668. cardId: state.cardId,
  669. openId: getItem(StorageKeys.OpenId),
  670. rechargeMoney: state.fee,
  671. };
  672. const options = {
  673. type: 2,
  674. data: data,
  675. method: "POST",
  676. showLoading: true,
  677. };
  678. return new Promise(async (resolve, reject) => {
  679. const res = await request(cardCzApply, options);
  680. const data = stringToJson(res.bizContent);
  681. resolve(data);
  682. }).catch((error) => {
  683. reject(error);
  684. });
  685. };
  686. //获取微信小程序openid
  687. const getOpenID = () => {
  688. uni.login({
  689. provider: "weixin",
  690. success: function (e) {
  691. getOpenid(e.code);
  692. },
  693. fail: function () {
  694. msg("获取不到oppenId,请检查AppID和Secret是否争取");
  695. },
  696. });
  697. };
  698. const getOpenid = (code) => {
  699. const options = {
  700. type: 2,
  701. data: {
  702. "jsCode": code
  703. },
  704. method: "POST",
  705. showLoading: true,
  706. };
  707. // #ifdef MP-WEIXIN
  708. request(getOpenidApi, options).then((res) => {
  709. const result = stringToJson(res.bizContent);
  710. console.log("获取微信小程序openid", result);
  711. const openidData = stringToJson(result.data);
  712. // setItem("QYorder", 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. request(cardCzPay, options).then((res) => {
  734. const data = stringToJson(res.bizContent);
  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. request(obtainUserId, optionsUser).then((res) => {
  771. const data = stringToJson(res.bizContent);
  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. request(cardCzPay, optionsali).then((res) => {
  786. const data = stringToJson(res.bizContent);
  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. request(cardCzPayResult, options).then((res) => {
  820. const data = stringToJson(res.bizContent);
  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>