<template>
  <!--  展示员工切换的模块  -->
  <el-dialog :title="titleCon" :close-on-click-modal="false"
               v-drag :visible.sync="visibleFlag" width="300px">
      <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: -5px;">
        <el-form-item :label="'操作员:'">
          <el-input v-model="operatorData.operatorId" style="width: 110px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: -5px;">
        <el-form-item :label="'操作员姓名:'">
          <el-input v-model="operatorData.operatorName" style="width: 110px"></el-input>
        </el-form-item>
      </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="visibleFlag = false">关闭</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:'操作员切换',
      visibleFlag: false,
      operatorFlag: false,
      operatorData: {
        site: this.$store.state.user.site,
        username: this.$store.state.user.name,
        operatorId: '',
        operatorName: '',
        status: ''
      },
    }
  },
  methods: {
    //初始化的
    init() {
      this.visibleFlag = true;
      //刷新当前派工单的信息
      //this.refreshPageData();
    },
    //查询操作员信息
    saveOperatorData() {
      getOperatorData(this.operatorData).then(({data}) => {
        //判断是否存在
        if(!data.row){
          this.$message.error('账号有误!');

        }
        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>
