riku
2025-09-19 58c0f11fe2f23a1be2dec768f9ac02107301a634
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<template>
  <el-row gutter="20">
    <el-col :span="16">
      <div>
        <el-text>监管场景</el-text>
      </div>
      <el-divider />
      <CompSubTaskSelect
        :data="seletedSceneList"
        :dayTask="dayTask"
        @delete="deleteScene"
        @submit="createSubtasks"
      ></CompSubTaskSelect>
      <div>
        <!-- <el-scrollbar height="50vh"> -->
        <CompMonitorObj :data="curMonitorObjList" height="50vh">
          <template #default="{ item }">
            <el-button
              v-if="item.select"
              size="small"
              type="info"
              plain
              disabled
              icon="select"
              >选择</el-button
            >
            <el-button
              v-else
              size="small"
              type="primary"
              plain
              @click="selectScene(item)"
              >选择</el-button
            >
          </template>
        </CompMonitorObj>
        <!-- </el-scrollbar> -->
      </div>
    </el-col>
    <el-col :span="8">
      <CompSubTaskList
        v-model="curSubTaskList"
        :height="height"
        @submit="deleteSubtasks"
      ></CompSubTaskList>
    </el-col>
  </el-row>
</template>
<script setup>
import { ref, watch, onMounted, inject } from 'vue';
import { useCloned } from '@vueuse/core';
import { useRoute, useRouter } from 'vue-router';
import { ElMessage, ElNotification, ElMessageBox } from 'element-plus';
import taskApi from '@/api/fysp/taskApi';
import subtaskApi from '@/api/fysp/subtaskApi';
import TaskProxy from '../TaskProxy';
 
import CompMonitorObj from './CompMonitorObj.vue';
import CompSubTaskSelect from './CompSubTaskSelect.vue';
import CompSubTaskList from './CompSubTaskList.vue';
import dayjs from 'dayjs';
 
const route = useRoute();
 
const props = defineProps({
  // 日任务
  dayTask: Object,
  mObjList: Array
});
 
const emit = defineEmits(['submit'])
 
/*************************** 数据初始化 ************************************/
// 巡查子任务集合
const curMonitorObjList = ref([]);
const curSubTaskList = ref([]);
const height = ref('70vh');
 
// 监听日任务变化
watch(
  () => props.dayTask,
  (nV) => {
    onDayTaskChange(nV);
  },
  { immediate: true }
);
 
// 监听监管场景变化
watch(
  () => props.mObjList,
  (nV, oV) => {
    if (nV != oV) {
      curMonitorObjList.value = useCloned(nV).cloned.value;
    }
  },
  { immediate: true }
);
 
// 根据日任务获取对应子任务
function onDayTaskChange(dayTask) {
  if (dayTask) {
    fetchSubTask(dayTask.guid);
  } else {
    curSubTaskList.value = [];
  }
}
 
// 获取巡查子任务
function fetchSubTask(dayTaskId) {
  taskApi.fetchSubtaskByDayTask(dayTaskId).then((res) => {
    curSubTaskList.value = res;
  });
}
 
/*************************** 添加子任务 ************************************/
 
// 所选场景
const seletedSceneList = ref([]);
// 选择任务场景
function selectScene(item) {
  item.select = true;
  seletedSceneList.value.push(item);
}
// 移除任务场景
function deleteScene(item) {
  item.select = false;
  const index = seletedSceneList.value.indexOf(item);
  seletedSceneList.value.splice(index, 1);
}
 
function createSubtasks(executors) {
  const dt = props.dayTask;
  const subtasks = seletedSceneList.value.map((_) => {
    const s = _.scene;
    return {
      // 主键由服务端创建
      stguid: undefined,
      tguid: dt.tsGuid,
      tsguid: dt.guid,
      name: `${s.name}巡查`,
      typeno: 1,
      type: '巡查',
      provincecode: s.provincecode,
      provincename: s.provincename,
      citycode: s.citycode,
      cityname: s.cityname,
      districtcode: s.districtcode,
      districtname: s.districtname,
      scensename: s.name,
      scenseid: s.guid,
      scenseaddress: s.location,
      planstarttime: dt.date,
      planendtime: dayjs(dt.date).endOf('day').set('millisecond', 0).toDate(),
      deployerguid: 'rAR0A4gJdlOZEqZs',
      deployerusername: 'ccheck',
      deployerrealname: '整改审核',
      executorguids: executors.ids,
      executorusernames: executors.uName,
      executorrealtimes: executors.rName,
      status: '未执行',
      remark: undefined
    };
  });
 
  // 更新场景监管次数
  seletedSceneList.value.forEach((s) => {
    s.extension1 = s.extension1 ? parseInt(s.extension1) + 1 + '' : '1';
  });
  taskApi.updateMonitorObject(seletedSceneList.value).then((res) => {
    if (res > 0) {
      subtaskApi.putSubtasks(subtasks).then((res) => {
        seletedSceneList.value = [];
        fetchSubTask(props.dayTask.guid);
        ElMessage({
          message: '巡查任务添加成功',
          type: 'success'
        });
        emit('submit')
      });
    }
  });
}
 
function deleteSubtasks() {
  emit('submit')
}
</script>
<style scoped></style>