<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}} 当前级别：{{allDecRole[userInfo.DEC_ROLE_ID] ?
            allDecRole[userInfo.DEC_ROLE_ID]['ROLE_NAME'] : ''}}
          </el-tag>
        </el-form-item>
        <el-form-item label="报单中心级别">
          <el-select v-model="form.levelId" placeholder="请选择报单中心级别">
            <el-option v-for="(item,key) in allDecRole" :label="item.ROLE_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-role',
    mounted() {
      this.loading = false
    },
    data() {
      return {
        form: {
          userName: null,
          levelId: null,
          remark: null,
        },
        loading: true,
        submitButtonStat: false,
        allDecRole: baseInfo.decRoles(),
        periodArr: [],
        userInfo: {
          REAL_NAME: null,
          DEC_ROLE_ID: 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-user-dec-role'
        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,
          levelId: null,
          remark: null,
        }
        this.userInfo= {
          REAL_NAME: null,
          DEC_ROLE_ID: null,
        }
      }
    }
  }
</script>

<style scoped>

</style>
