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

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