<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.levelName"></el-input>
        </el-form-item>
        <el-form-item label="所需业绩">
          <el-input v-model="form.perf"></el-input>
        </el-form-item>
        <!--<el-form-item label="是否可以调整礼包">-->
          <!--<el-switch v-model="form.isAdjustGift"></el-switch>-->
        <!--</el-form-item>-->
        <!--<el-form-item label="是否可以报单">-->
          <!--<el-switch v-model="form.isDec"></el-switch>-->
        <!--</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-level-edit',
  created () {

  },
  mounted () {
    if (this.$route.name === 'config_dec-level-edit') {
      network.getData('config/dec-level-edit/' + this.$route.params.id).then(response => {
        this.form.levelName = response.LEVEL_NAME
        this.form.perf = response.PERF
        this.form.isAdjustGift = response.IS_ADJUST_GIFT === '1' ? true : false
        this.form.isDec = response.IS_DEC === '1' ? true : false
        this.loading = false
      })
    } else {
      this.loading = false
    }
  },
  data () {
    return {
      form: {
        levelName: '',
        perf: '',
        isAdjustGift: true,
        isDec: '',
      },
      loading: true,
      submitButtonStat: false
    }
  },
  methods: {
    onSubmit () {
      this.submitButtonStat = true
      let path = 'config/dec-level-add'
      if (this.$route.name === 'config_dec-level-edit') {
        path = 'config/dec-level-edit/' + this.$route.params.id
      }
      network.postData(path, {
        levelName: this.form.levelName,
        perf: this.form.perf,
        isAdjustGift: this.form.isAdjustGift ? 1 : 0,
        isDec: this.form.isDec ? 1 : 0,
      }).then(response => {
        this.submitButtonStat = false
        this.$message({
          message: response,
          type: 'success'
        })
        this.$router.go(-1)
      }).catch(response => {
        this.submitButtonStat = false
      })
    }
  }
}
</script>

<style scoped>

</style>