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

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