<template>
  <div>
    <p class="edit_page_title">{{adminRole_type==='add'?'添加角色':'编辑角色'}}</p>
    <Form
      ref="adminRole"
      :model="adminRole"
      :rules="adminRole_rule"
      :label-width="120"
      class="add-adminrole-form"
      label-position="right"
    >
      <FormItem class="wid_440" label="角色名称：" prop="name">
        <Input v-model="adminRole.name" type="text" placeholder></Input>
      </FormItem>
      <FormItem class="wid_440" label="描述：" prop="summny">
        <Input v-model="adminRole.remark" type="textarea" :autosize="{minRows: 2,maxRows: 5}"></Input>
      </FormItem>
      <!-- <FormItem class="wid_440" label="使用对象：" prop="user_obj">
        <Input v-model="editAdminRole.user_obj" type="text" placeholder></Input>
      </FormItem>
      <FormItem class="wid_440" label="职务：" prop="duty">
        <Input v-model="editAdminRole.duty" type="text" placeholder></Input>
      </FormItem> -->
      <FormItem class="wid_440" label="启用状态：" prop="user_status">
        <RadioGroup v-model="adminRole.status">
          <Radio label="1">开启</Radio>
          <Radio label="0">禁用</Radio>
        </RadioGroup>
      </FormItem>
      <FormItem class="form_btn">
        <Button type="primary" @click="editAdminRoleInfo('adminRole')" >{{adminRole_type==='add'?'添加':'保存'}}</Button>
        <Button class="return_btn mar_L_15" @click="return_last">返回</Button>
      </FormItem>
    </Form>
  </div>
</template>
<script>
export default {
  name: "edit_adminRole",
  props: {
    adminRole_type: String,
    pindex: Number,
    curInfo: Object
  },
  data() {
    return {
      adminRole: {
        status: "1",
        name:'',
        remark:''
      },
      adminRole_rule: {
        name: {
          required: true,
          message: "请输入角色名称",
          trigger: "blur"
        }
      }
    };
  },
  methods: {
    // 修改权限
    editAdminRoleInfo(formname) {
      this.$refs[formname].validate(valid => {
        if (valid) {
          let api =
            this.adminRole_type === "add" ? "addRoleInfo" : "editRoleInfo";
          this.adminRole_type === "add" ?'':this.adminRole.id=this.curInfo.id
          this.$api[api](this.adminRole).then(data => {
            if (data.code === 200) {
              this.$Message.info(data.msg);
              this.$emit("return_last", 1);
            } else {
              this.$Message.info(data.msg);
            }
          });
        }
      });
    },
    // 返回
    return_last() {
      this.$emit("return_last");
    }
  },
  created() {
    if (this.curInfo && this.adminRole_type === "edit") {
      this.adminRole = this.curInfo
      this.adminRole.status = this.curInfo.status.toString()
      // this.editAdminRole.admin_username = this.curInfo.name;
      // this.editAdminRole.summny = this.curInfo.remark;
      // this.editAdminRole.duty = this.curInfo.duty;
      // this.editAdminRole.user_obj = this.curInfo.object;
      // this.editAdminRole.user_status = this.curInfo.status.toString();
    }
  }
};
</script>

