import { deviceStatusForm } from '../device-info-items.js'; import { fetchDeviceStatus, uploadDeviceStatus, } from '../../../../../services/inspection/fetchDevice'; var defaultForm = deviceStatusForm(); Page({ data: { // 设备状态表单内容 formArray: [], showNewStatus: false, deviceStatusList: [], // 图片上传列表 fileList: [], // 图片展示方式 gridConfig: { column: 3, width: 210, height: 210, }, // 图片限制大小 sizeLimit: { size: 5, unit: 'MB', message: '图片大小不超过5MB' }, // 定位信息 locations: { // 位置名称 name: '', address: '', // 使用 gcj02 国测局坐标系 longitude: '', latitude: '', }, }, onLoad(options) { this.getOpenerEventChannel().on('acceptDeviceStatusData', data => { if (data) { const { scene, type, deviceInfo } = data; defaultForm = deviceStatusForm({ dlDeviceId: deviceInfo._id, dlDeviceType: type, dlSceneGuid: scene.guid, dlSceneTypeId: scene.typeid, }); this.setData({ scene, type, deviceInfo, }); this.fetchDeviceStatus(); } }); }, fetchDeviceStatus() { const { scene, type, deviceInfo } = this.data; fetchDeviceStatus(scene.guid, deviceInfo._id, type).then(res => { this.setData({ deviceStatusList: res.data, }); }); }, // 显示新增设备状态输入表单 onAddStatus() { this.setData({ showNewStatus: true, formArray: defaultForm, fileList: [], locations: {}, }); }, // 保存新设备状态 saveNewStatus(e) { const { deviceStatusList, fileList, locations } = this.data; const formObj = e.detail; formObj.dlLocation = locations.address; formObj.dlLongitude = locations.longitude; formObj.dlLatitude = locations.latitude; const images = fileList.map(v => v.url); uploadDeviceStatus(formObj, images).then(res => { // if (res.success) { // deviceStatusList.push(formObj); // this.setData({ // showNewStatus: false, // deviceStatusList, // }); // } this.setData({ showNewStatus: false, }); this.fetchDeviceStatus(); }); }, // 取消设备状态表单编辑 cancelNewStatus() { this.setData({ showNewStatus: false, }); }, // 手动修改定位位置描述 handleLocation(e) {}, // 从地图选择定位 chooseLocation() { wx.chooseLocation({ success: res => { console.log(res); this.setData({ locations: res }); }, }); }, // 添加图片 handleAddImg(e) { const { fileList } = this.data; const { files } = e.detail; this.setData({ fileList: [...fileList, ...files], }); }, // 移除图片 handleRemoveImg(e) { const { index } = e.detail; const { fileList } = this.data; fileList.splice(index, 1); this.setData({ fileList, }); }, });