ZN
5 天以前 7eaaeeabd23c0172f4599601241dce20c4f52410
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
<template>
  <el-dialog
    :title="title"
    v-model="visible"
    width="1000px"
    append-to-body
    @close="handleClose"
  >
    <el-form ref="formRef" :model="form" :rules="rules" label-width="0">
      <!-- 顶部基础信息 -->
      <div class="base-info-row">
        <div class="info-item">
          <span class="item-label required">名称</span>
          <el-input
            v-model="form.name"
            placeholder="请输入名称"
            maxlength="10"
            show-word-limit
            style="width: 220px"
          />
        </div>
        <div class="info-item">
          <span class="item-label">备注</span>
          <el-input
            v-model="form.description"
            placeholder="请输入备注"
            maxlength="20"
            show-word-limit
            style="width: 220px"
          />
        </div>
        <div class="info-item">
          <span class="item-label">附件</span>
          <el-upload
            action="#"
            :auto-upload="false"
            :show-file-list="false"
            @change="handleFileChange"
          >
            <el-button type="primary">上传附件</el-button>
          </el-upload>
        </div>
      </div>
 
      <!-- 步骤配置表格 -->
      <div class="step-table-container">
        <el-table :data="form.savePlanNodeList" border style="width: 100%">
          <el-table-column label="步骤" width="80" align="center">
            <template #default="scope">
              {{ scope.$index + 1 }}
            </template>
          </el-table-column>
          
          <el-table-column label="阶段名称" min-width="150">
            <template #header>
              <span class="required-star">*</span> 阶段名称
            </template>
            <template #default="scope">
              <el-form-item
                :prop="'savePlanNodeList.' + scope.$index + '.name'"
                :rules="[{ required: true, message: '请输入阶段名称', trigger: 'blur' }]"
              >
                <el-input v-model="scope.row.name" placeholder="请输入" />
              </el-form-item>
            </template>
          </el-table-column>
 
          <el-table-column label="负责人" width="180">
            <template #header>
              <span class="required-star">*</span> 负责人
            </template>
            <template #default="scope">
              <el-form-item
                :prop="'savePlanNodeList.' + scope.$index + '.leaderId'"
                :rules="[{ required: true, message: '请选择负责人', trigger: 'change' }]"
              >
                <el-select
                  v-model="scope.row.leaderId"
                  placeholder="测试"
                  @change="(val) => handleLeaderChange(val, scope.row)"
                >
                  <el-option
                    v-for="item in userOptions"
                    :key="item.userId"
                    :label="item.nickName"
                    :value="item.userId"
                  />
                </el-select>
              </el-form-item>
            </template>
          </el-table-column>
 
          <el-table-column label="预计工期 (天)" width="150">
            <template #header>
              预计工期 (天)
              <el-tooltip content="完成该阶段预计需要的天数" placement="top">
                <el-icon class="info-icon"><QuestionFilled /></el-icon>
              </el-tooltip>
            </template>
            <template #default="scope">
              <el-input-number
                v-model="scope.row.estimatedDuration"
                :min="0"
                controls-position="right"
                style="width: 100%"
              />
            </template>
          </el-table-column>
 
          <el-table-column label="工时单价" width="120">
            <template #default="scope">
              <el-input v-model="scope.row.hourlyRate" placeholder="请输入" />
            </template>
          </el-table-column>
 
          <el-table-column label="作业内容" min-width="150">
            <template #default="scope">
              <el-input v-model="scope.row.workContent" placeholder="请输入" />
            </template>
          </el-table-column>
 
          <el-table-column label="操作" width="180" align="center">
            <template #default="scope">
              <el-button
                link
                type="primary"
                :disabled="scope.$index === 0"
                @click="moveStep(scope.$index, -1)"
              >上移</el-button>
              <el-button
                link
                type="primary"
                :disabled="scope.$index === form.savePlanNodeList.length - 1"
                @click="moveStep(scope.$index, 1)"
              >下移</el-button>
              <el-button
                link
                type="danger"
                @click="removeStep(scope.$index)"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
 
        <div class="add-row-btn" @click="addStep">
          <el-icon><Plus /></el-icon> 新增一行
        </div>
      </div>
    </el-form>
 
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="primary" @click="submitForm">提交</el-button>
      </div>
    </template>
  </el-dialog>
</template>
 
<script setup>
import { ref, watch, onMounted } from 'vue';
import { Plus, QuestionFilled } from '@element-plus/icons-vue';
import { userListNoPageByTenantId } from '@/api/system/user';
import { ElMessage } from 'element-plus';
 
