<template>
  <div class="wrapper editwrap">
    <el-dialog
      :visible.sync="dialogVisible"
      :title="title"
      :show-close="false"
      :close-on-click-modal="false"
    >
      <el-form ref="editForm" :model="editForm" :rules="rules" label-width="100px">
        <el-form-item label="角色名称" prop="roleName">
          <el-input v-model="editForm.roleName"></el-input>
        </el-form-item>
        <el-form-item label="角色代码" prop="roleCode">
          <el-input v-model="editForm.roleCode"></el-input>
        </el-form-item>
        <el-form-item label="描述" prop="description">
          <el-input v-model="editForm.description"></el-input>
        </el-form-item>
        <el-form-item label="角色状态" prop="roleStatus">
          <el-switch 
          v-model="editForm.roleStatus"
          active-value="1"
          active-text="已禁用"
          inactive-value="0"
          inactive-text="已启用"
          active-color='#c74343'
          ></el-switch>
        </el-form-item>
        <el-form-item label="排序" prop="sort">
          <el-input v-model="editForm.sort" type="number"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" size="small" @click="confirmFun('editForm')">确定</el-button>
        <el-button @click="$emit('dialogFun')" size="small">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<style lang="scss">
</style>
<script lang="ts">
import { Component, Vue, Provide, Prop, Watch } from "vue-property-decorator";
// import { State, Getter, Mutation, Action } from "vuex-class";

@Component({
  components: { }
})
export default class RoleMgEdit extends Vue {
  //属性或参数中使用!:表示强制解析（告诉typescript编译器，这里一定有值），常用于vue-decorator中的@Prop
  @Prop(Boolean) dialogVisible!: Boolean;

  @Prop(Object) editForm!: {
    roleStatus:string;
  };
  @Prop(String) title!: String;

  @Provide() dialogTableVisible: Boolean = false;

  @Provide() rules: any = {
    roleName: [{ required: true, trigger: "blur", message: "该项为必填项！" }],
    roleCode: [{ required: true, trigger: "blur", message: "该项为必填项！" }]
  };

  @Provide() loadmap:Boolean = false;

  //取消事件要在父级取消是所以用到 $emit
  confirmFun(formName: string) {
    let that = this,params = Object.assign({}, that.editForm);
    (that as any).$refs[formName].validate((valid: boolean) => {
      if (valid) {
        (that as any).$axios
          .post(`/role/addOrEditRoleInfo`,params )
          .then((res: any) => {
            if( res.code == 0 ){
              (that as any).$emit("dialogFun");
              (that as any).$message({
                message: "操作成功！",
                type: "success"
              });
              that.$emit("refreshTableData"); //刷新表格
            }
          });
      } else {
        return false;
      }
    });
  }
  created() {
    
  }
}
</script>
