Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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