<template>
  <div class="inline-16">
    <el-button type="primary" size="small" @click="onShow">一键创建账号</el-button>
    <el-dialog
      title="授权角色"
      :visible.sync="drawer"
      width="564px"
      @close="onClose">
      <div>
        <el-row :gutter="50">
          <el-form :model="form" :rules="rules" ref="form"  size="mini" label-position="left">
            <el-col :span="24">
              <el-form-item label="授权角色" label-width="100px" prop="roleids">
                <!-- <el-input v-model="form.sex" autocomplete="off" placeholder="输入性别"></el-input> -->
                <el-select v-model="form.roleids" style="width:100%" placeholder="请选择" multiple>
                  <el-option
                    v-for="item in options"
                    :key="item.index"
                    :label="item.rolename"
                    :value="item.roleid">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
      </div>
      <div class="dialog-footer">
        <el-button size="small" @click="drawer = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="warning" @click="createUser" class="normal-btn-width btn-warning">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

export default {
  data () {
    return {
      drawer:false,
      rules:{
        roleids: [
          { required: true, message: '请选择授权角色', trigger: 'change' }
        ],
      },
      form:{
        "userid": 0,
        "name": "",
        "phonenumber": "",
        "status": 1,
        "remarks":"",
        "roleids":[]
      },
      options:[]
    }
  },
  methods:{
    onShow () {
      console.log(this.data)
      this.drawer = true
      this.rolelist()
    },
    
    async rolelist () {
      let param = {
        "classname": "sysmanage.develop.optiontype.optiontype",
        "method": "optiontypeselect",
        "content": {
            "pageNumber": 1,
            "pageSize": 20,
            "typename": "role",
            "parameter": {
            }
        }
      }
      const res = await this.$api.requested(param)
      this.options = res.data
    },

    createUser () {
      this.$refs['form'].validate(async (valid) => {
        if (!valid) return false
          const res = await this.$api.requested({
          "classname": "webmanage.hr.hr",
          "method": "createUser",
          "content": {
            "hrid":this.$route.query.id,
            "roleids":this.form.roleids
          }
        })
        this.tool.showMessage(res,()=>{
          this.drawer = false
          this.$emit('onSuccess')
        })

      })
    },
    onClose () {
      this.$refs['form'].resetFields()
    }
  }
}

</script>
<style scoped>
.dialog-footer{
  margin-top:32px;
  text-align: center;
}
</style>