<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.periodNum" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="会员编号">
          <el-input v-model="form.userName" @change="handleChange"></el-input>
        </el-form-item>
        <el-form-item label="会员姓名" v-show="userInfo.REAL_NAME!==null">
          <el-input :value="userInfo.REAL_NAME" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="一市场总网业绩" v-show="userInfo.REAL_NAME!==null">
          <el-input :value="userInfo.PV_1L" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="二市场总网业绩" v-show="userInfo.REAL_NAME!==null">
          <el-input :value="userInfo.PV_2L" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="三市场总网业绩" v-show="userInfo.REAL_NAME!==null">
          <el-input :value="userInfo.PV_3L" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="四市场总网业绩" v-show="userInfo.REAL_NAME!==null">
          <el-input :value="userInfo.PV_4L" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="五市场总网业绩" v-show="userInfo.REAL_NAME!==null">
          <el-input :value="userInfo.PV_5L" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="一市场结余业绩" v-show="userInfo.REAL_NAME!==null">
          <el-input :value="userInfo.SURPLUS_1L" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="二市场结余业绩" v-show="userInfo.REAL_NAME!==null">
          <el-input :value="userInfo.SURPLUS_2L" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="三市场结余业绩" v-show="userInfo.REAL_NAME!==null">
          <el-input :value="userInfo.SURPLUS_3L" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="四市场结余业绩" v-show="userInfo.REAL_NAME!==null">
          <el-input :value="userInfo.SURPLUS_4L" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="五市场结余业绩" v-show="userInfo.REAL_NAME!==null">
          <el-input :value="userInfo.SURPLUS_5L" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="虚拟零售区结余业绩" v-show="userInfo.REAL_NAME!==null">
          <el-input :value="userInfo.SURPLUS_LS" :disabled="true"></el-input>
        </el-form-item>

        <el-form-item label="调整类型">
          <el-select v-model="form.perfType" @change="handlePerfTypeChange">
            <el-option label="总网业绩" :value="1"></el-option>
            <el-option label="大区结余" :value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="调整市场" v-if="form.perfType===1">
          <el-select v-model="form.location">
            <el-option label="一市场" :value="1"></el-option>
            <el-option label="二市场" :value="2"></el-option>
            <el-option label="三市场" :value="3"></el-option>
            <el-option label="四市场" :value="4"></el-option>
            <el-option label="五市场" :value="5"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="调整市场" v-if="form.perfType===2">
          <el-select v-model="form.location">
            <el-option label="一市场结余" :value="1"></el-option>
            <el-option label="二市场结余" :value="2"></el-option>
            <el-option label="三市场结余" :value="3"></el-option>
            <el-option label="四市场结余" :value="4"></el-option>
            <el-option label="五市场结余" :value="5"></el-option>
            <el-option label="虚拟零售区结余" :value="6"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="调整数额">
          <el-input v-model="form.amount"></el-input>
        </el-form-item>
        <el-form-item label="备注">
          <el-input type="textarea" :row="2" placeholder="请输入内容" v-model="form.remark"></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 store from '@/utils/vuexStore'
import network from '@/utils/network'
import tool from '@/utils/tool'

export default {
  name: 'user_perf-apply',
  created () {

  },
  mounted () {
    this.getData()
  },
  data () {
    return {
      form: {
        periodNum: '',
        userName: '',
        perfType: 1,
        location: 1,
        amount: null,
        remark: null,
      },
      userInfo: {
        REAL_NAME: null,
        PV_1L: null,
        PV_2L: null,
        PV_3L: null,
        PV_4L: null,
        PV_5L: null,
        SURPLUS_1L: null,
        SURPLUS_2L: null,
        SURPLUS_3L: null,
        SURPLUS_4L: null,
        SURPLUS_5L: null,
      },
      types: null,
      apps: null,
      closeSwitch: null,
      loading: true,
      submitButtonStat: false,
    }
  },
  methods: {
    handlePerfTypeChange(){
      this.form.location = 1;
    },
    getData(){
      network.getData('finance/perf-apply').then(response => {
        this.form.periodNum = response.periodNum
        this.loading=false
      }).catch(response => {
        this.loading=false
      })
    },
    handleChange() {
      if(this.form.userName===''){
        return false
      }
      this.loading=true
      network.getData('finance/perf-apply-get', {userName: this.form.userName}).then(response => {
        this.userInfo = response
        this.loading=false
      }).catch(response => {
        this.loading=false
      })
    },
    onSubmit () {
      this.submitButtonStat = true
      let path = 'finance/perf-apply'
      network.postData(path, this.form).then(response => {
        this.$message({
          message: response,
          type: 'success'
        })
        this.$router.back()
        this.submitButtonStat = false
      }).catch(response => {
        this.submitButtonStat = false
      })
    },
  }
}
</script>

<style scoped>

</style>