riku
2024-10-24 4f238e1ff525b6aa1f8c9981f044d606a89734ce
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<template>
  <FYForm
    ref="formRef"
    :form-info="formInfo"
    :rules="rules"
    :useCancel="true"
    label-width="120px"
    submit-name="创建"
    @submit="submit"
    @cancel="cancel"
  >
    <template #form-item="{ formObj }">
      <!-- 区县 -->
      <FYOptionLocation
        :allOption="false"
        :level="3"
        :initValue="false"
        :checkStrictly="false"
        v-model:value="formObj._locations"
        @change="handleLocationChange"
      ></FYOptionLocation>
      <el-form-item label="任务名称" prop="name">
        <el-input
          clearable
          show-word-limit
          v-model="formObj.name"
          placeholder="任务名称"
        />
      </el-form-item>
      <FYOptionTime
        label="起止日期"
        prop="_timeArr"
        :initValue="false"
        type="daterange"
        v-model:value="formObj._timeArr"
        @change="handleTimeChange"
      ></FYOptionTime>
 
      <el-form-item v-show="showMore" label="任务类型" prop="_type">
        <el-select v-model="formObj._type" style="width: 150px">
          <el-option
            v-for="s in taskTypeOptions"
            :key="s.label"
            :label="s.label"
            :value="s.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item v-show="showMore" label="任务期限类别" prop="_deadlinetype">
        <el-select v-model="formObj._deadlinetype" style="width: 150px">
          <el-option
            v-for="s in deadlineTypeOptions"
            :key="s.label"
            :label="s.label"
            :value="s.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item v-show="showMore" label="任务层次" prop="levelnum">
        <el-select v-model="formObj.levelnum" style="width: 150px">
          <el-option
            v-for="s in levelOptions"
            :key="s.label"
            :label="s.label"
            :value="s.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item v-show="showMore" label="执行人" prop="_executors">
        <el-select
          v-model="formObj._executors"
          multiple
          clearable
          collapse-tags
          placeholder="选择执行人"
          :max-collapse-tags="3"
          style="width: 300px"
        >
          <el-option
            v-for="s in executorOptions"
            :key="s.value"
            :label="s.label"
            :value="s.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-row justify="center">
          <el-link type="primary" @click="showMore = !showMore">
            {{ showMore ? '收起' : '更多选项' }}
            <el-icon v-if="showMore"><ArrowUp /></el-icon>
            <el-icon v-else><ArrowDown /></el-icon>
          </el-link>
        </el-row>
      </el-form-item>
    </template>
  </FYForm>
</template>
<script setup>
import { ref, reactive, watch, onMounted } from 'vue';
import domainApi from '@/api/fysp/domainApi';
import userApi from '@/api/fysp/userApi';
import dayjs from 'dayjs';
import taskApi from '@/api/fysp/taskApi';
 
const props = defineProps({
  //数据
  model: {
    type: Object,
    default: () => {
      return {};
    }
  },
  //是创建或者更新场景,默认更新
  create: Boolean
});
 
const emit = defineEmits(['submit', 'cancel']);
 
const rules = reactive({
  name: [
    {
      required: true,
      message: '任务名称不能为空',
      trigger: 'change'
    }
  ],
  _type: [
    {
      required: true,
      message: '任务类型不能为空',
      trigger: 'change'
    }
  ],
  _deadlinetype: [
    {
      required: true,
      message: '任务期限类型不能为空',
      trigger: 'change'
    }
  ],
  levelnum: [
    {
      required: true,
      message: '任务层次不能为空',
      trigger: 'change'
    }
  ],
  // starttime: [
  //   {
  //     required: true,
  //     message: '开始日期不能为空',
  //     trigger: 'change'
  //   }
  // ],
  // endtime: [
  //   {
  //     required: true,
  //     message: '结束日期不能为空',
  //     trigger: 'change'
  //   }
  // ],
  _timeArr: [
    {
      required: true,
      message: '起止日期不能为空',
      trigger: 'change'
    }
  ],
  _executors: [
    {
      required: true,
      message: '任务执行人不能为空',
      trigger: 'change'
    }
  ]
});
 
