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

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