houzhongjian
2024-07-23 8501060c4f921d1e744c477e4dc08eb47b52693c
提交 | 用户 | 时间
850106 1 <template>
H 2   <el-dialog
3     :title="!dataForm.id ? '新增' : '修改'"
4     :close-on-click-modal="false"
5     :visible.sync="visible">
6     <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
7       <el-form-item label="名称" prop="storetypename">
8         <el-input v-model="dataForm.storetypename" placeholder="名称" maxlength="50" clearable></el-input>
9       </el-form-item>
10       <el-form-item label="编号" prop="storetypeno">
11         <el-input v-model="dataForm.storetypeno" placeholder="编号" maxlength="16" clearable :disabled="!!dataForm.id"></el-input>
12       </el-form-item>
13       <el-form-item label="存储位置" prop="storetable">
14         <el-input v-model="dataForm.storetable" placeholder="存储位置" maxlength="32" clearable></el-input>
15       </el-form-item>
16     </el-form>
17     <span slot="footer" class="dialog-footer">
18       <el-button @click="visible = false">取消</el-button>
19       <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
20     </span>
21   </el-dialog>
22 </template>
23
24 <script>
25   export default {
26     data () {
27       return {
28
29         visible: false,
30         roleList: [],
31         dataForm: {
32           id: 0,
33           storetypename: '',
34           storetypeno: '',
35           storetable: ''
36         },
37         dataRule: {
38           storetypename: [
39             { required: true, message: '名称不能为空', trigger: 'blur' }
40           ],
41           storetypeno: [
42             { required: true, message: '编号不能为空', trigger: 'blur' }
43           ],
44           storetable: [
45             { required: true, message: '存储位置不能为空', trigger: 'blur' }
46           ]
47         }
48       }
49     },
50     methods: {
51       init (id) {
52         this.dataForm.id = id || 0
53         this.visible = true
54         this.$nextTick(() => {
55           this.$refs['dataForm'].resetFields()
56         })
57         if (id) {
58           this.$http({
59             url: `/data/data/store-type/info/${this.dataForm.id}`,
60             method: 'get',
61             params: this.$http.adornParams()
62           }).then(({data}) => {
63             if (data && data.code === 0) {
64               this.dataForm.storetypename = data.storeType.storetypename
65               this.dataForm.storetypeno = data.storeType.storetypeno
66               this.dataForm.storetable = data.storeType.storetable
67             }
68           })
69         }
70       },
71       // 表单提交
72       dataFormSubmit () {
73         this.$refs['dataForm'].validate((valid) => {
74           if (valid) {
75             this.$http['post'](`/data/data/store-type/${!this.dataForm.id ? 'save' : 'update'}`, this.dataForm).then(({ data: res }) => {
76               if (res.code !== 0) {
77                 return this.$message.error(res.msg)
78               }
79               this.$message({
80                 message: this.$t('prompt.success'),
81                 type: 'success',
82                 duration: 500,
83                 onClose: () => {
84                   this.visible = false
85                   this.$emit('refreshDataList')
86                 }
87               })
88             }).catch(() => {})
89           }
90         })
91       }
92     }
93   }
94 </script>