import api from "../../utils/api"; Page({ data: { pageStatus: 2, notesInput: '', room_name: '--', hotel_name: '--', count: 0, normal: 0, abnormal: 0, abnormal_d_name: '--', room_id: 0, show1: false, show2: false, show2Text: '', roomInfo: {}, logsInfo: {}, statusFlag:false, deviceList: [] }, onLoad: function (options) { this.setData({ room_id: options.room_id , room_name: options.room_name , hotel_name: options.hotel_name, pageStatus: 0 }) }, bindNotesInput: function (e) { this.setData({ notesInput: e.detail.value }); console.log(this.data.notesInput) }, onClose() { this.setData({ show1: false, show2: false }); }, onClose2() { this.setData({ pageStatus: 0 , notesInput: '' , deviceList: [] , logsInfo: {} , roomInfo: {} }); this.setData({ show1: false, show2: false }); }, onShow() { }, onShow1() { this.setData({ show1: true }); }, onShow2(text = null) { this.setData({ show2: true, show2Text: text }); }, onStartInspection() { wx.showToast({ icon: 'none', title: "开始巡检", }); this.setData({pageStatus: 1}); this.setData({ deviceList: [], logsInfo: {}, statusFlag:false, roomInfo: {} }) api.startCheck({ params: {room_id: this.data.room_id}, headers: {unionid: wx.getStorageSync("unionid")}, }) .then(data => { if (data.code === 1) { this.getNucEquips(data.data.logs.id) setInterval(() => { this.setData({ statusFlag:true, }) }, (data.data.ex_time||6)*1000) } else { this.setData({ deviceList: [], logsInfo: {}, statusFlag:false, roomInfo: {} }) this.setData({pageStatus: 0}); if (data[0]==="["){ this.onShow2("当前巡检并未结束,运行结束后再进行操作!") }else{ this.onShow2(data.info || "巡检异常请联系管理员") } } }) .catch(err => { console.log( err) this.setData({ deviceList: [], statusFlag:false, logsInfo: {}, roomInfo: {} }) this.setData({pageStatus: 0}); this.onShow2("巡检异常请联系管理员") }); } , getNucEquips(id) { api.nucEquips({ params: {room_id: this.data.room_id,id: id}, headers: {unionid: wx.getStorageSync("unionid")} }).then(data => { if (data.code === 1) { var logs = data.data.logs || {}; this.setData({ deviceList: logs.inspection || [], logsInfo: logs, roomInfo: data.data.room || {} }) } else { this.onShow2(data.info || "获取设备列表失败,请联系管理员!") } }).catch(err => { this.onShow2("获取设备列表失败,请联系管理员!") }); }, onConfirm() { api.confirm({ body: {note: this.data.notesInput, id: this.data.logsInfo.id}, headers: {unionid: wx.getStorageSync("unionid")} }).then(data => { if (data.code === 1) { this.setData({ pageStatus: 0 , notesInput: '' , deviceList: [] , logsInfo: {} , roomInfo: {} }); } else { this.onShow2(data.info || "提交失败,请联系管理员!") } }).catch(err => { this.onShow2("提交失败,请联系管理员!") }); this.onClose() }, onClosePage() { this.onConfirm() wx.navigateBack({ delta: 1 }); }, onSubmit() { api.inspect({ body: {inspection: this.data.deviceList, id: this.data.logsInfo.id}, headers: {unionid: wx.getStorageSync("unionid")} }).then(data => { if (data.code === 1) { let {count = 0, normal = 0, abnormal = 0, inspection = []} = data.data || {} wx.showToast({ icon: 'none', title: data.info || "提交成功!", }); this.setData({ pageStatus: 2, count, normal, abnormal, abnormal_d_name: inspection .filter(item => item.checked === 0) .map(item => item.entity_name) .join(',') || '--' }); } else { this.onShow2(data.info || "提交失败,请联系管理员!") } }).catch(err => { this.onShow2("提交失败,请联系管理员!") }); }, setDeviceStats(e) { let {index, status} = e.currentTarget.dataset this.setData({ [`deviceList[${index}].checked`]: status }) } });