<template>
  <div class="app-container" style="margin-left: 500px;width: 1000px" >
    <el-form :model="userParams" label-width="68px" ref="queryForm" :inline="true" label-position="left" style="margin-left: 100px">

      <el-row style="width: 900px">
        <el-col :span="24">
          <el-form-item>
            <el-input
            v-model="userParams.phone"
            placeholder="请输入手机号"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
            >
              <template slot="prepend">手机号:</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24"> <el-form-item>

          <el-input
          v-model="userParams.realName"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        >
            <template slot="prepend"> 姓名：</template>
          </el-input>
        </el-form-item></el-col>
        <el-col :span="24"> <el-form-item>
        <el-input
          v-model="userParams.serverAge"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        >
          <template slot="prepend">  工龄：</template>
        </el-input>
        </el-form-item></el-col>
        <el-col :span="24"> <el-form-item>
          等级：
          <el-select v-model="userParams.serverLevel" placeholder="请选择 " clearable size="small" >
            <el-option
              v-for="item in serverLevelOptions"
              :key="item.label"
              :label="item.label"
              :value="item.value">
            </el-option>
        </el-select>
        </el-form-item></el-col>
        <el-col  :span="24">
          <el-form-item>
            个人简介：
            <el-input
              type="textarea"
              :rows="20"
              placeholder="请输入内容"
              v-model="userParams.desc">
            </el-input>
          </el-form-item>
        </el-col>

        <el-col>
          <el-button @click="add()">保存</el-button>
        </el-col>


      </el-row>
    </el-form>
  </div>

</template>

<script>

  import { updateUser } from '../../../api/system/ServiceUserService'
  import { addUser } from '../../../api/system/ServiceUserService'

  export default {
    name: 'ServicePeopleAdd',
    data(){
      return{
        userParams:{
          phone:null,
          realName:null,
          serverAge:null,
          serverLevel:null,
          desc:null,
          serverId:null
        },
        serverLevelOptions:[]
      }
    },
    created(){
      if(this.$route.query.selfInfo!==undefined){
        this.userParams.serverId=this.$route.query.selfInfo.serverId
        this.userParams.phone=this.$route.query.selfInfo.phone;
        this.userParams.realName=this.$route.query.selfInfo.realName;
        this.userParams.serverAge=this.$route.query.selfInfo.serverAge;
        this.userParams.serverLevel=this.$route.query.selfInfo.serverLevel;
        this.userParams.desc=this.$route.query.selfInfo.desc;
      }
      this.serverLevelOptions = this.$store.state.dict.data['007'];
    },
    methods:{
      add(){

        for(let j in this.serverLevelOptions){
          if(this.userParams.serverLevel==this.serverLevelOptions[j].label){
            this.userParams.serverLevel=this.serverLevelOptions[j].value
          }

        }



        if(this.userParams.serverId!==null){
          updateUser(this.userParams).then(res=>{
            this.$modal.msgSuccess("修改成功");
          })
        }
        else{
          addUser(this.userParams).then(res=>{

          })
        }

      }
    },
  }
</script>

<style scoped>

</style>
