riku
2025-06-24 4fbdf4c6b13d19b9be54900b5dcff29e2ca7ef01
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<template>
  <div class="wrapper">
    <el-row>
      <FYForm
        :inline="true"
        label-width=""
        :form-info="formInfo"
        :rules="rules"
        @submit="submit"
      >
        <template #form-item="{ formObj }">
          <el-form-item label="执行人" prop="executor">
            <el-select
              v-model="formObj.executor"
              multiple
              clearable
              collapse-tags
              placeholder="选择执行人"
              :max-collapse-tags="1"
              style="width: 240px"
            >
              <template #header>
                <el-checkbox
                  v-model="checkAll"
                  :indeterminate="indeterminate"
                  @change="handleCheckAll"
                >
                  全选
                </el-checkbox>
              </template>
              <el-option
                v-for="item in executors"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </template>
      </FYForm>
    </el-row>
    <div>
      <el-scrollbar :height="scrollHeight" v-if="data.length > 0">
        <el-space wrap>
          <ItemMonitorObj v-for="obj in data" :key="obj.movid" :item="obj">
            <template #default="{ item }">
              <el-button
                size="small"
                type="danger"
                plain
                @click="deleteScene(item)"
                >移除</el-button
              >
            </template>
          </ItemMonitorObj>
        </el-space>
      </el-scrollbar>
      <el-empty v-else description=" ">
        <template #image>
          <el-row align="middle">
            <el-icon size="20"><WarningFilled /></el-icon>
            <el-text size="small" type="info">未选择场景</el-text>
          </el-row>
        </template>
      </el-empty>
    </div>
  </div>
</template>
<script setup>
/**
 * 巡查子任务创建
 */
import { ref, reactive, watch, computed, onMounted, inject } from 'vue';
import { ElMessageBox, ElNotification, ElMessage } from 'element-plus';
import taskApi from '@/api/fysp/taskApi';
import TaskProxy from '../TaskProxy';
 
// const topTask = inject('topTask');
 
const props = defineProps({
  // 子任务集合
  data: {
    type: Array,
    default: () => []
  },
  height: String,
  // 日任务
  dayTask: Object
});
 
const emit = defineEmits(['submit', 'delete']);
 
const scrollHeight = ref('14vh');
 
// 移除任务场景
function deleteScene(item) {
  emit('delete', item);
}
 
/************************* 任务创建表单 *******************************/
const formInfo = ref({});
const rules = reactive({
  name: [
    {
      required: true,
      message: '场景名称不能为空',
      trigger: 'blur'
    }
  ]
});
function submit(v, success, fail) {
  if (props.data.length == 0) {
    // ElMessage({
    //   message: '未选择监管场景',
    //   type: 'warning'
    // });
    fail('未选择监管场景');
  } else {
    success();
    // 将任务执行人格式化并传递
    const param = TaskProxy.getExecutors(v.value.executor, executors.value);
    emit('submit', param);
  }
}
 
/************************* 任务执行人下拉选框 *******************************/
// onMounted(() => {
//   getExecutors(topTask.value);
// });
 
const executors = ref([]);
// 是否全选
const checkAll = ref(false);
// 多选框是否中间状态
const indeterminate = ref(false);
// 全选事件
function handleCheckAll(val) {
  indeterminate.value = false;
  if (val) {
    formInfo.value.executor = executors.value.map((_) => _.value);
  } else {
    formInfo.value.executor = [];
  }
}
 
function getExecutors(t) {
  const ids = t.executorguids.split('#');
  const userNames = t.executorusernames.split('#');
  const realNames = t.executorrealnames.split('#');
  const list = [];
  ids.forEach((e, i) => {
    if (i < userNames.length && i < realNames.length) {
      list.push({
        label: realNames[i],
        value: e,
        data: {
          id: e,
          userName: userNames[i],
          realName: realNames[i]
        }
      });
    }
  });
 
  executors.value = list;
}
// watch(topTask, (nV, oV) => {
//   if (nV != oV) {
//     getExecutors(nV);
//   }
// });
 
watch(
  () => props.dayTask,
  (nV, oV) => {
    if (nV != oV) {
      taskApi.fetchTaskById(nV.guid).then((res) => {
        getExecutors(res);
      });
    }
  },
  { immediate: true }
);
 
watch(
  () => formInfo.value.executor,
  (val) => {
    if (val.length === 0) {
      checkAll.value = false;
      indeterminate.value = false;
    } else if (val.length === executors.value.length) {
      checkAll.value = true;
      indeterminate.value = false;
    } else {
      indeterminate.value = true;
    }
  }
);
</script>
<style scoped>
.wrapper {
  border-bottom: 1px solid var(--el-color-info-light-7);
}
</style>