<template>
  <div style="display:inline">
    <el-button size="mini" type="primary" icon="el-icon-edit" @click="onShow">编 辑</el-button>
    <el-dialog title="新增角色" width="400px" :visible.sync="dialogFormVisible">
      <el-form :model="form" size="small" label-position="left">
        <el-form-item label="角色名称" label-width="80px">
          <el-input v-model="form.rolename" autocomplete="off" placeholder="输入角色名称"></el-input>
        </el-form-item>
        <el-form-item label="角色描述" label-width="80px">
          <el-input v-model="form.remarks" autocomplete="off" placeholder="输入角色描述"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false" size="small">取 消</el-button>
        <el-button type="primary" @click="onSubmit" size="small">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props:['data'],
  data () {
    return{
      dialogFormVisible:false,
      form:{
        "roleid":0,
        "rolename":"",
        "remarks":""
      }
    }
  },
  methods:{
    onSubmit () {
      this.$api.requested({
         "classname": "webmanage.role.role",
        "method": "insertormodify_role",
        "content": this.form
      }).then(res=>{
        if (res.code === 1) {
          this.$notify({
            title: '成功',
            message: '角色添加成功',
            type: 'success'
          });
          this.$emit('onSuccess')
          this.dialogFormVisible = false
        } else {
          this.$notify({
            title: '失败',
            message: res.data,
            type: 'error'
          });
        }
      })
    },
    onShow () {
      this.form = Object.assign({},this.form,this.data)
      this.dialogFormVisible = true
    }
  }
}

</script>
<style>
</style>