<template>
  <el-dialog
    title="权限配置"
    :visible.sync="dialogVisible"
    width="500px"
    @closed="closedHandler"
    :close-on-click-modal="false"
  >
    <el-form
      ref="dataForm"
      :model="dataForm"
      size="small"
      label-width="150px"
      :rules="rules"
    >
      <el-form-item
        label="角色类型："
        prop="roleId"
      >
        <el-radio-group
          class="radio-group-type1"
          v-model="dataForm.roleId"
        >
          <el-radio :label="1">管理员</el-radio>
          <el-radio :label="2">机构用户</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <span
      slot="footer"
      class="dialog-footer"
    >
      <el-button
        size="small"
        @click="dialogVisible = false"
      >取 消</el-button>
      <el-button
        type="primary"
        size="small"
        @click="submitForm()"
      >确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { updateInsideRole } from '@/api/user'
export default {
  data() {
    return {
      dialogVisible: false,
      dataForm: {
        roleId: ''
      },
      rules: {
        roleId: [
          { required: true, message: '请选择角色类型' },
        ]
      }
    }
  },
  mounted() {

  },
  methods: {
    init(userId, roleId) {
      this.dialogVisible = true
      this.dataForm.roleId = roleId
      this.dataForm.userId = userId
    },
    submitForm() {
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          const params = {
            ...this.dataForm
          }
          updateInsideRole(params).then(res => {
            if (res.msg === 201) {
              this.dialogVisible = false
              this.$message.success('配置成功')
              this.$emit('subsucc')
            } else {
              this.$message.error(res.content)
            }
          })
        }
      })
    },
    closedHandler() {
      this.$refs.dataForm.resetFields()
    }
  }
}
</script>

<style>
</style>