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

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