<template>
  <el-dialog title="角色信息" @close="$emit('close')" :visible="show">
    <el-form :model="form" :rules="rules" ref="roleForm">
      <el-form-item
        label="角色名称："
        :label-width="formLabelWidth"
        prop="roleName"
      >
        <el-input placeholder="请输入角色名称" v-model="form.roleName" :maxlength="INPUTLENGTH" show-word-limit>
        </el-input>
      </el-form-item>
      <el-form-item
        label="职能描述："
        :label-width="formLabelWidth"
        prop="roleDesc"
      >
        <el-input
          type="textarea"
          :autosize="{ minRows: 2, maxRows: 4 }"
          placeholder="请输入职能描述"
          :maxlength="INPUTLENGTH*10" show-word-limit
          v-model="form.roleDesc"
        >
        </el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="$emit('close')">取 消</el-button>
      <el-button type="primary" @click="saveRole">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { saveSys } from "@/configue/api";
let rules = {
  roleName: [{ required: true, message: "请输入角色名称", trigger: "blur" }],
  roleDesc: [{ required: true, message: "请输入职能描述", trigger: "blur" }],
};
export default {
  props: {
    show: {
      type: Boolean,
    },
    form: Object,
  },
  data() {
    return {
      formLabelWidth: "100px",
      rules,
    };
  },
  methods: {
    saveRole() {
      this.$refs.roleForm.validate((valid) => {
        if (valid) {
          let params = {
            resources: [],
            roleDesc: "",
            roleKey: "",
            roleName: "",
            ...this.form,
          };
          saveSys("role", params, () => {
            this.$alert("操作成功", "提示", {
              confirmButtonText: "确定",
              callback: () => {
                this.$emit("close", true);
              },
            });
          });
        }
      });
    },
  },
};
</script>
