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

1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
1 년 전
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. 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. tools.hideLoadingAlert();
  350. }
  351. function getCardIdReturn(res : any) {
  352. tools.hideLoadingAlert();
  353. //10:写卡 20:写OBU
  354. let str = res[2].substring(res[2].length - 4, res[2].length);
  355. let str3 = res[3].substring(res[3].length - 4, res[3].length);
  356. if (str == "9000" || str3 == "9000") {
  357. if (res[2].length > 86 || res[3] >= 12) {
  358. state.cardId = res[2].substring(20, 40); //卡号
  359. card.cardId = res[2].substring(20, 40); //卡号
  360. card.startTime = res[2].substring(40, 48);
  361. card.endTime = res[2].substring(48, 56);
  362. card.version = res[2].substring(18, 19) >= 4 ? "4x" : "2x";
  363. card.netId = res[2].substring(20, 24);
  364. card.cardType = res[2].substring(28, 29) == 23 ? 1 : 2;
  365. card.vehiclePlateColor = parseInt(res[2].substring(82, 84), 16);
  366. (card.money = parseInt(parseInt(res[3].substring(0, 8), 16), 10)),
  367. console.log("======卡信息======", card, card.money);
  368. quanCheckActionTrue().then((val) => {
  369. checkQuanCengEvent(val);
  370. });
  371. } else {
  372. console.error("CMD_READBINARY指令长度不符" + res[2]);
  373. tools.hideLoadingAlert();
  374. }
  375. }
  376. console.error("CMD_READBINARY指令长度不符" + res[2]);
  377. tools.hideLoadingAlert();
  378. }
  379. const checkQuanCengEvent = (val : any) => {
  380. if (val.chargeStatus === 1) {
  381. let cmdArr = val.command.split(",");
  382. uni.showLoading({
  383. title: "写入中",
  384. });
  385. transCmd(cmdArr, function (res : any) {
  386. let response = res.toString();
  387. var dic = {
  388. command: val.command,
  389. cosResponse: response,
  390. };
  391. uni.hideLoading();
  392. quanApplyAction(dic).then((value : any) => {
  393. console.log("圈存申请完后的结果");
  394. console.log(value.commandType, value);
  395. //圈存初始化验证通过 , 进行圈存
  396. if (value.commandType === 2) {
  397. uanConfirmAction(value);
  398. } else {
  399. console.log("第二次70", value)
  400. let cmdArr = value.command.split(",");
  401. uni.showLoading({
  402. title: "写入中",
  403. });
  404. transCmd(cmdArr, function (res : any) {
  405. let response = res.toString();
  406. var dic = {
  407. command: val.command,
  408. cosResponse: response,
  409. };
  410. uni.hideLoading();
  411. quanApplyAction(dic).then((values) => {
  412. console.log("圈存申请完后的结果");
  413. uanConfirmAction(values);
  414. });
  415. })
  416. }
  417. });
  418. });
  419. } else {
  420. let cmdArr = val.command.split(",");
  421. uni.showLoading({
  422. title: "写入中",
  423. });
  424. transCmd(cmdArr, function (res : any) {
  425. var status = res[1].substring(res[1].length - 4, res[1].length);
  426. console.log("打印状态");
  427. console.log(status);
  428. if (status === "9000") {
  429. console.log("修复指令入参");
  430. let response = res.toString();
  431. var dic = {
  432. command: val.command,
  433. cosResponse: response,
  434. rechargeId: val.rechargeId,
  435. };
  436. quanFixAction(dic).then((value : any) => {
  437. state.orderNum = value.orderId
  438. state.tradeType = value.tradeType
  439. console.log(value);
  440. console.log("修复结果返回");
  441. var fixStatus = value.fixStatus;
  442. //圈存修复COS指令Response信息不足,重新进行修复初始化
  443. if (fixStatus === 3) {
  444. let xfcmdArr = value.command.split(",");
  445. bluetoothUtil.transCmd(xfcmdArr, "10", function (resValueData) {
  446. var status = resValueData[1].substring(
  447. resValueData[1].length - 4,
  448. resValueData[1].length
  449. );
  450. console.log("打印状态");
  451. console.log(status);
  452. if (status === "9000") {
  453. console.log(resValueData);
  454. var valueResponse = resValueData.toString();
  455. console.log(response);
  456. var applyDic = {
  457. command: value.command,
  458. cosResponse: valueResponse,
  459. rechargeId: value.rechargeId,
  460. };
  461. console.log("消费成功");
  462. quanApplyAction(applyDic).then((applyValue) => {
  463. uanConfirmAction(applyValue);
  464. });
  465. }
  466. });
  467. } else if (fixStatus === 2) {
  468. uanConfirmSucessAction(value).then((confirmResult) => {
  469. console.log("充值成功")
  470. getCardId(1)
  471. setTimeout(() => {
  472. msg("充值成功");
  473. navTo(`/pages/recharge/result?cardId=${card.cardId}`)
  474. }, 2000)
  475. });
  476. } else if (fixStatus === 1) {
  477. quanCheckActionTrue().then((val) => {
  478. checkQuanCengEvent(val);
  479. });
  480. }
  481. });
  482. uni.hideLoading();
  483. }
  484. });
  485. }
  486. };
  487. /*透传*/
  488. const transCmd = (cmd : any, click : any) => {
  489. if (state.transWay == 'blu') {
  490. bluetoothUtil.transCmd(cmd, "10", function (res : any) {
  491. click(res);
  492. });
  493. } else {
  494. //nfc透传
  495. NFCAPI.transCmd(cmd, function (res : any) {
  496. tools.hideLoadingAlert();
  497. if (res.code == 0) {
  498. click(res.data);
  499. } else {
  500. //透传失败返回
  501. tools.alertF(res.msg);
  502. }
  503. });
  504. }
  505. };
  506. const quanCheckActionTrue = () => {
  507. console.log("进行真实圈存检测");
  508. var data = {
  509. cardId: card.cardId,
  510. fee: state.fee,
  511. preBalance: card.money,
  512. tradeType: 14,
  513. };
  514. const options = {
  515. type: 2,
  516. data: data,
  517. method: "POST",
  518. showLoading: true,
  519. };
  520. return new Promise(async (resolve, reject) => {
  521. const res = await request(quanCheck, options);
  522. const data = stringToJson(res.bizContent);
  523. resolve(data);
  524. }).catch((error) => {
  525. reject(error);
  526. });
  527. };
  528. /*圈存修复*/
  529. const quanFixAction = (val) => {
  530. var data = {
  531. command: val.command, //修复初始化的指令
  532. cosResponse: val.cosResponse, //修复初始化结果
  533. rechargeId: val.rechargeId, //充值流水号
  534. };
  535. const options = {
  536. type: 2,
  537. data: data,
  538. method: "POST",
  539. showLoading: true,
  540. };
  541. return new Promise(async (resolve, reject) => {
  542. const res = await request(quanXf, options);
  543. const data = stringToJson(res.bizContent);
  544. resolve(data);
  545. }).catch((error) => {
  546. reject(error);
  547. });
  548. };
  549. /*圈存申请*/
  550. const quanApplyAction = (data) => {
  551. console.log("圈存申请data====", data, data.rechargeId)
  552. var form = {
  553. cardId: card.cardId,
  554. fee: state.fee,
  555. preBalance: card.money,
  556. tradeType: state.tradeType,
  557. command: data.command,
  558. cosResponse: data.cosResponse,
  559. orderId: state.orderNum,
  560. rechargeId: data.rechargeId,
  561. openId: getItem(StorageKeys.OpenId)
  562. };
  563. const options = {
  564. type: 2,
  565. data: form,
  566. method: "POST",
  567. showLoading: true,
  568. };
  569. return new Promise(async (resolve, reject) => {
  570. const res = await request(quanApply, options);
  571. const data = stringToJson(res.bizContent);
  572. resolve(data);
  573. }).catch((error) => {
  574. reject(error);
  575. });
  576. };
  577. /*圈存确认*/
  578. const uanConfirmAction = (data : any) => {
  579. console.log("圈存确认进入");
  580. let cmdArr = data.command.split(",");
  581. console.log(cmdArr);
  582. transCmd(cmdArr, function (res : any) {
  583. console.log("圈存透传");
  584. console.log(res);
  585. var arraylenth = res.length;
  586. var status = res[arraylenth - 1].substring(
  587. res[arraylenth - 1].length - 4,
  588. res[arraylenth - 1].length
  589. );
  590. console.log("打印圈存确认指令状态");
  591. if (status === "9000") {
  592. var form = {
  593. command: data.command,
  594. cosResponse: res.toString(),
  595. rechargeId: data.rechargeId,
  596. paidAmount: state.fee,
  597. giftAmount: 0,
  598. };
  599. const options = {
  600. type: 2,
  601. data: form,
  602. method: "POST",
  603. showLoading: true,
  604. };
  605. return new Promise(async () => {
  606. const res = await request(quanConfirm, options);
  607. const data = stringToJson(res.bizContent);
  608. console.log("data充值成功", data);
  609. getCardId(1)
  610. setTimeout(() => {
  611. msg("充值成功");
  612. navTo(`/pages/recharge/result?cardId=${card.cardId}`)
  613. }, 2000)
  614. }).catch((error) => {
  615. console.log('输出内容', error)
  616. });
  617. }
  618. });
  619. };
  620. const uanConfirmSucessAction = (data) => {
  621. var form = {
  622. command: data.command,
  623. cosResponse: "9000",
  624. rechargeId: data.rechargeId,
  625. paidAmount: state.fee,
  626. giftAmount: 0,
  627. };
  628. const options = {
  629. type: 2,
  630. data: form,
  631. method: "POST",
  632. showLoading: true,
  633. };
  634. return new Promise(async (resolve, reject) => {
  635. const res = await request(quanConfirm, options);
  636. const data = stringToJson(res.bizContent);
  637. resolve(data);
  638. console.log("uanConfirmSucessAction", data)
  639. }).catch((error) => {
  640. reject(error);
  641. });
  642. };
  643. /*充值检测*/
  644. const czCheckAction = () => {
  645. var form = {
  646. cardId: state.cardId,
  647. openId: getItem(StorageKeys.OpenId),
  648. };
  649. const options = {
  650. type: 2,
  651. data: form,
  652. method: "POST",
  653. showLoading: true,
  654. };
  655. return new Promise(async (resolve, reject) => {
  656. const res = await request(cardCzPayResultCheck, options);
  657. const data = stringToJson(res.bizContent);
  658. console.log("充值检测", data)
  659. resolve(data);
  660. }).catch((error) => {
  661. reject(error);
  662. });
  663. };
  664. /*充值申请*/
  665. const cardCzApplyAction = () => {
  666. var data = {
  667. cardId: state.cardId,
  668. openId: getItem(StorageKeys.OpenId),
  669. rechargeMoney: state.fee,
  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>