Blame view

src/components/machine/addMachineType.vue 5.95 KB
21e37d17   wuxw   开发设备类型功能
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
  <template>
    <el-dialog
      :title="$t('machineTypeTree.add')"
      :visible.sync="dialogVisible"
      width="50%"
      @close="handleClose"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item :label="$t('machineTypeTree.machineTypeName')" prop="machineTypeName">
          <el-input
            v-model.trim="form.machineTypeName"
            :placeholder="$t('machineTypeTree.requiredPlaceholder', {field: $t('machineTypeTree.machineTypeName')})"
          ></el-input>
        </el-form-item>
        <el-form-item :label="$t('machineTypeTree.machineTypeCode')" prop="machineTypeCode">
          <el-input
            v-model.trim="form.machineTypeCode"
            :placeholder="$t('machineTypeTree.requiredPlaceholder', {field: $t('machineTypeTree.machineTypeCode')})"
          ></el-input>
        </el-form-item>
        <el-form-item :label="$t('machineTypeTree.status')" prop="isEnable">
          <el-radio-group v-model="form.isEnable">
            <el-radio :label="'1000'">{{ $t('machineTypeTree.enable') }}</el-radio>
            <el-radio :label="'2000'">{{ $t('machineTypeTree.disable') }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item :label="$t('machineTypeTree.importanceLevel')" prop="importanceLevel">
          <el-select
            v-model="form.importanceLevel"
            :placeholder="$t('machineTypeTree.requiredPlaceholder', {field: $t('machineTypeTree.importanceLevel')})"
            style="width:100%"
          >
            <el-option
              v-for="item in importanceLevels"
              :key="item.statusCd"
              :label="item.name"
              :value="item.statusCd"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('machineTypeTree.seq')" prop="seq">
          <el-input-number
            v-model="form.seq"
            :placeholder="$t('machineTypeTree.requiredPlaceholder', {field: $t('machineTypeTree.seq')})"
            controls-position="right"
            :min="1"
            style="width:100%"
          ></el-input-number>
        </el-form-item>
        <el-form-item :label="$t('machineTypeTree.unit')">
          <el-input
            v-model.trim="form.unit"
            :placeholder="$t('machineTypeTree.optionalPlaceholder', {field: $t('machineTypeTree.unit')})"
          ></el-input>
        </el-form-item>
        <el-form-item :label="$t('machineTypeTree.warrantyDeadline')">
          <el-date-picker
            v-model="form.warrantyDeadline"
            type="date"
            :placeholder="$t('machineTypeTree.optionalPlaceholder', {field: $t('machineTypeTree.warrantyDeadline')})"
            style="width:100%"
            value-format="yyyy-MM-dd"
          ></el-date-picker>
        </el-form-item>
        <el-form-item :label="$t('machineTypeTree.remark')">
          <el-input
            v-model.trim="form.remark"
            type="textarea"
            :placeholder="$t('machineTypeTree.optionalPlaceholder', {field: $t('machineTypeTree.remark')})"
          ></el-input>
        </el-form-item>
      </el-form>
      
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">{{ $t('common.cancel') }}</el-button>
        <el-button type="primary" @click="handleSubmit">{{ $t('common.confirm') }}</el-button>
      </span>
    </el-dialog>
  </template>
  
  <script>
  import { saveMachineType } from '@/api/machine/machineTypeTreeManageApi'
  import { getDict } from '@/api/community/communityApi'
  import { getCommunityId } from '@/api/community/communityApi'
  
  export default {
    name: 'AddMachineType',
    data() {
      return {
        dialogVisible: false,
        form: {
          parentTypeId: '',
          machineTypeName: '',
          machineTypeCode: '',
          isEnable: '1000',
          importanceLevel: '',
          unit: '',
          warrantyDeadline: '',
          seq: 1,
          remark: '',
          communityId: ''
        },
        importanceLevels: [],
        rules: {
          machineTypeName: [
            { required: true, message: this.$t('machineTypeTree.requiredMessage', {field: this.$t('machineTypeTree.machineTypeName')}), trigger: 'blur' },
            { max: 30, message: this.$t('machineTypeTree.maxLengthMessage', {length: 30}), trigger: 'blur' }
          ],
          machineTypeCode: [
            { required: true, message: this.$t('machineTypeTree.requiredMessage', {field: this.$t('machineTypeTree.machineTypeCode')}), trigger: 'blur' },
            { max: 30, message: this.$t('machineTypeTree.maxLengthMessage', {length: 30}), trigger: 'blur' }
          ],
          isEnable: [
            { required: true, message: this.$t('machineTypeTree.requiredMessage', {field: this.$t('machineTypeTree.status')}), trigger: 'change' }
          ],
          importanceLevel: [
            { required: true, message: this.$t('machineTypeTree.requiredMessage', {field: this.$t('machineTypeTree.importanceLevel')}), trigger: 'change' }
          ],
          seq: [
            { required: true, message: this.$t('machineTypeTree.requiredMessage', {field: this.$t('machineTypeTree.seq')}), trigger: 'blur' }
          ]
        }
      }
    },
    created() {
      this.form.communityId = getCommunityId()
      this.getDictData()
    },
    methods: {
      async getDictData() {
        try {
          const data = await getDict('machine_type', 'importance_level')
          this.importanceLevels = data
        } catch (error) {
          console.error('获取字典数据失败:', error)
        }
      },
      open(params) {
        this.form.parentTypeId = params.typeId || ''
        this.dialogVisible = true
        this.$nextTick(() => {
          this.$refs.form && this.$refs.form.resetFields()
        })
      },
      handleClose() {
        this.$refs.form.resetFields()
      },
      handleSubmit() {
        this.$refs.form.validate(async valid => {
          if (valid) {
            try {
              await saveMachineType(this.form)
              this.$message.success(this.$t('common.addSuccess'))
              this.dialogVisible = false
              this.$emit('success')
            } catch (error) {
              console.error('添加设备类型失败:', error)
            }
          }
        })
      }
    }
  }
  </script>