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

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