Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

activate.vue 34KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. <template>
  2. <view class="containers">
  3. <view class="sec_info">
  4. <view class="info_txt">信息确认</view>
  5. <view class="info_plate">
  6. <text>车牌号码</text>
  7. <text>{{ fileDataStrings.vehiclePlate }}</text>
  8. </view>
  9. <view class="info_plate">
  10. <text>车牌颜色</text>
  11. <text>{{ fileDataStrings.vehiclePlateColorStr }}</text>
  12. </view>
  13. <view class="info_plate">
  14. <text>手机号码</text>
  15. <text>{{ fileDataStrings.customerTel }}</text>
  16. </view>
  17. <view class="info_plate" style="border: none">
  18. <text>卡号</text>
  19. <text>{{ fileDataStrings.cardId }}</text>
  20. </view>
  21. <view class="info_plate">
  22. <text>OBU号</text>
  23. <text>{{ fileDataStrings.obuId }}</text>
  24. </view>
  25. </view>
  26. <view class="up_btn" v-if="state.showBtn">
  27. <button aria-disabled="true" @click="btn" v-if="!state.isSuccess" :disabled="!state.disabled"
  28. :class="state.disabled?'button':'hui'">
  29. 点击开始激活
  30. </button>
  31. <button aria-disabled="true" @click="back" v-else>
  32. 点击返回首页
  33. </button>
  34. </view>
  35. </view>
  36. <!-- 激活成功popup -->
  37. <u-popup v-model="state.showPopup" mode="center">
  38. <active-success @cancel="state.showPopup = false"></active-success>
  39. </u-popup>
  40. </template>
  41. <script setup>
  42. import {
  43. reactive,
  44. ref
  45. } from "vue";
  46. import {
  47. formatTime,
  48. formatTime2,
  49. expireDate,
  50. expireDate2,
  51. getFormatDate,
  52. msg
  53. } from "@/utils/utils";
  54. import {
  55. onLoad
  56. } from '@dcloudio/uni-app'
  57. import {
  58. getItem
  59. } from "@/utils/storage";
  60. import {
  61. request
  62. } from "@/utils/network/request.js";
  63. import {
  64. IntegerToHexString,
  65. AsciToHexString,
  66. } from "@/utils/util/fileData.js";
  67. import {
  68. stringToJson
  69. } from "@/utils/network/encryption.js";
  70. import * as IFCODE from "@/utils/network/api.js";
  71. import {
  72. agentId
  73. } from "@/utils/network/difference";
  74. const cmd = require("../../../static/etcUtil/cmdConfig.js");
  75. const tools = require("../../../static/etcUtil/tools.js");
  76. const bluetoothUtil = require("../../../static/etcUtil/index.js");
  77. import activeSuccess from "./components/popup-device-active-success";
  78. import {
  79. getVehiclePlateColor
  80. } from "@/datas/vehiclePlateColor";
  81. import {
  82. searchVehicleInfoQuery
  83. } from "@/utils/publicRequest";
  84. import {
  85. channelId
  86. } from "@/utils/network/difference";
  87. const state = reactive({
  88. orderId: "",
  89. id: "",
  90. cardStatus: "",
  91. obuStatus: "",
  92. isSuccess: false, //是否激活成功
  93. showPopup: false,
  94. transfer: 0, //0 是原来的激活 1 是过户激活
  95. showBtn: true,
  96. disabled: true
  97. })
  98. let snums = 0
  99. onLoad((option) => {
  100. //读取传入 存储的数据orderInfo
  101. let orderData = getItem("orderInfo");
  102. state.id = orderData.id;
  103. state.orderId = orderData.orderId;
  104. console.log(state);
  105. state.transfer = Number(option.transfer)
  106. //获取订单详情
  107. getOrderDetails(state.id);
  108. console.log("state.transfer", state.transfer, state.transfer == 0, state.transfer == 1)
  109. })
  110. const card = reactive({
  111. cardId: "",
  112. netId: "",
  113. cardType: "",
  114. startTime: "",
  115. endTime: "",
  116. userName: "",
  117. idNum: "",
  118. vehiclePlate: "",
  119. vehiclePlateColor: "",
  120. color: "",
  121. version: "",
  122. type: "",
  123. favourable: "",
  124. money: "",
  125. v_userType: "",
  126. });
  127. const obu = reactive({
  128. obuId: "",
  129. startTime: "",
  130. endTime: "",
  131. version: "",
  132. approvedCount: "",
  133. axleCount: "",
  134. axleDistance: "",
  135. engineNum: "",
  136. type: "",
  137. userType: "",
  138. contractNo: "",
  139. vehiclePlate: "",
  140. vehiclePlateColor: "",
  141. vin: "",
  142. wheelCount: 0,
  143. isJH: ""
  144. });
  145. let cmdRandNum = '';
  146. let orderInfo = {};
  147. const fileDataStrings = reactive({
  148. approvedCount: 0, //核载人数
  149. cardId: "", //卡号
  150. obuId: "", //obu号
  151. obuId: "", //obu号
  152. packageNum: "", //套餐编号
  153. axleCount: 0, //轴数
  154. axleDistance: "", //轴距
  155. engineNum: "", //发动机
  156. vehicleVin: "",
  157. vehicleEngineNum: "",
  158. cardStatus: "",
  159. obuStatus: "",
  160. type: 0, //类型
  161. userType: 0, //用户类型
  162. vehiclePlate: "", //车牌
  163. vehiclePlateColor: 0, //车牌颜色
  164. vehicleDimensions: "",
  165. outlineL: 0, //外廓 长
  166. outlineW: 0, //外廓 宽
  167. outlineH: 0, //外廓 高
  168. wheelCount: 0, //车轮数
  169. vehicleIdNo: "", //车牌号
  170. vehiclePlateColorStr: "",
  171. customerTel: "",
  172. customerId: "",
  173. orderId: ""
  174. });
  175. //开始激活 按钮事件
  176. const btn = () => {
  177. state.disabled = false
  178. console.log('orderInfo参数', orderInfo, state.disabled)
  179. //0 是原来的激活 1 是过户激活
  180. if (state.transfer) {
  181. // 获取cardId
  182. getCardId()
  183. // 过户激活 1
  184. // 1. 过户激活申请 2.设备升级 3.过户升级(跟过户升级一样) 4.79(BDS-安装申请)(后台数据)-
  185. // >76(VFJ-OBU在线激活)(指令接口)->80(BDS-安装确认)->73(BDS-卡签绑定)(指令接口)->51(BDS-写卡指令返回)(指令接口)
  186. } else {
  187. console.log("=================================")
  188. if (orderInfo) {
  189. //根据订单详情走相应的断步功能
  190. const cardId = orderInfo.cardId;
  191. const cardStatus = orderInfo.cardStatus != null ? orderInfo.cardStatus : '0'
  192. const obuId = orderInfo.obuId;
  193. const obuStatus = orderInfo.obuStatus != null ? orderInfo.obuStatus : '9'
  194. console.log('当前卡签状态', cardId, obuId, cardStatus, obuStatus)
  195. console.log('输出内容', obu.obuId, '=======', fileDataStrings.obuId, obu.obuId != fileDataStrings.obuId)
  196. if (fileDataStrings.obuId) {
  197. if (obu.obuId + '' != fileDataStrings.obuId + '') {
  198. tools.showModalAlert("订单设备号信息与当前设备号信息不符!");
  199. return
  200. }
  201. }
  202. if (!cardId) { //卡发行
  203. getCardId()
  204. } else if (cardId && cardStatus == '0') { //卡发行
  205. getCardId()
  206. } else if (!obuId) { //OBU发行
  207. getObuApply();
  208. } else if (obuId && obuStatus == '9') { //OBU发行
  209. getObuApply();
  210. } else if (cardId && obuId && (obuStatus == '1' || obuStatus == '11' || obuStatus == '0')) {
  211. getInstallApply(); //激活
  212. } else {
  213. getCardId()
  214. }
  215. }
  216. }
  217. };
  218. //获取订单详情
  219. const getOrderDetails = (id) => {
  220. console.log('======获取订单信息======')
  221. const options = {
  222. type: 2,
  223. data: {
  224. id: id,
  225. },
  226. method: "POST",
  227. showLoading: true,
  228. };
  229. state.disabled = false
  230. request(IFCODE.orderDetail, options).then((res) => {
  231. orderInfo = JSON.parse(res.bizContent);
  232. console.log("orderInfo", orderInfo);
  233. console.log("orderInfores", res);
  234. if (orderInfo) {
  235. fileDataStrings.userType = orderInfo.userType; //用户类型
  236. fileDataStrings.cardId = orderInfo.cardId;
  237. fileDataStrings.packageNum = orderInfo.packageNum;
  238. fileDataStrings.obuId = orderInfo.obuId;
  239. fileDataStrings.customerTel = orderInfo.customerTel;
  240. fileDataStrings.customerId = orderInfo.customerId;
  241. fileDataStrings.orderId = orderInfo.orderId;
  242. let vehicleId = orderInfo.vehiclePlate + "_" + orderInfo.vehiclePlateColor
  243. searchVehicleInfoQuery(vehicleId).then((orderInfo) => {
  244. console.log("orderInfo1111", orderInfo)
  245. fileDataStrings.approvedCount = parseInt(orderInfo.approvedCount); //核载人数
  246. fileDataStrings.vehicleVin = orderInfo.vin;
  247. fileDataStrings.vehicleEngineNum = orderInfo.engineNum;
  248. fileDataStrings.axleCount = parseInt(orderInfo.axleCount); //轴数
  249. fileDataStrings.engineNum = orderInfo.engineNum; //发动机
  250. fileDataStrings.type = parseInt(orderInfo.type); //类型
  251. fileDataStrings.vehiclePlate = orderInfo.vehiclePlate; //车牌
  252. fileDataStrings.vehiclePlateColor = orderInfo.vehiclePlateColor; //车牌颜色
  253. console.log("车辆信息", orderInfo)
  254. fileDataStrings.vehicleDimensions = orderInfo.vehicleDimensions;
  255. // let arr = orderInfo.vehicleDimensions.split("X");
  256. // console.log("orderInfo.vehicleDimensions", orderInfo.vehicleDimensions.split("X"))
  257. // fileDataStrings.outlineL = parseInt(arr[0]); //外廓 长
  258. // fileDataStrings.outlineW = parseInt(arr[1]); //外廓 宽
  259. // if(arr[2].indexOf('mm')){
  260. // fileDataStrings.outlineH = parseInt(arr[2].substring(0, arr[2].length - 2)); //外廓 高
  261. // }else{
  262. // fileDataStrings.outlineH = arr[2] //外廓 高
  263. // }
  264. fileDataStrings.vehicleIdNo = orderInfo.vehicleEngineNum; //车编号
  265. fileDataStrings.vehiclePlateColorStr = getVehiclePlateColor(orderInfo
  266. .vehiclePlateColor);
  267. console.log("fileDataStrings", fileDataStrings);
  268. })
  269. cancelOrderRequest(orderInfo.orderId)
  270. }
  271. });
  272. getObuId();
  273. };
  274. //更换设备 去注销前订单的 卡签
  275. const cancelOrderRequest = (orderId) => {
  276. console.log('======更换设备 去注销前订单的 卡签 ======')
  277. const options = {
  278. type: 2,
  279. data: {
  280. orderId: orderId,
  281. },
  282. method: "POST",
  283. showLoading: true,
  284. };
  285. request(IFCODE.cancelOrderApi, options).then((res) => {
  286. })
  287. }
  288. /**
  289. * 获取OBU号 读OBU
  290. */
  291. const getObuId = () => {
  292. console.log('======获取OBU号======')
  293. let cmdArray = [cmd.HOME_DIRECTORY, cmd.OBU_SYSTEM_FILE, cmd.RANDOM_NUMBER];
  294. tools.showLoadingAlert("正在执行指令");
  295. bluetoothUtil.transCmd(cmdArray, "20", function(res) {
  296. tools.hideLoadingAlert();
  297. var status = res[1].substring(res[1].length - 4, res[1].length);
  298. console.log('获取OBU号执行结果' + status, res)
  299. //第一次获取随机数
  300. if (status == "9000") {
  301. state.disabled = true
  302. obu.obuId = res[1].substring(20, 36);
  303. console.log(containsEnglishCharacters(card.obuId), '获取OBU号执行结果=========' + obu.obuId)
  304. obu.vin = res[1].substring(18, 20);
  305. obu.version = res[1].substring(18, 19) >= 4 ? "4x" : "2x";
  306. cmdRandNum = res[2].substring(0, res[2].length - 4);
  307. state.showBtn = true
  308. } else {
  309. showModals('获取设备信息错误!')
  310. }
  311. }, () => {
  312. showModals('获取设备信息错误')
  313. });
  314. };
  315. //获取fileData
  316. const getFileData = (fun) => {
  317. searchVehicleInfoQuery(orderInfo.vehiclePlate + "_" + orderInfo.vehiclePlateColor, cmdRandNum).then((
  318. orderInfo) => {
  319. console.log("orderInfo==", orderInfo, orderInfo.fileData)
  320. fun(orderInfo.fileData);
  321. })
  322. };
  323. function containsEnglishCharacters(str) {
  324. // // 使用正则表达式匹配英文字母
  325. // const regex = /[a-zA-Z]/;
  326. // return regex.test(str);
  327. // 使用正则表达式匹配纯数字
  328. const regex = /^\d+$/;
  329. return regex.test(str);
  330. }
  331. /**
  332. * 获取卡号 读卡
  333. */
  334. const getCardId = () => {
  335. console.log('======获取卡信息======')
  336. let cmdArr = [
  337. cmd.HOME_DIRECTORY,
  338. //选择主目
  339. cmd.APPLICATION_DIRECTORY,
  340. //选择文件1001--DF01联网收费应用目录
  341. cmd.CMD_READBINARY,
  342. //15文件--卡片发行基本数据文件
  343. cmd.CMD_GETBALANCE
  344. //钱包
  345. ];
  346. tools.showLoadingAlert("正在执行指令");
  347. bluetoothUtil.transCmd(cmdArr, "10", function(res) {
  348. tools.hideLoadingAlert();
  349. //10:写卡 20:写OBU
  350. let str = res[2].substring(res[2].length - 4, res[2].length);
  351. let str3 = res[3].substring(res[3].length - 4, res[3].length);
  352. if (str == "9000" || str3 == "9000") {
  353. if (res[2].length > 86 || res[3] >= 12) {
  354. card.cardId = res[2].substring(20, 40); //卡号
  355. if (!containsEnglishCharacters(card.cardId)) {
  356. if (snums > 2) {
  357. showModals('获取卡信息错误')
  358. return
  359. }
  360. snums++
  361. getCardId()
  362. return
  363. }
  364. card.startTime = res[2].substring(40, 48); //启用
  365. card.endTime = res[2].substring(48, 56);
  366. card.version = res[2].substring(18, 19) >= 4 ? "4x" : "2x";
  367. card.netId = res[2].substring(20, 24);
  368. card.cardType = res[2].substring(28, 30) == 23 ? 1 : 2; //23记账卡 非 23储值卡 1:记账卡 2:储值卡
  369. card.vehiclePlateColor = parseInt(res[2].substring(82, 84), 16);
  370. console.log('======卡信息======', card.cardId, fileDataStrings.cardId)
  371. if (fileDataStrings.cardId) {
  372. if (card.cardId != fileDataStrings.cardId) {
  373. tools.showModalAlert("订单卡号与当前设备卡号信息不符!");
  374. return
  375. }
  376. }
  377. if (!state.transfer) {
  378. console.log("正常", state.transfer)
  379. getCardApply()
  380. } else {
  381. console.log("过户", !state.transfer, state.transfer)
  382. transferApplyRequest()
  383. }
  384. } else {
  385. console.error("CMD_READBINARY指令长度不符" + res[2])
  386. tools.hideLoadingAlert();
  387. }
  388. } else {
  389. showModals('获取卡信息错误!')
  390. }
  391. console.error("CMD_READBINARY指令长度不符" + res[2])
  392. tools.hideLoadingAlert();
  393. }, () => {
  394. showModals('获取卡信息错误')
  395. });
  396. };
  397. function showModals(msg) {
  398. uni.showModal({
  399. title: '提示',
  400. content: msg,
  401. showCancel: false,
  402. success: function(res) {
  403. if (res.confirm) {
  404. uni.navigateBack()
  405. console.log('用户点击确定1');
  406. } else if (res.cancel) {
  407. console.log('用户点击取消1');
  408. }
  409. }
  410. });
  411. }
  412. // *------------------------------------*
  413. // OBU开卡模块
  414. // *------------------------------------*
  415. /**
  416. * 写卡指令申请 请求
  417. */
  418. const getCardApply = () => {
  419. console.log('======写卡指令申请======')
  420. tools.showLoadingAlert("加载中");
  421. let options = {
  422. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  423. data: {
  424. cardId: card.cardId,
  425. orderId: fileDataStrings.orderId,
  426. cardType: card.cardType,
  427. userId: fileDataStrings.customerId,
  428. vehicleId: fileDataStrings.vehiclePlate + "_" + fileDataStrings.vehiclePlateColor,
  429. cosProvider: "1",
  430. enableTime: getFormatDate(new Date(), "yyyyMMdd"),
  431. expireTime: expireDate2(new Date())
  432. }, //请求参数
  433. method: "POST", //提交方式(默认POST)
  434. showLoading: true, //是否显示加载中(默认显示)
  435. };
  436. //调用方式
  437. request(IFCODE.writeCardApply, options)
  438. .then((res) => {
  439. tools.hideLoadingAlert();
  440. let result = stringToJson(res.bizContent);
  441. tools.showLoadingAlert("执行指令中");
  442. console.log('写卡指令', result.command)
  443. bluetoothUtil.transCmd(result.command.split(","), "10", function(res) {
  444. tools.hideLoadingAlert();
  445. getCommandBack(result.command, result.cosRecordId, res.toString());
  446. }, () => {
  447. showModals('写卡指令信息错误!')
  448. });
  449. })
  450. };
  451. /**
  452. * 写卡指令返回 请求
  453. */
  454. const getCommandBack = (command, cosRecordId, response) => {
  455. console.log('======循环写卡指令中======')
  456. tools.showLoadingAlert("加载中");
  457. let options = {
  458. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  459. data: {
  460. cardId: card.cardId,
  461. orderId: fileDataStrings.orderId,
  462. command: command,
  463. response: response,
  464. cosRecordId: cosRecordId,
  465. cosType: "1"
  466. }, //请求参数
  467. method: "POST", //提交方式(默认POST)
  468. showLoading: true, //是否显示加载中(默认显示)
  469. };
  470. //调用方式
  471. request(IFCODE.writeCardBack, options)
  472. .then((res) => {
  473. tools.hideLoadingAlert();
  474. let result = JSON.parse(res.bizContent);
  475. console.log("写卡指令============", result)
  476. if (result.orderStatus == 1 || result.orderStatus == "1") {
  477. tools.showLoadingAlert("执行指令中");
  478. bluetoothUtil.transCmd(result.command.split(","), "10", function(res) {
  479. tools.hideLoadingAlert();
  480. let response = res.toString();
  481. getCommandBack(result.command, cosRecordId, response);
  482. }, () => {
  483. showModals('写卡指令返回错误!')
  484. })
  485. } else {
  486. getWriteCard();
  487. }
  488. })
  489. };
  490. /**
  491. * 写卡确认 请求
  492. */
  493. const getWriteCard = () => {
  494. tools.showLoadingAlert("请求中");
  495. console.log('======写卡确认======')
  496. let options = {
  497. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  498. data: {
  499. cardId: card.cardId,
  500. orderId: fileDataStrings.orderId,
  501. netId: card.netId,
  502. packageNum: fileDataStrings.packageNum,
  503. cardType: card.cardType == 1 ? "111" : "211",
  504. brand: "3",
  505. model: "0",
  506. enableTime: formatTime(new Date()),
  507. expireTime: formatTime2(new Date()),
  508. accountOrganization: "",
  509. accountCardNo: "",
  510. cosRecordId: "",
  511. openId: getItem('openId')
  512. }, //请求参数
  513. method: "POST", //提交方式(默认POST)
  514. showLoading: true, //是否显示加载中(默认显示)
  515. };
  516. //调用方式
  517. request(IFCODE.writeCardConfirm, options)
  518. .then((res) => {
  519. tools.hideLoadingAlert();
  520. console.log(stringToJson(res.bizContent));
  521. //OBU发行申请 请求
  522. // getObuApply()
  523. const cardId = orderInfo.cardId;
  524. const cardStatus = orderInfo.cardStatus != null ? orderInfo.cardStatus : '0'
  525. const obuId = orderInfo.obuId;
  526. const obuStatus = orderInfo.obuStatus != null ? orderInfo.obuStatus : '9'
  527. if (!obuId) { //OBU发行
  528. getObuApply();
  529. } else if (obuId && obuStatus == '9') { //OBU发行
  530. getObuApply();
  531. } else if (cardId && obuId && (obuStatus == '1' || obuStatus == '11' || obuStatus ==
  532. '0')) {
  533. getInstallApply(); //激活
  534. }
  535. })
  536. .catch((err) => {
  537. console.log(err);
  538. });
  539. };
  540. // *------------------------------------*
  541. // OBU 发行模块
  542. // *------------------------------------*
  543. /**
  544. * OBU发行申请 请求
  545. */
  546. const getObuApply = () => {
  547. console.log('======OBU发行申请======')
  548. tools.showLoadingAlert("加载中");
  549. console.log('获取OBU号执行结果=========' + obu.obuId)
  550. let options = {
  551. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  552. data: {
  553. obuId: obu.obuId,
  554. userId: fileDataStrings.customerId,
  555. vehicleId: fileDataStrings.vehiclePlate + "_" + fileDataStrings.vehiclePlateColor
  556. }, //请求参数
  557. method: "POST", //提交方式(默认POST)
  558. showLoading: true, //是否显示加载中(默认显示)
  559. };
  560. //调用方式
  561. request(IFCODE.writeObuApply, options)
  562. .then(() => {
  563. tools.hideLoadingAlert();
  564. modifyFileInfo()
  565. })
  566. };
  567. /**
  568. * 修改系统信息 请求
  569. */
  570. const modifyFileInfo = () => {
  571. console.log('======修改系统信息请求======')
  572. var datetime = new Date();
  573. var year = datetime.getFullYear();
  574. var year1 = datetime.getFullYear() + 10;
  575. var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
  576. var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
  577. tools.showLoadingAlert("加载中");
  578. let options = {
  579. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  580. data: {
  581. obuSerailNo: obu.obuId, //OBU号
  582. obuVersion: obu.vin, //OBU版本号
  583. effTime: year + "" + month + "" + date, //启用时间
  584. expIime: year1 + "" + month + "" + date, //结束时间
  585. plateNo: fileDataStrings.vehiclePlate,
  586. pColor: fileDataStrings.vehiclePlateColor,
  587. random: cmdRandNum
  588. }, //请求参数
  589. method: "POST", //提交方式(默认POST)
  590. showLoading: true, //是否显示加载中(默认显示)
  591. };
  592. //调用方式
  593. request(IFCODE.modifyObuSysInfo, options)
  594. .then((res) => {
  595. tools.hideLoadingAlert();
  596. const datas = stringToJson(res.bizContent);
  597. tools.showLoadingAlert("执行指令");
  598. //如果存在APDU->穿透指令
  599. if (datas.data.APDU) {
  600. bluetoothUtil.transCmd([datas.data.APDU], "20", function(res) {
  601. tools.hideLoadingAlert();
  602. if (res[0] == "9000") {
  603. tools.showLoadingAlert("执行指令");
  604. //再次获取随机数
  605. let cmdArr = [cmd.HOME_DIRECTORY, cmd.OBU_DF01, cmd.OBU_EF01, cmd
  606. .RANDOM_NUMBER
  607. ];
  608. bluetoothUtil.transCmd(cmdArr, '20', function(res) {
  609. var str = res[3].substring(res[3].length - 4, res[3].length);
  610. if (str == "9000") {
  611. cmdRandNum = res[3].substring(0, res[3].length - 4);
  612. getFileData((demos) => {
  613. modifyVehicle(demos);
  614. })
  615. } else {
  616. tools.alertF("RANDOM_NUMBER指令长度不符" + res[1]);
  617. }
  618. }, () => {
  619. showModals('修改系统信息错误')
  620. })
  621. }
  622. }, () => {
  623. showModals('修改系统信息错误!')
  624. });
  625. }
  626. })
  627. .catch((err) => {
  628. console.log(err);
  629. });
  630. };
  631. /**
  632. * 修改车辆信息 请求
  633. */
  634. const modifyVehicle = (ites) => {
  635. tools.showLoadingAlert("加载中");
  636. console.log('======修改车辆信息======', ites)
  637. let options = {
  638. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  639. data: {
  640. Status: "0",
  641. random: cmdRandNum,
  642. obuSerailNo: obu.obuId,
  643. fileData: ites,
  644. orderId: fileDataStrings.orderId,
  645. }, //请求参数
  646. method: "POST", //提交方式(默认POST)
  647. showLoading: true, //是否显示加载中(默认显示)
  648. };
  649. //调用方式
  650. request(IFCODE.modifyObuVehicleInfo, options)
  651. .then((res) => {
  652. tools.hideLoadingAlert();
  653. const datas = stringToJson(res.bizContent);
  654. tools.showLoadingAlert("正在执行指令");
  655. if (datas.data.APDU) {
  656. bluetoothUtil.transCmd([datas.data.APDU], "20", function(res) {
  657. console.log('执行指令结果', res)
  658. tools.hideLoadingAlert();
  659. if (res[0] == "9000") {
  660. if (!state.transfer) {
  661. // 正常激活 走obu发行
  662. getObuConfirm();
  663. } else {
  664. transferSureRequest();
  665. }
  666. }
  667. }, () => {
  668. showModals('修改车辆信息错误')
  669. });
  670. }
  671. })
  672. };
  673. /**
  674. * OBU确认发行 请求
  675. */
  676. const getObuConfirm = () => {
  677. console.log('======OBU确认发行======')
  678. tools.showLoadingAlert("加载中");
  679. let options = {
  680. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  681. data: {
  682. obuId: obu.obuId,
  683. orderId: fileDataStrings.orderId,
  684. netId: obu.obuId.substring(0, 4),
  685. brand: obu.brand,
  686. model: obu.version,
  687. enableTime: formatTime(new Date()),
  688. expireTime: expireDate(new Date())
  689. }, //请求参数
  690. method: "POST", //提交方式(默认POST)
  691. showLoading: true, //是否显示加载中(默认显示)
  692. };
  693. //调用方式
  694. request(IFCODE.obuConfirm, options)
  695. .then((res) => {
  696. tools.hideLoadingAlert();
  697. let datas = stringToJson(res.bizContent);
  698. if (datas.obuId) {
  699. getInstallApply()
  700. }
  701. })
  702. .catch((err) => {
  703. console.log(err);
  704. });
  705. };
  706. // *------------------------------------*
  707. // 设备发行模块
  708. // *------------------------------------*
  709. /**
  710. * BDS-安装申请 请求
  711. */
  712. const getInstallApply = () => {
  713. console.log('======安装申请======')
  714. tools.showLoadingAlert("加载中");
  715. let options = {
  716. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  717. data: {
  718. obuId: obu.obuId,
  719. vehicleId: fileDataStrings.vehiclePlate + "_" + fileDataStrings.vehiclePlateColor,
  720. orderId: fileDataStrings.orderId,
  721. agentId: agentId,
  722. channelId: channelId,
  723. channelType: "1",
  724. staffId: "opId",
  725. terminalId: "999999999",
  726. }, //请求参数
  727. method: "POST", //提交方式(默认POST)
  728. showLoading: true, //是否显示加载中(默认显示)
  729. };
  730. //调用方式
  731. request(IFCODE.installApply, options)
  732. .then(() => {
  733. tools.hideLoadingAlert();
  734. //再次获取随机数
  735. let cmdArr = [cmd.HOME_DIRECTORY, cmd.RANDOM_NUMBER];
  736. bluetoothUtil.transCmd(cmdArr, '20', function(res) {
  737. var str = res[1].substring(res[1].length - 4, res[1].length);
  738. if (str == "9000") {
  739. cmdRandNum = res[1].substring(0, res[1].length - 4);
  740. getObuActivation();
  741. } else {
  742. tools.alertF("RANDOM_NUMBER指令长度不符" + res[1]);
  743. }
  744. }, () => {
  745. showModals('安装申请异常')
  746. })
  747. })
  748. };
  749. /**
  750. * VFJ-OBU在线激活 请求
  751. */
  752. const getObuActivation = () => {
  753. console.log('======VFJ-OBU在线激活======')
  754. tools.showLoadingAlert("加载中");
  755. let options = {
  756. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  757. data: {
  758. random: cmdRandNum,
  759. obuSerailNo: obu.obuId,
  760. orderId: fileDataStrings.orderId,
  761. }, //请求参数
  762. method: "POST", //提交方式(默认POST)
  763. showLoading: true, //是否显示加载中(默认显示)
  764. };
  765. //调用方式
  766. request(IFCODE.obuActivation, options)
  767. .then((res) => {
  768. tools.hideLoadingAlert();
  769. console.log("在线激活 请求");
  770. console.log(stringToJson(res.bizContent));
  771. const datas = stringToJson(res.bizContent);
  772. tools.showLoadingAlert("执行指令");
  773. bluetoothUtil.transCmd([datas.data.APDU], "20", function(res) {
  774. tools.hideLoadingAlert();
  775. console.log(res);
  776. if (res[0] == "9000") {
  777. console.log("在线激活执行指令88888 请求", res);
  778. getObuInstall(0, ""); //status 0 - 安装成功 || 1 - 安装失败
  779. }
  780. }, () => {
  781. showModals('在线激活异常')
  782. });
  783. })
  784. .catch((err) => {
  785. console.log(err);
  786. });
  787. };
  788. /**
  789. * BDS-安装确认 请求
  790. */
  791. const getObuInstall = (status, reason) => {
  792. console.log('======OBU安装确认======')
  793. tools.showLoadingAlert("加载中");
  794. let options = {
  795. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  796. data: {
  797. installStatus: status,
  798. failReason: reason,
  799. installType: "1",
  800. installChannelId: channelId,
  801. obuId: obu.obuId,
  802. orderId: fileDataStrings.orderId,
  803. openId: getItem('openId')
  804. }, //请求参数
  805. method: "POST", //提交方式(默认POST)
  806. showLoading: true, //是否显示加载中(默认显示)
  807. };
  808. //调用方式
  809. request(IFCODE.obuInstall, options)
  810. .then(() => {
  811. tools.hideLoadingAlert();
  812. bindCardAndObu();
  813. });
  814. };
  815. /**
  816. * 卡签绑定 请求
  817. */
  818. const bindCardAndObu = () => {
  819. console.log('======卡签绑定======')
  820. tools.showLoadingAlert("加载中");
  821. let options = {
  822. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  823. data: {
  824. obuId: obu.obuId,
  825. cardId: card.cardId ? card.cardId : fileDataStrings.cardId,
  826. }, //请求参数
  827. method: "POST", //提交方式(默认POST)
  828. showLoading: true, //是否显示加载中(默认显示)
  829. };
  830. //调用方式
  831. request(IFCODE.bindCardAndObu, options)
  832. .then((res) => {
  833. tools.hideLoadingAlert();
  834. let result = JSON.parse(res.bizContent);
  835. console.log("写卡指令============", result)
  836. tools.showLoadingAlert("执行指令中");
  837. bluetoothUtil.transCmd(result.command.split(","), "10", function(res) {
  838. tools.hideLoadingAlert();
  839. let response = res.toString();
  840. getCommandBackEnd(result.command, result.cosRecordId, response);
  841. }, () => {
  842. showModals('卡签绑定异常!')
  843. });
  844. })
  845. .catch((err) => {
  846. console.log(err);
  847. });
  848. };
  849. /**
  850. * 卡签绑定写卡指令返回 请求
  851. */
  852. const getCommandBackEnd = (command, cosRecordId, response) => {
  853. console.log('======卡签绑定循环写卡指令中======')
  854. tools.showLoadingAlert("加载中");
  855. let options = {
  856. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  857. data: {
  858. cardId: card.cardId ? card.cardId : fileDataStrings.cardId,
  859. orderId: fileDataStrings.orderId,
  860. command: command,
  861. response: response,
  862. cosRecordId: cosRecordId,
  863. cosType: "4"
  864. }, //请求参数
  865. method: "POST", //提交方式(默认POST)
  866. showLoading: true, //是否显示加载中(默认显示)
  867. };
  868. //调用方式
  869. request(IFCODE.writeCardBack, options)
  870. .then((res) => {
  871. tools.hideLoadingAlert();
  872. let result = JSON.parse(res.bizContent);
  873. console.log("写卡指令============", result)
  874. if (result.orderStatus == 1 || result.orderStatus == "1") {
  875. tools.showLoadingAlert("执行指令中");
  876. bluetoothUtil.transCmd(result.command.split(","), "10", function(res) {
  877. tools.hideLoadingAlert();
  878. let response = res.toString();
  879. getCommandBackEnd(result.command, cosRecordId, response);
  880. }, () => {
  881. showModals('卡签绑定返回异常!')
  882. });
  883. } else {
  884. state.disabled = true
  885. // #ifdef MP-ALIPAY
  886. uni.closeBluetoothAdapter({
  887. success(res) {
  888. }
  889. })
  890. msg("激活成功")
  891. state.showPopup = true
  892. state.isSuccess = true
  893. // #endif
  894. DataSynchronizationRequest();
  895. // #ifdef MP-WEIXIN
  896. msg("激活成功")
  897. setTimeout(() => {
  898. uni.navigateTo({
  899. url: "/subpackage/after-sale/deviceInfo/deviceInfo",
  900. });
  901. }, 2000)
  902. // #endif
  903. }
  904. })
  905. };
  906. const DataSynchronizationRequest = () => {
  907. const options = {
  908. type: 2,
  909. data: {
  910. orderId: fileDataStrings.orderId
  911. },
  912. method: "POST",
  913. showLoading: false,
  914. };
  915. request(IFCODE.DataSynchronizationApi, options).then((res) => {
  916. })
  917. }
  918. const back = () => {
  919. uni.switchTab({
  920. url: "/pages/index/index"
  921. });
  922. }
  923. // 过户激活申请
  924. const transferApplyRequest = () => {
  925. const options = {
  926. type: 2,
  927. data: {
  928. orderId: fileDataStrings.orderId
  929. },
  930. method: "POST",
  931. showLoading: false,
  932. };
  933. request(IFCODE.transferApply, options).then((res) => {
  934. // 设备升级
  935. getDeviceUpgrade()
  936. })
  937. }
  938. // 过户激活确认
  939. const transferSureRequest = () => {
  940. const options = {
  941. type: 2,
  942. data: {
  943. orderId: fileDataStrings.orderId
  944. },
  945. method: "POST",
  946. showLoading: false,
  947. };
  948. request(IFCODE.transferSure, options).then((res) => {
  949. // 设备升级
  950. getInstallApply()
  951. })
  952. }
  953. //设备升级 请求
  954. const getDeviceUpgrade = () => {
  955. const options = {
  956. type: 2,
  957. data: {
  958. cardId: fileDataStrings.cardId,
  959. orderId: fileDataStrings.orderId,
  960. isTransfer: state.transfer
  961. },
  962. method: "POST",
  963. showLoading: true,
  964. };
  965. request(IFCODE.deviceUpgrade, options).then((res) => {
  966. tools.hideLoadingAlert();
  967. let result = stringToJson(res.bizContent);
  968. console.log("&&&&&&&&&&&&", result);
  969. let cmdArray = result.command ? result.command.split(",") : "";
  970. if (cmdArray.length > 0) {
  971. tools.showLoadingAlert("正在执行指令");
  972. bluetoothUtil.transCmd(cmdArray, "10", function(res) {
  973. tools.hideLoadingAlert();
  974. let status = res[cmdArray.length - 1].substring(res[cmdArray.length - 1].length -
  975. 4, res[cmdArray.length - 1].length);
  976. if (status == "9000") {
  977. getCommandBackUp(result.command, result.cosRecordId, res.toString());
  978. }
  979. }, () => {
  980. showModals('设备升级异常!')
  981. })
  982. }
  983. })
  984. };
  985. /**
  986. * 写卡指令返回 请求
  987. */
  988. const getCommandBackUp = (command, cosRecordId, response) => {
  989. console.log('======循环写卡指令中======')
  990. tools.showLoadingAlert("加载中");
  991. let options = {
  992. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  993. data: {
  994. cardId: fileDataStrings.cardId,
  995. orderId: fileDataStrings.orderId,
  996. command: command,
  997. response: response,
  998. cosRecordId: cosRecordId,
  999. cosType: 2
  1000. }, //请求参数
  1001. method: "POST", //提交方式(默认POST)
  1002. showLoading: true, //是否显示加载中(默认显示)
  1003. };
  1004. //调用方式
  1005. request(IFCODE.writeCardBack, options)
  1006. .then((res) => {
  1007. tools.hideLoadingAlert();
  1008. let result = JSON.parse(res.bizContent);
  1009. if (result.orderStatus == 1 || result.orderStatus == "1") {
  1010. tools.showLoadingAlert("执行指令中");
  1011. bluetoothUtil.transCmd(result.command.split(","), "10", function(res) {
  1012. tools.hideLoadingAlert();
  1013. let response = res.toString();
  1014. getCommandBackUp(result.command, cosRecordId, response);
  1015. }, () => {
  1016. showModals('写卡异常!')
  1017. });
  1018. } else {
  1019. obuWriteAgainRequest();
  1020. }
  1021. })
  1022. };
  1023. /**
  1024. * 修改系统信息 请求
  1025. */
  1026. const obuWriteAgainRequest = () => {
  1027. let cmdArray1 = [cmd.HOME_DIRECTORY, cmd.OBU_SYSTEM_FILE, cmd.RANDOM_NUMBER];
  1028. tools.showLoadingAlert("正在执行指令");
  1029. bluetoothUtil.transCmd(cmdArray1, "20", function(res) {
  1030. tools.hideLoadingAlert();
  1031. var str = res[2].substring(res[2].length - 4, res[2].length);
  1032. if (str == "9000") {
  1033. cmdRandNum = res[2].substring(0, res[2].length - 4);
  1034. const options = {
  1035. type: 2,
  1036. data: {
  1037. obuId: fileDataStrings.obuId,
  1038. random: cmdRandNum
  1039. },
  1040. method: "POST",
  1041. showLoading: true,
  1042. };
  1043. request(IFCODE.obuWriteAgain, options).then((res) => {
  1044. let datas = stringToJson(res.bizContent);
  1045. console.log("899", datas, datas.data.APDU);
  1046. if (datas.data.APDU) {
  1047. tools.showLoadingAlert("正在执行指令");
  1048. bluetoothUtil.transCmd([datas.data.APDU], "20", function(res) {
  1049. tools.hideLoadingAlert();
  1050. console.log("res=====", res, res[0])
  1051. let cmdArr = [cmd.HOME_DIRECTORY, cmd.OBU_DF01, cmd.OBU_EF01, cmd
  1052. .RANDOM_NUMBER
  1053. ];
  1054. bluetoothUtil.transCmd(cmdArr, "20", function(res) {
  1055. console.log("chelaing======", res)
  1056. var str = res[3].substring(res[3].length - 4, res[3]
  1057. .length);
  1058. if (str == "9000") {
  1059. cmdRandNum = res[3].substring(0, res[3].length -
  1060. 4);
  1061. console.log("0000000000000000000000000")
  1062. getFileData((demos) => {
  1063. modifyVehicle(demos);
  1064. })
  1065. } else {
  1066. tools.alertF("RANDOM_NUMBER指令长度不符" + res[1]);
  1067. }
  1068. })
  1069. })
  1070. }
  1071. })
  1072. } else {
  1073. tools.alertF("RANDOM_NUMBER指令长度不符" + res[1]);
  1074. }
  1075. })
  1076. };
  1077. </script>
  1078. <style>
  1079. .containers {
  1080. height: 100%;
  1081. display: flex;
  1082. flex-direction: column;
  1083. align-items: center;
  1084. justify-content: space-between;
  1085. box-sizing: border-box;
  1086. }
  1087. .sec_info {
  1088. width: 90%;
  1089. height: auto;
  1090. margin: 0 auto;
  1091. box-shadow: 0rpx 6rpx 25rpx 0rpx rgba(0, 0, 0, 0.2);
  1092. margin-top: 50rpx;
  1093. border-radius: 20rpx;
  1094. }
  1095. .info_txt {
  1096. width: 100%;
  1097. height: 120rpx;
  1098. line-height: 120rpx;
  1099. text-align: center;
  1100. color: #000;
  1101. font-size: 36rpx;
  1102. margin-bottom: 20rpx;
  1103. }
  1104. .info_plate {
  1105. display: flex;
  1106. flex-direction: row;
  1107. width: 94%;
  1108. height: 100rpx;
  1109. margin: 0 auto;
  1110. border-bottom: 2rpx solid #f2f2f2;
  1111. }
  1112. .info_plate text:nth-child(1) {
  1113. height: 100rpx;
  1114. text-align: left;
  1115. line-height: 100rpx;
  1116. font-size: 32rpx;
  1117. color: #999;
  1118. }
  1119. .info_plate text:nth-child(2) {
  1120. flex: 1;
  1121. height: 100rpx;
  1122. line-height: 100rpx;
  1123. font-size: 32rpx;
  1124. color: #333;
  1125. margin-left: 50rpx;
  1126. text-align: right;
  1127. }
  1128. /*提交按钮样式*/
  1129. .up_btn {
  1130. width: 85%;
  1131. height: 100rpx;
  1132. margin: 0 auto;
  1133. margin-top: 50rpx;
  1134. margin-bottom: 100rpx;
  1135. }
  1136. .up_btn button {
  1137. width: 100%;
  1138. height: 80rpx;
  1139. line-height: 80rpx;
  1140. color: white;
  1141. font-size: 32rpx;
  1142. text-align: center;
  1143. background: linear-gradient(to left, #43a1e0 0%, #13e7c1 100%);
  1144. border-radius: 40rpx;
  1145. outline: none;
  1146. border: #4cd95f;
  1147. }
  1148. .button {
  1149. width: 100%;
  1150. height: 80rpx;
  1151. line-height: 80rpx;
  1152. color: white;
  1153. font-size: 32rpx;
  1154. text-align: center;
  1155. background: linear-gradient(to left, #43a1e0 0%, #13e7c1 100%);
  1156. border-radius: 40rpx;
  1157. outline: none;
  1158. border: #4cd95f;
  1159. }
  1160. .hui {
  1161. width: 100%;
  1162. height: 80rpx;
  1163. line-height: 80rpx;
  1164. color: white;
  1165. font-size: 32rpx;
  1166. text-align: center;
  1167. background: linear-gradient(to left, #b9b9b9 0%, #e7e7e7 100%) !important;
  1168. border-radius: 40rpx;
  1169. outline: none;
  1170. border: #4cd95f;
  1171. }
  1172. .up_btn button[disabled] {
  1173. background-color: rgba(0, 191, 112, 0.5);
  1174. color: white;
  1175. font-size: 34rpx;
  1176. border-radius: 20rpx;
  1177. }
  1178. </style>