hejianhao
2025-04-30 a190295afba4e7f09729b9771fd4241cb8108e25
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
<template>
  <el-dialog
    :title="dialogTitle"
    :visible.sync="dialogVisible"
    width="500px"
    :before-close="handleClose"
  >
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      label-width="100px"
      label-position="right"
    >
      <el-form-item label="步骤名称" prop="stepName">
        <el-input v-model="form.stepName" placeholder="请输入步骤名称"></el-input>
      </el-form-item>
    </el-form>
 
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="handleSubmit" style="margin-left: 10px;">确 定</el-button>
    </span>
  </el-dialog>
</template>
 
<script>
export default {
  name: 'AddStep',
  data() {
    return {
      dialogVisible: false,
      isEdit: false,
      form: {
        stepName: ''
      },
      rules: {
        stepName: [
          { required: true, message: '请输入步骤名称', trigger: 'blur' },
          { min: 2, max: 50, message: '长度在 2 到 50 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    dialogTitle() {
      return this.isEdit ? '编辑步骤' : '新增步骤'
    }
  },
  methods: {
    open(isEdit = false) {
      this.isEdit = isEdit
      this.dialogVisible = true
    },
    setStepName(name) {
      this.form.stepName = name
    },
    handleClose() {
      this.isEdit = false
      this.$refs.form.resetFields()
      this.dialogVisible = false
    },
    handleSubmit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.$emit('submit', {...this.form})
          this.handleClose()
        }
      })
    }
  }
}
</script>
 
<style lang="less" scoped>
.el-input-number {
  width: 120px;
}
</style>