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

activate.vue 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  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)
  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. obu.vin = res[1].substring(18, 20);
  250. obu.version = res[1].substring(18, 19) >= 4 ? "4x" : "2x";
  251. cmdRandNum = res[2].substring(0, res[2].length - 4);
  252. }
  253. });
  254. };
  255. //获取fileData
  256. const getFileData = (fun) => {
  257. //调用方式
  258. request('6ed853e432fb4811a3c0d7d27034bd39', {
  259. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  260. data: {
  261. fileData: fileDataStrings.vehiclePlate,
  262. nLen: 24
  263. }, //请求参数
  264. method: "POST", //提交方式(默认POST)
  265. showLoading: true, //是否显示加载中(默认显示)
  266. }).then((les) => {
  267. let result = stringToJson(les.bizContent);
  268. console.log(les, '=========123')
  269. let res1 = result.gbkFileData; //车牌号
  270. let res2 = IntegerToHexString(fileDataStrings.vehiclePlateColor, 4); //车牌颜色
  271. let res3 = IntegerToHexString(1, 2); //类型
  272. let res4 = IntegerToHexString(1, 2); //用户类型
  273. let res5 = IntegerToHexString(fileDataStrings.outlineL, 4); //车辆尺寸 长
  274. let res6 = IntegerToHexString(fileDataStrings.outlineW, 2); //车辆尺寸 宽
  275. let res7 = IntegerToHexString(fileDataStrings.outlineH, 2); //车辆尺寸 高
  276. let res8 = IntegerToHexString(4, 2); //获取轮数
  277. let res9 = IntegerToHexString(4, 2); //轴数
  278. let res10 = IntegerToHexString(null, 4); //轴距32
  279. let res11 = IntegerToHexString(fileDataStrings.approvedCount, 6); //核载人数
  280. let res12 = AsciToHexString(fileDataStrings.vehicleVin, 32); //车编号
  281. // let res12 = JSON.parse(res.bizContent).gbkFileData; //车编号
  282. let res13 = AsciToHexString(fileDataStrings.vehicleEngineNum, 32); //发动机
  283. fun(res1 + res2 + res3 + res4 + res5 + res6 + res7 + res8 + res9 + res10 + res11 + res12 + res13);
  284. })
  285. };
  286. /**
  287. * 获取卡号 读卡
  288. */
  289. const getCardId = () => {
  290. console.log('======获取卡信息======')
  291. let cmdArr = [
  292. cmd.HOME_DIRECTORY,
  293. //选择主目
  294. cmd.APPLICATION_DIRECTORY,
  295. //选择文件1001--DF01联网收费应用目录
  296. cmd.CMD_READBINARY,
  297. //15文件--卡片发行基本数据文件
  298. cmd.CMD_GETBALANCE
  299. //钱包
  300. ];
  301. tools.showLoadingAlert("正在执行指令");
  302. bluetoothUtil.transCmd(cmdArr, "10", function(res) {
  303. tools.hideLoadingAlert();
  304. //10:写卡 20:写OBU
  305. let str = res[2].substring(res[2].length - 4, res[2].length);
  306. let str3 = res[3].substring(res[3].length - 4, res[3].length);
  307. if (str == "9000" || str3 == "9000") {
  308. if (res[2].length > 86 || res[3] >= 12) {
  309. card.cardId = res[2].substring(20, 40); //卡号
  310. card.startTime = res[2].substring(40, 48); //启用
  311. card.endTime = res[2].substring(48, 56);
  312. card.version = res[2].substring(18, 19) >= 4 ? "4x" : "2x";
  313. card.netId = res[2].substring(20, 24);
  314. card.cardType = res[2].substring(28, 30) == 23 ? 1 : 2; //23记账卡 非 23储值卡 1:记账卡 2:储值卡
  315. card.vehiclePlateColor = parseInt(res[2].substring(82, 84), 16);
  316. console.log('======卡信息======', card.cardId, fileDataStrings.cardId)
  317. if (card.cardId != fileDataStrings.cardId) {
  318. tools.showModalAlert("订单卡号与当前设备卡号信息不符!");
  319. return
  320. }
  321. getCardApply()
  322. } else {
  323. console.error("CMD_READBINARY指令长度不符" + res[2])
  324. tools.hideLoadingAlert();
  325. }
  326. }
  327. console.error("CMD_READBINARY指令长度不符" + res[2])
  328. tools.hideLoadingAlert();
  329. });
  330. };
  331. // *------------------------------------*
  332. // OBU开卡模块
  333. // *------------------------------------*
  334. /**
  335. * 写卡指令申请 请求
  336. */
  337. const getCardApply = () => {
  338. console.log('======写卡指令申请======')
  339. tools.showLoadingAlert("加载中");
  340. let options = {
  341. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  342. data: {
  343. cardId: card.cardId,
  344. orderId: fileDataStrings.orderId,
  345. cardType: card.cardType,
  346. userId: fileDataStrings.customerId,
  347. vehicleId: fileDataStrings.vehiclePlate + "_" + fileDataStrings.vehiclePlateColor,
  348. cosProvider: "1",
  349. enableTime: getFormatDate(new Date(), "yyyyMMdd"),
  350. expireTime: expireDate2(new Date())
  351. }, //请求参数
  352. method: "POST", //提交方式(默认POST)
  353. showLoading: true, //是否显示加载中(默认显示)
  354. };
  355. //调用方式
  356. request(IFCODE.writeCardApply, options)
  357. .then((res) => {
  358. tools.hideLoadingAlert();
  359. let result = stringToJson(res.bizContent);
  360. tools.showLoadingAlert("执行指令中");
  361. console.log('写卡指令', result.command)
  362. bluetoothUtil.transCmd(result.command.split(","), "10", function(res) {
  363. tools.hideLoadingAlert();
  364. getCommandBack(result.command, result.cosRecordId, res.toString());
  365. });
  366. })
  367. };
  368. /**
  369. * 写卡指令返回 请求
  370. */
  371. const getCommandBack = (command, cosRecordId, response) => {
  372. console.log('======循环写卡指令中======')
  373. tools.showLoadingAlert("加载中");
  374. let options = {
  375. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  376. data: {
  377. cardId: card.cardId,
  378. orderId: fileDataStrings.orderId,
  379. command: command,
  380. response: response,
  381. cosRecordId: cosRecordId,
  382. cosType: "1"
  383. }, //请求参数
  384. method: "POST", //提交方式(默认POST)
  385. showLoading: true, //是否显示加载中(默认显示)
  386. };
  387. //调用方式
  388. request(IFCODE.writeCardBack, options)
  389. .then((res) => {
  390. tools.hideLoadingAlert();
  391. let result = JSON.parse(res.bizContent);
  392. console.log("写卡指令============", result)
  393. if (result.orderStatus == 1 || result.orderStatus == "1") {
  394. tools.showLoadingAlert("执行指令中");
  395. bluetoothUtil.transCmd(result.command.split(","), "10", function(res) {
  396. tools.hideLoadingAlert();
  397. let response = res.toString();
  398. getCommandBack(result.command, cosRecordId, response);
  399. });
  400. } else {
  401. getWriteCard();
  402. }
  403. })
  404. };
  405. /**
  406. * 写卡确认 请求
  407. */
  408. const getWriteCard = () => {
  409. tools.showLoadingAlert("请求中");
  410. console.log('======写卡确认======')
  411. let options = {
  412. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  413. data: {
  414. cardId: card.cardId,
  415. orderId: fileDataStrings.orderId,
  416. netId: card.netId,
  417. packageNum: fileDataStrings.packageNum,
  418. cardType: card.cardType == 1 ? "111" : "211",
  419. brand: "3",
  420. model: "0",
  421. enableTime: formatTime(new Date()),
  422. expireTime: formatTime(new Date()),
  423. accountOrganization: "",
  424. accountCardNo: "",
  425. cosRecordId: "",
  426. openId: getItem('openId')
  427. }, //请求参数
  428. method: "POST", //提交方式(默认POST)
  429. showLoading: true, //是否显示加载中(默认显示)
  430. };
  431. //调用方式
  432. request(IFCODE.writeCardConfirm, options)
  433. .then((res) => {
  434. tools.hideLoadingAlert();
  435. console.log(stringToJson(res.bizContent));
  436. //OBU发行申请 请求
  437. getObuApply()
  438. })
  439. .catch((err) => {
  440. console.log(err);
  441. });
  442. };
  443. // *------------------------------------*
  444. // OBU 发行模块
  445. // *------------------------------------*
  446. /**
  447. * OBU发行申请 请求
  448. */
  449. const getObuApply = () => {
  450. console.log('======OBU发行申请======')
  451. tools.showLoadingAlert("加载中");
  452. let options = {
  453. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  454. data: {
  455. obuId: obu.obuId,
  456. userId: fileDataStrings.customerId,
  457. vehicleId: fileDataStrings.vehiclePlate + "_" + fileDataStrings.vehiclePlateColor
  458. }, //请求参数
  459. method: "POST", //提交方式(默认POST)
  460. showLoading: true, //是否显示加载中(默认显示)
  461. };
  462. //调用方式
  463. request(IFCODE.writeObuApply, options)
  464. .then(() => {
  465. tools.hideLoadingAlert();
  466. modifyFileInfo()
  467. })
  468. };
  469. /**
  470. * 修改系统信息 请求
  471. */
  472. const modifyFileInfo = () => {
  473. console.log('======修改系统信息请求======')
  474. var datetime = new Date();
  475. var year = datetime.getFullYear();
  476. var year1 = datetime.getFullYear() + 10;
  477. var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
  478. var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
  479. tools.showLoadingAlert("加载中");
  480. let options = {
  481. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  482. data: {
  483. obuSerailNo: obu.obuId, //OBU号
  484. obuVersion: obu.vin, //OBU版本号
  485. effTime: year + "" + month + "" + date, //启用时间
  486. expIime: year1 + "" + month + "" + date, //结束时间
  487. plateNo: fileDataStrings.vehiclePlate,
  488. pColor: fileDataStrings.vehiclePlateColor,
  489. random: cmdRandNum
  490. }, //请求参数
  491. method: "POST", //提交方式(默认POST)
  492. showLoading: true, //是否显示加载中(默认显示)
  493. };
  494. //调用方式
  495. request(IFCODE.modifyObuSysInfo, options)
  496. .then((res) => {
  497. tools.hideLoadingAlert();
  498. const datas = stringToJson(res.bizContent);
  499. tools.showLoadingAlert("执行指令");
  500. //如果存在APDU->穿透指令
  501. if (datas.data.APDU) {
  502. bluetoothUtil.transCmd([datas.data.APDU], "20", function(res) {
  503. tools.hideLoadingAlert();
  504. if (res[0] == "9000") {
  505. tools.showLoadingAlert("执行指令");
  506. //再次获取随机数
  507. let cmdArr = [cmd.HOME_DIRECTORY, cmd.OBU_DF01, cmd.OBU_EF01, cmd
  508. .RANDOM_NUMBER
  509. ];
  510. bluetoothUtil.transCmd(cmdArr, '20', function(res) {
  511. var str = res[3].substring(res[3].length - 4, res[3].length);
  512. if (str == "9000") {
  513. cmdRandNum = res[3].substring(0, res[3].length - 4);
  514. getFileData((demos) => {
  515. modifyVehicle(demos);
  516. })
  517. } else {
  518. tools.alertF("RANDOM_NUMBER指令长度不符" + res[1]);
  519. }
  520. })
  521. }
  522. });
  523. }
  524. })
  525. .catch((err) => {
  526. console.log(err);
  527. });
  528. };
  529. /**
  530. * 修改车辆信息 请求
  531. */
  532. const modifyVehicle = (ites) => {
  533. tools.showLoadingAlert("加载中");
  534. console.log('======修改车辆信息======', ites)
  535. let options = {
  536. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  537. data: {
  538. Status: "0",
  539. random: cmdRandNum, //5202192509222239
  540. obuSerailNo: obu.obuId, //5202192509551922
  541. fileData: ites,
  542. orderId: fileDataStrings.orderId,
  543. }, //请求参数
  544. method: "POST", //提交方式(默认POST)
  545. showLoading: true, //是否显示加载中(默认显示)
  546. };
  547. //调用方式
  548. request(IFCODE.modifyObuVehicleInfo, options)
  549. .then((res) => {
  550. tools.hideLoadingAlert();
  551. const datas = stringToJson(res.bizContent);
  552. tools.showLoadingAlert("正在执行指令");
  553. if (datas.data.APDU) {
  554. bluetoothUtil.transCmd([datas.data.APDU], "20", function(res) {
  555. console.log('执行指令结果', res)
  556. tools.hideLoadingAlert();
  557. if (res[0] == "9000") {
  558. getObuConfirm();
  559. }
  560. });
  561. }
  562. })
  563. };
  564. /**
  565. * OBU确认发行 请求
  566. */
  567. const getObuConfirm = () => {
  568. console.log('======OBU确认发行======')
  569. tools.showLoadingAlert("加载中");
  570. let options = {
  571. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  572. data: {
  573. obuId: obu.obuId,
  574. orderId: fileDataStrings.orderId,
  575. netId: obu.obuId.substring(0, 4),
  576. brand: obu.brand,
  577. model: obu.version,
  578. enableTime: formatTime(new Date()),
  579. expireTime: expireDate(new Date())
  580. }, //请求参数
  581. method: "POST", //提交方式(默认POST)
  582. showLoading: true, //是否显示加载中(默认显示)
  583. };
  584. //调用方式
  585. request(IFCODE.obuConfirm, options)
  586. .then((res) => {
  587. tools.hideLoadingAlert();
  588. let datas = stringToJson(res.bizContent);
  589. if (datas.obuId) {
  590. getInstallApply()
  591. }
  592. })
  593. .catch((err) => {
  594. console.log(err);
  595. });
  596. };
  597. // *------------------------------------*
  598. // 设备发行模块
  599. // *------------------------------------*
  600. /**
  601. * BDS-安装申请 请求
  602. */
  603. const getInstallApply = () => {
  604. console.log('======安装申请======')
  605. tools.showLoadingAlert("加载中");
  606. let options = {
  607. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  608. data: {
  609. obuId: obu.obuId,
  610. vehicleId: fileDataStrings.vehiclePlate + "_" + fileDataStrings.vehiclePlateColor,
  611. orderId: fileDataStrings.orderId,
  612. agentId: agentId,
  613. channelId: channelId,
  614. channelType: "1",
  615. staffId: "opId",
  616. terminalId: "999999999",
  617. }, //请求参数
  618. method: "POST", //提交方式(默认POST)
  619. showLoading: true, //是否显示加载中(默认显示)
  620. };
  621. //调用方式
  622. request(IFCODE.installApply, options)
  623. .then(() => {
  624. tools.hideLoadingAlert();
  625. // //再次获取随机数
  626. // let cmdArr = [cmd.HOME_DIRECTORY, cmd.RANDOM_NUMBER];
  627. // bluetoothUtil.transCmd(cmdArr, '20', function(res) {
  628. // var str = res[1].substring(res[1].length - 4, res[1].length);
  629. // if (str == "9000") {
  630. // cmdRandNum = res[1].substring(0, res[1].length - 4);
  631. // getObuActivation(cmdRandNum);
  632. // } else {
  633. // tools.alertF("RANDOM_NUMBER指令长度不符" + res[1]);
  634. // }
  635. // })
  636. //再次获取随机数
  637. let cmdArr = [cmd.HOME_DIRECTORY, cmd.RANDOM_NUMBER];
  638. bluetoothUtil.transCmd(cmdArr, '20', function(res) {
  639. var str = res[1].substring(res[1].length - 4, res[1].length);
  640. if (str == "9000") {
  641. cmdRandNum = res[1].substring(0, res[1].length - 4);
  642. getObuActivation();
  643. } else {
  644. tools.alertF("RANDOM_NUMBER指令长度不符" + res[1]);
  645. }
  646. })
  647. })
  648. };
  649. /**
  650. * VFJ-OBU在线激活 请求
  651. */
  652. const getObuActivation = () => {
  653. console.log('======VFJ-OBU在线激活======')
  654. tools.showLoadingAlert("加载中");
  655. let options = {
  656. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  657. data: {
  658. random: cmdRandNum,
  659. obuSerailNo: obu.obuId,
  660. orderId: fileDataStrings.orderId,
  661. }, //请求参数
  662. method: "POST", //提交方式(默认POST)
  663. showLoading: true, //是否显示加载中(默认显示)
  664. };
  665. //调用方式
  666. request(IFCODE.obuActivation, options)
  667. .then((res) => {
  668. tools.hideLoadingAlert();
  669. console.log("在线激活 请求");
  670. console.log(stringToJson(res.bizContent));
  671. const datas = stringToJson(res.bizContent);
  672. tools.showLoadingAlert("执行指令");
  673. bluetoothUtil.transCmd([datas.data.APDU], "20", function(res) {
  674. tools.hideLoadingAlert();
  675. console.log(res);
  676. if (res[0] == "9000") {
  677. console.log("在线激活执行指令88888 请求", res);
  678. getObuInstall(0, ""); //status 0 - 安装成功 || 1 - 安装失败
  679. }
  680. });
  681. })
  682. .catch((err) => {
  683. console.log(err);
  684. });
  685. };
  686. /**
  687. * BDS-安装确认 请求
  688. */
  689. const getObuInstall = (status, reason) => {
  690. console.log('======OBU安装确认======')
  691. tools.showLoadingAlert("加载中");
  692. let options = {
  693. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  694. data: {
  695. installStatus: status,
  696. failReason: reason,
  697. installType: "1",
  698. installChannelId: channelId,
  699. obuId: obu.obuId,
  700. orderId: fileDataStrings.orderId,
  701. openId: getItem('openId')
  702. }, //请求参数
  703. method: "POST", //提交方式(默认POST)
  704. showLoading: true, //是否显示加载中(默认显示)
  705. };
  706. //调用方式
  707. request(IFCODE.obuInstall, options)
  708. .then(() => {
  709. tools.hideLoadingAlert();
  710. // uni.navigateTo({
  711. // url: "/subpackage/orders/order-details-new?id=" +
  712. // state.id +
  713. // "&orderId=" +
  714. // state.orderId,
  715. // });
  716. bindCardAndObu();
  717. });
  718. };
  719. /**
  720. * 卡签绑定 请求
  721. */
  722. const bindCardAndObu = () => {
  723. console.log('======卡签绑定======')
  724. tools.showLoadingAlert("加载中");
  725. let options = {
  726. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  727. data: {
  728. obuId: obu.obuId,
  729. cardId: card.cardId,
  730. }, //请求参数
  731. method: "POST", //提交方式(默认POST)
  732. showLoading: true, //是否显示加载中(默认显示)
  733. };
  734. //调用方式
  735. request(IFCODE.bindCardAndObu, options)
  736. .then((res) => {
  737. tools.hideLoadingAlert();
  738. let result = JSON.parse(res.bizContent);
  739. console.log("写卡指令============", result)
  740. tools.showLoadingAlert("执行指令中");
  741. bluetoothUtil.transCmd(result.command.split(","), "10", function(res) {
  742. tools.hideLoadingAlert();
  743. let response = res.toString();
  744. getCommandBackEnd(result.command, result.cosRecordId, response);
  745. // uni.navigateTo({
  746. // url: "/subpackage/after-sale/deviceInfo/deviceInfo",
  747. // });
  748. });
  749. })
  750. .catch((err) => {
  751. console.log(err);
  752. });
  753. };
  754. /**
  755. * 卡签绑定写卡指令返回 请求
  756. */
  757. const getCommandBackEnd = (command, cosRecordId, response) => {
  758. console.log('======卡签绑定循环写卡指令中======')
  759. tools.showLoadingAlert("加载中");
  760. let options = {
  761. type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  762. data: {
  763. cardId: card.cardId,
  764. orderId: fileDataStrings.orderId,
  765. command: command,
  766. response: response,
  767. cosRecordId: cosRecordId,
  768. cosType: "4"
  769. }, //请求参数
  770. method: "POST", //提交方式(默认POST)
  771. showLoading: true, //是否显示加载中(默认显示)
  772. };
  773. //调用方式
  774. request(IFCODE.writeCardBack, options)
  775. .then((res) => {
  776. tools.hideLoadingAlert();
  777. let result = JSON.parse(res.bizContent);
  778. console.log("写卡指令============", result)
  779. if (result.orderStatus == 1 || result.orderStatus == "1") {
  780. tools.showLoadingAlert("执行指令中");
  781. bluetoothUtil.transCmd(result.command.split(","), "10", function(res) {
  782. tools.hideLoadingAlert();
  783. let response = res.toString();
  784. getCommandBackEnd(result.command, cosRecordId, response);
  785. });
  786. } else {
  787. // #ifdef MP-ALIPAY
  788. uni.closeBluetoothAdapter({
  789. success(res) {
  790. }
  791. })
  792. msg("激活成功")
  793. state.showPopup = true
  794. state.isSuccess = true
  795. // #endif
  796. DataSynchronizationRequest();
  797. // #ifdef MP-WEIXIN
  798. uni.navigateTo({
  799. url: "/subpackage/after-sale/deviceInfo/deviceInfo",
  800. });
  801. // #endif
  802. }
  803. })
  804. };
  805. const DataSynchronizationRequest = () => {
  806. const options = {
  807. type: 2,
  808. data: {
  809. orderId: fileDataStrings.orderId
  810. },
  811. method: "POST",
  812. showLoading: true,
  813. };
  814. request(IFCODE.DataSynchronizationApi, options).then((res) => {
  815. uni.hideLoading()
  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>