123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490 |
- import bleapi from "../../bluetooth/bleUtil.js"
- import { facapi } from "../../bluetooth/facUtil.js"
- import Api from "../../api/index.js"
- import { requestFnc } from "../../utils/request.js"
- import {
- vehicleTypeMap,
- cpuCardTypeMap,
- userTypeMap,
- plateColorToColorMap,
- } from "../../utils/systemConstant.js"
- import { desensitization } from "../../utils/index.js"
- Page({
- data: {
- cpuCardInfo: {
- cpuCardNo: "",
- licenseColor: "",
- licensePlate: "",
- tollVehicleType: "",
- issueId: "",
- cpuCardType: "",
- signDate: "",
- expirationDate: "",
- },
- obuCardInfo: {
- obuCardNo: "",
- licenseColor: "",
- licensePlate: "",
- tollVehicleType: "",
- signDate: "",
- expirationDate: "",
- activateState: "",
- },
- isLoading: false,
- isDisabled: false,
- bluetoothName: "",
- bluethList: [],
- show: false,
- needShowList: false,
- connectLoaingText: "请稍后...",
- },
- onLoad: function () {
- this.closeBle()
- // wx.navigateTo({
- // url: 'plugin://issuer-plugin/monthly-bill-detail',
- // })
- },
- goNextProbingObu() {
- this.setData({
- obuCardInfo: {},
- cpuCardInfo: {},
- })
- this.scanDevice((isConnected) => {
- if (isConnected) {
- this.probingObu()
- }
- })
- },
- endLoading() {
- this.setData({
- isLoading: false,
- })
- },
- // 开启扫描蓝牙设备
- scanDevice(callback) {
- this.setData({
- isLoading: true,
- })
- if (this.needShowList) {
- this.setData({
- connectLoaingText: "设备搜索中...",
- })
- }
- bleapi.ScanDevice([], this.needShowList, (devResult, list) => {
- console.log("ScanDevice", devResult)
- if (devResult.code != 0) {
- console.log("搜索失败", devResult)
- this.endLoading()
- // 正常列表展示搜索结束不弹窗
- if (devResult.code === 99) {
- return
- }
- //搜索设备失败
- this.showModal({
- title: "错误",
- devResult: devResult,
- content: devResult.err_msg,
- showMyContent: true,
- })
- } else {
- if (this.needShowList) {
- this.setData({
- bluethList: list,
- show: true,
- isLoading: false,
- })
- } else {
- console.log(
- "搜索到设备:" +
- devResult +
- " " +
- devResult.data.device_name
- )
- this.connectDevice(devResult, callback)
- this.setData({
- bluetoothName: devResult.data.device_name,
- })
- }
- }
- })
- },
- // sdk连接蓝牙
- connectDevice(devResult, callback) {
- facapi.ConnectDevice(
- devResult.data,
- (onDisconnect) => {
- console.log("连接回调:" + onDisconnect)
- },
- (result) => {
- bleapi.StopScanDevice(function (code) {
- console.log("返回数据", code)
- })
- if (result.code == 0) {
- console.log("连接标签设备成功")
- callback(true)
- } else {
- this.showModal({
- title: "错误",
- devResult: result,
- content: "设备连接失败,请将手机靠近设备后重试。",
- })
- callback(false)
- }
- }
- )
- },
- probingCpu() {
- let cpuCardInfo = {}
- facapi.OpenCard((devResult) => {
- console.log("OpenCard-devResult=>", devResult)
- if (devResult.code == 0) {
- facapi.GetCardNo((devResult) => {
- if (devResult.code == 0) {
- console.log("|||=>>GetCardNo-devResult={}", devResult)
- cpuCardInfo.cpuCardNo = devResult.data || ""
- cpuCardInfo.encryptionCpuCardNo =
- desensitization(devResult.data, 4, -4) || ""
- this.setData({
- cpuCardInfo,
- })
- this.getCardFile0016()
- } else {
- this.showModal({
- title: "错误",
- devResult: devResult,
- content:
- "获取卡号失败:" +
- devResult.code +
- ":" +
- devResult.err_msg +
- (devResult.msg ? ":" + devResult.msg : ""),
- })
- }
- })
- } else {
- this.showModal({
- title: "错误",
- devResult: devResult,
- content:
- "打开卡失败:" +
- devResult.code +
- ":" +
- devResult.err_msg +
- (devResult.msg ? ":" + devResult.msg : ""),
- })
- }
- })
- },
- probingObu() {
- facapi.OpenChannel((devResult) => {
- console.log("sdk的OpenChannel调用")
- if (devResult.code == 0) {
- // 读取设备sn号
- facapi.GetSerialNo((devResult) => {
- console.log("getSerialNo==>>", JSON.stringify(devResult))
- this.getObuSystemInfo(devResult)
- })
- } else {
- this.showModal({
- title: "错误",
- devResult: devResult,
- content:
- "打开Obu失败:" +
- devResult.code +
- ":" +
- devResult.err_msg +
- (devResult.msg ? ":" + devResult.msg : ""),
- })
- }
- })
- },
- getCardFile0016() {
- facapi.GetCardFile16((devResult) => {
- console.log("GetCardFile0016-devResult=>", devResult)
- if (devResult.code == 0) {
- this.getCardFile0015()
- } else {
- this.endLoading()
- this.disConnect()
- }
- })
- },
- getCardFile0015() {
- let cpuCardInfo = {
- cpuCardNo: this.data.cpuCardInfo.cpuCardNo,
- encryptionCpuCardNo: this.data.cpuCardInfo.encryptionCpuCardNo,
- }
- facapi.GetCardFile15((devResult) => {
- console.log("GetCardFile0015-devResult=>", devResult)
- if (devResult.code == 0) {
- console.log(
- " getCardFile0015-this.cpuCardInfo = >",
- devResult.code
- )
- let data = {
- filename: Api.systemDecoder.filename,
- data: {
- type: "3",
- content: devResult.data,
- },
- }
- requestFnc(
- Api.systemDecoder.url,
- data,
- (res) => {
- console.log(
- "getCardFile0015-Api.systemDecoder-res=>",
- res
- )
- //车牌号脱敏
- var licensePlate = res.licensePlate
- let begain = 3 + (licensePlate.length - 7)
- cpuCardInfo.licensePlate =
- desensitization(res.licensePlate, begain, -2) || ""
- cpuCardInfo.licenseColor = plateColorToColorMap.get(
- `${res.licenseColor}`
- )
- cpuCardInfo.tollVehicleType = vehicleTypeMap.get(`${res.carType}`)
- cpuCardInfo.issueId = res.netWorkCode || ""
- cpuCardInfo.cpuCardType = cpuCardTypeMap.get(`${res.cardType}`)
- cpuCardInfo.signDate = res.signedDate || ""
- if (
- cpuCardInfo.signDate != "" &&
- cpuCardInfo.signDate.length == 8
- ) {
- cpuCardInfo.signDate =
- cpuCardInfo.signDate.substring(0, 4) +
- "-" +
- cpuCardInfo.signDate.substring(4, 6) +
- "-" +
- cpuCardInfo.signDate.substring(6, 8)
- }
- cpuCardInfo.expirationDate = res.expireDate || ""
- if (
- cpuCardInfo.expirationDate != "" &&
- cpuCardInfo.expirationDate.length == 8
- ) {
- cpuCardInfo.expirationDate =
- cpuCardInfo.expirationDate.substring(0, 4) +
- "-" +
- cpuCardInfo.expirationDate.substring(4, 6) +
- "-" +
- cpuCardInfo.expirationDate.substring(6, 8)
- }
- cpuCardInfo.userType = userTypeMap.get(
- `${res.userType}`
- )
- this.setData({
- cpuCardInfo,
- })
- this.endLoading()
- this.disConnect()
- },
- (error) => {
- console.log(
- "getCardFile0015-Api.systemDecoder-error=>",
- error
- )
- this.endLoading()
- this.disConnect()
- }
- )
- } else {
- this.endLoading()
- this.disConnect()
- }
- })
- },
- getObuSystemInfo(devResult) {
- let obuCardInfo = {}
- console.log("|||getSystemInfo==>", JSON.stringify(devResult))
- if (devResult.code == 0) {
- obuCardInfo.obuCardNo = devResult.data || ""
- facapi.GetSystemInfo((devResult) => {
- console.log("getSystemInfo=>", devResult)
- let data = {
- filename: Api.systemDecoder.filename,
- data: {
- type: "1",
- content: devResult.data,
- },
- }
- requestFnc(
- Api.systemDecoder.url,
- data,
- (res) => {
- console.log(
- "getObuSystemInfo-Api.systemDecoder-res=>>",
- res
- )
- obuCardInfo.obuCardNo = res.serialNumber || ""
- obuCardInfo.encryptionObuCardNo =
- desensitization(res.serialNumber, 4, -4) || ""
- obuCardInfo.signDate = res.signedDate || ""
- obuCardInfo.expirationDate = res.expiredDate || ""
-
- if (
- obuCardInfo.signDate != "" &&
- obuCardInfo.signDate.length == 8
- ) {
- obuCardInfo.signDate =
- obuCardInfo.signDate.substring(0, 4) +
- "-" +
- obuCardInfo.signDate.substring(4, 6) +
- "-" +
- obuCardInfo.signDate.substring(6, 8)
- }
-
- if (
- obuCardInfo.expirationDate != "" &&
- obuCardInfo.expirationDate.length == 8
- ) {
- obuCardInfo.expirationDate =
- obuCardInfo.expirationDate.substring(0, 4) +
- "-" +
- obuCardInfo.expirationDate.substring(4, 6) +
- "-" +
- obuCardInfo.expirationDate.substring(6, 8)
- }
- obuCardInfo.tearFlag = res.tearFlag
- this.setData({
- obuCardInfo,
- })
- facapi.OpenCard((devResult) => {
- this.getVehicleInfo(devResult)
- })
- },
- (error) => {
- console.log(
- "getObuSystemInfo-Api.systemDecoder-error=>",
- error
- )
- this.endLoading()
- this.disConnect()
- }
- )
- })
- } else {
- this.showModal({
- title: "错误",
- devResult: devResult,
- content:
- "获取Obu编号失败:" +
- devResult.code +
- ":" +
- devResult.err_msg +
- (devResult.msg ? ":" + devResult.msg : ""),
- })
- this.endLoading()
- this.disConnect()
- }
- },
- getVehicleInfo(devResult) {
- console.log("|||getVehicleInfo==>", JSON.stringify(devResult))
- if (devResult.code == 0) {
- facapi.GetVehicleInfo("1122334455667788", (devResult) => {
- console.log("getVehicleInfo=>", devResult)
- let params = {
- filename: Api.obuRead.filename,
- data: {
- obuId: this.data.obuCardInfo.obuCardNo,
- encryptedInfo: devResult.data,
- },
- }
- console.log("获取车辆信息入参", params)
- requestFnc(
- Api.obuRead.url,
- params,
- (res) => {
- console.log("obuRead", res)
- let vehicleInfo = JSON.parse(res.vehicleInfo)
- console.log(
- "GetVehicleInfo-res.issue_info=>",
- vehicleInfo
- )
- this.data.obuCardInfo.licenseColor =
- plateColorToColorMap.get(
- `${vehicleInfo.licenseColor}`
- )
- //车牌号脱敏
- var licensePlate = vehicleInfo.licensePlate
- let begain = 3 + (licensePlate.length - 7)
- this.data.obuCardInfo.licensePlate =
- desensitization(
- vehicleInfo.licensePlate,
- begain,
- -2
- ) || ""
-
- this.data.obuCardInfo.tollVehicleType =
- vehicleTypeMap.get(`${vehicleInfo.carType}`)
- this.data.obuCardInfo.userType = userTypeMap.get(
- `${vehicleInfo.userType}`
- )
- let typeObj = {
- "00": "未激活",
- "01": "已激活",
- }
- if (this.data.obuCardInfo.licensePlate) {
- typeObj["00"] = "标签异常"
- }
- this.data.obuCardInfo.activateState =
- typeObj[this.data.obuCardInfo.tearFlag] || "未知"
- this.setData({
- obuCardInfo: this.data.obuCardInfo,
- })
- this.probingCpu()
- },
- (error) => {
- console.log("GetVehicleInfo-Api.obuRead-error=>", error)
- this.endLoading()
- this.disConnect()
- }
- )
- })
- } else {
- this.showModal({
- title: "错误",
- devResult: devResult,
- content:
- "获取车辆失败:" +
- devResult.code +
- ":" +
- devResult.err_msg +
- (devResult.msg ? ":" + devResult.msg : ""),
- })
- this.endLoading()
- this.disConnect()
- }
- },
- disConnect() {
- if (facapi.facSdk && facapi.facSdk.DisconnectDevice) {
- facapi.facSdk.DisconnectDevice(function (code) {
- console.log("关闭连接结果", code)
- })
- }
- // 完成后关闭蓝牙模块
- bleapi.CloseBle((obj) => {
- console.log(obj)
- })
- },
- closeBle() {
- // 进入前关闭蓝牙,初始化
- bleapi.CheckBle((res) => {
- if (res.available) {
- this.disConnect()
- }
- })
- },
- //显示弹框
- showModal(data) {
- this.endLoading()
- this.disConnect()
- //显示弹框
- wx.showModal({
- title: "提示",
- content: data.content,
- showCancel: false,
- })
- },
- })
|