董国庆
7 天以前 b3f4499793fa7b21f6c5d1e099d6ed170ecbe47a
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
<template>
  <el-dialog title="新增表头" :visible.sync="dialogVisible" width="30%" :close-on-click-modal="false" @close="handleClose">
    <div class="sample-dialog">
      <div class="sample-content">
        <div class="form-content">
          <el-form ref="form" :model="form" :rules="rules" label-position="top">
            <el-row :gutter="24">
              <el-col :span="24">
                <el-form-item label="表头名称" prop="name">
                  <el-input v-model="form.name" style="width: 100%" placeholder="请输入表头名称" />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="表头类型" prop="type">
                  <el-radio-group v-model="form.type" style="width: 100%">
                    <el-radio-button label="text">文本框</el-radio-button>
                    <el-radio-button label="image">图片上传</el-radio-button>
                    <el-radio-button label="date">日期选择</el-radio-button>
                    <el-radio-button label="user">人员选择</el-radio-button>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="操作权限" prop="role">
                  <el-select v-model="form.role" placeholder="请选择" style="width: 100%" multiple>
                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="24" v-if="['text', 'date', 'user'].includes(form.type)">
                <el-form-item label="提示文案" prop="message">
                  <el-input v-model="form.message" style="width: 100%" placeholder="请输入提示文案" />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="是否必填" prop="required">
                  <el-radio-group v-model="form.required">
                    <el-radio label="true">是</el-radio>
                    <el-radio label="false">否</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </div>
    </div>
    <div slot="footer" class="dialog-footer select-member-footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="handleSubmit">确 定</el-button>
    </div>
  </el-dialog>
</template>
 
<script>
export default {
  name: "AddDialog",
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    participants: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      isIPad: /iPad/i.test(navigator.userAgent),
      form: {
        name: "",
        type: "",
        role: "",
        message: "",
        required: "true",
      },
      rules: {
        name: [
          { required: true, message: "请输入表头名称", trigger: "blur" },
        ],
        type: [
          { required: true, message: "请选择表头类型", trigger: "blur" },
        ],
        role: [
          {
            type: "array",
            required: true,
            message: "请至少选择一个操作人",
            trigger: "change",
          },
        ],
        message: [
          {
            required: false,
            message: "请输入提示文案",
            trigger: "blur",
          },
        ],
        required: [
          {
            required: true,
            message: "请选择是否必填",
            trigger: "change",
          },
        ],
      },
      value: ''
    };
  },
  computed: {
    dialogVisible: {
      get() {
        return this.visible;
      },
      set(val) {
        this.$emit("update:visible", val);
      },
    },
    options() {
      // 将participants转换为select组件需要的格式
      let userId = JSON.parse(sessionStorage.getItem('userInfo'))?.userId
      let nickName = JSON.parse(sessionStorage.getItem('userInfo'))?.nickName
      let newList = JSON.parse(JSON.stringify(this.participants))
      newList.push({ userId, nickName })
      return newList.map(participant => ({
        value: participant.userId,
        label: participant.nickName
      }));
    }
  },
  mounted() {
    // 组件挂载时的初始化逻辑
  },
  methods: {
    setFormData(data) {
      // 设置基础表单数据
      this.form.name = data.name;
      this.form.type = data.type;
      this.form.role = data.role;
      this.form.message = data.message;
      this.form.required = data.required || "true";
      // 重置表单校验状态
      this.$nextTick(() => {
        this.$refs.form?.clearValidate();
      });
    },
    handleClose() {
      this.dialogVisible = false;
      this.$refs.form?.resetFields();
      this.form = {
        name: "",
        type: "",
        role: "",
        message: "",
        required: "true",
      };
    },
    handleSubmit() {
      // 对于需要提示文案的类型,添加额外验证
      if (['text', 'date', 'user'].includes(this.form.type) && !this.form.message) {
        this.$message.error('请输入提示文案');
        return;
      }
 
      this.$refs.form.validate((valid) => {
        if (valid) {
          const submitData = {
            ...this.form,
          };
          this.$emit("confirm", submitData);
        }
      });
    },
  },
};
</script>
 
<style scoped lang="less">
::v-deep .el-dialog__body {
  padding: 0;
  max-height: calc(100vh - 200px); // 设置最大高度
}
 
::v-deep .el-dialog {
  margin-top: 5vh !important; // 调整弹窗位置
  max-height: 90vh; // 设置弹窗最大高度
  display: flex;
  flex-direction: column;
 
  .el-dialog__body {
    flex: 1;
    overflow: hidden; // 防止出现双滚动条
 
    .el-input__inner {
      width: 100% !important;
    }
  }
}
 
.sample-dialog {
  height: 100%;
 
  .sample-content {
    background: #ffffff;
    border-radius: 10px;
    padding: 20px;
    height: 100%;
    display: flex;
    padding-left: 10%;
    flex-direction: column;
 
    .form-content {
      flex: 1;
      overflow-y: auto;
      padding: 0 10px;
      max-height: calc(90vh - 250px); // 设置内容区域最大高度
 
      &::-webkit-scrollbar {
        width: 6px;
      }
 
      &::-webkit-scrollbar-thumb {
        background: #c0c4cc;
        border-radius: 3px;
      }
 
      &::-webkit-scrollbar-track {
        background: #f5f7fa;
      }
    }
  }
}
 
.dialog-footer {
  align-items: center;
  display: flex;
  justify-content: center;
  padding: 15px 20px;
  border-top: 1px solid #e4e7ed;
  margin-top: auto; // 保持在底部
 
  button {
    width: 150px;
  }
}
 
.upload-demo {
  ::v-deep {
    .el-upload--picture-card {
      width: 120px;
      height: 120px;
      line-height: 120px;
    }
 
    .el-upload-list--picture-card {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
 
      .el-upload-list__item {
        width: 120px;
        height: 120px;
        margin: 0;
      }
    }
 
    // 让上传按钮始终显示在列表最后
    .el-upload--picture-card {
      order: 9999;
      margin: 0;
    }
  }
 
  // 包裹容器也使用flex布局
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
 
.el-row {
  margin-bottom: 20px;
 
  &:last-child {
    margin-bottom: 0; // 最后一行不要margin
  }
}
 
::v-deep .el-form-item--small.el-form-item {
  margin-bottom: 0;
}
 
::v-deep .el-form-item__label {
  padding-bottom: 8px;
}
 
// 优化表单布局
::v-deep .el-form {
  .el-form-item {
    width: 100% !important;
    margin-bottom: 15px !important; // 减小表单项间距
 
    &:last-child {
      margin-bottom: 15px !important;
    }
  }
}
 
// 优化上传区域布局
::v-deep .el-upload-list--picture-card {
  display: flex;
  flex-wrap: wrap;
  gap: 8px; // 设置图片间距
}
 
.upload-file {
  ::v-deep {
    .el-upload-list {
      margin-top: 10px;
    }
 
    .el-upload-list__item {
      transition: all 0.3s;
 
      &:hover {
        background-color: #f5f7fa;
      }
    }
 
    .el-upload__tip {
      color: #909399;
      font-size: 12px;
      margin-top: 8px;
    }
  }
}
</style>