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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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消费明细修复 11 卡签续期
  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. setItem("payMoney", option.payMoney)
  59. }
  60. console.log("传过来的参数", option, routeType.value)
  61. });
  62. //已准备
  63. onReady(() => {
  64. scanNfc();
  65. })
  66. function load() {
  67. scanNfc();
  68. }
  69. function scanNfc() {
  70. console.log("routeType.value1", routeType.value)
  71. tools.showLoadingAlert("扫描NFC中");
  72. //先断开所有设备
  73. NFCAPI.remove(() => {
  74. console.log("routeType.value2=======", routeType.value)
  75. //开始扫描设备
  76. const ConRouteType = routeType.value
  77. NFCAPI.startScanDevice((res) => {
  78. tools.hideLoadingAlert();
  79. console.log("routeType.value3===123===1111", ConRouteType, res.code)
  80. if (res.code != 0) {
  81. console.log("1111111")
  82. if (res.code == 1203) {
  83. tools.showModalAlert("扫描超时请重新扫描NFC标签", function(res) {
  84. if (res.confirm) {
  85. scanNfc();
  86. }
  87. }, null, "", true)
  88. } else {
  89. tools.showToastAlert(res.msg);
  90. }
  91. return;
  92. } else {
  93. console.log("2222", routeType.value)
  94. NFCAPI.connectDevice(function(res) {
  95. console.log("resnfc", res)
  96. // datas.setData("bluLinkStatus", true);
  97. // datas.setData("connectPrefixName", connectPrefixName.value);
  98. if (res.code != 0) {
  99. tools.showToastAlert(res.msg);
  100. return;
  101. }
  102. //获取卡信息
  103. transCmd(function(items) {
  104. getCardId(items, function() {
  105. console.log("routeType.value", routeType.value)
  106. if (getItem('routeType') == "2") {
  107. tools.toUrl(
  108. `/subpackage/carPark/recharge/recharge-weixin?connectSuccess=1&&cardId=${state.cardId}&&fee=${state.fee}&&transWay=nfc`
  109. ); //跳转到圈存界面
  110. } else if (getItem('routeType') ==
  111. "7") { //7消费明细去修复nfc
  112. tools.toUrl(
  113. `/subpackage/personal-center/trapping-and-repairing/recharge-two?rechargeMoney=${state.rechargeMoney}&&orderNum=${state.orderNum}&&payMoney=${getItem('payMoney')}&&transWay=nfc`
  114. ); //跳转到圈存界面
  115. } else if (getItem('routeType') == "11") {
  116. tools.toUrl(
  117. `/subpackage/after-sale/renewalContral/result?cardId=${state.cardId}&&transWay=nfc`
  118. ); //跳转到圈存界面
  119. }
  120. })
  121. })
  122. });
  123. }
  124. })
  125. })
  126. }
  127. function getCardId(resultCmdArr: any, callback: any) {
  128. var that = this;
  129. console.log(resultCmdArr, '==============123')
  130. if (resultCmdArr.length == 4) {
  131. var str = resultCmdArr[2].substring(resultCmdArr[2].length - 4, resultCmdArr[2].length); //判断是否为9000
  132. var str3 = resultCmdArr[3].substring(resultCmdArr[3].length - 4, resultCmdArr[3].length); //判断是否为9000
  133. if (str == "9000" || str3 == "9000") {
  134. if (resultCmdArr[2].length > 86 || resultCmdArr[3] >= 12) {
  135. var card = {
  136. cardNo: resultCmdArr[2].substring(20, 40),
  137. startTime: resultCmdArr[2].substring(40, 48),
  138. endTime: resultCmdArr[2].substring(48, 56),
  139. version: resultCmdArr[2].substring(18, 19) >= 4 ? "4x" : "2x",
  140. money: hex2int(resultCmdArr[3].substring(0, 8)),
  141. v_userType: parseInt(resultCmdArr[2].substring(80, 82), 16)
  142. };
  143. console.log("写命令拿到卡号:" + JSON.stringify(card))
  144. var jizhangka = card.cardNo.substring(8, 10);
  145. if (jizhangka == '23') {
  146. console.log('记账卡');
  147. tools.alertFback("不支持记账卡圈存", function() {
  148. //返回首页
  149. uni.reLaunch({
  150. url: 'pages/index/index'
  151. })
  152. })
  153. return;
  154. }
  155. // that.setData({
  156. // cardNo: card.cardNo,
  157. // cardMoney: card.money > 0 ? card.money : 0,
  158. // })
  159. callback(card.cardNo);
  160. } else {
  161. tools.showToastAlert("CMD_READBINARY指令长度不符" + resultCmdArr[2]);
  162. }
  163. return;
  164. }
  165. } else {
  166. tools.showToastAlert("回包长度不符");
  167. }
  168. }
  169. /**
  170. * 十六进制字符串转十进制
  171. */
  172. function hex2int(hex) {
  173. var len = hex.length,
  174. a = new Array(len),
  175. code;
  176. for (var i = 0; i < len; i++) {
  177. code = hex.charCodeAt(i);
  178. if (48 <= code && code < 58) {
  179. code -= 48;
  180. } else {
  181. code = (code & 0xdf) - 65 + 10;
  182. }
  183. a[i] = code;
  184. }
  185. return a.reduce(function(acc, c) {
  186. acc = 16 * acc + c;
  187. return acc;
  188. }, 0);
  189. }
  190. function transCmd(callback: any) {
  191. tools.showLoadingAlert('透传指令中');
  192. var cmdArr = [cmd.HOME_DIRECTORY, cmd.APPLICATION_DIRECTORY, cmd.CMD_READBINARY, cmd.CMD_GETBALANCE];
  193. NFCAPI.transCmd(cmdArr, function(res) {
  194. tools.hideLoadingAlert();
  195. console.log(res);
  196. if (res.code == 0) {
  197. callback(res.data);
  198. } else {
  199. tools.showToastAlert(res.msg);
  200. }
  201. });
  202. }
  203. </script>
  204. <style lang='scss' scoped>
  205. image {
  206. width: 40rpx;
  207. height: 40rpx;
  208. margin-right: 20rpx;
  209. }
  210. .devices {
  211. padding: 30rpx;
  212. }
  213. .btn {
  214. margin-top: 30rpx;
  215. }
  216. .tishi {
  217. margin-bottom: 20rpx;
  218. }
  219. </style>