<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="handleChange"></el-input>
          <el-tag v-show="userInfo.REAL_NAME!==null">会员姓名：{{userInfo.REAL_NAME}} 当前级别：{{userInfo.LEVEL_NAME}}
          </el-tag>
        </el-form-item>
        <!--<el-form-item label="期数">-->
          <!--<el-select v-model="form.periodNum">-->
            <!--<el-option v-for="(item,key) in periodArr" :value="item"-->
                       <!--:key="key"></el-option>-->
          <!--</el-select>-->
        <!--</el-form-item>-->
        <el-form-item label="报单级别">
          <el-select v-model="form.levelId" placeholder="请选择报单级别">
            <el-option v-for="(item,key) in allDecLevel" :label="item.LEVEL_NAME" :value="item.ID"
                       :key="key"></el-option>
          </el-select>
        </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 store from '@/utils/vuexStore'
  import network from '@/utils/network'
  import tool from '@/utils/tool'
  import baseInfo from '../../utils/baseInfo'

  export default {
    name: 'user_change-user-dec-level',
    mounted() {
      this.loading = false
      //this.getPeriodNum()
    },
    data() {
      return {
        form: {
          userName: null,
          periodNum: null,
          levelId: null,
          remark: null,
        },
        loading: true,
        submitButtonStat: false,
        allDecLevel: baseInfo.decLevels(),
        periodArr: [],
        userInfo: {
          REAL_NAME: null,
          DEC_LV: null,
        },
      }
    },
    methods: {
      // getPeriodNum() {
      //   this.loading = true
      //   network.getData('user/get-period-num').then(response => {
      //     this.periodArr = response
      //     this.form.periodNum = response[0]
      //     this.loading = false
      //   }).catch(response => {
      //     this.loading = false
      //   })
      // },
      handleChange() {
        network.getData('user/full-info', {userName: this.form.userName}).then(response => {
          this.userInfo = response
        }).catch(response => {

        })
      },
      onSubmit() {
        let thisObj = this
        thisObj.$confirm('是否要修改当前会员级别？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          thisObj._handleSubmit()
        }).catch(() => {

        })
      },
      _handleSubmit() {
        this.submitButtonStat = true
        let path = 'user/change-user-dec-level'
        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
        })
        this._clearData()
      },
      _clearData(){
        this.form = {
          userName: null,
          periodNum: null,
          levelId: null,
          remark: null,
        }
        this.userInfo= {
          REAL_NAME: null,
          DEC_LV: null,
        }
      }
    }
  }
</script>

<style scoped>

</style>
