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 26KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060
  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. });
  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. console.log("第二次70", value)
  409. let cmdArr = value.command.split(",");
  410. uni.showLoading({
  411. title: "写入中",
  412. });
  413. transCmd(cmdArr, function (res : any) {
  414. let response = res.toString();
  415. var dic = {
  416. command: val.command,
  417. cosResponse: response,
  418. };
  419. uni.hideLoading();
  420. quanApplyAction(dic).then((values) => {
  421. console.log("圈存申请完后的结果");
  422. uanConfirmAction(values);
  423. });
  424. })
  425. // msg("圈存初始化指令验证失败, 重新初始化");
  426. }
  427. });
  428. // });
  429. });
  430. } else {
  431. let cmdArr = val.command.split(",");
  432. uni.showLoading({
  433. title: "写入中",
  434. });
  435. transCmd(cmdArr, function (res : any) {
  436. var status = res[1].substring(res[1].length - 4, res[1].length);
  437. console.log("打印状态");
  438. console.log(status);
  439. if (status === "9000") {
  440. console.log("修复指令入参");
  441. let response = res.toString();
  442. var dic = {
  443. command: val.command,
  444. cosResponse: response,
  445. rechargeId: val.rechargeId,
  446. };
  447. quanFixAction(dic).then((value : any) => {
  448. console.log(value);
  449. console.log("修复结果返回");
  450. var fixStatus = value.fixStatus;
  451. //圈存修复COS指令Response信息不足,重新进行修复初始化
  452. if (fixStatus === 3) {
  453. let xfcmdArr = value.command.split(",");
  454. bluetoothUtil.transCmd(xfcmdArr, "10", function (resValueData) {
  455. var status = resValueData[1].substring(
  456. resValueData[1].length - 4,
  457. resValueData[1].length
  458. );
  459. console.log("打印状态");
  460. console.log(status);
  461. if (status === "9000") {
  462. console.log(resValueData);
  463. var valueResponse = resValueData.toString();
  464. console.log(response);
  465. var applyDic = {
  466. command: value.command,
  467. cosResponse: valueResponse,
  468. rechargeId: value.rechargeId,
  469. };
  470. console.log("消费成功");
  471. quanApplyAction(applyDic).then((applyValue) => {
  472. uanConfirmAction(applyValue);
  473. });
  474. }
  475. });
  476. } else if (fixStatus === 2) {
  477. uanConfirmSucessAction(value).then((confirmResult) => {
  478. console.log("充值成功")
  479. getCardId(1)
  480. setTimeout(() => {
  481. msg("充值成功");
  482. navTo(`/pages/recharge/result`)
  483. }, 2000)
  484. });
  485. } else if (fixStatus === 1) {
  486. quanCheckActionTrue().then((val) => {
  487. checkQuanCengEvent(val);
  488. });
  489. }
  490. });
  491. uni.hideLoading();
  492. }
  493. });
  494. }
  495. };
  496. /*透传*/
  497. const transCmd = (cmd : any, click : any) => {
  498. if (state.transWay == 'blu') {
  499. bluetoothUtil.transCmd(cmd, "10", function (res : any) {
  500. click(res);
  501. });
  502. } else {
  503. //nfc透传
  504. NFCAPI.transCmd(cmd, function (res : any) {
  505. tools.hideLoadingAlert();
  506. if (res.code == 0) {
  507. click(res.data);
  508. } else {
  509. //透传失败返回
  510. tools.alertF(res.msg);
  511. }
  512. });
  513. }
  514. };
  515. const quanCheckActionTrue = () => {
  516. console.log("进行真实圈存检测");
  517. var data = {
  518. cardId: card.cardId,
  519. fee: state.fee,
  520. preBalance: card.money,
  521. tradeType: 14,
  522. };
  523. const options = {
  524. type: 2,
  525. data: data,
  526. method: "POST",
  527. showLoading: true,
  528. };
  529. return new Promise(async (resolve, reject) => {
  530. const res = await request(quanCheck, options);
  531. const data = stringToJson(res.bizContent);
  532. resolve(data);
  533. }).catch((error) => {
  534. reject(error);
  535. });
  536. };
  537. /*充值消费*/
  538. const cardCzXFCheckAction = () => {
  539. var data = {
  540. cardId: card.cardId, //修复初始化的指令
  541. openId: getItem(StorageKeys.OpenId), //修复初始化结果
  542. orderNum: state.orderNum, //充值流水号
  543. };
  544. const options = {
  545. type: 2,
  546. data: data,
  547. method: "POST",
  548. showLoading: true,
  549. };
  550. return new Promise(async (resolve, reject) => {
  551. const res = await request(cardCzXFCheck, options);
  552. const data = stringToJson(res.bizContent);
  553. resolve(data);
  554. }).catch((error) => {
  555. reject(error);
  556. });
  557. };
  558. /*圈存修复*/
  559. const quanFixAction = (val) => {
  560. var data = {
  561. command: val.command, //修复初始化的指令
  562. cosResponse: val.cosResponse, //修复初始化结果
  563. rechargeId: val.rechargeId, //充值流水号
  564. };
  565. const options = {
  566. type: 2,
  567. data: data,
  568. method: "POST",
  569. showLoading: true,
  570. };
  571. return new Promise(async (resolve, reject) => {
  572. const res = await request(quanXf, options);
  573. const data = stringToJson(res.bizContent);
  574. resolve(data);
  575. }).catch((error) => {
  576. reject(error);
  577. });
  578. };
  579. /*圈存申请*/
  580. const quanApplyAction = (data) => {
  581. console.log("圈存申请data====", data, data.rechargeId)
  582. var form = {
  583. cardId: card.cardId,
  584. fee: state.fee,
  585. preBalance: card.money,
  586. tradeType: 14,
  587. command: data.command,
  588. cosResponse: data.cosResponse,
  589. orderId: state.orderNum,
  590. rechargeId: data.rechargeId,
  591. openId: getItem(StorageKeys.OpenId)
  592. };
  593. const options = {
  594. type: 2,
  595. data: form,
  596. method: "POST",
  597. showLoading: true,
  598. };
  599. return new Promise(async (resolve, reject) => {
  600. const res = await request(quanApply, options);
  601. const data = stringToJson(res.bizContent);
  602. resolve(data);
  603. }).catch((error) => {
  604. reject(error);
  605. });
  606. };
  607. /*圈存确认*/
  608. const uanConfirmAction = (data : any) => {
  609. console.log("圈存确认进入");
  610. let cmdArr = data.command.split(",");
  611. console.log(cmdArr);
  612. transCmd(cmdArr, function (res : any) {
  613. console.log("圈存透传");
  614. console.log(res);
  615. var arraylenth = res.length;
  616. var status = res[arraylenth - 1].substring(
  617. res[arraylenth - 1].length - 4,
  618. res[arraylenth - 1].length
  619. );
  620. console.log("打印圈存确认指令状态");
  621. if (status === "9000") {
  622. var form = {
  623. command: data.command,
  624. cosResponse: res.toString(),
  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 () => {
  636. const res = await request(quanConfirm, options);
  637. const data = stringToJson(res.bizContent);
  638. console.log("data充值成功", data);
  639. getCardId(1)
  640. setTimeout(() => {
  641. msg("充值成功");
  642. navTo(`/pages/recharge/result`)
  643. }, 2000)
  644. }).catch((error) => {
  645. console.log('输出内容', error)
  646. });
  647. }
  648. });
  649. };
  650. const uanConfirmSucessAction = (data) => {
  651. var form = {
  652. command: data.command,
  653. cosResponse: "9000",
  654. rechargeId: data.rechargeId,
  655. paidAmount: state.fee,
  656. giftAmount: 0,
  657. };
  658. const options = {
  659. type: 2,
  660. data: form,
  661. method: "POST",
  662. showLoading: true,
  663. };
  664. return new Promise(async (resolve, reject) => {
  665. const res = await request(quanConfirm, options);
  666. const data = stringToJson(res.bizContent);
  667. resolve(data);
  668. console.log("uanConfirmSucessAction", data)
  669. }).catch((error) => {
  670. reject(error);
  671. });
  672. };
  673. /*充值检测*/
  674. const czCheckAction = () => {
  675. var form = {
  676. cardId: state.cardId,
  677. openId: getItem(StorageKeys.OpenId),
  678. };
  679. const options = {
  680. type: 2,
  681. data: form,
  682. method: "POST",
  683. showLoading: true,
  684. };
  685. return new Promise(async (resolve, reject) => {
  686. const res = await request(cardCzPayResultCheck, options);
  687. const data = stringToJson(res.bizContent);
  688. console.log("充值检测", data)
  689. resolve(data);
  690. }).catch((error) => {
  691. reject(error);
  692. });
  693. };
  694. /*充值申请*/
  695. const cardCzApplyAction = () => {
  696. var data = {
  697. cardId: state.cardId,
  698. openId: getItem(StorageKeys.OpenId),
  699. rechargeMoney: state.fee,
  700. };
  701. const options = {
  702. type: 2,
  703. data: data,
  704. method: "POST",
  705. showLoading: true,
  706. };
  707. return new Promise(async (resolve, reject) => {
  708. const res = await request(cardCzApply, options);
  709. const data = stringToJson(res.bizContent);
  710. resolve(data);
  711. }).catch((error) => {
  712. reject(error);
  713. });
  714. };
  715. //获取微信小程序openid
  716. const getOpenID = () => {
  717. uni.login({
  718. provider: "weixin",
  719. success: function (e) {
  720. getOpenid(e.code);
  721. },
  722. fail: function () {
  723. msg("获取不到oppenId,请检查AppID和Secret是否争取");
  724. },
  725. });
  726. };
  727. const getOpenid = (code) => {
  728. const options = {
  729. type: 2,
  730. data: {
  731. "jsCode": code
  732. },
  733. method: "POST",
  734. showLoading: true,
  735. };
  736. // #ifdef MP-WEIXIN
  737. request(getOpenidApi, options).then((res) => {
  738. const result = stringToJson(res.bizContent);
  739. console.log("获取微信小程序openid", result);
  740. const openidData = stringToJson(result.data);
  741. // setItem("QYorder", result.data);
  742. state.openid = openidData.openid
  743. });
  744. // #endif
  745. }
  746. //掉起微信支付
  747. const wxPayment = () => {
  748. // #ifdef MP-WEIXIN
  749. const options = {
  750. type: 2,
  751. data: {
  752. openId: getItem(StorageKeys.OpenId),
  753. wxOpenId: state.openid,
  754. cardId: state.cardId,
  755. orderNum: state.orderNum,
  756. payConfigId: wechatPayConfigId,
  757. body: "储值卡充值",
  758. },
  759. method: "POST",
  760. showLoading: true,
  761. };
  762. request(cardCzPay, options).then((res) => {
  763. const data = stringToJson(res.bizContent);
  764. uni.requestPayment({
  765. provider: "wxpay",
  766. orderInfo: "",
  767. timeStamp: data.timestamp,
  768. nonceStr: data.noncestr,
  769. package: data.wxPackage ? data.wxPackage : "",
  770. signType: data.signType,
  771. paySign: data.sign,
  772. success: function () {
  773. //回调订单状态
  774. console.log("回调订单状态");
  775. checkOrder();
  776. },
  777. fail: function (err) {
  778. confirm(err, () => { }, "支付失败", false);
  779. },
  780. });
  781. });
  782. // #endif
  783. };
  784. //掉起支付宝支付
  785. const aliPayment = () => {
  786. // #ifdef MP-ALIPAY
  787. my.getAuthCode({
  788. scopes: 'auth_base',
  789. success: res => {
  790. const optionsUser = {
  791. type: 2,
  792. data: {
  793. payConfigId: aliPayConfigId,
  794. code: res.authCode
  795. },
  796. method: "POST",
  797. showLoading: true,
  798. };
  799. request(obtainUserId, optionsUser).then((res) => {
  800. const data = stringToJson(res.bizContent);
  801. const optionsali = {
  802. type: 2,
  803. data: {
  804. openId: getItem(StorageKeys.OpenId),
  805. wxOpenId: data.openId,
  806. cardId: state.cardId,
  807. orderNum: state.orderNum,
  808. payConfigId: "6a9a54123456578934edfre132b1234",
  809. body: "储值卡充值",
  810. },
  811. method: "POST",
  812. showLoading: true,
  813. };
  814. request(cardCzPay, optionsali).then((res) => {
  815. const data = stringToJson(res.bizContent);
  816. my.tradePay({
  817. // 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号 trade_no
  818. tradeNO: data.tranPackage,
  819. success: res => {
  820. console.log("支付成功", res);
  821. checkOrder();
  822. },
  823. fail: res => {
  824. confirm(res, () => { }, "支付失败", false);
  825. },
  826. });
  827. });
  828. });
  829. },
  830. fail: err => {
  831. console.log('my.getAuthCode 调用失败', err)
  832. }
  833. });
  834. // #endif
  835. };
  836. //支付成功改变订单状态
  837. const checkOrder = () => {
  838. const options = {
  839. type: 2,
  840. data: {
  841. cardId: state.cardId,
  842. openId: getItem(StorageKeys.OpenId),
  843. orderNum: state.orderNum,
  844. },
  845. method: "POST",
  846. showLoading: true,
  847. };
  848. request(cardCzPayResult, options).then((res) => {
  849. const data = stringToJson(res.bizContent);
  850. if (data.tradeState === "SUCCESS") {
  851. getCardId();
  852. }
  853. console.log(data);
  854. });
  855. };
  856. const goRecord = () => {
  857. uni.navigateTo({
  858. url: `/subpackage/personal-center/consumption-record?cardId=${state.cardId}`
  859. })
  860. }
  861. // 校验金额输入框
  862. const checkNum = (event) => {
  863. let sNum = event.target.value.toString(); //先转换成字符串类
  864. if (sNum.indexOf('.') == 0) {//第一位就是 .
  865. console.log('first str is .')
  866. sNum = '0' + sNum
  867. }
  868. sNum = sNum.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
  869. sNum = sNum.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
  870. sNum = sNum.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
  871. sNum = sNum.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');//只能输入两个小数
  872. //以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额
  873. if (sNum.indexOf(".") < 0 && sNum != "") {
  874. sNum = parseFloat(sNum);
  875. }
  876. console.log('输入的值1', sNum)
  877. setTimeout(() => {
  878. state.money = sNum
  879. }, 20)
  880. }
  881. </script>
  882. <style>
  883. .account {
  884. height: 224rpx;
  885. width: 690rpx;
  886. margin: 30rpx;
  887. position: relative;
  888. }
  889. .account .account-text {
  890. display: flex;
  891. justify-content: space-between;
  892. padding: 20rpx 50rpx;
  893. height: 100%;
  894. }
  895. .account .balance {
  896. display: flex;
  897. flex-direction: column;
  898. justify-content: center;
  899. align-items: flex-start;
  900. color: #ffffff;
  901. }
  902. .account .balance-tit {
  903. font-size: 26rpx;
  904. margin-bottom: 10rpx;
  905. }
  906. .account .balance-val {
  907. font-size: 56rpx;
  908. }
  909. .account .right-box {
  910. display: flex;
  911. flex-direction: column;
  912. justify-content: flex-start;
  913. align-items: flex-end;
  914. }
  915. .account .right-box .no {
  916. font-size: 26rpx;
  917. color: #ffffff;
  918. }
  919. .account .right-box .btn {
  920. font-size: 26rpx;
  921. padding: 0 20rpx;
  922. box-sizing: border-box;
  923. height: 42rpx;
  924. line-height: 42rpx;
  925. color: #28d20f;
  926. background: #ffffff;
  927. border-radius: 21rpx;
  928. display: inline-block;
  929. margin-top: 18rpx;
  930. }
  931. .account .head-bg {
  932. width: 690rpx;
  933. height: 224rpx;
  934. position: absolute;
  935. left: 0;
  936. top: 0;
  937. z-index: -99;
  938. }
  939. .input-box {
  940. display: flex;
  941. flex-direction: column;
  942. justify-content: center;
  943. align-items: center;
  944. padding: 20rpx 0;
  945. }
  946. .input-box .input {
  947. width: 430rpx;
  948. height: 98rpx;
  949. line-height: 98rpx;
  950. background: #f8f8f8;
  951. border: 1px solid #999999;
  952. border-radius: 6rpx;
  953. font-size: 30rpx;
  954. text-align: center;
  955. }
  956. .input-box .tips {
  957. color: #666666;
  958. font-size: 26rpx;
  959. margin-top: 18rpx;
  960. }
  961. .tabs {}
  962. .tabs .tab-tit {
  963. font-size: 30rpx;
  964. color: #333;
  965. padding: 45rpx 0 22rpx 30rpx;
  966. }
  967. .tabs .tab {
  968. display: flex;
  969. flex-wrap: wrap;
  970. justify-content: space-evenly;
  971. }
  972. .tabs .tab .item {
  973. width: 210rpx;
  974. height: 100rpx;
  975. background: #f6fff7;
  976. border: 1px solid #dcdde1;
  977. box-sizing: border-box;
  978. line-height: 100rpx;
  979. border-radius: 6rpx;
  980. text-align: center;
  981. margin-bottom: 24rpx;
  982. color: #333333;
  983. font-size: 32rpx;
  984. }
  985. .tabs .tab .item.active {
  986. border: 1px solid #24cc49;
  987. color: #24cc49;
  988. }
  989. .btn-primary {
  990. width: 670rpx;
  991. height: 80rpx;
  992. line-height: 80rpx;
  993. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  994. border-radius: 40rpx;
  995. font-size: 32rpx;
  996. color: #ffffff;
  997. margin: 200rpx 40rpx 0;
  998. text-align: center;
  999. }
  1000. .uni-list {
  1001. padding: 120rpx 10rpx 0 10rpx;
  1002. font-size: 34rpx;
  1003. }
  1004. label {
  1005. display: flex;
  1006. justify-content: space-between;
  1007. margin-top: 30rpx;
  1008. }
  1009. </style>