123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <template>
- <el-dialog
- :title="dialogTitle"
- v-model="dialogVisible"
- width="400px"
- @close="closeDialog(0)"
- @open="open"
- >
- <el-form
- ref="formInfo"
- :model="form"
- class="demo-form-inline"
- label-width="100px"
- :rules="rules"
- >
- <el-form-item label="分组名称:" prop="watchName">
- <el-input v-model="form.watchName" ></el-input>
- </el-form-item>
-
- <div style="text-align: right">
- <el-button type="primary" @click="submitForm('formInfo')"
- >保存</el-button
- >
- </div>
- </el-form>
- </el-dialog>
- </template>
- <script>
- export default {
- name: "AddGroupCom",
- props: {
- dialogTitle: {
- type: String,
- default: "新建分组",
- },
- itemInfo: {
- type: Object,
- default: function () {
- return {};
- },
- },
- },
- data() {
- return {
- checked: true,
- showDialog: false,
- formInfo: JSON.parse(JSON.stringify(this.itemInfo)),
- rules: {
- watchName: [
- // required 是否为必填项, trigger:表单验证的触发时机,失去焦点进行验证
- { required: true, message: "请输入分组名称", trigger: "blur" },
- {
- min: 3,
- max: 6,
- message: "用户名长度在 3 到 6 个字符",
- trigger: "blur",
- },
- ],
- },
- };
- },
- methods: {
- roleValid(rule, value, callback) {
- if (value.length === 0) {
- callback(new Error("不能为空"));
- } else {
- callback();
- }
- },
- // 保存操作
- submitForm(formName) {
- const params = Object.assign(this.formInfo, {});
- params
- this.$refs[formName].validate((valid) => {
- if (valid) {
- // 走保存请求
- this.$message({
- message: "操作成功!",
- type: "success",
- });
- this.closeDialog(1);
- } else {
- return false;
- }
- });
- },
- // 关闭弹框
- closeDialog(flag) {
- this.$refs["formInfo"].resetFields();
- this.showDialog = false;
- this.$emit("closeDialog", flag);
- },
- },
- };
- </script>
-
- <style scoped lang="scss">
- </style>
|