riku
2024-10-24 3d3e7f45086799fdd7a412e2079710a6cdf8dc2b
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
<template>
  <el-row justify="space-between">
    <el-text>单日计划</el-text>
    <el-button
      v-show="create && data && data.length > 0"
      type="success"
      size="small"
      @click="add"
      >任务调整</el-button
    >
  </el-row>
  <el-divider />
  <div>
    <el-scrollbar v-loading="loading" :height="height">
      <el-space
        v-if="data && data.length > 0"
        fill
        :fill-ratio="100"
        direction="vertical"
        style="width: 100%"
      >
        <ItemSubTask v-for="s in data" :key="s.guid" :item="s">
          <template #default="{ item }">
            <el-space direction="vertical">
              <el-button
                :disabled="item.status != '未执行'"
                plain
                type="primary"
                size="small"
                @click="edit(item)"
                >编辑</el-button
              >
              <el-button
                :disabled="item.status != '未执行'"
                type="default"
                size="small"
                @click="remove(item)"
                >移除</el-button
              >
            </el-space>
          </template>
        </ItemSubTask>
      </el-space>
      <div v-else>
        <el-empty description="无任务记录" />
        <el-row v-if="create" justify="center">
          <el-button type="success" size="small" @click="add"
            >添加任务</el-button
          >
        </el-row>
      </div>
    </el-scrollbar>
  </div>
  <el-dialog
    v-model="dialogVisible"
    width="600"
    title="巡查任务编辑"
    destroy-on-close
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    :show-close="false"
  >
    <CompSubTaskEdit
      v-model="activeItem"
      @submit="onEditSubmit"
      @cancel="dialogVisible = false"
    ></CompSubTaskEdit>
  </el-dialog>
</template>
<script setup>
import { ref, computed, watch, onMounted, onUnmounted } from 'vue';
import { ElMessageBox, ElNotification, ElMessage } from 'element-plus';
import CompSubTaskEdit from './CompSubTaskEdit.vue';
import subtaskApi from '@/api/fysp/subtaskApi';
 
const props = defineProps({
  modelValue: Array,
  height: {
    type: String,
    default: '70vh'
  },
  // 是否显示添加任务按钮
  create: Boolean,
  loading: Boolean
});
 
const dialogVisible = ref(false);
const activeItem = ref(null);
const data = computed(() => props.modelValue);
 
const emit = defineEmits(['submit', 'add', 'remove', 'update:modelValue']);
 
function remove(item) {
  if (item.status == '未执行') {
    ElMessageBox.confirm('是否移除监管任务', `移除确认`, {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning'
    }).then(() => {
      return subtaskApi.deleteSubtask(item.stguid).then(res=>{
        if (res == 1) {
          const index = data.value.indexOf(item);
          data.value.splice(index, 1); 
 
          emit('update:modelValue', data.value);
          emit('remove', item);
        } else {
          Promise.reject('删除巡查任务失败')
        }
      })
    });
  }
}
 
function edit(item) {
  activeItem.value = item;
  dialogVisible.value = true;
}
 
function onEditSubmit(item) {
  dialogVisible.value = false;
  const index = data.value.findIndex((v) => {
    return item.stguid == v.stguid;
  });
  data.value.splice(index, 1, item);
  emit('update:modelValue', data.value);
  emit('submit');
}
 
function add() {
  emit('add');
}
 
onUnmounted(() => {
  dialogVisible.value = false;
});
</script>