futian.liu
2023-12-13 494fbb222f0ec270f764f84f13987984fad09b82
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
<template>
  <win-md title="新增规格型号" @close="close" width="500px" :loading="loading">
    <el-form ref="ruleForm" :model="formData" :rules="rules" class="demo-ruleForm" label-width="100px">
      <el-form-item label="型号名称" prop="modelName">
        <el-input v-model="formData.modelName" placeholder="请输入型号名称" clearable maxlength="20" show-word-limit
                  style="width: 100%"/>
      </el-form-item>
      <el-form-item label="单位" prop="unit">
        <el-input v-model="formData.unit" placeholder="请输入单位" clearable maxlength="20" show-word-limit
                  style="width: 100%"/>
      </el-form-item>
      <el-form-item label="状态" prop="states">
        <el-radio-group v-model="formData.states">
          <el-radio :label="1" border>启用</el-radio>
          <el-radio :label="0" border>禁用</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <div slot="footer" align="center" class="dialog-footer">
      <my-button name="取消" site="form" @click="close"/>
      <my-button name="保存" site="form" @click="save"/>
    </div>
  </win-md>
</template>
 
<script>
import winMd from '@/components/win/win-md'
import myButton from '@/components/myButton/myButton'
import {mapGetters} from 'vuex'
import {addSpecs} from "@/api/foudation/material";
 
 
export default {
  name: 'specsAdd',
  components: {winMd, myButton},
  props: {
    setting: {
      type: Object,
      default: () => {
      }
    }
  },
  data() {
    return {
      loading: false,
      formData: {
        goodsTemplatesId: '',
        modelName: '',
        unit: '',
        states: 1,
      },
      rules: {
        modelName: [
          {required: true, message: '请输入型号名称', trigger: 'blur'}
        ],
        unit: [
          {required: true, message: '请输入单位', trigger: 'blur'}
        ]
      }
    }
  },
  computed: {
    ...mapGetters(['userInfo'])
  },
  created() {
  },
  methods: {
    close() {
      this.$emit('close')
    },
    save() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          const params = Object.assign({}, this.formData)
          if (this.loading) return
          this.loading = true
          addSpecs(params).then(res => {
            this.loading = false
            if (res) {
              this.$message.success('保存成功!')
              this.close()
              this.$emit('search')
            } else {
              this.$message.error('保存失败')
            }
          }).catch(() => {
            this.loading = false
          });
        } else {
          this.$message.error('校验未通过,请检查。')
        }
      })
    }
  }
}
</script>