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: {}, 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 }); }, onShow() { this.setData({ pageStatus: 0 , notesInput: '' , deviceList: [] , logsInfo: {} , roomInfo:{} }); }, onShow1() { this.setData({ show1: true }); }, onShow2(text=null) { this.setData({ show2: true, show2Text: text }); }, onStartInspection() { api.startCheck({ params: {room_id: this.data.room_id}, headers: {unionid: wx.getStorageSync("unionid")}, }) .then(data => { if (data.code === 1) { wx.showToast({ icon: 'none', title: "开始巡检", }); this.setData({ deviceList:[], logsInfo: {}, roomInfo:{} }) this.getNucEquips() this.setData({pageStatus: 1}); } else { this.onShow2(data.info|| "巡检异常请联系管理员") } }) .catch(err => { this.onShow2("巡检异常请联系管理员") }); } , getNucEquips() { api.nucEquips({ params: {room_id: this.data.room_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.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 }) } });