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="username">
8         <el-input v-model="dataForm.username" placeholder="名称" maxlength="50" clearable></el-input>
9       </el-form-item>
10       <el-form-item label="调整状态" prop="adjuststatus">
11         <el-select v-model="dataForm.adjuststatus" placeholder="请选择">
12           <el-option
13             v-for="item in isList"
14             :key="item.code"
15             :label="item.name"
16             :value="item.code">
17           </el-option>
18         </el-select>
19       </el-form-item>
20     </el-form>
21     <span slot="footer" class="dialog-footer">
22       <el-button @click="visible = false">取消</el-button>
23       <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
24     </span>
25   </el-dialog>
26 </template>
27
28 <script>
29   export default {
30     data () {
31       return {
32
33         visible: false,
34         roleList: [],
35         isList: [
36           {
37             code: '0',
38             name: '禁用'
39           },
40           {
41             code: '1',
42             name: '启用'
43           }],
44         dataForm: {
45           id: 0,
46           username: '',
47           adjuststatus: ''
48         },
49         dataRule: {
50           username: [
51             { required: true, message: '名称不能为空', trigger: 'blur' }
52           ],
53           adjuststatus: [
54             { required: true, message: '调整状态不能为空', trigger: 'blur' }
55           ]
56         }
57       }
58     },
59     methods: {
60       init (id) {
61         this.dataForm.id = id || 0
62         this.visible = true
63         this.$nextTick(() => {
64           this.$refs['dataForm'].resetFields()
65         })
66         if (id) {
67           this.$http({
68             url: `/iailab-ntt-model/mcs/schedule-user/info/${this.dataForm.id}`,
69             method: 'get',
70             params: this.$http.adornParams()
71           }).then(({data}) => {
72             if (data && data.code === 0) {
73               this.dataForm.username = data.scheduleUser.username
74               this.dataForm.adjuststatus = data.scheduleUser.adjuststatus
75             }
76           })
77         }
78       },
79       // 表单提交
80       dataFormSubmit () {
81         this.$refs['dataForm'].validate((valid) => {
82           if (valid) {
83             this.$http({
84               url: `/iailab-ntt-model/mcs/schedule-user/${!this.dataForm.id ? 'save' : 'update'}`,
85               method: 'post',
86               data: this.$http.adornData({
87                 'id': this.dataForm.id || undefined,
88                 'username': this.dataForm.username,
89                 'adjuststatus': this.dataForm.adjuststatus
90               })
91             }).then(({data}) => {
92               if (data && data.code === 0) {
93                 this.$message({
94                   message: '操作成功',
95                   type: 'success',
96                   duration: 1500,
97                   onClose: () => {
98                     this.visible = false
99                     this.$emit('refreshDataList')
100                   }
101                 })
102               } else {
103                 this.$message.error(data.msg)
104               }
105             })
106           }
107         })
108       }
109     }
110   }
111 </script>
112 <style>
113   .el-select {
114     width: 100%
115   }
116 </style>