| | |
| | | // package_supervision/pages/inspection/index.js |
| | | Page({ |
| | | import { inspectPicUrl } from '../../../config/index'; |
| | | import taskApi from '../../api/taskApi'; |
| | | import { fetchScene } from '../../../services/inspection/fetchScene'; |
| | | import Message from 'tdesign-miniprogram/message/index'; |
| | | |
| | | /** |
| | | * status: 未执行 | 正在执行 | 已结束 |
| | | * action: 开始任务 | 结束任务 | 已结束 |
| | | * theme: primary | danger | default |
| | | * icon: play-circle-stroke | pause-circle-stroke | stop-circle |
| | | */ |
| | | const TASK_STATUS = { |
| | | 未执行: { |
| | | status: '未执行', |
| | | action: '开始任务', |
| | | theme: 'primary', |
| | | icon: 'play-circle-stroke', |
| | | }, |
| | | 正在执行: { |
| | | status: '正在执行', |
| | | action: '结束任务', |
| | | theme: 'danger', |
| | | icon: 'pause-circle-stroke', |
| | | }, |
| | | 已结束: { |
| | | status: '已结束', |
| | | action: '已结束', |
| | | theme: 'default', |
| | | icon: 'stop-circle-stroke', |
| | | }, |
| | | }; |
| | | |
| | | Page({ |
| | | /** |
| | | * 页面的初始数据 |
| | | */ |
| | | data: { |
| | | title: '现场监管', |
| | | // 巡查子任务 |
| | | subtask: {}, |
| | | // 场景信息 |
| | | scene: {}, |
| | | inspeciton: {}, |
| | | // |
| | | mapMarkers: [], |
| | | // 功能菜单 |
| | | menu1: [ |
| | | { |
| | | name: '问题复核', |
| | | icon: `${inspectPicUrl}icons/icon_patrol_check.png`, |
| | | disabled: true, |
| | | }, |
| | | { |
| | | name: '问题取证', |
| | | icon: `${inspectPicUrl}icons/icon_patrol_new_question.png`, |
| | | disabled: true, |
| | | url: '/package_supervision/pages/menu_evidence/index' |
| | | }, |
| | | { |
| | | name: '问题清单', |
| | | icon: `${inspectPicUrl}icons/icon_patrol_question_list.png`, |
| | | disabled: true, |
| | | }, |
| | | { |
| | | name: '现场整改', |
| | | icon: `${inspectPicUrl}icons/icon_patrol_change.png`, |
| | | disabled: true, |
| | | }, |
| | | { |
| | | name: '任意拍照', |
| | | icon: `${inspectPicUrl}icons/icon_patrol_camera.png`, |
| | | disabled: true, |
| | | }, |
| | | { |
| | | name: '导航', |
| | | icon: `${inspectPicUrl}icons/icon_patrol_navi.png`, |
| | | disabled: false, |
| | | }, |
| | | { |
| | | name: '重新定位', |
| | | icon: `${inspectPicUrl}icons/icon_patrol_latlng.png`, |
| | | disabled: false, |
| | | }, |
| | | { |
| | | name: '修改信息', |
| | | icon: `${inspectPicUrl}icons/icon_patrol_edit.png`, |
| | | disabled: false, |
| | | }, |
| | | { |
| | | name: '问题审核', |
| | | icon: `${inspectPicUrl}icons/icon_patrol_online.png`, |
| | | disabled: true, |
| | | }, |
| | | { |
| | | name: '整改审核', |
| | | icon: `${inspectPicUrl}icons/icon_patrol_promiss.png`, |
| | | disabled: true, |
| | | }, |
| | | ], |
| | | menu2: [ |
| | | { |
| | | name: '图片取证', |
| | | icon: `${inspectPicUrl}icons/icon_patrol_new_question.png`, |
| | | disabled: true, |
| | | }, |
| | | { |
| | | name: '整改承诺', |
| | | icon: `${inspectPicUrl}icons/icon_patrol_promiss.png`, |
| | | disabled: true, |
| | | }, |
| | | { |
| | | name: '综合评分', |
| | | icon: `${inspectPicUrl}icons/icon_patrol_rate.png`, |
| | | disabled: true, |
| | | }, |
| | | { |
| | | name: '一键分享', |
| | | icon: `${inspectPicUrl}icons/icon_patrol_submit.png`, |
| | | disabled: true, |
| | | }, |
| | | { |
| | | name: '技防措施', |
| | | icon: `${inspectPicUrl}icons/icon_patrol_newgit.png`, |
| | | disabled: true, |
| | | }, |
| | | ], |
| | | |
| | | // 任务状态 |
| | | taskStatus: { |
| | | loading: false, |
| | | ...TASK_STATUS.已结束, |
| | | }, |
| | | // 任务状态按钮加载样式 |
| | | loadProps: { |
| | | theme: 'spinner', |
| | | tClass: 'ins-buttons__loading', |
| | | }, |
| | | // 任务状态更改确认弹出框 |
| | | taskStatusDialog: { |
| | | show: false, |
| | | title: '要开始任务吗?', |
| | | content: '', |
| | | }, |
| | | }, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面加载 |
| | | */ |
| | | onLoad(options) { |
| | | |
| | | // 获取巡查任务参数 subtask,并更新任务状态 taskStatus |
| | | this.getOpenerEventChannel().on('acceptSubTaskData', data => { |
| | | if (data) { |
| | | this.setData({ |
| | | subtask: data.subtask, |
| | | taskStatus: { |
| | | loading: false, |
| | | ...TASK_STATUS[data.subtask.status], |
| | | }, |
| | | }); |
| | | this.fetchInspectionData(); |
| | | } |
| | | }); |
| | | }, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面初次渲染完成 |
| | | * 根据任务状态,更新按钮是否可点击 |
| | | * @param {string} status 任务状态: 未执行 | 正在执行 | 已结束 |
| | | */ |
| | | onReady() { |
| | | |
| | | refreshMenuStatus(status) { |
| | | const { menu1, menu2 } = this.data; |
| | | if (status == '正在执行') { |
| | | menu1.forEach(m => { |
| | | m.disabled = false; |
| | | }); |
| | | menu2.forEach(m => { |
| | | m.disabled = false; |
| | | }); |
| | | } else if (status == '已结束') { |
| | | menu1[1].disabled = true; |
| | | menu2[0].disabled = true; |
| | | } else { |
| | | menu1.forEach(m => { |
| | | m.disabled = true; |
| | | }); |
| | | menu2.forEach(m => { |
| | | m.disabled = true; |
| | | }); |
| | | [5, 6, 7].forEach(i => { |
| | | menu1[i].disabled = false; |
| | | }); |
| | | } |
| | | this.setData({ menu1, menu2 }); |
| | | }, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面显示 |
| | | * 获取巡查信息和场景信息 |
| | | */ |
| | | onShow() { |
| | | fetchInspectionData() { |
| | | const { subtask } = this.data; |
| | | taskApi.fetchInspectionData(subtask.stguid).then(res => { |
| | | this.setData({ |
| | | inspeciton: res, |
| | | }); |
| | | }); |
| | | fetchScene(subtask.scenseid).then(res => { |
| | | const { mapMarkers } = this.data; |
| | | mapMarkers.push({ |
| | | id: 1, |
| | | longitude: res.longitude, |
| | | latitude: res.latitude, |
| | | title: res.name, |
| | | callout: res.name, |
| | | width: 16, |
| | | height: 24, |
| | | }); |
| | | this.setData({ |
| | | scene: res, |
| | | mapMarkers, |
| | | title: res.name, |
| | | }); |
| | | }); |
| | | }, |
| | | |
| | | showTaskStatusChangeDialog() { |
| | | let { taskStatusDialog, taskStatus } = this.data; |
| | | if (taskStatus.status == '未执行') { |
| | | taskStatusDialog = { |
| | | show: true, |
| | | title: '要开始任务吗?', |
| | | content: '', |
| | | }; |
| | | } else if (taskStatus.status == '正在执行') { |
| | | taskStatusDialog = { |
| | | show: true, |
| | | title: '要结束任务吗?', |
| | | content: '结束任务后不能再新增问题', |
| | | }; |
| | | } |
| | | this.setData({ taskStatusDialog }); |
| | | }, |
| | | |
| | | closeDialog() { |
| | | this.setData({ 'taskStatusDialog.show': false }); |
| | | }, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面隐藏 |
| | | * 任务状态变更事件处理函数 |
| | | */ |
| | | onHide() { |
| | | |
| | | handleTaskStatusChange() { |
| | | this.closeDialog(); |
| | | let { taskStatus, subtask } = this.data; |
| | | this.setData({ 'taskStatus.loading': true }); |
| | | if (taskStatus.status == '已结束') { |
| | | return; |
| | | } |
| | | if (taskStatus.status == '未执行') { |
| | | taskStatus = { |
| | | loading: true, |
| | | ...TASK_STATUS.正在执行, |
| | | }; |
| | | } else if (taskStatus.status == '正在执行') { |
| | | taskStatus = { |
| | | loading: true, |
| | | ...TASK_STATUS.已结束, |
| | | }; |
| | | } |
| | | taskApi |
| | | .changeSubTaskStatus(subtask.stguid) |
| | | .then(res => { |
| | | if (res.success) { |
| | | this.setData({ taskStatus }); |
| | | this.getOpenerEventChannel().emit('changeStatusEvent', { subtask: res.data }); |
| | | this.refreshMenuStatus(taskStatus.status) |
| | | } else { |
| | | Message.error({ |
| | | context: this, |
| | | offset: [90, 32], |
| | | duration: 2000, |
| | | content: res.message, |
| | | }); |
| | | } |
| | | }) |
| | | .finally(() => this.setData({ 'taskStatus.loading': false })); |
| | | }, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面卸载 |
| | | */ |
| | | onUnload() { |
| | | |
| | | }, |
| | | |
| | | /** |
| | | * 页面相关事件处理函数--监听用户下拉动作 |
| | | */ |
| | | onPullDownRefresh() { |
| | | |
| | | }, |
| | | |
| | | /** |
| | | * 页面上拉触底事件的处理函数 |
| | | */ |
| | | onReachBottom() { |
| | | |
| | | }, |
| | | |
| | | /** |
| | | * 用户点击右上角分享 |
| | | */ |
| | | onShareAppMessage() { |
| | | |
| | | } |
| | | }) |
| | | }); |