Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <!--设备选择 -->
  2. <template>
  3. <view class="devices">
  4. <view class="hint">
  5. <view class="orange-txt as-layout-horizontal as-gravity-center-start tishi">
  6. <image :src="`${$imgUrl}common/icon-hint.png`" mode="aspectFill"></image>
  7. <view>温馨提示:</view>
  8. </view>
  9. <view>1、请在手机设置中打开NFC功能。</view>
  10. <view>2、请将ETC储值卡对准手机NFC天线位置(手机背部顶端),不灵敏或无响应时,请及时调整卡片位置。</view>
  11. <view>3、充值过程请保证卡片在手机背部,请勿移开。</view>
  12. </view>
  13. <view class="btn">
  14. <submit-button title="点击重新扫描NFC标签" @submit="load"></submit-button>
  15. </view>
  16. </view>
  17. </template>
  18. <script setup lang='ts'>
  19. import {
  20. onLoad,
  21. onReady
  22. } from "@dcloudio/uni-app";
  23. import {
  24. getItem,
  25. setItem
  26. } from "@/utils/storage";
  27. import {
  28. ref,
  29. reactive
  30. } from "vue";
  31. import * as NFCAPI from "../../static/nfc/NFCAPI.js";
  32. const tools = require("../../static/etcUtil/tools.js");
  33. // const NFCAPI = require('../../static/nfc/NFCAPI.js');
  34. const cmd = require("../../static/etcUtil/cmdConfig.js");
  35. const routeType = ref(null); //来源 1激活 2圈存 3信息重写 4信息读取 7消费明细修复
  36. const state = reactive({
  37. fee: "",
  38. cardId: "",
  39. rechargeMoney: "", //消费明细圈存传过来的金额
  40. orderNum: 0, //消费明细 传orderNum说明去支付
  41. payMoney: 0, //0 修复 1 支付
  42. });
  43. onLoad((option) => {
  44. routeType.value = option.routeType ? option.routeType : "1";
  45. setItem("routeType", option.routeType)
  46. state.cardId = option.cardId;
  47. if (option.fee) {
  48. state.fee = option.fee;
  49. }
  50. if (option.rechargeMoney) {
  51. state.rechargeMoney = option.rechargeMoney
  52. }
  53. if (option.orderNum) {
  54. state.orderNum = option.orderNum
  55. }
  56. if (option.payMoney) {
  57. state.payMoney = option.payMoney
  58. }
  59. console.log("传过来的参数", option, routeType.value)
  60. });
  61. //已准备
  62. onReady(() => {
  63. scanNfc();
  64. })
  65. function load() {
  66. scanNfc();
  67. }
  68. function scanNfc() {
  69. console.log("routeType.value1", routeType.value)
  70. tools.showLoadingAlert("扫描NFC中");
  71. //先断开所有设备
  72. NFCAPI.remove(() => {
  73. console.log("routeType.value2=======", routeType.value)
  74. //开始扫描设备
  75. // NFCAPI.startScanDeviceNfc(routeType.value, function(res, routeType) {
  76. // routeType.value = routeType
  77. const ConRouteType = routeType.value
  78. NFCAPI.startScanDevice((res) => {
  79. tools.hideLoadingAlert();
  80. console.log("routeType.value3===123===1111", ConRouteType, res.code)
  81. if (res.code != 0) {
  82. console.log("1111111")
  83. if (res.code == 1203) {
  84. tools.showModalAlert("扫描超时请重新扫描NFC标签", function(res) {
  85. if (res.confirm) {
  86. scanNfc();
  87. }
  88. }, null, "", true)
  89. } else {
  90. tools.showToastAlert(res.msg);
  91. }
  92. return;
  93. } else {
  94. console.log("2222", routeType.value)
  95. NFCAPI.connectDevice(function() {
  96. if (res.code != 0) {
  97. tools.showToastAlert(res.msg);
  98. return;
  99. }
  100. //获取卡信息
  101. transCmd(function(items) {
  102. getCardId(items, function() {
  103. console.log("routeType.value", routeType.value)
  104. if (getItem('routeType') == "2") {
  105. tools.toUrl(
  106. `/pages/recharge/recharge-weixin?connectSuccess=1&&cardId=${state.cardId}&&fee=${state.fee}&&transWay=nfc`
  107. ); //跳转到圈存界面
  108. } else if (getItem('routeType') ==
  109. "7") { //7消费明细去修复nfc
  110. tools.toUrl(
  111. `/subpackage/personal-center/trapping-and-repairing/recharge-two?rechargeMoney=${state.rechargeMoney}&&orderNum=${state.orderNum}&&payMoney=${state.payMoney}&&transWay=nfc`
  112. ); //跳转到圈存界面
  113. }
  114. })
  115. })
  116. });
  117. }
  118. })
  119. })
  120. }
  121. function getCardId(resultCmdArr: any, callback: any) {
  122. var that = this;
  123. console.log(resultCmdArr, '==============123')
  124. if (resultCmdArr.length == 4) {
  125. var str = resultCmdArr[2].substring(resultCmdArr[2].length - 4, resultCmdArr[2].length); //判断是否为9000
  126. var str3 = resultCmdArr[3].substring(resultCmdArr[3].length - 4, resultCmdArr[3].length); //判断是否为9000
  127. if (str == "9000" || str3 == "9000") {
  128. if (resultCmdArr[2].length > 86 || resultCmdArr[3] >= 12) {
  129. var card = {
  130. cardNo: resultCmdArr[2].substring(20, 40),
  131. startTime: resultCmdArr[2].substring(40, 48),
  132. endTime: resultCmdArr[2].substring(48, 56),
  133. version: resultCmdArr[2].substring(18, 19) >= 4 ? "4x" : "2x",
  134. money: hex2int(resultCmdArr[3].substring(0, 8)),
  135. v_userType: parseInt(resultCmdArr[2].substring(80, 82), 16)
  136. };
  137. console.log("写命令拿到卡号:" + JSON.stringify(card))
  138. var jizhangka = card.cardNo.substring(8, 10);
  139. if (jizhangka == '23') {
  140. console.log('记账卡');
  141. tools.alertFback("不支持记账卡圈存", function() {
  142. //返回首页
  143. uni.reLaunch({
  144. url: 'pages/index/index'
  145. })
  146. })
  147. return;
  148. }
  149. // that.setData({
  150. // cardNo: card.cardNo,
  151. // cardMoney: card.money > 0 ? card.money : 0,
  152. // })
  153. callback(card.cardNo);
  154. } else {
  155. tools.showToastAlert("CMD_READBINARY指令长度不符" + resultCmdArr[2]);
  156. }
  157. return;
  158. }
  159. } else {
  160. tools.showToastAlert("回包长度不符");
  161. }
  162. }
  163. /**
  164. * 十六进制字符串转十进制
  165. */
  166. function hex2int(hex) {
  167. var len = hex.length,
  168. a = new Array(len),
  169. code;
  170. for (var i = 0; i < len; i++) {
  171. code = hex.charCodeAt(i);
  172. if (48 <= code && code < 58) {
  173. code -= 48;
  174. } else {
  175. code = (code & 0xdf) - 65 + 10;
  176. }
  177. a[i] = code;
  178. }
  179. return a.reduce(function(acc, c) {
  180. acc = 16 * acc + c;
  181. return acc;
  182. }, 0);
  183. }
  184. function transCmd(callback: any) {
  185. tools.showLoadingAlert('透传指令中');
  186. var cmdArr = [cmd.HOME_DIRECTORY, cmd.APPLICATION_DIRECTORY, cmd.CMD_READBINARY, cmd.CMD_GETBALANCE];
  187. NFCAPI.transCmd(cmdArr, function(res) {
  188. tools.hideLoadingAlert();
  189. console.log(res);
  190. if (res.code == 0) {
  191. callback(res.data);
  192. } else {
  193. tools.showToastAlert(res.msg);
  194. }
  195. });
  196. }
  197. </script>
  198. <style lang='scss' scoped>
  199. image {
  200. width: 40rpx;
  201. height: 40rpx;
  202. margin-right: 20rpx;
  203. }
  204. .devices {
  205. padding: 30rpx;
  206. }
  207. .btn {
  208. margin-top: 30rpx;
  209. }
  210. .tishi {
  211. margin-bottom: 20rpx;
  212. }
  213. </style>