<template>
  <!--  展示员工切换的模块  -->
  <el-dialog :title="titleCon" v-bind="$attrs" v-on="$listeners"  width="280px">
      <el-form :inline="true" @submit.native.prevent label-position="top" label-width="100px" style="margin-top: -5px;">
        <el-row>
          <el-form-item :label="'操作员:'">
            <el-input ref="operatorId" @keyup.enter.native="saveOperatorData"
                      v-model="operatorData.operatorId"
                      style="width: 110px">
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item :label="'操作员姓名:'">
            <el-input v-model="operatorData.operatorName" style="width: 110px"></el-input>
          </el-form-item>
        </el-row>
      </el-form>
      <el-form :inline="true" label-position="top" label-width="100px"
               style="margin-left: 180px; margin-top: -80px; width: 60px;">
        <el-form-item label="">
          <el-button type="primary">列表</el-button>
        </el-form-item>
        <el-form-item label="" style="margin-top: 10px; margin-bottom: 0px;">
          <el-button type="primary" @click="saveOperatorData">保存</el-button>
        </el-form-item>
        <el-form-item label="" style="margin-top: 15px; margin-bottom: 5px;">
          <el-button type="primary" @click="closeDialog">关闭</el-button>
        </el-form-item>

      </el-form>
    </el-dialog>
</template>

<script>
import {
  getOperatorData,
} from '@/api/yieldReport/produce_order.js'
export default {
  name: "com_switch_operator",
  data() {
    return {
      titleCon:'操作员切换',
      operatorFlag: false,
      operatorData: {
        site: this.$store.state.user.site,
        username: this.$store.state.user.name,
        operatorId: '',
        operatorName: '',
        status: ''
      },
    }
  },
  methods: {

    /*关闭modal*/
    closeDialog(){
      //调用不初始化用户的方法
      this.$emit('notInitOperatorData');
      //关闭组件
      this.$emit('update:visible', false);
    },

    //初始化的
    init() {
      //删除操作的信息
      this.operatorData.operatorName = '';
      this.operatorData.operatorId = '';
      //自动获取焦点
      this.$nextTick(() => {
        this.$refs.operatorId.focus();
      });
      //刷新当前派工单的信息
      //this.refreshPageData();
    },
    //查询操作员信息
    saveOperatorData() {
      getOperatorData(this.operatorData).then(({data}) => {
        //判断是否存在
        if(!data.row){
          this.$message.error('账号有误!');
          return false;
        }
        let status = data.row.status;
        this.operatorData.operatorName = data.row.operatorName;
        //重置操作员信息状态
        this.operatorData.status = status;
        //判断是否验证通过
        if (status == 'N') {
          this.operatorFlag = false;
        } else {
          this.operatorFlag = true;
        }
        if (!this.operatorFlag) {
          this.$message.error('操作员信息不可用!');
        }
      })
      //检查是否通过  不通过报错  通过继续
      .then(() => {
        this.visibleFlag = false;
        this.$emit('initOperatorData', this.operatorData)
      });
    },
  },
  created() {
  }
}
</script>

<style scoped lang="scss">
</style>
