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

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