<template>
  <div v-loading="loading">
    <div class="white-box">
      <el-form ref="form" :model="form" label-width="150px" style="width:500px;">
        <el-form-item label="报单级别名称">
          <el-input v-model="form.roleName"></el-input>
        </el-form-item>
        <el-form-item label="服务费(%)">
          <el-input v-model="form.fwBonusPercent"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit" :loading="submitButtonStat">保存</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: 'dec-role-edit',
  created () {

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

<style scoped>

</style>
