// pagesA/passwordList/passwordList.js
const WXAPI = require('../../utils/request.js')
import moment from '../../utils/moment'
import ICINLocker from '../../utils/ICINPakage/ICINLocker.js'
const bleall = require('../../utils/bleall')
// import dayjs from 'dayjs'
const app = getApp()
import util from '../../utils/util'
import {
    BLE
} from '../../utils/btls/ble'
import methods from '../../utils/methods'
const emitter = app.globalData.emitter
const ADD_NFC_MODE = 10
Page({

    /**
     * 页面的初始数据
     */
    data: {
        voucherlist: [{
                id: 0,
                title: "卡管理"
            },
            {
                id: 1,
                title: "密码管理"
            },
            {
                id: 2,
                title: "指纹管理"
            }
        ],
        active: 1,
        personLi: '',
        deviceInfo: '',
        cardlist: [],
        passwordlist: [],
        fingerlist: [],
        blecount: 0,
        cgInfo: '',
        userSignKey: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        const personLi = wx.getStorageSync('deviceinfo')
        const deviceInfo = wx.getStorageSync('deviceinfo')
        const cgInfo = wx.getStorageSync('cgInfo')
        this.setData({
            personLi: personLi,
            deviceInfo: deviceInfo,
            cgInfo: cgInfo
        })
        this.getvoucher()
    },
    // 标签页切换
    onChange(e) {
        this.setData({
            active: e.detail.index
        })
    },
    // 获取凭证数据
    getvoucher() {
        var data = JSON.stringify({
            id: this.data.personLi.cardId,
            signature: wx.getStorageSync('signature')
        })
        WXAPI.tsGetCertificate(data).then(res => {
            res.data.map(li => {
                li.content = JSON.parse(li.content)
                li.content.passwordStartTime = moment(li.startTime*1000).format('YYYY-MM-DD HH:mm:ss')
                li.content.passwordEndTime = moment(li.endTime*1000).format('YYYY-MM-DD HH:mm:ss')
            })
            const list = res.data.filter(li => {
                return li.type == 3 && (li.status == 1 || li.status == 0);
            })
            const list1 = res.data.filter(li => {
                return li.type == 4 && (li.status == 1 || li.status == 0);
            })
            const list2 = res.data.filter(li => {
                return li.type == 1 && (li.status == 1 || li.status == 0);
            })
            this.setData({
                cardlist: list,
                passwordlist: list1,
                fingerlist: list2
            })
        })
    },
    // 蓝牙连接
    btnset() {
        wx.showLoading({
            title: '蓝牙连接中...',
            mask: true
        })
        if (this.data.blecount >= 10) {
            wx.hideLoading()
            wx.showToast({
                title: '蓝牙连接失败次数过多，请联系管理人员',
                icon: 'none',
                duration: 2000
            })
        } else {
            if (this.data.deviceInfo.manufactureId == 201) {
                ICINLocker.scanDevices(this.data.deviceInfo.deviceNum).then(res => {
                    if (res.status == 0) {
                        app.globalData.blueDeviceId = res.blueDeviceId
                        ICINLocker.connect(res.deviceId).then(res1 => {
                          console.log(res1)
                            if (res1.status == 0) {
                                wx.hideLoading()
                                app.globalData.bleStatus = true
                                wx.showToast({
                                    title: '蓝牙连接成功',
                                    icon: 'none',
                                    duration: 2000
                                })
                                this.setData({
                                    blecount: 0
                                })
                            } else {
                                wx.hideLoading()
                                wx.showToast({
                                    title: '蓝牙连接失败',
                                    duration: 2000,
                                    icon: 'none'
                                })
                                this.setData({
                                    blecount: this.data.blecount++
                                })
                            }
                        }).catch(err => {
                          console.log(err,'err')
                          if(err.status === 1 && err.statusReason == 'createBLEConnection:fail:already connect'){
                            wx.hideLoading()
                            app.globalData.bleStatus = true
                            wx.showToast({
                                title: '蓝牙连接成功',
                                icon: 'none',
                                duration: 2000
                            })
                            this.setData({
                                blecount: 0
                            })
                          }else{
                            wx.hideLoading()
                            wx.showToast({
                                title: err.statusReason,
                                icon: 'none',
                                duration: 2000
                            })
                            this.setData({
                                blecount: this.data.blecount++
                            })
                          }
                        })
                    } else {
                        wx.hideLoading()
                        wx.showToast({
                            title: '蓝牙连接失败',
                            duration: 2000,
                            icon: 'none'
                        })
                        this.setData({
                            blecount: this.data.blecount++
                        })
                    }
                }).catch(err => {
                    wx.hideLoading()
                    wx.showToast({
                        title: err.statusReason,
                        icon: 'none',
                        duration: 2000
                    })
                    this.setData({
                        blecount: this.data.blecount++
                    })
                })
            } else if (this.data.deviceInfo.manufactureId == 101) {
                const ble = new BLE(this.data.deviceInfo.deviceNum, emitter)
                app.globalData.ble = ble
                if (app.globalData.ble) {
                    app.globalData.ble.listen(res => {
                        console.log('1', res)
                        if (res.type == 'connect') {
                            if (res.data == '未打开适配器') {
                                wx.hideLoading()
                                wx.showToast({
                                    title: '请检查手机蓝牙和定位功能是否打开？',
                                    icon: 'none',
                                    duration: 3000
                                })
                            } else {
                                if (res.data == '蓝牙已连接') {
                                    app.globalData.bleStatus = true
                                    wx.hideLoading()
                                    wx.showToast({
                                        title: '蓝牙连接成功',
                                        icon: 'none',
                                        duration: 2000
                                    })
                                    this.setData({
                                        blecount: 0
                                    })
                                } else if (res.data == '蓝牙已断开') {
                                    app.globalData.bleStatus = false
                                }
                            }
                        } else {
                            this.setData({
                                blecount: this.data.blecount++
                            })
                        }
                    })
                    app.globalData.ble.init()
                } else {
                    wx.hideLoading()
                    wx.showToast({
                        title: '蓝牙连接失败',
                        icon: 'none',
                        duration: 2000
                    })
                    this.setData({
                        blecount: this.data.blecount++
                    })
                }
            }
        }
    },
    // 删除凭证
    deletevoucher(e) {
        var index = e.currentTarget.dataset.index
        var that = this
        if (app.globalData.bleStatus) {
            wx.showModal({
                title: '确定删除该凭证？',
                success(res) {
                    if (res.confirm) {
                        if (that.data.active == 0) {
                            that.delNFC(index)
                        } else if (that.data.active == 1) {
                            that.delPwd(index)
                        } else if (that.data.active == 2) {
                            that.delFin(index)
                        }
                    }
                }
            })
        } else {
            this.btnset()
        }
    },
    // 删除NFC
    delNFC(index) {
        wx.showLoading({
            title: '删除NFC中...',
            mask: true
        })
        if (this.data.deviceInfo.manufactureId == 201) {
            var cgInfo = this.data.cgInfo
            var personLi = this.data.cardlist[index]
            var deviceinfo = this.data.deviceInfo
            var info = personLi.content
            var userSignKey = this.data.userSignKey
            var personInfo = JSON.parse(this.data.personLi.info)
            var _this = this
            var dataPasswod = {
                code: "zg/cardOperate",
                data: {
                    lockerId: deviceinfo.deviceNum,
                    imei: deviceinfo.imei,
                    lockerUserId: personInfo.userId,
                    keyId: personInfo.userId,
                    action: 2,
                    taskStatus: 1,
                    cardType: 50,
                    cardNo: info.password,
                    startTime: personLi.startTime,
                    endTime: personLi.endTime,
                    order: 6212,
                    type: 12,
                    roomName: _this.data.deviceInfo.roomName,
                    cardName: _this.data.personLi.name + info.pzname,
                },
                signature: wx.getStorageSync('signature'),
                cardId: _this.data.deviceInfo.cardId,
            }
            WXAPI.sendCommandOne(dataPasswod).then(res => {
                console.log('获取索引', res)
                if (res.success) {
                    var cardIndex = res.data.index
                    var serialNumber = res.data.serialNumber
                    var cardNo = cardIndex.toString(16)
                    if (cardNo < 10) {
                        cardNo = '0' + cardNo
                    } else {
                        cardNo = cardNo
                    }
                    if (_this.data.userSignKey == '') {
                        console.log('数据', cgInfo.lockerId, cgInfo.superId, personInfo.userId, cgInfo.superId, cgInfo.authKey, '01')
                        ICINLocker.getUserSignKey(cgInfo.lockerId, cgInfo.superId, personInfo.userId, cgInfo.superId, cgInfo.authKey, '01', callback11 => {
                            console.log('1', callback11)
                            if (callback11.status == '00') {
                                _this.setData({
                                    userSignKey: callback11.userSignKey
                                })
                                // ICINLocker.getCommonKey(cgInfo.lockerId, personInfo.userId, personInfo.userId, callback11.userSignKey, callback22 => {
                                //     console.log('2', callback22)
                                //     if (callback22.status == '00') {
                                        var startTime = personLi.startTime.toString(16).toUpperCase()
                                        var endTime = personLi.endTime.toString(16).toUpperCase()
                                        console.log('数据3', cgInfo.lockerId, cgInfo.superId, personInfo.userId, personInfo.userId, cardNo.toUpperCase(), '', '01', callback11.userSignKey, startTime, endTime, callback11.userCommonKey)
                                        ICINLocker.modifyRFCard(cgInfo.lockerId, cgInfo.superId, personInfo.userId, personInfo.userId, cardNo.toUpperCase(), '', '01', callback11.userSignKey, startTime, endTime, callback11.userCommonKey,callback33 => {
                                            console.log('3', callback33)
                                            if (callback33.status == '00') {
                                                var datacom = {
                                                    code: "zg/bleSendVoucherReply",
                                                    data: {
                                                        lockerId: deviceinfo.deviceNum,
                                                        serialNumber: serialNumber,
                                                        index: cardIndex,
                                                        type: 12,
                                                        result: 1
                                                    },
                                                    cardId: deviceinfo.cardId,
                                                    signature: wx.getStorageSync('signature')
                                                }
                                                WXAPI.sendCommandOne(datacom).then(res1 => {
                                                    console.log('成功', res1)
                                                })
                                                var data = {
                                                    id: passwordLi.id,
                                                    signature: wx.getStorageSync('signature'),
                                                    status: 0
                                                }
                                                WXAPI.editCertificate(data).then(res2 => {
                                                    console.log('4', res2)
                                                    if (res2.success) {
                                                        _this.getvoucher()
                                                        wx.hideLoading()
                                                        wx.showToast({
                                                            title: '删除NFC成功',
                                                            icon: 'none',
                                                            duration: 2000
                                                        })
                                                    } else {
                                                        wx.hideLoading()
                                                        wx.showToast({
                                                            title: '删除NFC失败',
                                                            icon: 'none',
                                                            duration: 2000
                                                        })
                                                    }
                                                })
                                            } else {
                                                wx.hideLoading()
                                                wx.showToast({
                                                    title: '删除NFC失败',
                                                    icon: 'none',
                                                    duration: 2000
                                                })
                                            }
                                        })
                                    // } else {
                                    //     wx.hideLoading()
                                    //     wx.showToast({
                                    //         title: '删除NFC失败',
                                    //         icon: 'none',
                                    //         duration: 2000
                                    //     })
                                    // }
                                // })
                            } else {
                                wx.hideLoading()
                                wx.showToast({
                                    title: '删除NFC失败',
                                    icon: 'none',
                                    duration: 2000
                                })
                            }
                        })
                    } else {
                        ICINLocker.getCommonKey(cgInfo.lockerId, personInfo.userId, personInfo.userId, userSignKey, callback22 => {
                            console.log('2', callback22)
                            if (callback22.status == '00') {
                                var startTime = personLi.startTime.toString(16).toUpperCase()
                                var endTime = personLi.endTime.toString(16).toUpperCase()
                                console.log('数据3', cgInfo.lockerId, cgInfo.superId, personInfo.userId, personInfo.userId, cardNo.toUpperCase(), '', '01', userSignKey, startTime, endTime, callback22.commonKey, )
                                ICINLocker.modifyRFCard(cgInfo.lockerId, cgInfo.superId, personInfo.userId, personInfo.userId, cardNo.toUpperCase(), '', '01', userSignKey, startTime, endTime, callback22.commonKey, callback33 => {
                                    console.log('3', callback33)
                                    if (callback33.status == '00') {
                                        var datacom = {
                                            code: "zg/bleSendVoucherReply",
                                            data: {
                                                lockerId: deviceinfo.deviceNum,
                                                serialNumber: serialNumber,
                                                index: cardIndex,
                                                type: 12,
                                                result: 1
                                            },
                                            cardId: deviceinfo.cardId,
                                            signature: wx.getStorageSync('signature')
                                        }
                                        WXAPI.sendCommandOne(datacom).then(res1 => {
                                            console.log('成功', res1)
                                        })
                                        var data = {
                                            id: passwordLi.id,
                                            signature: wx.getStorageSync('signature'),
                                            status: 0
                                        }
                                        WXAPI.editCertificate(data).then(res2 => {
                                            console.log('4', res2)
                                            if (res2.success) {
                                                _this.getvoucher()
                                                wx.hideLoading()
                                                wx.showToast({
                                                    title: '删除NFC成功',
                                                    icon: 'none',
                                                    duration: 2000
                                                })
                                            } else {
                                                wx.hideLoading()
                                                wx.showToast({
                                                    title: '删除NFC失败',
                                                    icon: 'none',
                                                    duration: 2000
                                                })
                                            }
                                        })
                                    } else {
                                        wx.hideLoading()
                                        wx.showToast({
                                            title: '删除NFC失败',
                                            icon: 'none',
                                            duration: 2000
                                        })
                                    }
                                })
                            } else {
                                wx.hideLoading()
                                wx.showToast({
                                    title: '删除NFC失败',
                                    icon: 'none',
                                    duration: 2000
                                })
                            }
                        })
                    }
                } else {
                    wx.hideLoading()
                    wx.showToast({
                        title: '删除NFC失败',
                        icon: 'none',
                        duration: 2000
                    })
                }
            })
        }
    },
    // 删除密码
    delPwd(index) {
        if (this.data.deviceInfo.manufactureId == 201) {
            var _this = this
            var deviceinfo = this.data.deviceInfo
            var passwordLi = this.data.passwordlist[index]
            var info = passwordLi.content
            var personInfo = JSON.parse(this.data.personLi.info)
            var cgInfo = this.data.cgInfo
            var userSignKey = this.data.userSignKey
            var dataPassword = {
                code: "zg/tempPassword",
                data: {
                    lockerId: deviceinfo.deviceNum,
                    imei: deviceinfo.imei,
                    passwordCount: 255,
                    lockerUserId: personInfo.userId,
                    keyId: personInfo.userId,
                    passwordStartTime: passwordLi.startTime,
                    passwordEndTime: passwordLi.endTime,
                    order: 6209,
                    action: 2,
                    password: info.password,
                    type: 1,
                    cardName: _this.data.personLi.name,
                    roomName: deviceinfo.roomName
                },
                signature: wx.getStorageSync('signature'),
                cardId: deviceinfo.cardId,
            }
            WXAPI.sendCommandOne(dataPassword).then(res => {
                console.log('获取索引', res)
                if (res.success) {
                    var pwdNo = res.data.index.toString(16)
                    var passwordIndex = res.data.index
                    if (pwdNo < 9) {
                        pwdNo = '0' + pwdNo
                    } else {
                        pwdNo = pwdNo
                    }
                    if (_this.data.userSignKey == '') {
                        console.log('数据', cgInfo.lockerId, cgInfo.superId, personInfo.userId, cgInfo.superId, cgInfo.authKey, '01')
                        ICINLocker.getUserSignKey(cgInfo.lockerId, cgInfo.superId, personInfo.userId, cgInfo.superId, cgInfo.authKey, '01', callback => {
                            console.log('1', callback)
                            if (callback.status == '00') {
                                _this.setData({
                                    userSignKey: callback.userSignKey
                                })
                                // ICINLocker.getCommonKey(cgInfo.lockerId, personInfo.userId, personInfo.userId, callback.userSignKey, callback1 => {
                                //     console.log('2', callback1)
                                //     if (callback1.status == '00') {
                                        var startTime = passwordLi.startTime.toString(16).toUpperCase()
                                        var endTime = passwordLi.endTime.toString(16).toUpperCase()
                                        console.log('3数据', deviceinfo.deviceNum, "---", cgInfo.superId, "---", personInfo.userId, "---", info.password, "---", pwdNo, "---", cgInfo.superId, "---", cgInfo.authKey, "---", '', "---", startTime, "---", endTime, "---", 0, "---", callback.userCommonKey)
                                        ICINLocker.handlePwd(deviceinfo.deviceNum, cgInfo.superId, personInfo.userId, info.password, pwdNo, cgInfo.superId, cgInfo.authKey, '', startTime, endTime, 0, callback.userCommonKey, callback2 => {
                                            console.log('3', callback2)
                                            if (callback2.status == '00') {
                                                var datacom = {
                                                    code: "zg/bleSendVoucherReply",
                                                    data: {
                                                        lockerId: deviceinfo.deviceNum,
                                                        serialNumber: res.data.serialNumber,
                                                        index: passwordIndex,
                                                        type: 9,
                                                        result: 1
                                                    },
                                                    cardId: deviceinfo.cardId,
                                                    signature: wx.getStorageSync('signature')
                                                }
                                                WXAPI.sendCommandOne(datacom).then(res1 => {
                                                    console.log('4', res1)
                                                })
                                                var data = {
                                                  id: passwordLi.id,
                                                  signature: wx.getStorageSync('signature'),
                                                  // cardId: deviceinfo.cardId,
                                                  status: 703
                                                }
                                                WXAPI.editCertificate(data).then(res2 => {
                                                    console.log('5', res2)
                                                    if (res2.success) {
                                                        _this.getvoucher()
                                                        wx.hideLoading()
                                                        wx.showToast({
                                                            title: '删除成功',
                                                            duration: 2000,
                                                            icon: 'none'
                                                        })
                                                    } else {
                                                        wx.hideLoading()
                                                        wx.showToast({
                                                            title: '删除失败',
                                                            duration: 2000,
                                                            icon: ' none'
                                                        })
                                                    }
                                                })
                                            } else {
                                                wx.hideLoading()
                                                wx.showToast({
                                                    title: '删除失败',
                                                    duration: 2000,
                                                    icon: ' none'
                                                })
                                                var datacom = {
                                                    code: "zg/bleSendVoucherReply",
                                                    data: {
                                                        lockerId: deviceinfo.deviceNum,
                                                        serialNumber: res.data.serialNumber,
                                                        index: res.data.index,
                                                        type: 9,
                                                        result: 0
                                                    },
                                                    cardId: deviceinfo.cardId,
                                                    signature: wx.getStorageSync('signature')
                                                }
                                                WXAPI.sendCommandOne(datacom).then(res1 => {
                                                    console.log('7 失败', res1)
                                                })
                                            }
                                        })
                                    // } else {
                                    //     wx.hideLoading()
                                    //     wx.showToast({
                                    //         title: '删除失败',
                                    //         icon: 'none',
                                    //         duration: 2000
                                    //     })
                                    // }
                                // })
                            } else {
                                wx.hideLoading()
                                wx.showToast({
                                    title: '删除失败',
                                    icon: 'none',
                                    duration: 2000
                                })
                            }
                        })
                    } else {
                        ICINLocker.getCommonKey(cgInfo.lockerId, personInfo.userId, personInfo.userId, userSignKey, callback1 => {
                            console.log('2', callback1)
                            if (callback1.status == '00') {
                                var startTime = passwordLi.startTime.toString(16).toUpperCase()
                                var endTime = passwordLi.endTime.toString(16).toUpperCase()
                                console.log('3数据', deviceinfo.deviceNum, "---", cgInfo.superId, "---", personInfo.userId, "---", info.password, "---", pwdNo, "---", cgInfo.superId, "---", cgInfo.authKey, "---", '', "---", startTime, "---", endTime, "---", 0, "---", callback1.commonKey)
                                ICINLocker.handlePwd(deviceinfo.deviceNum, cgInfo.superId, personInfo.userId, info.password, pwdNo, cgInfo.superId, cgInfo.authKey, '', startTime, endTime, 0, callback1.commonKey, callback2 => {
                                    console.log('3', callback2)
                                    if (callback2.status == '00') {
                                        var datacom = {
                                            code: "zg/bleSendVoucherReply",
                                            data: {
                                                lockerId: deviceinfo.deviceNum,
                                                serialNumber: res.data.serialNumber,
                                                index: passwordIndex,
                                                type: 9,
                                                result: 1
                                            },
                                            cardId: deviceinfo.cardId,
                                            signature: wx.getStorageSync('signature')
                                        }
                                        WXAPI.sendCommandOne(datacom).then(res1 => {
                                            console.log('4', res1)
                                        })                                        
                                        var data = {
                                          id: passwordLi.id,
                                          signature: wx.getStorageSync('signature'),
                                          // cardId: deviceinfo.cardId,
                                          status: 703
                                      }
                                      WXAPI.editCertificate(data).then(res2 => {
                                            console.log('5', res2)
                                            if (res2.success) {
                                                _this.getvoucher()
                                                wx.hideLoading()
                                                wx.showToast({
                                                    title: '删除成功',
                                                    duration: 2000,
                                                    icon: 'none'
                                                })
                                            } else {
                                                wx.hideLoading()
                                                wx.showToast({
                                                    title: '删除失败',
                                                    duration: 2000,
                                                    icon: ' none'
                                                })
                                            }
                                        })
                                    } else {
                                        wx.hideLoading()
                                        wx.showToast({
                                            title: '删除失败',
                                            duration: 2000,
                                            icon: ' none'
                                        })
                                        var datacom = {
                                            code: "zg/bleSendVoucherReply",
                                            data: {
                                                lockerId: deviceinfo.deviceNum,
                                                serialNumber: res.data.serialNumber,
                                                index: res.data.index,
                                                type: 9,
                                                result: 0
                                            },
                                            cardId: deviceinfo.cardId,
                                            signature: wx.getStorageSync('signature')
                                        }
                                        WXAPI.sendCommandOne(datacom).then(res1 => {
                                            console.log('7 失败', res1)
                                        })
                                    }
                                })
                            } else {
                                wx.hideLoading()
                                wx.showToast({
                                    title: '删除失败',
                                    icon: 'none',
                                    duration: 2000
                                })
                            }
                        })
                    }
                } else {
                    wx.hideLoading()
                    wx.showToast({
                        title: res.msg,
                        icon: 'none',
                        duration: 2000
                    })
                }
            })
        }
    },
    // 删除指纹
    delFin(index) {
        // return
        wx.showLoading({
            title: '删除指纹中...',
            mask: true
        })
        var cgInfo = this.data.cgInfo
        var personLi = this.data.fingerlist[index]
        var deviceinfo = this.data.deviceInfo
        var info = personLi.content
        var personInfo = JSON.parse(this.data.personLi.info)
        var _this = this
        var dataPassword = {
            code: "zg/fpOperate",
            data: {
                lockerId: deviceinfo.deviceNum,
                imei: deviceinfo.imei,
                lockerUserId: personInfo.userId,
                keyId: personInfo.userId,
                fingerType: '0',
                fingerId: '',
                startTime: personLi.startTime,
                endTime: personLi.endTime,
                order: 6218,
                action: 2,
                type: 1,
                roomName: _this.data.deviceInfo.roomName,
                cardName: _this.data.personLi.name,
            },
            cardId: deviceinfo.cardId,
            signature: wx.getStorageSync('signature')
        }
        WXAPI.sendCommandOne(dataPassword).then(res => {
            console.log('获取索引', res)
            if (res.success) {
                var Fgindex = res.data.index
                var fingerNo = Fgindex.toString(16)
                if (fingerNo < 10) {
                    fingerNo = '000' + fingerNo
                } else {
                    fingerNo = '00' + fingerNo
                }
                ICINLocker.getUserSignKey(cgInfo.lockerId, cgInfo.superId, personInfo.userId, cgInfo.superId, cgInfo.authKey, '01', callbackfp => {
                    console.log('1', callbackfp)
                    if (callbackfp.status == '00') {
                        ICINLocker.getCommonKey(cgInfo.lockerId, personInfo.userId, personInfo.userId, callbackfp.userSignKey, callbcakfp1 => {
                            console.log('2', callbackfp1)
                            if (callbcakfp1.status == '00') {
                                var startTime = personLi.startTime.toString(16).toUpperCase()
                                var endTime = personLi.endTime.toString(16).toUpperCase()
                                ICINLocker.modifyFingerPrints(cgInfo.lockerId, cgInfo.superId, personInfo.userId, personInfo.userId, '01', fingerNo, '', '00', startTime, endTime, callbcakfp1.commonKey, callbackfp2 => {
                                    console.log('3', callbackfp2)
                                    if (callbackfp2.status == '00') {
                                        var datacom = {
                                            code: "zg/bleSendVoucherReply",
                                            data: {
                                                lockerId: deviceinfo.deviceNum,
                                                serialNumber: res.data.serialNumber,
                                                index: Fgindex,
                                                type: 18,
                                                result: 1
                                            },
                                            cardId: deviceinfo.cardId,
                                            signature: wx.getStorageSync('signature')
                                        }
                                        WXAPI.sendCommandOne(datacom).then(res1 => {
                                            console.log('成功', res1)
                                        })
                                        var data = {
                                            id: passwordLi.id,
                                            signature: wx.getStorageSync('signature'),
                                            status: 0
                                        }
                                        WXAPI.editCertificate(data).then(res2 => {
                                            console.log('4', res2)
                                            if (res2.success) {
                                                _this.getvoucher()
                                                wx.hideLoading()
                                                wx.showToast({
                                                    title: '删除指纹成功',
                                                    icon: 'none',
                                                    duration: 2000
                                                })
                                            } else {
                                                wx.hideLoading()
                                                wx.showToast({
                                                    title: '删除指纹失败',
                                                    icon: 'none',
                                                    duration: 2000
                                                })
                                            }
                                        })
                                    } else {
                                        wx.hideLoading()
                                        wx.showToast({
                                            title: '删除指纹失败',
                                            icon: 'none',
                                            duration: 2000
                                        })
                                    }
                                })
                            } else {
                                wx.hideLoading()
                                wx.showToast({
                                    title: '删除指纹失败',
                                    icon: 'none',
                                    duration: 2000
                                })
                            }
                        })
                    } else {
                        wx.hideLoading()
                        wx.showToast({
                            title: '删除指纹失败',
                            icon: 'none',
                            duration: 2000
                        })
                    }
                })
            } else {
                wx.hideLoading()
                wx.showToast({
                    title: '删除指纹失败',
                    icon: 'none',
                    duration: 2000
                })
            }
        })
    },






    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    closeblue() {
        app.globalData.ble.close()
        app.globalData.bleStatus = false
    },
    closeblue1() {
        ICINLocker.disConnect(this.data.deviceInfo.deviceNum).then(res => {}).catch(err => {})
        app.globalData.bleStatus = false
    },
    onUnload: function () {
        if (this.data.deviceInfo.manufactureId == 201) {
            this.closeblue1()
        } else if (this.data.deviceInfo.manufactureId == 101) {
            this.closeblue()
        }
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})