Blame view

src/components/oa/newOaWorkflowForm.vue 9 KB
9d019fa6   wuxw   测试OA相关流程
1
2
3
  <template>
    <div class="new-oa-workflow-form">
      <el-card class="form-card">
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
4
5
6
7
8
9
        <el-form ref="form" :model="formData" label-width="120px" label-position="right" class="text-left">
          <div v-for="(item, index) in components" :key="index">
            <!-- 标题 -->
            <el-divider v-if="item.type == 'text'" content-position="left">
              <span class="form-title">{{ item.text }}</span>
            </el-divider>
9d019fa6   wuxw   测试OA相关流程
10
  
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
11
12
13
            <!-- 文本框 -->
            <el-form-item v-if="item.type == 'textfield'" :label="item.label" :prop="item.key"
              :rules="getValidationRules(item)">
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
14
              <el-input v-model="formData[item.key]" :placeholder="item.description" clearable>
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
15
16
17
18
19
20
              </el-input>
            </el-form-item>
  
            <!-- 数字框 -->
            <el-form-item v-if="item.type == 'number'" :label="item.label" :prop="item.key"
              :rules="getValidationRules(item)">
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
21
              <el-input-number v-model="formData[item.key]" :placeholder="item.description" :min="0" style="width: 100%">
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
22
23
24
25
26
27
              </el-input-number>
            </el-form-item>
  
            <!-- 文本域 -->
            <el-form-item v-if="item.type == 'textarea'" :label="item.label" :prop="item.key"
              :rules="getValidationRules(item)">
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
28
              <el-input v-model="formData[item.key]" type="textarea" :rows="4" :placeholder="item.description">
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
29
30
31
32
33
34
              </el-input>
            </el-form-item>
  
            <!-- 日期选择 -->
            <el-form-item v-if="item.type == 'textdate'" :label="item.label" :prop="item.key"
              :rules="getValidationRules(item)">
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
35
              <el-date-picker v-model="formData[item.key]" type="date" :placeholder="item.description" format="yyyy-MM-dd"
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
36
37
38
39
40
41
42
                value-format="yyyy-MM-dd" style="width: 100%">
              </el-date-picker>
            </el-form-item>
  
            <!-- 时间选择 -->
            <el-form-item v-if="item.type == 'textdatetime'" :label="item.label" :prop="item.key"
              :rules="getValidationRules(item)">
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
43
              <el-time-picker v-model="formData[item.key]" :placeholder="item.description" format="HH:mm"
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
44
45
46
47
48
49
50
                value-format="HH:mm" style="width: 100%">
              </el-time-picker>
            </el-form-item>
  
            <!-- 单选框 -->
            <el-form-item v-if="item.type == 'radio'" :label="item.label" :prop="item.key"
              :rules="getValidationRules(item)">
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
51
              <el-radio-group v-model="formData[item.key]">
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
52
53
54
55
56
57
58
59
60
                <el-radio v-for="(option, optionIndex) in item.values" :key="optionIndex" :label="option.value">
                  {{ option.label }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
  
            <!-- 下拉选择 -->
            <el-form-item v-if="item.type == 'select'" :label="item.label" :prop="item.key"
              :rules="getValidationRules(item)">
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
61
              <el-select v-model="formData[item.key]" :placeholder="item.description" style="width: 100%" clearable>
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
62
63
64
65
66
67
68
69
70
                <el-option v-for="(option, optionIndex) in item.values" :key="optionIndex" :label="option.label"
                  :value="option.value">
                </el-option>
              </el-select>
            </el-form-item>
  
            <!-- 复选框 -->
            <el-form-item v-if="item.type == 'checkbox'" :label="item.label" :prop="item.key"
              :rules="getValidationRules(item)">
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
71
              <el-checkbox-group v-model="formData[item.key]">
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
                <el-checkbox v-for="(option, optionIndex) in item.values" :key="optionIndex" :label="option.value">
                  {{ option.label }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
  
            <!-- 文件上传 -->
            <el-form-item v-if="item.type == 'button' && item.action == 'submit'" :label="$t('common.file')">
              <div class="upload-section">
                <upload-file ref="uploadFile" @notify="handleFileUpload" />
              </div>
            </el-form-item>
  
            <!-- 提交按钮 -->
            <el-form-item v-if="item.type == 'button' && item.action == 'submit'" class="text-right">
              <el-button type="primary" @click="_doSubmit" :loading="submitLoading">
                <i class="el-icon-check"></i>
                {{ item.label }}
              </el-button>
            </el-form-item>
  
            <!-- 重置按钮 -->
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
94
            <el-form-item v-if="item.type == 'button' && item.action == 'reset'" class="text-right">
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
95
96
97
98
99
              <el-button @click="_doReset">
                <i class="el-icon-refresh"></i>
                {{ item.label }}
              </el-button>
            </el-form-item>
9d019fa6   wuxw   测试OA相关流程
100
          </div>
9d019fa6   wuxw   测试OA相关流程
101
  
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
102
        </el-form>
9d019fa6   wuxw   测试OA相关流程
103
104
105
106
107
108
109
      </el-card>
    </div>
  </template>
  
  <script>
  import UploadFile from '@/components/upload/uploadFile'
  import { queryOaWorkflowForm, saveOaWorkflowFormData } from '@/api/oa/newOaWorkflowApi'
9d019fa6   wuxw   测试OA相关流程
110
111
112
113
114
115
116
117
  
  export default {
    name: 'NewOaWorkflowForm',
    components: { UploadFile },
  
    data() {
      return {
        formJson: {},
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
118
119
        components: [],
        formData: {},
9d019fa6   wuxw   测试OA相关流程
120
121
122
123
        fileName: '',
        realFileName: '',
        callBackListener: 'newOaWorkflowForm',
        callBackFunction: 'fileName',
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
124
        submitLoading: false,
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
125
126
        showUploadComponent: false,
        flowId: null
9d019fa6   wuxw   测试OA相关流程
127
128
      }
    },
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
129
  
9d019fa6   wuxw   测试OA相关流程
130
131
    mounted() {
    },
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
132
  
9d019fa6   wuxw   测试OA相关流程
133
134
135
136
137
    methods: {
      open(params) {
        this.flowId = params.flowId
        this.listOaWorkflowForm()
      },
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
138
  
9d019fa6   wuxw   测试OA相关流程
139
140
141
142
143
144
145
146
      async listOaWorkflowForm() {
        try {
          const res = await queryOaWorkflowForm({
            page: 1,
            row: 1,
            flowId: this.flowId
          })
          console.log(res)
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
147
  
9d019fa6   wuxw   测试OA相关流程
148
149
          this.formJson = JSON.parse(res.data[0].formJson)
          this.initForm()
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
150
  
9d019fa6   wuxw   测试OA相关流程
151
152
        } catch (error) {
          console.error('获取表单配置失败:', error)
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
153
          this.$message.error('获取表单配置失败')
9d019fa6   wuxw   测试OA相关流程
154
155
        }
      },
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
156
  
9d019fa6   wuxw   测试OA相关流程
157
      initForm() {
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
158
159
  
        let _components = this.formJson.components
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
160
        this.formData = {}
9d019fa6   wuxw   测试OA相关流程
161
  
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
162
        _components.forEach(item => {
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
163
          if (item.type !== 'button' && item.type !== 'text') {
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
164
            if (item.type === 'checkbox') {
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
165
              this.$set(this.formData, item.key, []);
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
166
            } else if (item.type === 'radio' || item.type === 'select') {
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
167
              this.$set(this.formData, item.key, item.values && item.values.length > 0 ? item.values[0].value : '');
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
168
            } else {
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
169
              this.$set(this.formData, item.key, '');
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
170
171
            }
          }
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
172
173
        });
        this.components = _components
9d019fa6   wuxw   测试OA相关流程
174
      },
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
175
176
177
178
179
180
181
  
      getValidationRules(item) {
        const rules = []
        if (item.validate && item.validate.required) {
          rules.push({
            required: true,
            message: `${item.label}不能为空`,
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
182
183
184
185
186
187
188
189
190
            trigger: item.type === 'select' ? 'change' : 'blur'
          })
        }
  
        // 添加其他验证规则,如正则表达式
        if (item.validate && item.validate.pattern) {
          rules.push({
            pattern: new RegExp(item.validate.pattern),
            message: item.validate.customMessage || `${item.label}格式不正确`,
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
191
192
            trigger: 'blur'
          })
9d019fa6   wuxw   测试OA相关流程
193
        }
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
194
  
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
195
196
        return rules
      },
9d019fa6   wuxw   测试OA相关流程
197
  
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
198
      async _doSubmit() {
9d019fa6   wuxw   测试OA相关流程
199
        try {
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
200
201
202
203
204
205
206
207
208
209
210
211
212
          // 表单验证
          await this.$refs.form.validate()
  
          this.submitLoading = true
  
          const _data = {
            fileName: this.fileName,
            realFileName: this.realFileName,
            flowId: this.flowId,
            ...this.formData
          }
  
          const res = await saveOaWorkflowFormData(_data)
9d019fa6   wuxw   测试OA相关流程
213
214
215
216
217
          if (res.code === 0) {
            this.$message.success(this.$t('common.submitSuccess'))
            this.resetForm()
            this.$emit('switch-tab', 'newOaWorkflowPool')
          } else {
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
218
            this.$message.error(res.msg || this.$t('common.submitFailed'))
9d019fa6   wuxw   测试OA相关流程
219
220
          }
        } catch (error) {
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
221
222
223
224
          if (error.message) {
            // 表单验证错误
            return
          }
9d019fa6   wuxw   测试OA相关流程
225
226
          console.error('提交表单失败:', error)
          this.$message.error(this.$t('common.submitFailed'))
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
227
228
        } finally {
          this.submitLoading = false
9d019fa6   wuxw   测试OA相关流程
229
230
        }
      },
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
231
232
  
      _doReset() {
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
233
234
235
236
237
238
        this.$refs.form.resetFields()
        // 特殊处理复选框
        Object.keys(this.formData).forEach(key => {
          const component = this.components.find(c => c.key === key)
          if (component && component.type === 'checkbox') {
            this.formData[key] = []
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
239
          }
e48bb242   wuxw   v1.9 oa 工作流表單必填問題處理
240
        })
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
241
242
243
244
245
246
247
248
249
      },
  
      _doUploadFile() {
        this.showUploadComponent = true
        this.$nextTick(() => {
          this.$refs.uploadFile.open()
        })
      },
  
9d019fa6   wuxw   测试OA相关流程
250
      resetForm() {
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
251
252
253
        this.$refs.form.resetFields()
        if (this.$refs.uploadFile) {
          this.$refs.uploadFile.clear()
9d019fa6   wuxw   测试OA相关流程
254
        }
9d019fa6   wuxw   测试OA相关流程
255
256
257
        this.fileName = ''
        this.realFileName = ''
        this.formJson = {}
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
258
259
260
        this.components = []
        this.formData = {}
        this.showUploadComponent = false
9d019fa6   wuxw   测试OA相关流程
261
      },
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
262
  
9d019fa6   wuxw   测试OA相关流程
263
264
265
266
267
268
269
270
      handleFileUpload(fileInfo) {
        this.fileName = fileInfo.fileName
        this.realFileName = fileInfo.realFileName
      }
    }
  }
  </script>
  
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
271
  <style lang="scss" scoped>
9d019fa6   wuxw   测试OA相关流程
272
273
  .new-oa-workflow-form {
    .form-card {
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
274
275
276
277
      .form-title {
        font-size: 16px;
        font-weight: 600;
        color: #303133;
9d019fa6   wuxw   测试OA相关流程
278
      }
9d019fa6   wuxw   测试OA相关流程
279
  
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
280
281
282
283
284
      .upload-section {
        .file-info {
          margin-bottom: 10px;
        }
      }
9d019fa6   wuxw   测试OA相关流程
285
  
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
286
287
288
      .el-form-item {
        margin-bottom: 22px;
      }
9d019fa6   wuxw   测试OA相关流程
289
  
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
290
291
292
      .el-divider {
        margin: 24px 0;
      }
9d019fa6   wuxw   测试OA相关流程
293
294
295
    }
  }
  </style>