import { visiteeList, threeElements, configList, riskQuery, areaInfo, } from '../../utils/api/api' import { getWaterDrop, getDate } from '../../utils/index/index' import { viceBroadcast, closeSecondaryScreen, openSecondaryScreen } from '../../utils/index/callAmpe' import { encryptAndSign } from '../../utils/index/getSM4' const app = getApp() Page({ data: { toTitleRef: null, snDisposition: {}, // 访客信息 remainingInfo: { avatar: '', visitorName: '', visitorIdCard: '', visitorPhone: '', visitorUnit: '', carnum: '', peopleNum: 1, causeMatterName: '', }, // 事由 causeMatterList: [ /*{ name: '业务拜访', id: 1 }, { name: '会议邀请', id: 2 }, { name: '施工单位', id: 3 }, { name: '其他事项', id: 4 },*/ ], isShowCauseMatter: false, //是否显示事由选项 floorNum: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], cs: [1, 2, 3, 4, 5, 6,], // 是否显示搜索项 isShowSearch: false, // 所有搜索项 searchList: [ { name: '姓名', placeholder: '请输入姓名', value: 'name', show: true, }, { name: '手机号', placeholder: '请输入手机号', value: 'phone', show: true, }, { name: '身份证', placeholder: '请输入身份证', value: 'idNumber', show: false, }, { name: '单位', placeholder: '请输入单位', value: 'company', show: true, }, { name: '部门', placeholder: '请输入部门', value: 'unitName', show: false, }, { name: '楼层', placeholder: '请选择楼层', value: 'floor', show: true, }, { name: '房间号', placeholder: '请输入房间号', value: 'room', show: true, }, { name: '标题', placeholder: '请输入标题', value: 'showTitle', show: true, } ], // 搜索项绑定值 searchForm: { name: '', phone: '', company: '', floor: '', //选中的楼层 room: '', showTitle: '', }, // 受访人信息 intervieweeForm: { name: '', phone: '', idNumber: '', company: '', unitName: '', floor: '', room: '', showTitle: '', }, intervieweeFormCopy: {}, // 是否是手动输入受访人 isEnterInterviewee: false, carNumberShow: true, // 触摸开始时间 touchStartTime: 0, // 触摸结束时间 touchEndTime: 0, // 最后一次单击事件点击发生时间 lastTapTime: 0, // 单击事件点击后要触发的函数 lastTapTimeoutFunc: null, allList: [], allListCopy: [], tableList: [], total: 0, pageNum: 0, //总页数 pageSize: 0, //当前页数 sliceStart: 0, //截取数组开始 sliceEnd: 15, //截取数组结束 mumberRows: 15, //每页条数 // 键盘开始 notNum: true, strDisabled: false, checked: false, provinceArr: ["粤", "京", "津", "渝", "沪", "冀", "晋", "辽", "吉", "黑", "苏", "浙", "皖", "闽", "赣", "鲁", "豫", "鄂", "湘", "琼", "川", "贵", "云", "陕", "甘", "青", "蒙", "桂", "宁", "新", "藏", "使", "领", "警", "学", "港", "澳"], strArr: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"], hiddenPro: true, // 隐藏省份键盘 hiddenStr: true, // 隐藏数字字母键盘 carnum: '', //车牌号码 // 键盘结束 downBtn: '返回', // 多选楼层开始 isShowfloor: false, allFloorList: [], chooseFloorIndex: [], //多选的index chooseFloorItem: [], //多选的item // 多选楼层结束 isPortraitScreen: false,// 是否为竖屏:true竖屏 false横屏 screenIntervalId: null, //定时器 }, onLoad() { my.hideBackHome(); const _this = this this.initScreenType().then(isPortraitScreenRes => { console.log('isPortraitScreenRes', isPortraitScreenRes) _this.setData({ isPortraitScreen: isPortraitScreenRes }) }) this.data.intervieweeFormCopy = JSON.parse(JSON.stringify(this.data.intervieweeForm)); this.data.searchFormCopy = JSON.parse(JSON.stringify(this.data.searchForm)); let visitReasonList = (app.globalData.snDisposition.visitReason || '业务拜访/会议邀请/施工单位/其他事项').split('/'); console.log(JSON.stringify(app.globalData.snDisposition)) console.log(JSON.stringify(app.globalData.registerNotDesensitizedColumn)) this.setData({ snDisposition: app.globalData.snDisposition, causeMatterList: visitReasonList, 'remainingInfo.visitorPhone': app.data.userInfo.phone || app.data.inputPhone, 'remainingInfo.visitorName': app.data.userInfo.xm, 'remainingInfo.visitorIdCard': app.data.userInfo.sfzh, 'remainingInfo.avatar': app.data.userInfo.avatar, 'remainingInfo.idCardPhoto': app.data.userInfo.idCardPhoto, 'remainingInfo.visitorUnit': app.data.userInfo.visitorUnit || '', carnum: app.data.userInfo.carnum || '', 'remainingInfo.causeMatterName': visitReasonList.length > 0 ? visitReasonList[0] : '', }) console.log(visitReasonList) // ⾃然⼈⻛险评分查询 if (this.data.snDisposition.riskCheck) { this.riskQuery() } this.getTable() this.configList() }, initScreenType() { let that = this return new Promise((resolve, reject) => { if (app.globalData.isPortraitScreen) { if (app.globalData.isPortraitScreen != null) { resolve(app.globalData.isPortraitScreen) } } else { that.data.screenIntervalId = setInterval(function () { console.log('asdasdsaddasdad', app.globalData) if (app.globalData.isPortraitScreen != null) { resolve(app.globalData.isPortraitScreen) clearInterval(that.data.screenIntervalId); } }, 1000); } }) }, async getTable(e) { try { let { sliceStart, mumberRows } = this.data let dto = { sn: app.globalData.sn, } let res = await visiteeList(app.globalData.snDisposition.visiteeUrl, dto) var pageNum = Math.ceil(res.data.length / mumberRows) sliceStart = 0 this.setData({ allList: res.data, allListCopy: res.data, tableList: res.data.slice(sliceStart, mumberRows), total: res.data.length, sliceStart: 0, sliceEnd: mumberRows, pageNum, pageSize: res.data.length > 0 ? 1 : 0, }) } catch (error) { console.log(error); } }, // ⾃然⼈⻛险评分查询 async riskQuery() { let appKeyRisk = app.globalData.appKeyRisk let appSecretRisk = app.globalData.appSecretRisk let privateKeyRisk = app.globalData.privateKeyRisk let content = { sn: app.globalData.sn, name: app.data.userInfo.xm, idNumber: app.data.userInfo.sfzh, phone: app.data.userInfo.phone } // let content = { // sn: '136D002002300012', // name: '张亮', // idNumber: '321323199007264912', // phone: '18762761616' // } content = JSON.stringify(content) // 加密 let sm4 = await encryptAndSign(appKeyRisk, appSecretRisk, privateKeyRisk, content, "encrypted") try { let data = { "appId": app.globalData.appIdRisk, "bizContent": sm4.encrypted, "reqTimestamp": sm4.timestamp, "sign": sm4.sign } let res = await riskQuery(data) // 解密 let decryptedData = encryptAndSign(appKeyRisk, appSecretRisk, privateKeyRisk, res.data.bizContent, "decrypt") this.data.isRisk = false if (!decryptedData.decrypted) { return } let decrypted = JSON.parse(decryptedData.decrypted) // console.log(222, decrypted); if (!decrypted.result) { app.globalData.riskResult = 1 } else if (decrypted.resultInfo.personFxpfjx && decrypted.resultInfo.personFxpfjx[4] == 1) { app.globalData.riskResult = 2 } else { app.globalData.riskResult = 3 } } catch (error) { console.log(error) // my.reLaunch({ // url: '/pages/resultPage/index?result=结果页超时&&timer=' + app.globalData.snDisposition.resultPageTimeout, // }) } }, // 上一页 previousFun() { let { allList, pageSize, sliceEnd, sliceStart, mumberRows } = this.data if (pageSize <= 1) { return } this.setData({ tableList: allList.slice(sliceStart - mumberRows, sliceEnd - mumberRows), sliceStart: sliceStart - mumberRows, sliceEnd: sliceEnd - mumberRows, pageSize: pageSize - 1 }) }, // 下一页 nextFun() { let { allList, pageSize, pageNum, sliceEnd, sliceStart, mumberRows } = this.data if (pageSize >= pageNum) { return } this.setData({ tableList: allList.slice(sliceStart + mumberRows, sliceEnd + mumberRows), sliceStart: sliceStart + mumberRows, sliceEnd: sliceEnd + mumberRows, pageSize: pageSize + 1 }) }, // 倒计时结束 finish() { this.backToSpecifiedPage('/pages/resultPage/index?result=结果页超时') }, // 访客信息输入 getValue(e) { let type = e.target.dataset.type let val = e.detail.value let key = `remainingInfo.${type}` this.setData({ [key]: val, }) }, // 事由 openChoose(e) { this.setData({ isShowCauseMatter: !this.data.isShowCauseMatter, hiddenPro: true, hiddenStr: true, }) }, closeCauseMatter() { getWaterDrop() this.setData({ isShowCauseMatter: false }) }, getCauseMatterVal(e) { let item = e.currentTarget.dataset.item this.setData({ 'remainingInfo.causeMatterName': item, isShowCauseMatter: false }) }, // 是否显示搜索项 getIsShow() { let { isShowSearch } = this.data let mumberRows = isShowSearch ? 15 : 9 let searchForm = JSON.parse(JSON.stringify(this.data.searchFormCopy)); this.setData({ isShowSearch: !isShowSearch, mumberRows: mumberRows, searchForm }) this.getTable() }, // 输入搜索项 getSearchValue(e) { let type = e.target.dataset.type let val = e.detail.value let key = `searchForm.${type}` this.setData({ [key]: val }) }, // 查询 inquireFun() { let { searchForm, allList, isShowSearch, mumberRows, allListCopy } = this.data allList = JSON.parse(JSON.stringify(allListCopy)) // 根据条件过滤数据 let result = this.filterData(searchForm, allList) var pageNum = Math.ceil(result.length / mumberRows) let sliceStart = 0 let sliceEnd = mumberRows this.setData({ tableList: result.slice(sliceStart, mumberRows), allList: result, sliceEnd, sliceStart, total: result.length, pageNum, pageSize: result.length > 0 ? 1 : 0, }) }, // 多条件过滤,参数queryObj(过滤条件对象),list(需要过滤的数组) filterData(queryObj, list) { let arr = list Object.keys(queryObj).forEach(key => { if (queryObj[key] == undefined || queryObj[key] == '') return arr if (key == 'name') { arr = arr.filter(p => p[key] !== null && (p[key].indexOf(queryObj[key]) > -1 || p['pinyinFirstLetter'].toLowerCase().indexOf(queryObj[key].toLowerCase()) == 0)) } else { arr = arr.filter(p => p[key] !== null && (p[key].indexOf(queryObj[key]) > -1)) } }) return arr }, //清空 clearFun() { let searchForm = JSON.parse(JSON.stringify(this.data.searchFormCopy)); this.setData({ searchForm }) this.getTable() }, // 是否是手动输入受访人 chooseInterviewee() { this.setData({ isEnterInterviewee: !this.data.isEnterInterviewee }) }, // 手动输入受访人 getIntervieweeValue(e) { let type = e.target.dataset.type let val = e.detail.value let key = `intervieweeForm.${type}` this.setData({ [key]: val }) }, // 清空充填受访人 clearIntervieweeValue() { let intervieweeForm = JSON.parse(JSON.stringify(this.data.intervieweeFormCopy)); this.setData({ intervieweeForm }) }, // 选择楼层层数 chooseFloor(e) { let val = e.currentTarget.dataset.item let { searchForm } = this.data if (searchForm.floor.length < 2) { this.setData({ 'searchForm.floor': searchForm.floor + val }) this.inquireFun() } }, // 删除选择的楼层 delFloor() { let { searchForm } = this.data this.setData({ 'searchForm.floor': searchForm.floor.substr(0, searchForm.floor.length - 1) }) this.inquireFun() }, /// 按钮触摸开始触发的事件 touchStart: function (e) { this.touchStartTime = e.timeStamp }, /// 按钮触摸结束触发的事件 touchEnd: function (e) { this.touchEndTime = e.timeStamp }, chooesFloor(e) { let item = e.currentTarget.dataset.item var that = this // 控制点击事件在350ms内触发,加这层判断是为了防止长按时会触发点击事件 if (that.data.touchEndTime - that.data.touchStartTime < 350) { // 当前点击的时间 var currentTime = e.timeStamp var lastTapTime = that.data.lastTapTime // 更新最后一次点击时间 that.data.lastTapTime = currentTime // 如果两次点击时间在300毫秒内,则认为是双击事件 if (currentTime - lastTapTime < 300) { // console.log("双击") // 成功触发双击事件时,取消单击事件的执行 clearTimeout(that.data.lastTapTimeoutFunc); that.setData({ intervieweeForm: item }) that.sure() } else { // 单击事件延时300毫秒执行,这和最初的浏览器的点击300ms延时有点像。 that.data.lastTapTimeoutFunc = setTimeout(function () { that.setData({ isEnterInterviewee: true, intervieweeForm: item }) }, 300); } } }, // 确定 async sure() { let { remainingInfo, intervieweeForm, carnum } = this.data console.log( 'remainingInfo', remainingInfo) console.log( 'intervieweeForm', intervieweeForm) let form = Object.assign({}, remainingInfo, intervieweeForm); console.log(form) form.carnum = carnum form.visitingTime = getDate() app.data.visitoMsgData = form // 启用进出记录推送 let transitPushSwitch = app.globalData.snDisposition.transitPushSwitch if (transitPushSwitch) { // 获取辖区配置 let areaRes = await areaInfo({ sn: app.globalData.sn, }).data || {} /*let data = { "reason": form.causeMatterName, "num_peoples": form.peopleNum, //人数 "machine_id": app.globalData.sn, "xm": form.visitorName, "sfzh": form.visitorIdCard, "phone": form.visitorPhone, // "xm": '张佳燕', // "sfzh": '331082199910045826', // "phone": '15888632412', "company": form.visitorUnit, "carno": form.carnum, "visitee_xm": form.name, //受访人姓名 "visitee_bm": form.unitName, "visitee_company": form.company, "visitee_room": form.room, "visiteePhone": intervieweeForm.phone, "visitee_floor": form.floor, xp: app.data.userInfo.idCardPhoto, scene_xp: app.data.userInfo.avatar, time: form.visitingTime, } console.log('data', data)*/ console.log(JSON.stringify(areaRes)) let newPushData = { "appType": "HHVisit", "recordid": 0, // 没有 "sn": app.globalData.sn, "adminId": null, // 没有 "pcsname": areaRes.policeStationName || '', // 所属辖区派出所名称 "pcsdm": areaRes.policeStationCode || '', // 所属辖区派出所代码 "provinceName": areaRes.provinceName || '', // 所属省份 "cityName": areaRes.cityName || '', // 所属城市 "areaName": areaRes.areaName || '', // 所属区/县 "streetName": areaRes.streetName || '', // 街道/乡/镇 "address": areaRes.address || '', // 详细地址 "deviceAddress": areaRes.deviceAddress || '', // 设备地点 "outType": 1, // 服务端设备所属进出口: 0 通用 1进门 2出门 "status": true,// 人员进入是否有效: true 有效 false 无效 "reasonType": null,// 无效原因: 1 未成年人禁止进入 2 黑名单 "userId": 0,// 服务端用户id "verifyType": app.data.userInfo.verifyType,// todo 识别类型 "certName": form.visitorName, // 用户姓名 "certNo": form.visitorIdCard, // 用户证件号 "certContent": JSON.stringify(app.data.userInfo.certContent || '') || '', // 身份证阅读器返回全部 todo "phone": form.visitorPhone, // 用户手机号 "cardidex": null, // 用户卡号 "photo": app.data.userInfo.avatar, // 用户现场照片 "originPhoto": '', // 比对源照片url todo "originPhotoBase64": app.data.userInfo.idCardPhoto, // 比对源照片base64 todo "verifyScore": null, // 人脸比对分值: 0-100 todo "company": form.visitorUnit, // 用户单位名称 "carno": form.carnum, // 用户车牌号 "reason": form.causeMatterName, // 拜访事由 "time": form.visitingTime, // 刷脸时间 "visiteeXm": form.name, //受访人姓名 "visiteePhone": intervieweeForm.phone, // 受访人手机号 "visiteeCompany": form.company, // 受访人单位 "visiteeBm": form.unitName, // 受访人部门 "visiteeFloor": form.floor, // 受访人所在楼层 "visiteeRoom": form.room, // 受访人所在房间号 "startTime": null, // 有效期开始时间 "endTime": null, // 有效期结束时间 "event": 1 // 事件类型: 1 登记 2 签离 } console.log(JSON.stringify(newPushData)) let url = app.globalData.snDisposition.transitPushUrl try { // 进出记录推送 let res = await threeElements(url, newPushData) console.log('commonQrCode', res.data.commonQrCode); console.log('ladderQrCode', res.data.ladderQrCode); app.data.visitoMsgData.commonQrCode = res.data.commonQrCode app.data.visitoMsgData.ladderQrCode = res.data.ladderQrCode this.backToSpecifiedPage('/pages/resultPage/index?result=登记成功') viceBroadcast(app.globalData.snDisposition.registerSuccessVoice) } catch (error) { this.backToSpecifiedPage('/pages/resultPage/index?result=登记失败') } } else { this.backToSpecifiedPage('/pages/resultPage/index?result=登记成功') viceBroadcast(app.globalData.snDisposition.registerSuccessVoice) } }, closeCanNot() { this.setData({ hiddenPro: true, hiddenStr: true, isShowCauseMatter: false }) }, // 多选楼层开始 async configList() { try { let data = { sn: app.globalData.sn } let res = await configList(data) this.setData({ allFloorList: res.data }) } catch (error) { console.log(error); } }, openFloor() { let { intervieweeForm, allFloorList } = this.data let floorList = [] if (intervieweeForm.floor) { floorList = intervieweeForm.floor.split(',') } let indexList = [] if (floorList.length > 0) { floorList.forEach(item1 => { let index = allFloorList.findIndex(item => { return item1 == item.actualityFloor }) if (index > -1) { indexList.push(index) } }) } this.setData({ isShowfloor: true, chooseFloorIndex: indexList, chooseFloorItem: floorList }) }, multipleChoiceFloor(e) { let index = e.currentTarget.dataset.index let item = e.currentTarget.dataset.item let { chooseFloorIndex, chooseFloorItem, } = this.data let index1 = chooseFloorIndex.findIndex(item => { return item == index }) if (index1 == -1) { chooseFloorIndex.push(index) chooseFloorItem.push(item.actualityFloor) } else { chooseFloorIndex.splice(index1, 1); chooseFloorItem.splice(index1, 1); } this.setData({ chooseFloorIndex, chooseFloorItem, }) }, delmultipleChoiceFloor(e) { let index = e.currentTarget.dataset.index let { chooseFloorIndex, chooseFloorItem, } = this.data chooseFloorIndex.splice(index, 1); chooseFloorItem.splice(index, 1); this.setData({ chooseFloorIndex, chooseFloorItem, }) }, floorCancel() { this.setData({ isShowfloor: false, chooseFloorIndex: [], chooseFloorItem: [] }) }, floorSure() { let str = this.data.chooseFloorItem.join(','); this.setData({ isShowfloor: false, 'intervieweeForm.floor': str }) }, // 多选楼层结束 // 键盘函数开始 proTap(e) { //点击省份 let that = this; let province = e.currentTarget.dataset.province; let carnum = this.data.carnum; if (carnum.length < 1) { //避免连续点击 carnum += province; } this.setData({ carnum: carnum, hiddenPro: true, hiddenStr: false, }) }, strTap(e) { //点击字母数字 let that = this; this.setData({ waiting: true }) let province = e.currentTarget.dataset.str; let carnum = this.data.carnum; // console.log(carnum.length) if (carnum.length <= 8) { //避免连续点击 carnum += province; console.log(carnum); } this.setData({ notNum: false, carnum: carnum, }) this.setData({ notNum: false, carnum: carnum, }) setTimeout(() => { that.setData({ waiting: false }) }, 100); if (carnum.length > 6) { this.setData({ downBtn: '完成', strDisabled: true, }) // this.searchCardInfo() return; // 车牌长度最多为7个 } }, backSpace() { //退格 let carnum = this.data.carnum; if (carnum.length <= 7) { this.setData({ downBtn: '返回', strDisabled: false, }) } var arr = carnum.split(''); arr.splice(-1, 1) var str = arr.join('') if (arr.length < 2) { this.setData({ notNum: true }) } if (str == '') { this.setData({ hiddenPro: false, hiddenStr: true }) } this.setData({ carnum: str }) }, backKeyboard() { //返回省份键盘 if (this.data.carnum.length > 6) { this.setData({ downBtn: '完成', hiddenPro: true, hiddenStr: false }) } else if (this.data.carnum.length > 0) { this.setData({ hiddenPro: true, hiddenStr: false }) } else { this.setData({ hiddenPro: false, hiddenStr: true }) } }, applyNum() { this.setData({ hiddenPro: true, hiddenStr: true, }) }, closeSecondaryScreenFuc() { console.log('关闭副屏', app.data.isSecondaryScreenState) if (app.data.isSecondaryScreenState) { closeSecondaryScreen() // closeCycleSecondaryScreen() } }, // 键盘函数结束 saveRef(ref) { // 将ref存起来,在想要调用的地方使用 this.toTitleRef = ref }, /** * 跳转指定页面 并清除顶部计时器 */ backToSpecifiedPage(url) { this.toTitleRef && this.toTitleRef.clearIntervalAll() my.reLaunch({ url: url, }) setTimeout(() => { this.closeSecondaryScreenFuc(); }, 500) }, back() { // 是否能加载到副屏 let isSecondaryScreenState = app.data.isSecondaryScreenState; if (isSecondaryScreenState) { // 是否启用副屏处理中页面 let processingPageSwitch = app.globalData.snDisposition.processingPageSwitch; // 是否启用副屏轮播图 let secondaryPageSwitch = app.globalData.snDisposition.secondaryPageSwitch; if (processingPageSwitch && secondaryPageSwitch) {// 启用副屏处理中页面 && 启用副屏轮播图 app.data.cycleIntervalSwitch = true let url = app.globalData.snDisposition.secondaryPageImages[app.data.secondaryPageImagesIndex] || '' if (url) { openSecondaryScreen(url) } setTimeout(() => { this.toTitleRef && this.toTitleRef.clearIntervalAll() my.reLaunch({ url: '/pages/home/index', }) }, 500) } else if (!processingPageSwitch && secondaryPageSwitch) { // 不启用副屏处理中页面 && 启用副屏轮播图 app.data.cycleIntervalSwitch = true let url = app.globalData.snDisposition.secondaryPageImages[app.data.secondaryPageImagesIndex] || '' if (url) { openSecondaryScreen(url) } setTimeout(() => { this.toTitleRef && this.toTitleRef.clearIntervalAll() my.reLaunch({ url: '/pages/home/index', }) }, 500) } else { this.backToSpecifiedPage('/pages/home/index') } } else { this.backToSpecifiedPage('/pages/home/index') } }, didUnmount() { // this.closeSecondaryScreenFuc(); }, onUnload() { // this.closeSecondaryScreenFuc(); }, });