Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

recharge.vue 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  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}}元</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. aliPayConfigIdTwo,
  64. obtainUserId,
  65. getOpenidApi
  66. } from "@/utils/network/api.js";
  67. import {
  68. request
  69. } from "@/utils/network/request.js";
  70. import {
  71. reactive
  72. } from "vue";
  73. import {
  74. navTo
  75. } from "@/utils/utils"
  76. import {
  77. msg
  78. } from "@/utils/utils";
  79. import {
  80. getItem,
  81. StorageKeys,
  82. setItem
  83. } from "@/utils/storage";
  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. onLoad((option) => {
  169. /*获取openId 用途:(用户支付)*/
  170. // #ifdef MP-WEIXIN
  171. getOpenID();/*传参*/
  172. // #endif
  173. console.log("开始option", option)
  174. state.transWay = option.transWay == 'nfc' ? "nfc" : "blu"
  175. state.cardId = option.cardId;
  176. state.connectSuccess = option.connectSuccess;
  177. state.orderNum = getItem("orderNum");
  178. // 金额回填,本来是好的,但是他跳转了,跳转过来就得刷新页面,所以就是默认的5000
  179. if (option.fee) {
  180. state.fee = option.fee
  181. state.money = option.fee / 100
  182. } else {
  183. state.fee = state.money * 100; //元换成分
  184. }
  185. console.log("state.fee", option, state.fee)
  186. //跳转过来走圈存流程
  187. if (state.connectSuccess === "1") {
  188. /*读卡*/
  189. getCardId();
  190. } else {
  191. quanCheckActionTrue().then((val : any) => {
  192. console.log("圈层检测val", val)
  193. //如果 圈层检测正常
  194. if (val.chargeStatus === 1) {
  195. console.log(`进行充值检测`);
  196. czCheckAction().then((checkResult : any) => {
  197. //判断订单逻辑如果有订单充值 则直接拿到订单去链接蓝牙
  198. if (checkResult.orders && checkResult.orders.length > 0) {
  199. //拿到订单,存起来
  200. state.orderNum = checkResult.orders[0].orderNum;
  201. setItem("orderNum", state.orderNum);
  202. // 检测用户是否存在有半条流水
  203. // go()
  204. } else {
  205. console.log('没有可修复的流水')
  206. }
  207. });
  208. } else {
  209. // 检测用户是否存在有半条流水
  210. // go()
  211. }
  212. });
  213. }
  214. });
  215. function radioChange(evt) {
  216. console.log('输出内容', evt)
  217. state.transWay = evt.detail.value; //“blu”为蓝牙充值方式、“nfc”为NFC充值方式
  218. }
  219. function go(money) {
  220. let content = ""
  221. if (money) {
  222. content = '待消费订单' + money + '元'
  223. } else {
  224. content = '待消费订单'
  225. }
  226. uni.showModal({
  227. title: '提示',
  228. content: content,
  229. showCancel: false,
  230. success: (res) => {
  231. if (res.confirm) {
  232. //走蓝牙进行修复
  233. if (state.transWay == 'blu') {
  234. uni.redirectTo({
  235. url: `/pages/bluetooth/bluetooth?routeType=2&&cardId=${state.cardId}&&fee=${state.fee}`,
  236. });
  237. } else {
  238. uni.redirectTo({
  239. url: `/pages/nfc/nfc?routeType=2&&cardId=${state.cardId}&&fee=${state.fee}`,
  240. });
  241. }
  242. } else if (res.cancel) {
  243. console.log('用户点击取消');
  244. }
  245. // state.isShowBlue=true;
  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. go()
  304. }
  305. });
  306. }
  307. }
  308. });
  309. };
  310. /*读卡*/
  311. const getCardId = () => {
  312. console.log("======获取卡信息======");
  313. let cmdArr = [
  314. cmd.HOME_DIRECTORY,
  315. //选择主目
  316. cmd.APPLICATION_DIRECTORY,
  317. //选择文件1001--DF01联网收费应用目录
  318. cmd.CMD_READBINARY,
  319. //15文件--卡片发行基本数据文件
  320. cmd.CMD_GETBALANCE,
  321. //钱包
  322. ];
  323. tools.showLoadingAlert("正在执行指令");
  324. transCmd(cmdArr, function (res : any) {
  325. getCardIdReturn(res);
  326. })
  327. };
  328. function getCardIdReturn(res : any) {
  329. tools.hideLoadingAlert();
  330. //10:写卡 20:写OBU
  331. let str = res[2].substring(res[2].length - 4, res[2].length);
  332. let str3 = res[3].substring(res[3].length - 4, res[3].length);
  333. if (str == "9000" || str3 == "9000") {
  334. if (res[2].length > 86 || res[3] >= 12) {
  335. card.cardId = res[2].substring(20, 40); //卡号
  336. card.startTime = res[2].substring(40, 48);
  337. card.endTime = res[2].substring(48, 56);
  338. card.version = res[2].substring(18, 19) >= 4 ? "4x" : "2x";
  339. card.netId = res[2].substring(20, 24);
  340. card.cardType = res[2].substring(28, 29) == 23 ? 1 : 2;
  341. card.vehiclePlateColor = parseInt(res[2].substring(82, 84), 16);
  342. (card.money = parseInt(parseInt(res[3].substring(0, 8), 16), 10)),
  343. console.log("======卡信息======", card, card.money);
  344. if (card.cardId !== state.cardId) {
  345. msg("设备卡信息与当前充值卡号不匹配,请核对卡号");
  346. return;
  347. }
  348. quanCheckActionTrue().then((val) => {
  349. checkQuanCengEvent(val);
  350. });
  351. } else {
  352. console.error("CMD_READBINARY指令长度不符" + res[2]);
  353. tools.hideLoadingAlert();
  354. }
  355. }
  356. console.error("CMD_READBINARY指令长度不符" + res[2]);
  357. tools.hideLoadingAlert();
  358. }
  359. const checkQuanCengEvent = (val : any) => {
  360. if (val.chargeStatus === 1) {
  361. let cmdArr = val.command.split(",");
  362. uni.showLoading({
  363. title: "写入中",
  364. });
  365. transCmd(cmdArr, function (res : any) {
  366. let response = res.toString();
  367. var dic = {
  368. command: val.command,
  369. cosResponse: response,
  370. };
  371. uni.hideLoading();
  372. cardCzXFCheckAction().then((xfRes) => {
  373. quanApplyAction(dic).then((value : any) => {
  374. console.log("圈层申请完后的结果");
  375. console.log(value.commandType, value);
  376. //圈存初始化验证通过 , 进行圈存
  377. if (value.commandType === 2) {
  378. uanConfirmAction(value);
  379. } else {
  380. quanApplyAction(value).then((values) => {
  381. console.log("圈层申请完后的结果");
  382. uanConfirmAction(values);
  383. });
  384. // msg("圈存初始化指令验证失败, 重新初始化");
  385. }
  386. });
  387. });
  388. });
  389. } else {
  390. let cmdArr = val.command.split(",");
  391. uni.showLoading({
  392. title: "写入中",
  393. });
  394. transCmd(cmdArr, function (res : any) {
  395. var status = res[1].substring(res[1].length - 4, res[1].length);
  396. console.log("打印状态");
  397. console.log(status);
  398. if (status === "9000") {
  399. console.log("修复指令入参");
  400. let response = res.toString();
  401. var dic = {
  402. command: val.command,
  403. cosResponse: response,
  404. rechargeId: val.rechargeId,
  405. };
  406. quanFixAction(dic).then((value : any) => {
  407. console.log(value);
  408. console.log("修复结果返回");
  409. var fixStatus = value.fixStatus;
  410. //圈存修复COS指令Response信息不足,重新进行修复初始化
  411. if (fixStatus === 3) {
  412. let xfcmdArr = value.command.split(",");
  413. bluetoothUtil.transCmd(xfcmdArr, "10", function (resValueData) {
  414. var status = resValueData[1].substring(
  415. resValueData[1].length - 4,
  416. resValueData[1].length
  417. );
  418. console.log("打印状态");
  419. console.log(status);
  420. if (status === "9000") {
  421. console.log(resValueData);
  422. var valueResponse = resValueData.toString();
  423. console.log(response);
  424. var applyDic = {
  425. command: value.command,
  426. cosResponse: valueResponse,
  427. rechargeId: value.rechargeId,
  428. };
  429. console.log("消费成功");
  430. quanApplyAction(applyDic).then((applyValue) => {
  431. uanConfirmAction(applyValue);
  432. });
  433. }
  434. });
  435. } else if (fixStatus === 2) {
  436. uanConfirmSucessAction(value).then((confirmResult) => {
  437. console.log("充值成功")
  438. msg("充值成功");
  439. navTo(`/pages/recharge/result`)
  440. });
  441. } else if (fixStatus === 1) {
  442. quanCheckActionTrue().then((val) => {
  443. checkQuanCengEvent(val);
  444. });
  445. }
  446. });
  447. uni.hideLoading();
  448. }
  449. });
  450. }
  451. };
  452. /*透传*/
  453. const transCmd = (cmd : any, click : any) => {
  454. if (state.transWay == 'blu') {
  455. bluetoothUtil.transCmd(cmd, "10", function (res : any) {
  456. click(res);
  457. });
  458. } else {
  459. //nfc透传
  460. NFCAPI.transCmd(cmd, function (res : any) {
  461. tools.hideLoadingAlert();
  462. if (res.code == 0) {
  463. click(res.data);
  464. } else {
  465. //透传失败返回
  466. tools.alertF(res.msg);
  467. }
  468. });
  469. }
  470. };
  471. /*圈层检测 -假数据校验*/
  472. const quanCheckAction = () => {
  473. var data = {
  474. cardId: state.cardId, //卡号
  475. fee: state.fee,
  476. preBalance: state.mockpreBalance, //假余额
  477. tradeType: 14,
  478. };
  479. const options = {
  480. type: 2,
  481. data: data,
  482. method: "POST",
  483. showLoading: true,
  484. };
  485. return new Promise(async (resolve, reject) => {
  486. const res = await request(quanCheck, options);
  487. const data = stringToJson(res.bizContent);
  488. resolve(data);
  489. }).catch((error) => {
  490. reject(error);
  491. });
  492. };
  493. const quanCheckActionTrue = async () => {
  494. console.log("进行真实圈层检测");
  495. var data = {
  496. cardId: card.cardId,
  497. fee: state.fee,
  498. preBalance: card.money,
  499. tradeType: 14,
  500. };
  501. const options = {
  502. type: 2,
  503. data: data,
  504. method: "POST",
  505. showLoading: true,
  506. };
  507. try {
  508. return await new Promise(async (resolve) => {
  509. const res = await request(quanCheck, options);
  510. const data_1 = stringToJson(res.bizContent);
  511. resolve(data_1);
  512. });
  513. } catch (error) {
  514. console.log('输出内容', error);
  515. }
  516. };
  517. /*充值消费*/
  518. const cardCzXFCheckAction = () => {
  519. var data = {
  520. cardId: card.cardId, //修复初始化的指令
  521. openId: getItem(StorageKeys.OpenId), //修复初始化结果
  522. orderNum: state.orderNum, //充值流水号
  523. };
  524. const options = {
  525. type: 2,
  526. data: data,
  527. method: "POST",
  528. showLoading: true,
  529. };
  530. return new Promise(async (resolve, reject) => {
  531. const res = await request(cardCzXFCheck, options);
  532. const data = stringToJson(res.bizContent);
  533. resolve(data);
  534. }).catch((error) => {
  535. reject(error);
  536. });
  537. };
  538. /*圈存修复*/
  539. const quanFixAction = (val) => {
  540. var data = {
  541. command: val.command, //修复初始化的指令
  542. cosResponse: val.cosResponse, //修复初始化结果
  543. rechargeId: val.rechargeId, //充值流水号
  544. };
  545. const options = {
  546. type: 2,
  547. data: data,
  548. method: "POST",
  549. showLoading: true,
  550. };
  551. return new Promise(async (resolve, reject) => {
  552. const res = await request(quanXf, options);
  553. const data = stringToJson(res.bizContent);
  554. resolve(data);
  555. }).catch((error) => {
  556. reject(error);
  557. });
  558. };
  559. /*圈层申请*/
  560. const quanApplyAction = (data) => {
  561. var form = {
  562. cardId: card.cardId,
  563. fee: state.fee,
  564. preBalance: card.money,
  565. tradeType: 14,
  566. command: data.command,
  567. cosResponse: data.cosResponse,
  568. orderId: state.orderNum,
  569. rechargeId: data.rechargeId,
  570. };
  571. const options = {
  572. type: 2,
  573. data: form,
  574. method: "POST",
  575. showLoading: true,
  576. };
  577. return new Promise(async (resolve, reject) => {
  578. const res = await request(quanApply, options);
  579. const data = stringToJson(res.bizContent);
  580. resolve(data);
  581. console.log("quanApplyAction", data)
  582. }).catch((error) => {
  583. reject(error);
  584. });
  585. };
  586. /*圈层确认*/
  587. const uanConfirmAction = (data : any) => {
  588. console.log("圈层确认进入");
  589. let cmdArr = data.command.split(",");
  590. console.log(cmdArr);
  591. transCmd(cmdArr, function (res : any) {
  592. console.log("圈层透传");
  593. console.log(res);
  594. var arraylenth = res.length;
  595. var status = res[arraylenth - 1].substring(
  596. res[arraylenth - 1].length - 4,
  597. res[arraylenth - 1].length
  598. );
  599. console.log("打印圈层确认指令状态");
  600. if (status === "9000") {
  601. var form = {
  602. command: data.command,
  603. cosResponse: res.toString(),
  604. rechargeId: data.rechargeId,
  605. paidAmount: state.fee,
  606. giftAmount: 0,
  607. };
  608. const options = {
  609. type: 2,
  610. data: form,
  611. method: "POST",
  612. showLoading: true,
  613. };
  614. return new Promise(async () => {
  615. const res = await request(quanConfirm, options);
  616. const data = stringToJson(res.bizContent);
  617. // resolve(data);
  618. console.log("data", data);
  619. msg("充值成功");
  620. navTo(`/pages/recharge/result`)
  621. }).catch((error) => {
  622. console.log('输出内容', error)
  623. });
  624. }
  625. });
  626. };
  627. const uanConfirmSucessAction = (data) => {
  628. var form = {
  629. command: data.command,
  630. cosResponse: "9000",
  631. rechargeId: data.rechargeId,
  632. paidAmount: state.fee,
  633. giftAmount: 0,
  634. };
  635. const options = {
  636. type: 2,
  637. data: form,
  638. method: "POST",
  639. showLoading: true,
  640. };
  641. return new Promise(async (resolve, reject) => {
  642. const res = await request(quanConfirm, options);
  643. const data = stringToJson(res.bizContent);
  644. resolve(data);
  645. console.log("uanConfirmSucessAction", data)
  646. }).catch((error) => {
  647. reject(error);
  648. });
  649. };
  650. /*充值检测*/
  651. const czCheckAction = () => {
  652. var form = {
  653. cardId: state.cardId,
  654. openId: getItem(StorageKeys.OpenId),
  655. };
  656. const options = {
  657. type: 2,
  658. data: form,
  659. method: "POST",
  660. showLoading: true,
  661. };
  662. return new Promise(async (resolve, reject) => {
  663. const res = await request(cardCzPayResultCheck, options);
  664. const data = stringToJson(res.bizContent);
  665. console.log("充值检测", data)
  666. resolve(data);
  667. }).catch((error) => {
  668. reject(error);
  669. });
  670. };
  671. /*充值申请*/
  672. const cardCzApplyAction = () => {
  673. var data = {
  674. cardId: state.cardId,
  675. openId: getItem(StorageKeys.OpenId),
  676. rechargeMoney: state.fee,
  677. };
  678. const options = {
  679. type: 2,
  680. data: data,
  681. method: "POST",
  682. showLoading: true,
  683. };
  684. return new Promise(async (resolve, reject) => {
  685. const res = await request(cardCzApply, options);
  686. const data = stringToJson(res.bizContent);
  687. resolve(data);
  688. }).catch((error) => {
  689. reject(error);
  690. });
  691. };
  692. //获取微信小程序openid
  693. const getOpenID = () => {
  694. uni.login({
  695. provider: "weixin",
  696. success: function (e) {
  697. getOpenid(e.code);
  698. },
  699. fail: function () {
  700. msg("获取不到oppenId,请检查AppID和Secret是否争取");
  701. },
  702. });
  703. };
  704. const getOpenid = (code) => {
  705. const options = {
  706. type: 2,
  707. data: {
  708. "jsCode": code
  709. },
  710. method: "POST",
  711. showLoading: true,
  712. };
  713. // #ifdef MP-WEIXIN
  714. request(getOpenidApi, options).then((res) => {
  715. const result = stringToJson(res.bizContent);
  716. console.log("获取微信小程序openid", result);
  717. const openidData = stringToJson(result.data);
  718. // setItem("QYorder", result.data);
  719. state.openid = openidData.openid
  720. });
  721. // #endif
  722. }
  723. //掉起微信支付
  724. const wxPayment = () => {
  725. // #ifdef MP-WEIXIN
  726. const options = {
  727. type: 2,
  728. data: {
  729. openId: getItem(StorageKeys.OpenId),
  730. wxOpenId: state.openid,
  731. cardId: state.cardId,
  732. orderNum: state.orderNum,
  733. payConfigId: wechatPayConfigId,
  734. body: "储值卡充值",
  735. },
  736. method: "POST",
  737. showLoading: true,
  738. };
  739. request(cardCzPay, options).then((res) => {
  740. const data = stringToJson(res.bizContent);
  741. uni.requestPayment({
  742. provider: "wxpay",
  743. orderInfo: "",
  744. timeStamp: data.timestamp,
  745. nonceStr: data.noncestr,
  746. package: data.wxPackage ? data.wxPackage : "",
  747. signType: data.signType,
  748. paySign: data.sign,
  749. success: function () {
  750. //回调订单状态
  751. console.log("回调订单状态");
  752. checkOrder();
  753. },
  754. fail: function (err) {
  755. confirm(err, () => { }, "支付失败", false);
  756. },
  757. });
  758. });
  759. // #endif
  760. };
  761. //掉起支付宝支付
  762. const aliPayment = () => {
  763. // #ifdef MP-ALIPAY
  764. my.getAuthCode({
  765. scopes: 'auth_base',
  766. success: res => {
  767. const optionsUser = {
  768. type: 2,
  769. data: {
  770. payConfigId: aliPayConfigIdTwo,
  771. code: res.authCode
  772. },
  773. method: "POST",
  774. showLoading: true,
  775. };
  776. request(obtainUserId, optionsUser).then((res) => {
  777. const data = stringToJson(res.bizContent);
  778. const optionsali = {
  779. type: 2,
  780. data: {
  781. openId: getItem(StorageKeys.OpenId),
  782. wxOpenId: data.openId,
  783. cardId: state.cardId,
  784. orderNum: state.orderNum,
  785. payConfigId: aliPayConfigIdTwo,
  786. body: "储值卡充值",
  787. },
  788. method: "POST",
  789. showLoading: true,
  790. };
  791. request(cardCzPay, optionsali).then((res) => {
  792. const data = stringToJson(res.bizContent);
  793. my.tradePay({
  794. // 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号 trade_no
  795. tradeNO: data.tranPackage,
  796. success: res => {
  797. console.log("支付成功", res);
  798. checkOrder();
  799. },
  800. fail: res => {
  801. confirm(res, () => { }, "支付失败", false);
  802. },
  803. });
  804. });
  805. });
  806. },
  807. fail: err => {
  808. console.log('my.getAuthCode 调用失败', err)
  809. }
  810. });
  811. // #endif
  812. };
  813. //支付成功改变订单状态
  814. const checkOrder = () => {
  815. const options = {
  816. type: 2,
  817. data: {
  818. cardId: state.cardId,
  819. openId: getItem(StorageKeys.OpenId),
  820. orderNum: state.orderNum,
  821. },
  822. method: "POST",
  823. showLoading: true,
  824. };
  825. request(cardCzPayResult, options).then((res) => {
  826. const data = stringToJson(res.bizContent);
  827. if (data.tradeState === "SUCCESS") {
  828. if (state.transWay == 'blu') {
  829. uni.redirectTo({
  830. url: `/pages/bluetooth/bluetooth?routeType=2&&cardId=${state.cardId}&&fee=${state.fee}`,
  831. });
  832. } else {
  833. uni.redirectTo({
  834. url: `/pages/nfc/nfc?routeType=2&&cardId=${state.cardId}&&fee=${state.fee}`,
  835. });
  836. }
  837. }
  838. console.log(data);
  839. });
  840. };
  841. const goRecord = () => {
  842. uni.navigateTo({
  843. url: `/subpackage/personal-center/consumption-record?cardId=${state.cardId}`
  844. })
  845. }
  846. </script>
  847. <style>
  848. .account {
  849. height: 224rpx;
  850. width: 690rpx;
  851. margin: 30rpx;
  852. position: relative;
  853. }
  854. .account .account-text {
  855. display: flex;
  856. justify-content: space-between;
  857. padding: 20rpx 50rpx;
  858. height: 100%;
  859. }
  860. .account .balance {
  861. display: flex;
  862. flex-direction: column;
  863. justify-content: center;
  864. align-items: flex-start;
  865. color: #ffffff;
  866. }
  867. .account .balance-tit {
  868. font-size: 26rpx;
  869. margin-bottom: 10rpx;
  870. }
  871. .account .balance-val {
  872. font-size: 56rpx;
  873. }
  874. .account .right-box {
  875. display: flex;
  876. flex-direction: column;
  877. justify-content: flex-start;
  878. align-items: flex-end;
  879. }
  880. .account .right-box .no {
  881. font-size: 26rpx;
  882. color: #ffffff;
  883. }
  884. .account .right-box .btn {
  885. font-size: 26rpx;
  886. padding: 0 20rpx;
  887. box-sizing: border-box;
  888. height: 42rpx;
  889. line-height: 42rpx;
  890. color: #28d20f;
  891. background: #ffffff;
  892. border-radius: 21rpx;
  893. display: inline-block;
  894. margin-top: 18rpx;
  895. }
  896. .account .head-bg {
  897. width: 690rpx;
  898. height: 224rpx;
  899. position: absolute;
  900. left: 0;
  901. top: 0;
  902. z-index: -99;
  903. }
  904. .input-box {
  905. display: flex;
  906. flex-direction: column;
  907. justify-content: center;
  908. align-items: center;
  909. padding: 20rpx 0;
  910. }
  911. .input-box .input {
  912. width: 430rpx;
  913. height: 98rpx;
  914. line-height: 98rpx;
  915. background: #f8f8f8;
  916. border: 1px solid #999999;
  917. border-radius: 6rpx;
  918. font-size: 30rpx;
  919. text-align: center;
  920. }
  921. .input-box .tips {
  922. color: #666666;
  923. font-size: 26rpx;
  924. margin-top: 18rpx;
  925. }
  926. .tabs {}
  927. .tabs .tab-tit {
  928. font-size: 30rpx;
  929. color: #333;
  930. padding: 45rpx 0 22rpx 30rpx;
  931. }
  932. .tabs .tab {
  933. display: flex;
  934. flex-wrap: wrap;
  935. justify-content: space-evenly;
  936. }
  937. .tabs .tab .item {
  938. width: 210rpx;
  939. height: 100rpx;
  940. background: #f6fff7;
  941. border: 1px solid #dcdde1;
  942. box-sizing: border-box;
  943. line-height: 100rpx;
  944. border-radius: 6rpx;
  945. text-align: center;
  946. margin-bottom: 24rpx;
  947. color: #333333;
  948. font-size: 32rpx;
  949. }
  950. .tabs .tab .item.active {
  951. border: 1px solid #24cc49;
  952. color: #24cc49;
  953. }
  954. .btn-primary {
  955. width: 670rpx;
  956. height: 80rpx;
  957. line-height: 80rpx;
  958. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  959. border-radius: 40rpx;
  960. font-size: 32rpx;
  961. color: #ffffff;
  962. margin: 200rpx 40rpx 0;
  963. text-align: center;
  964. }
  965. .uni-list {
  966. padding: 120rpx 10rpx 0 10rpx;
  967. font-size: 34rpx;
  968. }
  969. label {
  970. display: flex;
  971. justify-content: space-between;
  972. margin-top: 30rpx;
  973. }
  974. </style>