選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

activate.vue 32KB

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