<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.userName" @change="chkUserName" :readonly="userNameReadOnly"></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="调整类型">
          <el-select v-model="form.type" placeholder="调整类型">
            <el-option label="调整积分余额" :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}}BV</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 label="备注前台显示">
          <el-switch v-model="form.isShow" active-value="1" inactive-value="0">
          </el-switch>
        </el-form-item>
        <el-form-item label="">
          <el-tag type="info">此操作仅调整余额，不作为复销活跃资格依据</el-tag>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit" :loading="submitButtonStat">Submit<!-- 提交 --></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: 'reconsume_change-audit-add',
    mounted() {
      this.getData()
    },
    data() {
      return {
        form: {
          userName: null,
          type: 0,
          changeAmount: null,
          remark: null,
          isShow: '1',
        },
        balance: {
          unusedPV: 0,
          unusedMonth: 0,
        },
        userInfo: {
          REAL_NAME: null,
        },
        loading: true,
        submitButtonStat: false,
        userNameReadOnly: false,
      }
    },
    methods: {
      onSubmit() {
        this.submitButtonStat = true
        let path = 'reconsume/change-audit-add'
        network.postData(path, this.form).then(response => {
          this.$message({
            message: response,
            type: 'success'
          })
          this.submitButtonStat = false
          this.$router.push({path:`/reconsume/pool-list`})
        }).catch(response => {
          this.submitButtonStat = false
        })
      },
      getData() {
        this.$message({
          message: '正在获取数据，请稍后',
        })
        if(this.form.userName = this.$route.params.userName) {
          this.userNameReadOnly = true
          this.chkUserName()
        }else{
          this.loading = false
        }
      },
      chkUserName(){
        if (this.form.userName !== null && this.form.userName !== '') {
          network.getData('user/full-info', {userName: this.form.userName}).then(response => {
            this.userInfo = response
            network.getData('reconsume/change-audit-add', {userName: this.form.userName}).then(response => {
              this.balance = response
              this.loading = false
            })
            this.loading = false
          }).catch(response => {
            this.loading = false
          })
        }
      }
    }
  }
</script>

<style scoped>

</style>
