Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

recharge.vue 26KB

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