<template>
  <div>
    <el-button size="mini" type="default" @click="editBtn">编 辑</el-button>
    <el-drawer
      title="编辑角色"
      :visible.sync="drawer"
      append-to-body
      size="30%"
      direction="rtl">
      <div class="drawer__panel">
        <div>
          <el-row>
            <el-form :inline="true" :model="form" :rules="rules" ref="form" size="small" label-width="100px" label-position="right" class="demo-form-inline">
              <el-col :span="24">
                <el-form-item label="角色名称" prop="rolename">
                  <el-input v-model="form.rolename" placeholder="输入角色名称"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="角色描述" prop="remarks">
                  <el-input v-model="form.remarks" placeholder="输入角色描述"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="角色类型" prop="usertype">
                  <el-select v-model="form.usertype" placeholder="角色类型">
                    <el-option v-for="item in options" :key="item.index" :label="item.remarks" :value="Number(item.value)"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-form>
          </el-row>
        </div>
      </div>
      <div class="fixed__btn__panel">
        <el-button size="small" @click="drawer = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="primary" @click="onSubmit" class="normal-btn-width">确 定</el-button>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import roleContentTemp from './roleContent copy.vue'
export default {
  data () {
    return{
      dialogFormVisible:false,
      drawer:false,
      options:[],
      form:{
        "roleid":0,
        "rolename":"",
        "remarks":"",
        "usertype":""
      },
      rules:{
        rolename: [
          { required: true, message: '请输入角色名称', trigger: 'blur' },
        ],
        remarks: [
          { required: true, message: '请输入角色描述', trigger: 'blur' },
        ],
        usertype: [
          { required: true, message: '请选择角色类型', trigger: 'change' }
        ],
      },
    }
  },
  props:['data'],
  components:{
    roleContentTemp
  },
  created () {
    this.usertype()
  },
  methods:{
    editBtn () {
      this.drawer = true
      this.form = Object.assign({},this.form,this.data)
    },
    onSuccess () {
      this.drawer = false
      this.$emit('onSuccess')
    },
    async usertype () {
      let param = {
        "classname": "sysmanage.develop.optiontype.optiontype",
        "method": "optiontypeselect",
        "content": {
            "pageNumber": 1,
            "pageSize": 20,
            "typename": "usertype",
            "parameter": {
            }
        }
      }
      const res = await this.$api.requested(param)
      this.options = res.data
    },
    onSubmit () {
      this.$refs['form'].validate((valid) => {
        if (!valid) return false
        this.$api.requested({
          "classname": "webmanage.role.role",
          "method": "insertormodify_role",
          "content": this.form
        }).then(res=>{
          this.tool.showMessage(res,()=>{
            this.drawer = false
            this.$emit('onSuccess')
          })
        })
      })
    },
  }
}

</script>
<style scoped>
/deep/.el-form-item,.el-select {
  width: 100% !important;
}
/deep/.el-form-item__content {
  width: calc(100% - 100px);
}
</style>