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

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