const formRef = ref(null);
const formInfo = ref({
  starttime: dayjs().add(1, 'month').startOf('month').toDate(),
  endtime: dayjs().add(1, 'month').endOf('month').toDate(),
  _timeArr: [
    dayjs().add(1, 'month').startOf('month').toDate(),
    dayjs().add(1, 'month').endOf('month').set('millisecond', 0).toDate()
  ]
});
// 任务类型选项
const taskTypeOptions = ref([]);
// 任务期限类别选项
const deadlineTypeOptions = ref([]);
// 任务层次类别选项
const levelOptions = ref([]);
// 任务执行人选项
const executorOptions = ref([]);
const showMore = ref(false);
 
function locationText(location) {
  if (location.pName == (undefined | null)) return '';
  let res = location.pName;
  if (location.cName && location.cName != location.pName) {
    res += location.cName;
  }
  if (location.dName && location.dName != location.cName) {
    res += location.dName;
  }
  return res;
}
 
function handleLocationChange(location) {
  genTaskName();
}
 
function handleTimeChange(timeArr) {
  genTaskName();
}
 
function genTaskName() {
  let name = dayjs(formRef.value.formObj._timeArr[0]).format('YYYY年MM月');
  name += locationText(formRef.value.formObj._locations);
  name += formRef.value.formObj._type.text;
  name += '任务';
  formRef.value.formObj.name = name;
}
 
/*************************** 数据更新 ************************************/
 
function getExecutors(data) {
  const ids = [];
  const uNames = [];
  const rNames = [];
  executorOptions.value.forEach((e) => {
    const index = data._executors.indexOf(e.value);
    if (index != -1) {
      ids.push(e.data.guid);
      uNames.push(e.data.acountname);
      rNames.push(e.data.realname);
    }
  });
  return {
    id: ids.join('#'),
    uName: uNames.join('#'),
    rName: rNames.join('#')
  };
}
 
function submit(data, success, fail) {
  const v = data.value;
  const executors = getExecutors(v);
  const task = {
    levelnum: v.levelnum,
    name: v.name,
    typeno: v._type.value,
    typename: v._type.text,
    deadlinetype: v._deadlinetype.text,
    provincecode: v._locations.pCode,
    provincename: v._locations.pName,
    citycode: v._locations.cCode,
    cityname: v._locations.cName,
    districtcode: v._locations.dCode,
    districtname: v._locations.dName,
    starttime: v._timeArr[0],
    endtime: v._timeArr[1],
    // fixme 2024.10.16, 后续加入用户系统后,采用当前登录用户信息
    plannerguid: 'rAR0A4gJdlOZEqZs',
    plannerusername: 'ccheck',
    plannerrealname: '整改审核',
    settime: new Date(),
    executorguids: executors.id,
    executorusernames: executors.uName,
    executorrealnames: executors.rName,
    t1stverifierguid: 'rAR0A4gJdlOZEqZs',
    t1stverifierusername: 'ccheck',
    t1stverifierrealname: '整改审核',
    t1stverifytime: new Date(),
    t1stisverify: true,
    runingstatus: '未执行',
    extension1: '3',
    extension2: '0'
  };
  // success();
  // emit('submit', task);
  taskApi
    .putTask(task)
    .then((res) => {
      success();
      emit('submit', res.data);
    })
    .catch((err) => fail(err));
}
function cancel() {
  emit('cancel');
}
 
/*************************** 数据初始化 ************************************/
 
// 各选项的初始化
function initOptions() {
  domainApi.fetchTaskType().then((res) => {
    taskTypeOptions.value = res.map((v) => {
      return {
        label: v.text,
        value: v
      };
    });
    formInfo.value._type = taskTypeOptions.value[0].value;
  });
  domainApi.fetchDeadlineType().then((res) => {
    deadlineTypeOptions.value = res.map((v) => {
      return {
        label: v.text,
        value: v
      };
    });
    formInfo.value._deadlinetype = deadlineTypeOptions.value[0].value;
  });
  domainApi.fetchLevelType().then((res) => {
    levelOptions.value = res.map((v) => {
      return {
        label: v.text,
        value: v.value
      };
    });
    formInfo.value.levelnum = levelOptions.value[1].value;
  });
  userApi.getUserByType(1).then((res) => {
    executorOptions.value = res.map((v) => {
      return {
        label: v.realname,
        value: v.guid,
        data: v
      };
    });
    formInfo.value._executors = executorOptions.value.map((v) => v.value);
  });
}
 
onMounted(() => {
  initOptions();
});
</script>
<style scoped></style>