From 45be153eaef9e1c1a3fe21515e9cbd785fba8e1f Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期二, 22 四月 2025 17:38:35 +0800 Subject: [PATCH] 线索任务 --- pages/inspection/scene/info/device-info/index.js | 134 +++++++++++++++++++++++++++++++++----------- 1 files changed, 99 insertions(+), 35 deletions(-) diff --git a/pages/inspection/scene/info/device-info/index.js b/pages/inspection/scene/info/device-info/index.js index b850077..52565b2 100644 --- a/pages/inspection/scene/info/device-info/index.js +++ b/pages/inspection/scene/info/device-info/index.js @@ -11,62 +11,126 @@ deviceType: 0, // 妯″紡锛宎dd: 鏂板璁惧锛泆pdate锛氭洿鏂拌澶� mode: 'add', + submitText: '淇濆瓨', }, onLoad(options) { - if (options.type) { - this.setData({ deviceType: parseInt(options.type) }); - let barTitle, _formArr; - switch (options.type) { - case '0': - barTitle = '鏂板鐩戞祴璁惧'; - _formArr = monitorDeviceForm; - break; - case '1': - barTitle = '鏂板娌荤悊璁惧'; - _formArr = treatmentDeviceForm; - break; - case '2': - barTitle = '鏂板鐢熶骇璁惧'; - _formArr = productionDeviceForm; - break; - default: - barTitle = '璁惧淇℃伅'; - _formArr = monitorDeviceForm; - break; + this.getOpenerEventChannel().on('acceptDeviceData', data => { + if (data) { + const { scene, type, mode, deviceInfo } = data; + let barTitle = mode == 'add' ? '鏂板' : '淇敼', + _formArr; + switch (type) { + case 1: + barTitle += '娌荤悊璁惧'; + let defaultValue1 = + mode == 'update' + ? deviceInfo + : { + piSceneGuid: scene.guid, + piSceneTypeId: scene.typeid, + }; + _formArr = treatmentDeviceForm(scene.typeid, defaultValue1); + break; + case 2: + barTitle += '鐢熶骇璁惧'; + let defaultValue2 = + mode == 'update' + ? deviceInfo + : { + wiSceneGuid: scene.guid, + wiSceneTypeId: scene.typeid, + }; + _formArr = productionDeviceForm(scene.typeid, defaultValue2); + break; + case 0: + default: + barTitle += '鐩戞祴璁惧'; + let defaultValue0 = + mode == 'update' + ? deviceInfo + : { + diSceneGuid: scene.guid, + diSceneTypeId: scene.typeid, + }; + _formArr = monitorDeviceForm(scene.typeid, defaultValue0); + break; + } + wx.setNavigationBarTitle({ + title: barTitle, + }); + this.setData({ + formArray: _formArr, + scene, + deviceType: type, + mode, + submitText: mode == 'add' ? '淇濆瓨' : '鏇存柊', + }); } - wx.setNavigationBarTitle({ - title: barTitle, - }); - this.setData({ formArray: _formArr }); - } - if (options.mode == 'add' || options.mode == 'update') { - this.setData({ mode: options.mode }); - } + }); }, // 鎻愪氦琛ㄥ崟 submit(e) { - const formArr = e.detail; + const formObj = e.detail; + const { mode } = this.data; + if (mode == 'add') { + this.addDevice(formObj); + } else { + this.updateDevice(formObj); + } console.log('submit'); - console.log(formArr); + console.log(formObj); }, // 鍙栨秷琛ㄥ崟 cancel() { - console.log('cancel'); + // console.log('cancel'); + wx.navigateBack({ + delta: 1, + success: res => {}, + fail: res => {}, + complete: res => {}, + }); }, // 鏂板璁惧淇℃伅 addDevice(formObj) { const { deviceType } = this.data; - formObj.diSceneGuid - formObj.diSceneTypeId uploadDevice(formObj, deviceType).then(res => { - console.log(res); + // console.log(res); + this.getOpenerEventChannel().emit('updateDeviceInfoOver'); + wx.navigateBack({ + delta: 1, + success: () => { + wx.showToast({ + title: '璁惧鏂板鎴愬姛', + duration: 2000, + icon: 'success', + mask: true, + }); + }, + }); }); }, // 鏇存柊璁惧淇℃伅 - updateDevice() {}, + updateDevice(formObj) { + const { deviceType } = this.data; + updateDevice(formObj, deviceType).then(res => { + // console.log(res); + this.getOpenerEventChannel().emit('updateDeviceInfoOver'); + wx.navigateBack({ + delta: 1, + success: () => { + wx.showToast({ + title: '璁惧淇敼鎴愬姛', + duration: 2000, + icon: 'success', + mask: true, + }); + }, + }); + }); + }, }); -- Gitblit v1.9.3