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.

activate.vue 33KB

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