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-weixin.vue 26KB

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