You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

recharge-weixin.vue 25KB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  1. <template>
  2. <view class="wrapper">
  3. <view class="account">
  4. <image :src="`${$imgUrl}common/bg-recharge.png`" class="head-bg" mode="aspectFill"></image>
  5. <view class="account-text">
  6. <view class="balance">
  7. <text class="balance-tit">账户余额</text>
  8. <text class="balance-val">{{card.money/100}}元</text>
  9. </view>
  10. <view class="right-box">
  11. <view class="no">账户编号:000100</view>
  12. <view class="btn btn-record" @click="goRecord()">账户充值记录</view>
  13. </view>
  14. </view>
  15. </view>
  16. <view class="input-box">
  17. <input v-model="state.money" placeholder="请输入金额" class="input" />
  18. <view class="tips">最低充值金额不小于10元</view>
  19. </view>
  20. <view class="tabs">
  21. <!-- <view class="tab-tit as-gravity-center-start">充值方式
  22. <u-input @click="state.transWayTypeShow = true" inputAlign="center" v-model="state.transWayName"
  23. type="select" />
  24. </view> -->
  25. <view class="tab-tit">在线充值</view>
  26. <view class="tab">
  27. <view v-for="(item,index) in state.moneryArray" @click="tableIndexAction(index)" :key="index"
  28. :class="{'item':state.moneryArray,'active':state.tableIndex===index}">{{item.name}}</view>
  29. </view>
  30. </view>
  31. <view class="btn btn-primary" @click="rechargeAction">立即充值</view>
  32. </view>
  33. <u-select v-model="state.transWayTypeShow" :list="state.transWayTypeList" @confirm="selectConfirm"></u-select>
  34. </template>
  35. <script setup lang="ts">
  36. import {
  37. stringToJson
  38. } from "@/utils/network/encryption";
  39. import {
  40. onLoad,
  41. onShow
  42. } from "@dcloudio/uni-app";
  43. import {
  44. quanCheck,
  45. quanApply,
  46. quanXf,
  47. cardCzPayResultCheck,
  48. cardCzApply,
  49. cardCzPay,
  50. cardCzPayResult,
  51. cardCzXFCheck,
  52. quanConfirm,
  53. wechatAppID,
  54. wechatPayConfigId,
  55. wechatSecret,
  56. aliPayConfigId,
  57. obtainUserId,
  58. getOpenidApi
  59. } from "@/utils/network/api.js";
  60. import {
  61. request
  62. } from "@/utils/network/request.js";
  63. import {
  64. reactive
  65. } from "vue";
  66. import {
  67. navTo
  68. } from "@/utils/utils"
  69. import {
  70. msg
  71. } from "@/utils/utils";
  72. import {
  73. getItem,
  74. StorageKeys,
  75. setItem
  76. } from "@/utils/storage";
  77. const datas = require("../../static/etcUtil/datas.js");
  78. const bluetoothUtil = require("../../static/etcUtil/index.js");
  79. const cmd = require("../../static/etcUtil/cmdConfig.js");
  80. const tools = require("../../static/etcUtil/tools.js");
  81. const NFCAPI = require('../../static/nfc/NFCAPI.js');
  82. const state = reactive({
  83. transWayTypeShow: false,
  84. transWayTypeList: [{
  85. label: "蓝牙",
  86. value: "blu",
  87. }, {
  88. label: "NFC",
  89. value: "nfc",
  90. }
  91. ],
  92. isShowBlue: false,
  93. moneryArray: [{
  94. name: '50元',
  95. value: 50
  96. }, {
  97. name: '100元',
  98. value: 100
  99. }, {
  100. name: '200元',
  101. value: 200
  102. }, {
  103. name: '300元',
  104. value: 300
  105. }, {
  106. name: '500元',
  107. value: 500
  108. }, {
  109. name: '1000元',
  110. value: 1000
  111. }],
  112. tableIndex: 0,
  113. openid: "",
  114. connectSuccess: undefined,
  115. fee: 5000,
  116. money: 50,
  117. orderNum: "",
  118. transWayName: "蓝牙",
  119. transWay: "blu", //“blu”为蓝牙充值方式、“nfc”为NFC充值方式
  120. cardId: "", //卡号 需要传参
  121. mockpreBalance: 2000, //fix:模拟余额 目前没有检测状态接口,第一次会模拟圈层检测来检测状态
  122. show: false,
  123. items: [{
  124. value: '0',
  125. name: '微信',
  126. checked: 'true'
  127. },
  128. {
  129. value: '1',
  130. name: '对公账户'
  131. }
  132. ],
  133. current: 0
  134. });
  135. const selectConfirm = (item : any) => {
  136. state.transWayName = item[0].label
  137. state.transWay = item[0].value
  138. };
  139. //读卡信息
  140. const card : any = reactive({
  141. cardId: "",
  142. netId: "",
  143. cardType: "",
  144. startTime: "",
  145. endTime: "",
  146. userName: "",
  147. idNum: "",
  148. vehiclePlate: "",
  149. vehiclePlateColor: "",
  150. color: "",
  151. version: "",
  152. type: "",
  153. favourable: "",
  154. money: undefined,
  155. v_userType: "",
  156. });
  157. onLoad((option) => {
  158. /*获取openId 用途:(用户支付)*/
  159. // #ifdef MP-WEIXIN
  160. getOpenID();/*传参*/
  161. // #endif
  162. console.log("开始option", option)
  163. state.transWay = option.transWay == 'nfc' ? "nfc" : "blu"
  164. // state.cardId = option.cardId;
  165. state.connectSuccess = option.connectSuccess;
  166. state.orderNum = getItem("orderNum");
  167. // 金额回填,本来是好的,但是他跳转了,跳转过来就得刷新页面,所以就是默认的5000
  168. if (option.fee) {
  169. state.fee = option.fee
  170. state.money = option.fee / 100
  171. } else {
  172. state.fee = state.money * 100; //元换成分
  173. }
  174. console.log("state.fee", option, state.fee)
  175. //跳转过来走圈存流程
  176. // connectSuccess 2 从选择方式进来去圈存检测 1 只读卡
  177. if (state.connectSuccess === "1") {
  178. /*读卡*/
  179. getCardId(1);
  180. } else {
  181. quanCheckActionTrue().then((val : any) => {
  182. console.log("圈层检测val", val)
  183. //如果 圈层检测正常
  184. if (val.chargeStatus === 1) {
  185. console.log(`进行充值检测`);
  186. czCheckAction().then((checkResult : any) => {
  187. //判断订单逻辑如果有订单充值 则直接拿到订单去链接蓝牙
  188. if (checkResult.orders && checkResult.orders.length > 0) {
  189. //拿到订单,存起来
  190. state.orderNum = checkResult.orders[0].orderNum;
  191. setItem("orderNum", state.orderNum);
  192. // 检测用户是否存在有半条流水
  193. } else {
  194. console.log('没有可修复的流水')
  195. }
  196. });
  197. } else {
  198. // 检测用户是否存在有半条流水
  199. }
  200. });
  201. }
  202. });
  203. function radioChange(evt) {
  204. console.log('输出内容', evt)
  205. state.transWay = evt.detail.value; //“blu”为蓝牙充值方式、“nfc”为NFC充值方式
  206. }
  207. function go(money) {
  208. let content = ""
  209. if (money) {
  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. setItem("orderNum", state.orderNum);
  232. // 检测用户是否存在有半条流水
  233. getCardId()
  234. } else {
  235. console.log('没有可修复的流水')
  236. }
  237. });
  238. } else {
  239. // 检测用户是否存在有半条流水
  240. // let fixFee = val.fixFee / 100
  241. // console.log("fixFee", fixFee)
  242. // go(fixFee)
  243. getCardId()
  244. }
  245. });
  246. } else if (res.cancel) {
  247. console.log('用户点击取消');
  248. }
  249. console.log("state.isShowBlue", state.isShowBlue)
  250. },
  251. fail: () => {
  252. }
  253. })
  254. }
  255. const tableIndexAction = (val : any) => {
  256. state.tableIndex = val
  257. state.money = state.moneryArray[val].value
  258. }
  259. /*点击充值按钮*/
  260. const rechargeAction = () => {
  261. state.fee = state.money * 100; //元换成分
  262. uni.showModal({
  263. title: '圈存确认',
  264. content: '您确定要充值圈存吗',
  265. success: function (res) {
  266. if (res.confirm) {
  267. /*进行圈层检测,此处检测仅为校验圈层状态来决定去哪里*/
  268. console.log("进行圈层检测");
  269. quanCheckActionTrue().then((val : any) => {
  270. console.log("圈存检测接口返回", val)
  271. //如果 圈层检测正常
  272. if (val.chargeStatus === 1) {
  273. console.log(`进行充值检测`);
  274. czCheckAction().then((checkResult : any) => {
  275. console.log("进行充值检测", checkResult)
  276. //判断订单逻辑如果有订单充值 则直接拿到订单去链接蓝牙
  277. if (checkResult.orders && checkResult.orders.length > 0) {
  278. state.fee = checkResult.orders[0]['rechargeMoney']
  279. state.money = checkResult.orders[0]['rechargeMoney'] / 100
  280. //拿到订单,存起来
  281. state.orderNum = checkResult.orders[0].orderNum;
  282. setItem("orderNum", state.orderNum);
  283. //链接蓝牙
  284. go(state.money)
  285. } else {
  286. cardCzApplyAction().then((applyResult : any) => {
  287. //拿到订单 存起来
  288. state.orderNum = applyResult.orderNum;
  289. setItem("orderNum", state.orderNum);
  290. //如果订单没有支付 走支付
  291. if (applyResult.orderStatus === "ORDER_NOT_PAY") {
  292. //走支付
  293. console.log("走支付");
  294. // #ifdef MP-WEIXIN
  295. wxPayment();
  296. // #endif
  297. // #ifdef MP-ALIPAY
  298. aliPayment()
  299. // #endif
  300. }
  301. });
  302. }
  303. });
  304. } else {
  305. //走蓝牙进行修复
  306. // 圈存检测异常,继续上次圈存 chargeStatus==2
  307. let fixFee = val.fixFee / 100
  308. console.log("fixFee", fixFee)
  309. go(fixFee)
  310. }
  311. });
  312. }
  313. }
  314. });
  315. };
  316. /*读卡*/
  317. const getCardId = (readCard) => {
  318. console.log("======获取卡信息======");
  319. let cmdArr = [
  320. cmd.HOME_DIRECTORY,
  321. //选择主目
  322. cmd.APPLICATION_DIRECTORY,
  323. //选择文件1001--DF01联网收费应用目录
  324. cmd.CMD_READBINARY,
  325. //15文件--卡片发行基本数据文件
  326. cmd.CMD_GETBALANCE,
  327. //钱包
  328. ];
  329. tools.showLoadingAlert("正在执行指令");
  330. transCmd(cmdArr, function (res : any) {
  331. if (readCard == 1) {
  332. // 只读卡号
  333. getCardIdReturnReadCard(res)
  334. } else {
  335. getCardIdReturn(res);
  336. }
  337. })
  338. };
  339. function getCardIdReturnReadCard(res : any) {
  340. tools.hideLoadingAlert();
  341. //10:写卡 20:写OBU
  342. let str = res[2].substring(res[2].length - 4, res[2].length);
  343. let str3 = res[3].substring(res[3].length - 4, res[3].length);
  344. if (str == "9000" || str3 == "9000") {
  345. if (res[2].length > 86 || res[3] >= 12) {
  346. state.cardId = res[2].substring(20, 40); //卡号
  347. card.cardId = res[2].substring(20, 40); //卡号
  348. card.money = parseInt(parseInt(res[3].substring(0, 8), 16), 10)
  349. console.log("======卡信息======", card, state.cardId);
  350. } else {
  351. console.error("CMD_READBINARY指令长度不符" + res[2]);
  352. tools.hideLoadingAlert();
  353. }
  354. }
  355. console.error("CMD_READBINARY指令长度不符" + res[2]);
  356. tools.hideLoadingAlert();
  357. }
  358. function getCardIdReturn(res : any) {
  359. tools.hideLoadingAlert();
  360. //10:写卡 20:写OBU
  361. let str = res[2].substring(res[2].length - 4, res[2].length);
  362. let str3 = res[3].substring(res[3].length - 4, res[3].length);
  363. if (str == "9000" || str3 == "9000") {
  364. if (res[2].length > 86 || res[3] >= 12) {
  365. state.cardId = res[2].substring(20, 40); //卡号
  366. card.cardId = res[2].substring(20, 40); //卡号
  367. card.startTime = res[2].substring(40, 48);
  368. card.endTime = res[2].substring(48, 56);
  369. card.version = res[2].substring(18, 19) >= 4 ? "4x" : "2x";
  370. card.netId = res[2].substring(20, 24);
  371. card.cardType = res[2].substring(28, 29) == 23 ? 1 : 2;
  372. card.vehiclePlateColor = parseInt(res[2].substring(82, 84), 16);
  373. (card.money = parseInt(parseInt(res[3].substring(0, 8), 16), 10)),
  374. console.log("======卡信息======", card, card.money);
  375. // if (card.cardId !== state.cardId) {
  376. // msg("设备卡信息与当前充值卡号不匹配,请核对卡号");
  377. // return;
  378. // }
  379. quanCheckActionTrue().then((val) => {
  380. checkQuanCengEvent(val);
  381. });
  382. } else {
  383. console.error("CMD_READBINARY指令长度不符" + res[2]);
  384. tools.hideLoadingAlert();
  385. }
  386. }
  387. console.error("CMD_READBINARY指令长度不符" + res[2]);
  388. tools.hideLoadingAlert();
  389. }
  390. const checkQuanCengEvent = (val : any) => {
  391. if (val.chargeStatus === 1) {
  392. let cmdArr = val.command.split(",");
  393. uni.showLoading({
  394. title: "写入中",
  395. });
  396. transCmd(cmdArr, function (res : any) {
  397. let response = res.toString();
  398. var dic = {
  399. command: val.command,
  400. cosResponse: response,
  401. };
  402. uni.hideLoading();
  403. cardCzXFCheckAction().then((xfRes) => {
  404. quanApplyAction(dic).then((value : any) => {
  405. console.log("圈层申请完后的结果");
  406. console.log(value.commandType, value);
  407. //圈存初始化验证通过 , 进行圈存
  408. if (value.commandType === 2) {
  409. uanConfirmAction(value);
  410. } else {
  411. quanApplyAction(value).then((values) => {
  412. console.log("圈层申请完后的结果");
  413. uanConfirmAction(values);
  414. });
  415. // msg("圈存初始化指令验证失败, 重新初始化");
  416. }
  417. });
  418. });
  419. });
  420. } else {
  421. let cmdArr = val.command.split(",");
  422. uni.showLoading({
  423. title: "写入中",
  424. });
  425. transCmd(cmdArr, function (res : any) {
  426. var status = res[1].substring(res[1].length - 4, res[1].length);
  427. console.log("打印状态");
  428. console.log(status);
  429. if (status === "9000") {
  430. console.log("修复指令入参");
  431. let response = res.toString();
  432. var dic = {
  433. command: val.command,
  434. cosResponse: response,
  435. rechargeId: val.rechargeId,
  436. };
  437. quanFixAction(dic).then((value : any) => {
  438. console.log(value);
  439. console.log("修复结果返回");
  440. var fixStatus = value.fixStatus;
  441. //圈存修复COS指令Response信息不足,重新进行修复初始化
  442. if (fixStatus === 3) {
  443. let xfcmdArr = value.command.split(",");
  444. bluetoothUtil.transCmd(xfcmdArr, "10", 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`)
  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 cardCzXFCheckAction = () => {
  529. var data = {
  530. cardId: card.cardId, //修复初始化的指令
  531. openId: getItem(StorageKeys.OpenId), //修复初始化结果
  532. orderNum: state.orderNum, //充值流水号
  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(cardCzXFCheck, options);
  542. const data = stringToJson(res.bizContent);
  543. resolve(data);
  544. }).catch((error) => {
  545. reject(error);
  546. });
  547. };
  548. /*圈存修复*/
  549. const quanFixAction = (val) => {
  550. var data = {
  551. command: val.command, //修复初始化的指令
  552. cosResponse: val.cosResponse, //修复初始化结果
  553. rechargeId: val.rechargeId, //充值流水号
  554. };
  555. const options = {
  556. type: 2,
  557. data: data,
  558. method: "POST",
  559. showLoading: true,
  560. };
  561. return new Promise(async (resolve, reject) => {
  562. const res = await request(quanXf, options);
  563. const data = stringToJson(res.bizContent);
  564. resolve(data);
  565. }).catch((error) => {
  566. reject(error);
  567. });
  568. };
  569. /*圈层申请*/
  570. const quanApplyAction = (data) => {
  571. console.log("圈层申请data====", data, data.rechargeId)
  572. var form = {
  573. cardId: card.cardId,
  574. fee: state.fee,
  575. preBalance: card.money,
  576. tradeType: 14,
  577. command: data.command,
  578. cosResponse: data.cosResponse,
  579. orderId: state.orderNum,
  580. rechargeId: data.rechargeId,
  581. openId: getItem(StorageKeys.OpenId)
  582. };
  583. const options = {
  584. type: 2,
  585. data: form,
  586. method: "POST",
  587. showLoading: true,
  588. };
  589. return new Promise(async (resolve, reject) => {
  590. const res = await request(quanApply, options);
  591. const data = stringToJson(res.bizContent);
  592. resolve(data);
  593. }).catch((error) => {
  594. reject(error);
  595. });
  596. };
  597. /*圈层确认*/
  598. const uanConfirmAction = (data : any) => {
  599. console.log("圈层确认进入");
  600. let cmdArr = data.command.split(",");
  601. console.log(cmdArr);
  602. transCmd(cmdArr, function (res : any) {
  603. console.log("圈层透传");
  604. console.log(res);
  605. var arraylenth = res.length;
  606. var status = res[arraylenth - 1].substring(
  607. res[arraylenth - 1].length - 4,
  608. res[arraylenth - 1].length
  609. );
  610. console.log("打印圈层确认指令状态");
  611. if (status === "9000") {
  612. var form = {
  613. command: data.command,
  614. cosResponse: res.toString(),
  615. rechargeId: data.rechargeId,
  616. paidAmount: state.fee,
  617. giftAmount: 0,
  618. };
  619. const options = {
  620. type: 2,
  621. data: form,
  622. method: "POST",
  623. showLoading: true,
  624. };
  625. return new Promise(async () => {
  626. const res = await request(quanConfirm, options);
  627. const data = stringToJson(res.bizContent);
  628. console.log("data充值成功", data);
  629. getCardId(1)
  630. setTimeout(() => {
  631. msg("充值成功");
  632. navTo(`/pages/recharge/result`)
  633. }, 2000)
  634. }).catch((error) => {
  635. console.log('输出内容', error)
  636. });
  637. }
  638. });
  639. };
  640. const uanConfirmSucessAction = (data) => {
  641. var form = {
  642. command: data.command,
  643. cosResponse: "9000",
  644. rechargeId: data.rechargeId,
  645. paidAmount: state.fee,
  646. giftAmount: 0,
  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(quanConfirm, options);
  656. const data = stringToJson(res.bizContent);
  657. resolve(data);
  658. console.log("uanConfirmSucessAction", data)
  659. }).catch((error) => {
  660. reject(error);
  661. });
  662. };
  663. /*充值检测*/
  664. const czCheckAction = () => {
  665. var form = {
  666. cardId: state.cardId,
  667. openId: getItem(StorageKeys.OpenId),
  668. };
  669. const options = {
  670. type: 2,
  671. data: form,
  672. method: "POST",
  673. showLoading: true,
  674. };
  675. return new Promise(async (resolve, reject) => {
  676. const res = await request(cardCzPayResultCheck, options);
  677. const data = stringToJson(res.bizContent);
  678. console.log("充值检测", data)
  679. resolve(data);
  680. }).catch((error) => {
  681. reject(error);
  682. });
  683. };
  684. /*充值申请*/
  685. const cardCzApplyAction = () => {
  686. var data = {
  687. cardId: state.cardId,
  688. openId: getItem(StorageKeys.OpenId),
  689. rechargeMoney: state.fee,
  690. };
  691. const options = {
  692. type: 2,
  693. data: data,
  694. method: "POST",
  695. showLoading: true,
  696. };
  697. return new Promise(async (resolve, reject) => {
  698. const res = await request(cardCzApply, options);
  699. const data = stringToJson(res.bizContent);
  700. resolve(data);
  701. }).catch((error) => {
  702. reject(error);
  703. });
  704. };
  705. //获取微信小程序openid
  706. const getOpenID = () => {
  707. uni.login({
  708. provider: "weixin",
  709. success: function (e) {
  710. getOpenid(e.code);
  711. },
  712. fail: function () {
  713. msg("获取不到oppenId,请检查AppID和Secret是否争取");
  714. },
  715. });
  716. };
  717. const getOpenid = (code) => {
  718. const options = {
  719. type: 2,
  720. data: {
  721. "jsCode": code
  722. },
  723. method: "POST",
  724. showLoading: true,
  725. };
  726. // #ifdef MP-WEIXIN
  727. request(getOpenidApi, options).then((res) => {
  728. const result = stringToJson(res.bizContent);
  729. console.log("获取微信小程序openid", result);
  730. const openidData = stringToJson(result.data);
  731. // setItem("QYorder", result.data);
  732. state.openid = openidData.openid
  733. });
  734. // #endif
  735. }
  736. //掉起微信支付
  737. const wxPayment = () => {
  738. // #ifdef MP-WEIXIN
  739. const options = {
  740. type: 2,
  741. data: {
  742. openId: getItem(StorageKeys.OpenId),
  743. wxOpenId: state.openid,
  744. cardId: state.cardId,
  745. orderNum: state.orderNum,
  746. payConfigId: wechatPayConfigId,
  747. body: "储值卡充值",
  748. },
  749. method: "POST",
  750. showLoading: true,
  751. };
  752. request(cardCzPay, options).then((res) => {
  753. const data = stringToJson(res.bizContent);
  754. uni.requestPayment({
  755. provider: "wxpay",
  756. orderInfo: "",
  757. timeStamp: data.timestamp,
  758. nonceStr: data.noncestr,
  759. package: data.wxPackage ? data.wxPackage : "",
  760. signType: data.signType,
  761. paySign: data.sign,
  762. success: function () {
  763. //回调订单状态
  764. console.log("回调订单状态");
  765. checkOrder();
  766. },
  767. fail: function (err) {
  768. confirm(err, () => { }, "支付失败", false);
  769. },
  770. });
  771. });
  772. // #endif
  773. };
  774. //掉起支付宝支付
  775. const aliPayment = () => {
  776. // #ifdef MP-ALIPAY
  777. my.getAuthCode({
  778. scopes: 'auth_base',
  779. success: res => {
  780. const optionsUser = {
  781. type: 2,
  782. data: {
  783. payConfigId: aliPayConfigId,
  784. code: res.authCode
  785. },
  786. method: "POST",
  787. showLoading: true,
  788. };
  789. request(obtainUserId, optionsUser).then((res) => {
  790. const data = stringToJson(res.bizContent);
  791. const optionsali = {
  792. type: 2,
  793. data: {
  794. openId: getItem(StorageKeys.OpenId),
  795. wxOpenId: data.openId,
  796. cardId: state.cardId,
  797. orderNum: state.orderNum,
  798. payConfigId: "6a9a54123456578934edfre132b1234",
  799. body: "储值卡充值",
  800. },
  801. method: "POST",
  802. showLoading: true,
  803. };
  804. request(cardCzPay, optionsali).then((res) => {
  805. const data = stringToJson(res.bizContent);
  806. my.tradePay({
  807. // 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号 trade_no
  808. tradeNO: data.tranPackage,
  809. success: res => {
  810. console.log("支付成功", res);
  811. checkOrder();
  812. },
  813. fail: res => {
  814. confirm(res, () => { }, "支付失败", false);
  815. },
  816. });
  817. });
  818. });
  819. },
  820. fail: err => {
  821. console.log('my.getAuthCode 调用失败', err)
  822. }
  823. });
  824. // #endif
  825. };
  826. //支付成功改变订单状态
  827. const checkOrder = () => {
  828. const options = {
  829. type: 2,
  830. data: {
  831. cardId: state.cardId,
  832. openId: getItem(StorageKeys.OpenId),
  833. orderNum: state.orderNum,
  834. },
  835. method: "POST",
  836. showLoading: true,
  837. };
  838. request(cardCzPayResult, options).then((res) => {
  839. const data = stringToJson(res.bizContent);
  840. if (data.tradeState === "SUCCESS") {
  841. getCardId();
  842. }
  843. console.log(data);
  844. });
  845. };
  846. const goRecord = () => {
  847. uni.navigateTo({
  848. url: `/subpackage/personal-center/consumption-record?cardId=${state.cardId}`
  849. })
  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>