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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942
  1. <!--设备选择 -->
  2. <template>
  3. <view class="devices">
  4. <view class="device" v-for="(item, index) in deviceList" :key="index" @click="connectDevice(item)">
  5. <image :src="`${$imgUrl}bluetooth/card1s.png`" class="head" mode="aspectFill"></image>
  6. <view class="center">
  7. <view class="name">{{ item._name }}</view>
  8. <view class="desc">编号 {{ item.name }}</view>
  9. </view>
  10. <image :src=" item.selected ? selectedUrl : unSelectedUrl" class="icon" mode="aspectFill"></image>
  11. </view>
  12. <view class="hint">
  13. <view class="txt">
  14. <image :src="`${$imgUrl}bluetooth/waring.png`" mode="aspectFill" class="imgs"></image>
  15. <view>温馨提示:</view>
  16. </view>
  17. <view class="grey-txt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  18. 指令执行过程中,请勿关闭蓝牙,勿将手机远离电子标签,以免导致写卡、写签失败。</view>
  19. </view>
  20. <!-- <view class="btn">
  21. <submit-button title="点击重新搜索蓝牙" @submit="load"></submit-button>
  22. </view> -->
  23. <view class="action">
  24. <button type="default" class="ui-btn" @click="load">
  25. 点击重新搜索蓝牙
  26. </button>
  27. </view>
  28. </view>
  29. </template>
  30. <script setup lang="ts">
  31. import { ref, reactive } from "vue";
  32. import { onLoad, onReady } from "@dcloudio/uni-app";
  33. import { fileURL } from "@/datas/fileURL.js";
  34. const cmd = require("../../static/etcUtil/cmdConfig.js");
  35. const imgURL = `${fileURL}image/`;
  36. const selectedUrl = imgURL + "bluetooth/select-icons.png";
  37. const unSelectedUrl = imgURL + "bluetooth/unselected_xin.png";
  38. const jyApi = require("../../static/etc/JYAPI/GenvictBleUtil.js");
  39. const jlQZApi = require("../../static/etc/JLQZAPI/JLObuSDK.js");
  40. const atApi = require("../../static/etc/ATAPI/ArtcBleUtil.js");
  41. const wqApi = require("../../static/etc/WQAPI/WCDObuSdk.js");
  42. const cgApi = require("../../static/etc/CGAPI/cguBle.js");
  43. const tools = require("../../static/etcUtil/tools.js");
  44. const datas = require("../../static/etcUtil/datas.js");
  45. const bluetoothUtil = require("../../static/etcUtil/index.js");
  46. // 微信小程序
  47. let jlApi = require("../../static/etc/JLAPI/JLObuSDK.js"); //聚力SDK
  48. let wjApi = require("../../static/etc/WJAPI/wjBleAPI");
  49. let tdApi = require("../../static/etc/TDAPI/TDRObuSDK.js");
  50. let zzApi = require("../../static/etc/WJAPI/wjBleAPI.js");
  51. let jtApi = require("../../static/etc/JTAPI/BleUtil.js");
  52. let kcApi = require("../../static/etc/kcBle/kcBleAPI.js");
  53. let mcApi = require("../../static/etc/MCAPI/MCObuSDK.js"); //5201
  54. // let jyApiEtc = require("../../static/etc/JYAPI-ETC/jy-bluetooth-obu-wechatmp.js"); //前装-金溢
  55. // 9901
  56. let wjApi9901 = require("../../static/etc/WJSDK9901/wjBleAPI.js");
  57. let ArtcBleUtilApi = require("../../static/etc/ArtcBleAPI/ArtcGuiZhouAPI.js");//艾特斯 ETC- 5201
  58. let mcApi9901 = require("../../static/etc/MCSDK9901/BleUtil9901.js"); //9901和国密5201单片
  59. // #ifdef MP-ALIPAY
  60. // 这部分代码将仅在支付宝小程序平台下执行
  61. jlApi = require("../../static/etc/JLObuSDK/JLObuSDK.js");
  62. wjApi = require("../../static/etc/wjBle/WJBleAPI");
  63. zzApi = require("../../static/etc/wjBle/WJBleAPI");
  64. tdApi = require("../../static/etc/TDRAPI/TDRObuSDK.js");
  65. jtApi = require("../../static/etc/JTAPIS/BleUtil.js");
  66. // 执行支付宝小程序的特定功能
  67. // #endif
  68. const state = reactive({
  69. fee: "",
  70. id: "",
  71. cardId: "",
  72. showPopup: false, //显示激活成功提示
  73. curDeviceId: "", //当前选中的设备ID
  74. deviceList: [
  75. //设备列表
  76. {
  77. id: "1",
  78. image: imgURL + "bluetooth/card1.png`",
  79. _name: "聚力",
  80. name: "235564444558855",
  81. },
  82. ],
  83. connectSuccess: 1,
  84. transfer: 0,
  85. rechargeMoney: "",//消费明细圈存传过来的金额
  86. orderNum: 0,//消费明细 传orderNum说明去支付
  87. payMoney: 0,//0 修复 1 支付
  88. accountId: "",//对公账户名称
  89. difference: "",//区分routeType5 1二次激活 2余额补领
  90. vehicleId: "",
  91. refundBalance: "",
  92. vehPosImgUrl: "",
  93. vehNegImgUrl: "",
  94. isAfter: '',
  95. backIndex:"",//1返回首页(卡签信息查询) ""返回订单列表 其他
  96. cardNo:""
  97. });
  98. const deviceList = ref([]);
  99. const connectPrefixName = ref(null);
  100. const routeType = ref(null); //来源 1激活 2圈存 3信息重写 4信息读取 10车辆信息变更预检
  101. interface DeviceType {
  102. name : string; //设备名称
  103. deviceId : string; //uuid
  104. prefixName : string; //前缀名称
  105. selected : boolean; //判断点击次数
  106. _name : string; //中文名称
  107. }
  108. let device : DeviceType = reactive({
  109. name: "", //设备名称
  110. deviceId: "", //uuid
  111. prefixName: "", //前缀名称
  112. selected: false, //判断点击次数
  113. _name: "", //中文名称
  114. });
  115. onReady(() => {
  116. load();
  117. });
  118. onLoad((option) => {
  119. routeType.value = option.routeType ? option.routeType : "1";
  120. state.cardId = option.cardId;
  121. if (option.fee) {
  122. state.fee = option.fee;
  123. }
  124. if (option.id) {
  125. state.id = option.id;
  126. }
  127. if (option.transfer) {
  128. state.transfer = option.transfer;
  129. }
  130. if (option.rechargeMoney) {
  131. state.rechargeMoney = option.rechargeMoney
  132. }
  133. if (option.orderNum) {
  134. state.orderNum = option.orderNum
  135. }
  136. if (option.payMoney) {
  137. state.payMoney = option.payMoney
  138. }
  139. if (option.accountId) {
  140. state.accountId = option.accountId
  141. }
  142. if (option.difference) {
  143. state.difference = option.difference;
  144. }
  145. if (option.vehicleId) {
  146. state.vehicleId = option.vehicleId;
  147. }
  148. if (option.refundBalance) {
  149. state.refundBalance = option.refundBalance;
  150. }
  151. if (option.vehPosImgUrl) {
  152. state.vehPosImgUrl = option.vehPosImgUrl;
  153. }
  154. if (option.vehNegImgUrl) {
  155. state.vehNegImgUrl = option.vehNegImgUrl;
  156. }
  157. if (option.isAfter) {
  158. state.isAfter = option.isAfter;
  159. }
  160. if (option.backIndex) {
  161. state.backIndex = option.backIndex;
  162. }
  163. console.log("传过来的参数", option)
  164. });
  165. /*
  166. * 蓝牙初始化
  167. */
  168. const load = () => {
  169. deviceList.value = [];
  170. console.log("****************蓝牙getsetting******************");
  171. uni.getSetting({
  172. success(res) {
  173. console.log("****************成功******************");
  174. console.log("scopebluetooth:" + res.authSetting["scope.bluetooth"]);
  175. console.log("成功结果:" + JSON.stringify(res));
  176. if (res.authSetting["scope.bluetooth"] == undefined) {
  177. //没有授权使用蓝牙功能,提示用户授权使用
  178. // #ifdef MP-WEIXIN
  179. uni.authorize({
  180. scope: "scope.bluetooth",
  181. success() {
  182. openBluetooth();
  183. },
  184. fail(err) {
  185. console.log('蓝牙授权失败', err)
  186. uni.showToast({
  187. title: "蓝牙授权失败",
  188. icon: "error",
  189. duration: 1500,
  190. });
  191. }
  192. });
  193. // #endif
  194. // #ifdef MP-ALIPAY
  195. openBluetooth();
  196. // #endif
  197. } else if (!res.authSetting["scope.bluetooth"]) {
  198. //false
  199. uni.showModal({
  200. title: "是否授权读取蓝牙",
  201. content: "需要获取你的蓝牙,请确认授权,否则无法获取蓝牙",
  202. success: function (mres) {
  203. if (mres.confirm) {
  204. uni.openSetting({
  205. success(authData) {
  206. if (authData.authSetting["scope.bluetooth"] == true) {
  207. tools.showLoadingAlert("扫描蓝牙中");
  208. openBluetooth();
  209. } else {
  210. uni.closeBluetoothAdapter();
  211. uni.showToast({
  212. title: "蓝牙授权失败",
  213. icon: "error",
  214. duration: 1500,
  215. });
  216. }
  217. },
  218. });
  219. } else if (mres.cancel) {
  220. uni.showToast({
  221. title: "蓝牙授权失败",
  222. icon: "error",
  223. duration: 1000,
  224. });
  225. }
  226. },
  227. });
  228. } else {
  229. tools.showLoadingAlert("扫描蓝牙中");
  230. openBluetooth();
  231. }
  232. },
  233. fail(res) {
  234. console.log("****************失败******************");
  235. console.log("失败结果:" + JSON.stringify(res));
  236. },
  237. });
  238. };
  239. /*
  240. * 打开蓝牙
  241. */
  242. const openBluetooth = () => {
  243. tools.hideLoadingAlert();
  244. let foundDevices = []; //扫描到的蓝牙列表
  245. uni.closeBluetoothAdapter(); //先关闭蓝牙
  246. console.log('执行断开蓝牙方法')
  247. //打开蓝牙
  248. uni.openBluetoothAdapter({
  249. success: function (item : any) {
  250. console.log('初始化蓝牙模块', item)
  251. tools.showLoadingAlert("扫描蓝牙中...");
  252. //开始搜索附近的蓝牙设备
  253. uni.startBluetoothDevicesDiscovery({
  254. success: function (res) {
  255. console.log('开始搜寻附近的蓝牙外围设备', res);
  256. //监听搜索到新设备的事件
  257. uni.onBluetoothDeviceFound(function (res) {
  258. console.log('监听寻找到新设备的事件', res, res.devices);
  259. for (let i = 0; i < res.devices.length; i++) {
  260. let name = res.devices[i]["name"];
  261. let prefixName = "";
  262. let deviceId = res.devices[i]["deviceId"];
  263. console.log("res.devices[i]", res.devices[i]["name"]);
  264. if (name != "" && name != undefined && name != "undefined") {
  265. if (name.indexOf("G-WJ") != -1 || name.indexOf("ETC") != -1 || name.indexOf("G-JL") != -1) {
  266. //前装设备
  267. prefixName = "ETC";
  268. } else {
  269. //聚力临时设备
  270. if (name.indexOf("5201121") != -1) {
  271. prefixName = "JL";
  272. } else {
  273. prefixName = name.substring(0, 2);
  274. }
  275. }
  276. prefixName = prefixName.toUpperCase();
  277. console.log("prefixName====", prefixName, name)
  278. if (
  279. prefixName == "WJ" ||
  280. prefixName == "JL" ||
  281. prefixName == "BY" ||
  282. prefixName == "JY" ||
  283. prefixName == "AT" ||
  284. prefixName == "JT" ||
  285. prefixName == "WQ" ||
  286. prefixName == "CG" ||
  287. prefixName == "TD" ||
  288. prefixName == "ZZ" ||
  289. prefixName == "MC" ||
  290. prefixName == "ETC"
  291. ) {
  292. // //隐藏加载框
  293. tools.hideLoadingAlert();
  294. device.name = name;
  295. datas.setData("deviceName", device.name);
  296. device.deviceId = deviceId;
  297. device.prefixName = prefixName;
  298. device.selected = false; //防止重复点击
  299. let _name = "";
  300. switch (prefixName) {
  301. case "ETC":
  302. if (name.split("-")[1] == "KC" || name.split("-")[1].indexOf('C') > 0 || name.split("-")[1].indexOf('K') > 0) {
  303. _name = "科畅";
  304. console.log("前装-科畅")
  305. } else if (name.split("-")[1] == "JL") {
  306. _name = "聚力"; //共用
  307. } else if (name.split("-")[1] == "WJ") {
  308. _name = "万集"; //共用
  309. } else if (name.split("-")[1] == "JY") {
  310. _name = "金溢";
  311. }else if (name.split("-")[1] == "ATS") {
  312. _name = "埃特斯";
  313. }else if (name.split("-")[1] == "MC") {
  314. _name = "铭创";
  315. }
  316. break;
  317. case "WJ":
  318. _name = "万集";
  319. break;
  320. case "JL":
  321. _name = "聚利";
  322. break;
  323. case "BY":
  324. _name = "宝溢";
  325. case "JY":
  326. _name = "金溢";
  327. break;
  328. case "AT":
  329. _name = "埃特斯";
  330. break;
  331. case "JT":
  332. _name = "建投";
  333. break;
  334. case "WQ":
  335. _name = "握奇";
  336. break;
  337. case "CG":
  338. _name = "成谷";
  339. break;
  340. case "TD":
  341. _name = "天地融";
  342. break;
  343. case "ZZ":
  344. _name = "智载";
  345. break;
  346. case "MC":
  347. _name = "铭创";
  348. break;
  349. default:
  350. _name = "未知";
  351. break;
  352. }
  353. device._name = _name;
  354. if (deviceList.value.length == 0) {
  355. // #ifdef MP-ALIPAY
  356. if (device._name == '聚利' || device._name == '万集' || device._name == '天地融' || device._name == '建投') {
  357. foundDevices.push(device);
  358. }
  359. // #endif
  360. // #ifdef MP-WEIXIN
  361. foundDevices.push(device);
  362. // #endif
  363. } else {
  364. let isHave = false;
  365. for (let j = 0; j < foundDevices.length; j++) {
  366. if (name == foundDevices[j].deviceId) {
  367. isHave = true;
  368. break;
  369. }
  370. }
  371. if (!isHave) {
  372. foundDevices.push(device);
  373. }
  374. }
  375. datas.setData("deviceNameZW", device._name);
  376. deviceList.value = foundDevices;
  377. foundDevices = [];
  378. console.log("deviceList.value", deviceList.value);
  379. }
  380. }
  381. }
  382. });
  383. },
  384. fail: function (res) {
  385. console.log(res);
  386. tools.hideLoadingAlert();
  387. },
  388. });
  389. },
  390. fail: function (res) {
  391. console.log(res);
  392. alertF("手机蓝牙未打开或不支持蓝牙");
  393. },
  394. });
  395. };
  396. /**
  397. * 连接蓝牙
  398. */
  399. const connectDevice = (e) => {
  400. console.log(e);
  401. let item = e;
  402. //停止扫描蓝牙
  403. console.info("停止搜寻附近的蓝牙外围设备");
  404. uni.stopBluetoothDevicesDiscovery({
  405. success: function (res) {
  406. console.log(device);
  407. if (item.selected == false) {
  408. console.log("第一次点击了");
  409. item.selected = true;
  410. setTimeout(function () {
  411. if (device.selected == undefined) {
  412. console.info("selected is undefined");
  413. linkFail(); //未找到设备, 请重新搜索
  414. return;
  415. }
  416. item.selected = false;
  417. }, 4000);
  418. } else {
  419. console.log("第二次点击了");
  420. return;
  421. }
  422. if (
  423. item.prefixName == undefined ||
  424. item.prefixName == "undefined" ||
  425. item.prefixName == ""
  426. ) {
  427. console.info("device.prefixName is undefined");
  428. linkFail(); //未找到设备, 请重新搜索
  429. return;
  430. }
  431. let prefixName = item.prefixName;
  432. connectPrefixName.value = item.prefixName;
  433. console.log(item);
  434. // datas.setData("connectPrefixName", connectPrefixName.value);
  435. // //断开蓝牙
  436. // bluetoothUtil.disconnectDevice();
  437. tools.showLoadingAlert("蓝牙连接中");
  438. console.info("连接的是" + prefixName, device);
  439. switch (prefixName) {
  440. case "ETC":
  441. console.log("device.name=====", device.name, device.name.includes("KC"), device.name.includes("JY"), device.name.includes("KC") || device.name.includes("K") || device.name.includes("C"))
  442. let obj = ""
  443. if (device.name.includes("KC") || device.name.includes("K")) {
  444. obj=kcApi
  445. } else if (device.name.includes("JL")) {
  446. obj=jlQZApi
  447. } else if (device.name.includes("WJ")) {
  448. obj=wjApi9901
  449. }else if (device.name.includes("ATS")) {
  450. obj=ArtcBleUtilApi
  451. }else if (device.name.includes("MC")) {
  452. obj=mcApi9901
  453. }
  454. console.log("新")
  455. obj.connectDevice(
  456. device,
  457. function (res) {
  458. preDevice(res);
  459. },
  460. function (res) {
  461. listenStatus(res);
  462. }
  463. );
  464. // else if (device.name.includes("JY")) {
  465. // console.log("进来了JY",device.name.includes("JY"))
  466. // jyApiEtc.connectDevice(
  467. // device,
  468. // function (res) {
  469. // preDevice(res);
  470. // },
  471. // function (res) {
  472. // listenStatus(res);
  473. // }
  474. // );
  475. // }
  476. break;
  477. case "WJ":
  478. console.log("旧")
  479. wjApi.connectDevice(
  480. device,
  481. function (res) {
  482. connectSuccess(res);
  483. },
  484. function (res) {
  485. listenStatus(res);
  486. }
  487. );
  488. break;
  489. case "JL":
  490. jlApi.connectDevice(
  491. device,
  492. function (res) {
  493. console.log('设备链接1', res)
  494. connectSuccess(res);
  495. },
  496. function (res) {
  497. console.log('设备链接2', res)
  498. listenStatus(res);
  499. }
  500. );
  501. break;
  502. case "BY":
  503. // 宝溢用金溢sdk
  504. jyApi.connectDevice(
  505. device,
  506. function (res) {
  507. console.log('设备链接1', res)
  508. connectSuccess(res);
  509. },
  510. function (res) {
  511. console.log('设备链接2', res)
  512. listenStatus(res);
  513. }
  514. );
  515. break;
  516. case "JY":
  517. jyApi.connectDevice(
  518. device,
  519. function (res) {
  520. connectSuccess(res);
  521. },
  522. function (res) {
  523. listenStatus(res);
  524. }
  525. );
  526. break;
  527. case "AT":
  528. atApi.connectDevice(
  529. device,
  530. function (res) {
  531. connectSuccess(res);
  532. },
  533. function (res) {
  534. listenStatus(res);
  535. }
  536. );
  537. break;
  538. case "JT":
  539. console.info("连接的是=====123" + prefixName, device);
  540. jtApi.connectDevice(
  541. device,
  542. function (res) {
  543. console.log('设备链接1', res)
  544. connectSuccess(res);
  545. },
  546. function (res) {
  547. console.log('设备链接2', res)
  548. listenStatus(res);
  549. }
  550. );
  551. break;
  552. case "WQ":
  553. wqApi.connectDevice(
  554. device,
  555. function (res) {
  556. connectSuccess(res);
  557. },
  558. function (res) {
  559. listenStatus(res);
  560. }
  561. );
  562. break;
  563. case "CG":
  564. cgApi.connectDevice(
  565. device,
  566. function (res) {
  567. connectSuccess(res);
  568. },
  569. function (res) {
  570. listenStatus(res);
  571. }
  572. );
  573. break;
  574. case "TD":
  575. tdApi.connectDevice(
  576. device,
  577. function (res) {
  578. connectSuccess(res)
  579. }, function (res) {
  580. listenStatus(res);
  581. }
  582. );
  583. break;
  584. case "ZZ":
  585. zzApi.connectDevice(
  586. device,
  587. function (res) {
  588. connectSuccess(res);
  589. },
  590. function (res) {
  591. listenStatus(res);
  592. }
  593. );
  594. break;
  595. case "MC":
  596. mcApi.connectDevice(
  597. device,
  598. function (res) {
  599. connectSuccess(res);
  600. },
  601. function (res) {
  602. listenStatus(res);
  603. }
  604. );
  605. break;
  606. default: //未找到设备, 请重新搜索
  607. linkFail();
  608. break;
  609. }
  610. },
  611. fail: function (res) {
  612. console.log(res);
  613. linkFail(); //未找到设备, 请重新搜索
  614. },
  615. });
  616. };
  617. /**
  618. * 未找到设备, 请重新搜索
  619. */
  620. const linkFail = () => {
  621. datas.setData("bluLinkStatus", false);
  622. datas.setData("connectPrefixName", "");
  623. tools.showModalAlert("未找到设备, 请重新搜索", function successFunc() {
  624. load();
  625. });
  626. };
  627. /**
  628. * 连接成功
  629. */
  630. const connectSuccess = (res) => {
  631. console.log("连接回调函数func1");
  632. console.log(res);
  633. if (res.code == 0) {
  634. console.log("连接成功");
  635. tools.hideLoadingAlert(); //关闭加载框
  636. datas.setData("bluLinkStatus", true);
  637. datas.setData("connectPrefixName", connectPrefixName.value);
  638. oks();
  639. } else {
  640. alertF(res.msg);
  641. }
  642. };
  643. function oks() {
  644. //routeType 1.激活(订单来) 2.圈存 (/pages/recharge/recharge来)3.ping码解锁 4.信息读取 5从哪里来回哪里去监听bluetoothLink 7消费明细去圈存 8单位账户圈存 9对公账户修复
  645. if (routeType.value == "1") {
  646. if (state.isAfter == '1') {
  647. uni.navigateTo({
  648. url: `/subpackage/after-sale/activation/activate-SH`,
  649. });
  650. } else {
  651. uni.navigateTo({
  652. url: `/subpackage/after-sale/activation/activate?transfer=${state.transfer}`,
  653. });
  654. }
  655. } else if (routeType.value == "2") {
  656. uni.navigateTo({
  657. url: `/subpackage/carPark/recharge/recharge-weixin?connectSuccess=${state.connectSuccess}`,
  658. });
  659. } else if (routeType.value == "3") {
  660. uni.navigateTo({
  661. url: "/subpackage/after-sale/pin-code-deblocking/pin-code-confirm?state=true&vehicleId=" + state.vehicleId,
  662. });
  663. } else if (routeType.value == "4") {
  664. uni.navigateTo({
  665. url: `/subpackage/after-sale/deviceInfo/deviceInfo?backIndex=${state.backIndex}`,
  666. });
  667. } else if (routeType.value == "5") {
  668. // #ifdef MP-ALIPAY
  669. uni.navigateTo({
  670. url: "/subpackage/after-sale/activation-once-again/activation-once-again-ali?state=true&id=" + state.id,
  671. });
  672. // #endif
  673. // #ifdef MP-WEIXIN
  674. if (state.difference == "1") {
  675. uni.navigateTo({
  676. url: `/subpackage/after-sale/activation-once-again/activation-once-again?status=true&state=true&vehicleId=${state.vehicleId}&vehPosImgUrl=${state.vehPosImgUrl}&vehNegImgUrl=${state.vehNegImgUrl}`,
  677. });
  678. } else if (state.difference == "2") {
  679. uni.navigateTo({
  680. url: `/subpackage/after-sale/refund-order-balance/refund-order-balance?status=true&state=true&vehicleId=${state.vehicleId}&&id=${state.id}&&refundBalance=${state.refundBalance}`,
  681. });
  682. } else {
  683. uni.$emit('bluetoothLink', { status: true })
  684. uni.navigateBack({
  685. delta: 1
  686. })
  687. }
  688. // #endif
  689. } else if (routeType.value == "6") {
  690. uni.navigateTo({
  691. url: "/subpackage/after-sale/activation-once-again/activation-once-again?state=true&id=" + state.id
  692. });
  693. } else if (routeType.value == "7") {
  694. uni.navigateTo({
  695. url: `/subpackage/personal-center/trapping-and-repairing/recharge-two?rechargeMoney=${state.rechargeMoney}&&orderNum=${state.orderNum}&&payMoney=${state.payMoney}`,
  696. });
  697. } else if (routeType.value == "8") {
  698. uni.navigateTo({
  699. url: `/subpackage/after-sale/account-recharge/recharge-weixin?accountId=${state.accountId}`,
  700. });
  701. } else if (routeType.value == "9") {
  702. uni.navigateTo({
  703. url: `/subpackage/personal-center/trapping-and-repairing-account/recharge-two?rechargeMoney=${state.rechargeMoney}&&orderNum=${state.orderNum}&&payMoney=${state.payMoney}&&accountId=${state.accountId}`,
  704. });
  705. } else if (routeType.value == "10") {
  706. uni.navigateTo({
  707. url: `/subpackage/personal-center/car-message-change?vehicleId=${state.vehicleId}`,
  708. });
  709. } else {
  710. return;
  711. }
  712. }
  713. /**
  714. * 前装设备
  715. */
  716. const preDevice = (res) => {
  717. console.log("连接成功1111=====", res);
  718. if (res.code == 0 || res.serviceCode==0) {
  719. console.log("连接成功=====");
  720. datas.setData("bluLinkStatus", true);
  721. datas.setData("connectPrefixName", connectPrefixName.value);
  722. getCardId((cardNo) => {
  723. console.log("cardNo",cardNo);
  724. if(cardNo.includes('5201')){
  725. // 正常激活 前装 5201
  726. oks()
  727. }else{
  728. // 前装9901
  729. etcOks()
  730. }
  731. })
  732. } else {
  733. alertF(res.msg);
  734. console.log(res.msg);
  735. }
  736. };
  737. function getCardId(fun){
  738. //执行0015文件
  739. tools.showLoadingAlert("执行指令");
  740. let cmdArr = [cmd.HOME_DIRECTORY, cmd.APPLICATION_DIRECTORY, cmd.CMD_READBINARY];
  741. console.log(cmdArr);
  742. console.log(bluetoothUtil);
  743. bluetoothUtil.transCmd(cmdArr, '10', function(res) { //10:写卡 20:写OBU
  744. console.log("res====", res)
  745. var cardStr = res[2];
  746. if (cardStr == undefined || cardStr == "undefined" || cardStr == "") {
  747. tools.alertF("卡指令不符" + cardStr);
  748. return;
  749. }
  750. if (cardStr.length < 40) {
  751. tools.alertF("卡指令长度不符" + cardStr);
  752. return;
  753. }
  754. tools.hideLoadingAlert();
  755. fun(cardStr.substring(20, 40));
  756. })
  757. }
  758. function etcOks() {
  759. if (routeType.value == "4") {
  760. uni.navigateTo({
  761. url: "/subpackage/carPark/etc/etcDeviceInfo",
  762. });
  763. }
  764. }
  765. /**
  766. * 监听蓝牙状态
  767. */
  768. const listenStatus = (res) => {
  769. console.log("时时监听蓝牙状态func2", connectPrefixName.value, res.code);
  770. console.log(res);
  771. if (res.code == 0) {
  772. datas.setData("bluLinkStatus", true);
  773. datas.setData("connectPrefixName", connectPrefixName.value);
  774. // oks();
  775. } else {
  776. //断开蓝牙
  777. bluetoothUtil.disconnectDevice();
  778. datas.setData("bluLinkStatus", false);
  779. datas.setData("connectPrefixName", "");
  780. tools.showToastAlert("蓝牙已断开");
  781. // #ifdef MP-ALIPAY
  782. my.closeBluetoothAdapter({
  783. success(res) {
  784. // 关闭蓝牙适配器成功
  785. },
  786. fail(err) {
  787. // 处理关闭蓝牙适配器失败的情况
  788. }
  789. })
  790. // #endif
  791. }
  792. };
  793. /**
  794. * 提示加关蓝牙
  795. */
  796. const alertF = (msg : string) => {
  797. //隐藏加载框
  798. tools.hideLoadingAlert();
  799. //断开蓝牙
  800. bluetoothUtil.disconnectDevice();
  801. //提示对话框
  802. tools.showModalAlert(msg);
  803. };
  804. </script>
  805. <style>
  806. page {
  807. background-color: #f3f3f3;
  808. }
  809. :deep(.u-mode-center-box) {
  810. border-radius: 20rpx;
  811. }
  812. </style>
  813. <style lang="scss" scoped>
  814. .devices {
  815. min-height: 100vh;
  816. box-sizing: border-box;
  817. padding-bottom: 160rpx;
  818. position: relative;
  819. padding-top: 30rpx;
  820. background: #E9EDF0;
  821. .action {
  822. position: absolute;
  823. bottom: 0rpx;
  824. left: 0;
  825. height: 128rpx;
  826. background-color: #fff;
  827. border-radius: 30rpx 30rpx 0 0;
  828. width: 100vw;
  829. display: flex;
  830. align-items: center;
  831. justify-content: center;
  832. flex-direction: column;
  833. }
  834. .device {
  835. margin: 0 auto;
  836. width: 701rpx;
  837. display: flex;
  838. flex-direction: row;
  839. align-items: center;
  840. background: white;
  841. padding: 25rpx 20rpx;
  842. box-sizing: border-box;
  843. background: #FFFFFF;
  844. box-shadow: 2rpx 6rpx 6rpx 6rpx #DFDFDF;
  845. border-radius: 12rpx;
  846. .head {
  847. width: 120rpx;
  848. height: 120rpx;
  849. border-radius: 10rpx;
  850. background-color: #f3f3f3;
  851. }
  852. .center {
  853. flex: 1;
  854. margin-left: 30rpx;
  855. margin-right: 30rpx;
  856. .name {
  857. font-size: 30rpx;
  858. color: #333333;
  859. }
  860. .desc {
  861. font-size: 26rpx;
  862. color: #666666;
  863. margin-top: 25rpx;
  864. }
  865. }
  866. .icon {
  867. width: 38rpx;
  868. height: 38rpx;
  869. margin-right: 12rpx;
  870. }
  871. }
  872. .hint {
  873. margin: 60rpx 30rpx 0px;
  874. .txt {
  875. font-family: MicrosoftYaHei;
  876. font-size: 28rpx;
  877. color: #111111;
  878. line-height: 40rpx;
  879. display: flex;
  880. align-items: center;
  881. .imgs {
  882. width: 30rpx;
  883. height: 30rpx;
  884. margin-right: 10rpx;
  885. }
  886. }
  887. .grey-txt {
  888. font-size: 28rpx;
  889. color: #999;
  890. line-height: 40rpx;
  891. margin-top: 16rpx;
  892. }
  893. }
  894. .btn {
  895. margin: 70rpx 40rpx;
  896. }
  897. }
  898. </style>