選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

recharge-weixin.vue 25KB

7ヶ月前
7ヶ月前
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年前
7ヶ月前
1年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029
  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. getOpenId
  53. } from "@/utils/network/api.js";
  54. import {
  55. request,requestNew
  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. console.log("xfcmdArr", xfcmdArr)
  444. transCmd(xfcmdArr, function (resValueData) {
  445. var status = resValueData[1].substring(
  446. resValueData[1].length - 4,
  447. resValueData[1].length
  448. );
  449. console.log("打印状态");
  450. console.log(status);
  451. if (status === "9000") {
  452. console.log(resValueData);
  453. var valueResponse = resValueData.toString();
  454. console.log(response);
  455. var applyDic = {
  456. command: value.command,
  457. cosResponse: valueResponse,
  458. rechargeId: value.rechargeId,
  459. };
  460. console.log("消费成功");
  461. quanApplyAction(applyDic).then((applyValue) => {
  462. uanConfirmAction(applyValue);
  463. });
  464. }
  465. });
  466. } else if (fixStatus === 2) {
  467. uanConfirmSucessAction(value).then((confirmResult) => {
  468. console.log("充值成功")
  469. getCardId(1)
  470. setTimeout(() => {
  471. msg("充值成功");
  472. navTo(`/pages/recharge/result?cardId=${card.cardId}`)
  473. }, 2000)
  474. });
  475. } else if (fixStatus === 1) {
  476. quanCheckActionTrue().then((val) => {
  477. checkQuanCengEvent(val);
  478. });
  479. }
  480. });
  481. uni.hideLoading();
  482. }
  483. });
  484. }
  485. };
  486. /*透传*/
  487. const transCmd = (cmd : any, click : any) => {
  488. if (state.transWay == 'blu') {
  489. bluetoothUtil.transCmd(cmd, "10", function (res : any) {
  490. click(res);
  491. });
  492. } else {
  493. //nfc透传
  494. NFCAPI.transCmd(cmd, function (res : any) {
  495. tools.hideLoadingAlert();
  496. if (res.code == 0) {
  497. click(res.data);
  498. } else {
  499. //透传失败返回
  500. tools.alertF(res.msg);
  501. }
  502. });
  503. }
  504. };
  505. const quanCheckActionTrue = () => {
  506. console.log("进行真实圈存检测");
  507. var data = {
  508. cardId: card.cardId,
  509. fee: state.fee,
  510. preBalance: card.money,
  511. tradeType: 14,
  512. };
  513. const options = {
  514. type: 2,
  515. data: data,
  516. method: "POST",
  517. showLoading: true,
  518. };
  519. return new Promise(async (resolve, reject) => {
  520. const res = await request(quanCheck, options);
  521. const data = stringToJson(res.bizContent);
  522. resolve(data);
  523. }).catch((error) => {
  524. reject(error);
  525. });
  526. };
  527. /*圈存修复*/
  528. const quanFixAction = (val) => {
  529. var data = {
  530. command: val.command, //修复初始化的指令
  531. cosResponse: val.cosResponse, //修复初始化结果
  532. rechargeId: val.rechargeId, //充值流水号
  533. };
  534. const options = {
  535. type: 2,
  536. data: data,
  537. method: "POST",
  538. showLoading: true,
  539. };
  540. return new Promise(async (resolve, reject) => {
  541. const res = await request(quanXf, options);
  542. const data = stringToJson(res.bizContent);
  543. resolve(data);
  544. }).catch((error) => {
  545. reject(error);
  546. });
  547. };
  548. /*圈存申请*/
  549. const quanApplyAction = (data) => {
  550. console.log("圈存申请data====", data, data.rechargeId)
  551. var form = {
  552. cardId: card.cardId,
  553. fee: state.fee,
  554. preBalance: card.money,
  555. tradeType: state.tradeType,
  556. command: data.command,
  557. cosResponse: data.cosResponse,
  558. orderId: state.orderNum,
  559. rechargeId: data.rechargeId,
  560. openId: getItem(StorageKeys.OpenId)
  561. };
  562. const options = {
  563. type: 2,
  564. data: form,
  565. method: "POST",
  566. showLoading: true,
  567. };
  568. return new Promise(async (resolve, reject) => {
  569. const res = await request(quanApply, options);
  570. const data = stringToJson(res.bizContent);
  571. resolve(data);
  572. }).catch((error) => {
  573. reject(error);
  574. });
  575. };
  576. /*圈存确认*/
  577. const uanConfirmAction = (data : any) => {
  578. console.log("圈存确认进入");
  579. let cmdArr = data.command.split(",");
  580. console.log(cmdArr);
  581. transCmd(cmdArr, function (res : any) {
  582. console.log("圈存透传");
  583. console.log(res);
  584. var arraylenth = res.length;
  585. var status = res[arraylenth - 1].substring(
  586. res[arraylenth - 1].length - 4,
  587. res[arraylenth - 1].length
  588. );
  589. console.log("打印圈存确认指令状态");
  590. if (status === "9000") {
  591. var form = {
  592. command: data.command,
  593. cosResponse: res.toString(),
  594. rechargeId: data.rechargeId,
  595. paidAmount: state.fee,
  596. giftAmount: 0,
  597. };
  598. const options = {
  599. type: 2,
  600. data: form,
  601. method: "POST",
  602. showLoading: true,
  603. };
  604. return new Promise(async () => {
  605. const res = await request(quanConfirm, options);
  606. const data = stringToJson(res.bizContent);
  607. console.log("data充值成功", data);
  608. getCardId(1)
  609. setTimeout(() => {
  610. msg("充值成功");
  611. navTo(`/pages/recharge/result?cardId=${card.cardId}`)
  612. }, 2000)
  613. }).catch((error) => {
  614. console.log('输出内容', error)
  615. });
  616. }
  617. });
  618. };
  619. const uanConfirmSucessAction = (data) => {
  620. var form = {
  621. command: data.command,
  622. cosResponse: "9000",
  623. rechargeId: data.rechargeId,
  624. paidAmount: state.fee,
  625. giftAmount: 0,
  626. };
  627. const options = {
  628. type: 2,
  629. data: form,
  630. method: "POST",
  631. showLoading: true,
  632. };
  633. return new Promise(async (resolve, reject) => {
  634. const res = await request(quanConfirm, options);
  635. const data = stringToJson(res.bizContent);
  636. resolve(data);
  637. console.log("uanConfirmSucessAction", data)
  638. }).catch((error) => {
  639. reject(error);
  640. });
  641. };
  642. /*充值检测*/
  643. const czCheckAction = () => {
  644. var form = {
  645. cardId: state.cardId,
  646. openId: getItem(StorageKeys.OpenId),
  647. };
  648. const options = {
  649. type: 2,
  650. data: form,
  651. method: "POST",
  652. showLoading: true,
  653. };
  654. return new Promise(async (resolve, reject) => {
  655. const res = await request(cardCzPayResultCheck, options);
  656. const data = stringToJson(res.bizContent);
  657. console.log("充值检测", data)
  658. resolve(data);
  659. }).catch((error) => {
  660. reject(error);
  661. });
  662. };
  663. /*充值申请*/
  664. const cardCzApplyAction = () => {
  665. var data = {
  666. cardId: state.cardId,
  667. openId: getItem(StorageKeys.OpenId),
  668. rechargeMoney: state.fee,
  669. tradeType: 14,
  670. preBalance: card.money,
  671. };
  672. const options = {
  673. type: 2,
  674. data: data,
  675. method: "POST",
  676. showLoading: true,
  677. };
  678. return new Promise(async (resolve, reject) => {
  679. const res = await request(cardCzApply, options);
  680. const data = stringToJson(res.bizContent);
  681. resolve(data);
  682. }).catch((error) => {
  683. reject(error);
  684. });
  685. };
  686. //获取微信小程序openid
  687. const getOpenID = () => {
  688. uni.login({
  689. provider: "weixin",
  690. success: function (e) {
  691. getOpenid(e.code);
  692. },
  693. fail: function () {
  694. msg("获取不到oppenId,请检查AppID和Secret是否争取");
  695. },
  696. });
  697. };
  698. const getOpenid = (code) => {
  699. const options = {
  700. type: 2,
  701. data: {
  702. "jsCode": code
  703. },
  704. method: "POST",
  705. showLoading: true,
  706. };
  707. // #ifdef MP-WEIXIN
  708. requestNew(getOpenId, options).then((res) => {
  709. const result = res;
  710. console.log("获取微信小程序openid", result);
  711. const openidData = stringToJson(result.data);
  712. state.openid = openidData.openid
  713. });
  714. // #endif
  715. }
  716. //掉起微信支付
  717. const wxPayment = () => {
  718. // #ifdef MP-WEIXIN
  719. const options = {
  720. type: 2,
  721. data: {
  722. openId: getItem(StorageKeys.OpenId),
  723. wxOpenId: state.openid,
  724. cardId: state.cardId,
  725. orderNum: state.orderNum,
  726. payConfigId: wechatPayConfigId,
  727. body: "储值卡充值",
  728. },
  729. method: "POST",
  730. showLoading: true,
  731. };
  732. request(cardCzPay, options).then((res) => {
  733. const data = stringToJson(res.bizContent);
  734. uni.requestPayment({
  735. provider: "wxpay",
  736. orderInfo: "",
  737. timeStamp: data.timestamp,
  738. nonceStr: data.noncestr,
  739. package: data.wxPackage ? data.wxPackage : "",
  740. signType: data.signType,
  741. paySign: data.sign,
  742. success: function () {
  743. //回调订单状态
  744. console.log("回调订单状态");
  745. checkOrder();
  746. },
  747. fail: function (err) {
  748. confirm(err, () => { }, "支付失败", false);
  749. },
  750. });
  751. });
  752. // #endif
  753. };
  754. //掉起支付宝支付
  755. const aliPayment = () => {
  756. // #ifdef MP-ALIPAY
  757. my.getAuthCode({
  758. scopes: 'auth_base',
  759. success: res => {
  760. const optionsUser = {
  761. type: 2,
  762. data: {
  763. payConfigId: aliPayConfigId,
  764. code: res.authCode
  765. },
  766. method: "POST",
  767. showLoading: true,
  768. };
  769. request(obtainUserId, optionsUser).then((res) => {
  770. const data = stringToJson(res.bizContent);
  771. const optionsali = {
  772. type: 2,
  773. data: {
  774. openId: getItem(StorageKeys.OpenId),
  775. wxOpenId: data.openId,
  776. cardId: state.cardId,
  777. orderNum: state.orderNum,
  778. payConfigId: "6a9a54123456578934edfre132b1234",
  779. body: "储值卡充值",
  780. },
  781. method: "POST",
  782. showLoading: true,
  783. };
  784. request(cardCzPay, optionsali).then((res) => {
  785. const data = stringToJson(res.bizContent);
  786. my.tradePay({
  787. // 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号 trade_no
  788. tradeNO: data.tranPackage,
  789. success: res => {
  790. console.log("支付成功", res);
  791. checkOrder();
  792. },
  793. fail: res => {
  794. confirm(res, () => { }, "支付失败", false);
  795. },
  796. });
  797. });
  798. });
  799. },
  800. fail: err => {
  801. console.log('my.getAuthCode 调用失败', err)
  802. }
  803. });
  804. // #endif
  805. };
  806. //支付成功改变订单状态
  807. const checkOrder = () => {
  808. const options = {
  809. type: 2,
  810. data: {
  811. cardId: state.cardId,
  812. openId: getItem(StorageKeys.OpenId),
  813. orderNum: state.orderNum,
  814. },
  815. method: "POST",
  816. showLoading: true,
  817. };
  818. request(cardCzPayResult, options).then((res) => {
  819. const data = stringToJson(res.bizContent);
  820. if (data.tradeState === "SUCCESS") {
  821. getCardId();
  822. }
  823. console.log(data);
  824. });
  825. };
  826. const goRecord = () => {
  827. uni.navigateTo({
  828. url: `/subpackage/personal-center/consumption-record?cardId=${state.cardId}`
  829. })
  830. }
  831. // 校验金额输入框
  832. const checkNum = (event) => {
  833. let sNum = event.target.value.toString(); //先转换成字符串类
  834. if (sNum.indexOf('.') == 0) {//第一位就是 .
  835. console.log('first str is .')
  836. sNum = '0' + sNum
  837. }
  838. sNum = sNum.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
  839. sNum = sNum.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
  840. sNum = sNum.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
  841. sNum = sNum.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');//只能输入两个小数
  842. //以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额
  843. if (sNum.indexOf(".") < 0 && sNum != "") {
  844. sNum = parseFloat(sNum);
  845. }
  846. console.log('输入的值1', sNum)
  847. setTimeout(() => {
  848. state.money = sNum
  849. }, 20)
  850. }
  851. </script>
  852. <style>
  853. .account {
  854. height: 224rpx;
  855. width: 690rpx;
  856. margin: 30rpx;
  857. position: relative;
  858. }
  859. .account .account-text {
  860. display: flex;
  861. justify-content: space-between;
  862. padding: 20rpx 50rpx;
  863. height: 100%;
  864. }
  865. .account .balance {
  866. display: flex;
  867. flex-direction: column;
  868. justify-content: center;
  869. align-items: flex-start;
  870. color: #ffffff;
  871. }
  872. .account .balance-tit {
  873. font-size: 26rpx;
  874. margin-bottom: 10rpx;
  875. }
  876. .account .balance-val {
  877. font-size: 56rpx;
  878. }
  879. .account .right-box {
  880. display: flex;
  881. flex-direction: column;
  882. justify-content: flex-start;
  883. align-items: flex-end;
  884. }
  885. .account .right-box .no {
  886. font-size: 26rpx;
  887. color: #ffffff;
  888. }
  889. .account .right-box .btn {
  890. font-size: 26rpx;
  891. padding: 0 20rpx;
  892. box-sizing: border-box;
  893. height: 42rpx;
  894. line-height: 42rpx;
  895. color: #28d20f;
  896. background: #ffffff;
  897. border-radius: 21rpx;
  898. display: inline-block;
  899. margin-top: 18rpx;
  900. }
  901. .account .head-bg {
  902. width: 690rpx;
  903. height: 224rpx;
  904. position: absolute;
  905. left: 0;
  906. top: 0;
  907. z-index: -99;
  908. }
  909. .input-box {
  910. display: flex;
  911. flex-direction: column;
  912. justify-content: center;
  913. align-items: center;
  914. padding: 20rpx 0;
  915. }
  916. .input-box .input {
  917. width: 430rpx;
  918. height: 98rpx;
  919. line-height: 98rpx;
  920. background: #f8f8f8;
  921. border: 1px solid #999999;
  922. border-radius: 6rpx;
  923. font-size: 30rpx;
  924. text-align: center;
  925. }
  926. .input-box .tips {
  927. color: #666666;
  928. font-size: 26rpx;
  929. margin-top: 18rpx;
  930. }
  931. .tabs {}
  932. .tabs .tab-tit {
  933. font-size: 30rpx;
  934. color: #333;
  935. padding: 45rpx 0 22rpx 30rpx;
  936. }
  937. .tabs .tab {
  938. display: flex;
  939. flex-wrap: wrap;
  940. justify-content: space-evenly;
  941. }
  942. .tabs .tab .item {
  943. width: 210rpx;
  944. height: 100rpx;
  945. background: #f6fff7;
  946. border: 1px solid #dcdde1;
  947. box-sizing: border-box;
  948. line-height: 100rpx;
  949. border-radius: 6rpx;
  950. text-align: center;
  951. margin-bottom: 24rpx;
  952. color: #333333;
  953. font-size: 32rpx;
  954. }
  955. .tabs .tab .item.active {
  956. border: 1px solid #24cc49;
  957. color: #24cc49;
  958. }
  959. .btn-primary {
  960. width: 670rpx;
  961. height: 80rpx;
  962. line-height: 80rpx;
  963. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  964. border-radius: 40rpx;
  965. font-size: 32rpx;
  966. color: #ffffff;
  967. margin: 200rpx 40rpx 0;
  968. text-align: center;
  969. }
  970. .uni-list {
  971. padding: 120rpx 10rpx 0 10rpx;
  972. font-size: 34rpx;
  973. }
  974. label {
  975. display: flex;
  976. justify-content: space-between;
  977. margin-top: 30rpx;
  978. }
  979. </style>