<template>
  <div v-loading="loading">
    <div class="white-box">
      <el-form ref="form" :model="form" label-width="100px" style="width:500px;">
        <el-form-item label="会员编号">
          <el-input v-model="form.userName" @change="getData"></el-input>
        </el-form-item>
        <el-form-item label="调整类型">
          <el-select v-model="form.type" placeholder="调整类型">
            <el-option label="调整余额PV" :value="0"></el-option>
            <el-option label="调整剩余月数" :value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="form.type === 0 ? '调整额度' : '调整月数'">
          <el-input v-model="form.changeAmount"></el-input>
          <template>
            <el-tag v-if="form.type === 0" type="success">可用余额：{{balance.unusedPV}}PV</el-tag>
            <el-tag v-if="form.type === 1" type="success">可用月数：{{balance.unusedMonth}}</el-tag>
          </template>

        </el-form-item>
        <el-form-item label="备注">
          <el-input type="textarea" :rows="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_re-consume-audit-add',
  mounted () {
    this.getData()
  },
  data () {
    return {
      form: {
        userName: null,
        type: 0,
        changeAmount: null,
        remark: null,
      },
      balance: {
        unusedPV: 0,
        unusedMonth: 0,
      },
      loading: true,
      submitButtonStat: false,
    }
  },
  methods: {
    onSubmit () {
      this.submitButtonStat = true
      let path = 'user/re-consume-audit-add'
      network.postData(path, this.form).then(response => {
        this.$message({
          message: response,
          type: 'success'
        })
        this.submitButtonStat = false
        this.$router.go(-1)
      }).catch(response => {
        this.submitButtonStat = false
      })
    },
    getData(){
      if(this.form.userName !== null && this.form.userName !== ''){
        network.getData('user/re-consume-audit-add', {userName: this.form.userName}).then(response => {
          this.balance = response
          this.loading = false
        })
      } else {
        this.loading = false
      }
    },
  }
}
</script>

<style scoped>

</style>