<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.EMP_LV ?
            allEmpLevel[userInfo.EMP_LV]['LEVEL_NAME'] : ''}} 前台显示聘级：{{userInfo.SHOW_EMP_LV ?
            allEmpLevel[userInfo.SHOW_EMP_LV]['LEVEL_NAME'] : ''}}
          </el-tag>
        </el-form-item>
        <el-form-item label="是否重置">
          <el-switch v-model="form.isReset"></el-switch>
          <el-tag type="info">选择重置，前台会显示会员实际聘级</el-tag>
        </el-form-item>
        <el-form-item label="前台显示聘级" v-if="!form.isReset">
          <el-select v-model="form.levelId" placeholder="请选择聘级">
            <el-option v-for="(item,key) in allEmpLevel" :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-show-emp-level',
    mounted() {
      this.loading = false
    },
    data() {
      return {
        form: {
          userName: null,
          levelId: null,
          isReset: false,
          remark: null,
        },
        loading: true,
        submitButtonStat: false,
        allEmpLevel: baseInfo.empLevels(),
        userInfo: {
          REAL_NAME: null,
          EMP_LV: null,
          SHOW_EMP_LV: null,
        },
      }
    },
    methods: {
      handleChange() {
        network.getData('user/full-info', {userName: this.form.userName}).then(response => {
          this.userInfo = response
        })
      },
      onSubmit() {
        let thisObj = this
        thisObj.$confirm('是否要修改当前会员前台显示聘级？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          thisObj._handleSubmit()
        }).catch(() => {

        })
      },
      _handleSubmit() {
        this.submitButtonStat = true
        let path = 'user/change-show-emp-level'
        if(this.form.isReset){
            this.form.levelId = null
        }
        network.postData(path, this.form).then(response => {
          this.$message({
            message: response,
            type: 'success'
          })
          this.handleChange()
          this.submitButtonStat = false
          //this.$router.go(-1)
        }).catch(response => {
          this.submitButtonStat = false
        })
      }
    }
  }
</script>

<style scoped>

</style>