const props = defineProps({
  modelValue: Boolean,
  title: String,
  data: Object
});
 
const emit = defineEmits(['update:modelValue', 'submit']);
 
const visible = ref(false);
const formRef = ref(null);
const userOptions = ref([]);
 
const form = ref({
  id: undefined,
  name: '',
  description: '',
  attachmentIds: [],
  savePlanNodeList: []
});
 
const rules = {
  name: [{ required: true, message: '请输入名称', trigger: 'blur' }]
};
 
// 监听弹窗显示/隐藏
watch(() => props.modelValue, (val) => {
  visible.value = val;
  if (val) {
    if (props.data) {
      // 编辑模式
      form.value = JSON.parse(JSON.stringify(props.data));
      if (!form.value.savePlanNodeList || form.value.savePlanNodeList.length === 0) {
        form.value.savePlanNodeList = [createDefaultNode()];
      }
    } else {
      // 新增模式
      resetForm();
    }
  }
});
 
watch(visible, (val) => {
  emit('update:modelValue', val);
});
 
/** 创建默认节点对象 */
function createDefaultNode() {
  return {
    name: '',
    leaderId: null,
    leaderName: null,
    estimatedDuration: null,
    hourlyRate: null,
    workContent: null
  };
}
 
/** 重置表单 */
function resetForm() {
  form.value = {
    id: undefined,
    name: '',
    description: '',
    attachmentIds: [],
    savePlanNodeList: [createDefaultNode()]
  };
  if (formRef.value) {
    formRef.value.resetFields();
  }
}
 
/** 获取用户列表 */
async function getUserList() {
  try {
    const res = await userListNoPageByTenantId();
    if (res.code === 200) {
      userOptions.value = res.data || [];
    }
  } catch (error) {
    console.error('获取用户列表失败:', error);
  }
}
 
/** 处理负责人变化 */
function handleLeaderChange(val, row) {
  const user = userOptions.value.find(u => u.userId === val);
  if (user) {
    row.leaderName = user.nickName;
  }
}
 
/** 处理文件变化 */
function handleFileChange(file) {
  // 这里实现文件上传逻辑,获取 attachmentId
  ElMessage.info('正在上传: ' + file.name);
  // 模拟上传成功
  // form.value.attachmentIds.push(newId);
}
 
/** 添加步骤 */
function addStep() {
  form.value.savePlanNodeList.push(createDefaultNode());
}
 
/** 移除步骤 */
function removeStep(index) {
  if (form.value.savePlanNodeList.length <= 1) {
    ElMessage.warning('至少保留一个步骤');
    return;
  }
  form.value.savePlanNodeList.splice(index, 1);
}
 
/** 移动步骤 */
function moveStep(index, direction) {
  const targetIndex = index + direction;
  if (targetIndex < 0 || targetIndex >= form.value.savePlanNodeList.length) return;
  
  const list = form.value.savePlanNodeList;
  const temp = list[index];
  list[index] = list[targetIndex];
  list[targetIndex] = temp;
}
 
/** 提交表单 */
async function submitForm() {
  if (!formRef.value) return;
  
  try {
    const valid = await formRef.value.validate();
    if (valid) {
      emit('submit', form.value);
    }
  } catch (error) {
    console.error('表单验证失败:', error);
  }
}
 
/** 关闭弹窗 */
function handleClose() {
  resetForm();
}
 
onMounted(() => {
  getUserList();
});
</script>
 
<style scoped lang="scss">
.base-info-row {
  display: flex;
  gap: 40px;
  margin-bottom: 25px;
  padding: 0 10px;
 
  .info-item {
    display: flex;
    align-items: center;
    gap: 12px;
 
    .item-label {
      font-size: 14px;
      color: #606266;
      white-space: nowrap;
 
      &.required::before {
        content: '*';
        color: #f56c6c;
        margin-right: 4px;
      }
    }
  }
}
 
.step-table-container {
  padding: 0 10px;
 
  :deep(.el-form-item) {
    margin-bottom: 0;
  }
 
  .required-star {
    color: #f56c6c;
    margin-right: 4px;
  }
 
  .info-icon {
    font-size: 14px;
    color: #909399;
    margin-left: 4px;
    cursor: pointer;
  }
 
  .add-row-btn {
    margin-top: 15px;
    height: 40px;
    border: 1px dashed #dcdfe6;
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #409eff;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
 
    &:hover {
      border-color: #409eff;
      background-color: #f0f7ff;
    }
  }
}
 
.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 15px;
  padding-top: 10px;
}
</style>