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 27KB

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