<template>
  <div v-loading="loading">
    <div class="white-box">
      <el-form ref="form" :model="form" label-width="250px" class="form-page">
        <el-form-item label="角色名称">
          <el-input v-model="form.roleName"></el-input>
        </el-form-item>
        <el-form-item label="描述">
          <el-input v-model="form.remark"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" :loading="submitButtonStat" @click="onSubmit">保存</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import network from './../../utils/network'
import tool from './../../utils/tool'

export default {
  name: 'role-add',
  created () {

  },
  mounted () {
    if (this.$route.name === 'admin_role-edit') {
      network.getData('admin/role-edit/' + this.$route.params.id).then(response => {
        this.form.roleName = response.ROLE_NAME
        this.form.remark = response.REMARK
        this.loading = false
      })
    }
  },
  data () {
    return {
      form: {
        roleName:null,
        remark:null,
      },
      loading: false,
      submitButtonStat: false,
    }
  },
  methods: {
    onSubmit () {
      this.submitButtonStat = true
      let path = 'admin/role-add'
      if (this.$route.name === 'admin_role-edit') {
        path = 'admin/role-edit/' + this.$route.params.id
      }
      network.postData(path, this.form).then(response => {
        this.submitButtonStat = false
        this.$message({
          message: response,
          type: 'success'
        })
        this.$router.go(-1)
      }).catch(() => {
        this.submitButtonStat = false
      })
    }
  }
}
</script>

<style scoped>

</style>