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.vue 23KB

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