<template>
  <div class="customer-css">
    <el-dialog :title="titleCon" v-drag v-bind="$attrs" v-on="$listeners"
               width="210px" style="height: 680px;" class="customer-dialog">
      <el-form :inline="true" label-position="top" @submit.native.prevent style="height: 60px;"
               label-width="80px">
        <!-- 半成品卷卷号 -->
        <el-row>
          <el-col :span="24" style="margin-left: 35px;">
            <el-form-item :label="'半成品卷卷号:'">
              <el-input ref="newRollNo" v-model="pageData.newRollNo" style="width: 120px;" ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="switchRollBun">确 定</el-button>
        <el-button type="primary" @click="closeDialog">关闭</el-button>
      </span>
    </el-dialog>


  </div>
</template>

<script>
/*添加组件*/
import comExceptionReason from "./com_exception_reason";//异常远远
/*添加js的方法和请求*/
import {
  checkSwitchSfdcRoll,/*校验是否可以切换卷*/
  switchSfdcRoll,/*执行切换卷的操作*/
} from '@/api/yieldReport/com_switch_roll.js'
export default {
  name: "com_merge_roll",
  data() {
    return {
      titleCon: '切换卷',
      scheduleData: {
        site: this.$store.state.user.site,
        username: this.$store.state.user.name,
        seqNo: '',
        orderNo: '',
        itemNo: 0,
        resourceId: '',
        scheduledDate: '',
        shiftNo: '',
        partNo: '',
        workCenterNo: '',
        workCenterDesc: '',
        resourceDesc: '',
        rollNo: '',
        partDesc: '',
        planStartTime: '',
        planFinishTime: '',
        qtyRequiredOriginal: 0,
        preItemDesc: '',
        nextItemDesc: '',
        nextItemNo: 0,
        operatorId: '',
        functionName: '',
        currentRollFlag: false
      },
      pageData: {
        site: this.$store.state.user.site,
        username: this.$store.state.user.name,
        seqNo: '',
        orderNo: '',
        itemNo: '',
        newRollNo: '',
        operatorId: ''
      },
      operatorData: {
        site: this.$store.state.user.site,
        username: this.$store.state.user.name,
        operatorId: '',
        operatorName: '',
        status: '',
        seqNo: '',
        showFlag: false
      },
    }
  },
  components: {
    comExceptionReason,/*异常原因的组件*/
  },
  methods: {
    //页面的初始化的方法
    init(scheduleData, operatorData) {
      //初始化参数
      this.scheduleData = scheduleData;
      //初始化操作员对象
      this.operatorData = JSON.parse(JSON.stringify(operatorData));
      //设置对应的参数
      this.pageData.orderNo = scheduleData.orderNo;
      this.pageData.itemNo = scheduleData.itemNo;
      this.pageData.seqNo = scheduleData.seqNo;
      this.pageData.operatorId = operatorData.operatorId;
      this.pageData.newRollNo = '';
      //自动获取焦点
      this.$nextTick(() => {
        this.$refs.newRollNo.focus();
      });
    },

    /*关闭modal*/
    closeDialog(){
      //刷新报工的页面
      this.$emit('refreshPageData');
      //关闭当前的页面
      this.$emit('update:visible', false);
    },

    switchRollBun() {
      //人员判断
      if (this.pageData.operatorId == '' || this.pageData.operatorId == null) {
        this.$message.error('请先切换人员!');
        return false;
      }
      //首先判断数值是否通过判断
      let newRollNo = this.pageData.newRollNo;
      if (newRollNo == null || newRollNo == '') {
        this.$message.error('请输入半成品卷号!');
        return false;
      }
      //校验是否继续
      checkSwitchSfdcRoll(this.pageData).then(({data}) => {
        //判断是否成功
        if (data.code == 500) {
          this.$message.error(data.msg);
        } else if (data.resultMap.resultCode == '201') {
          //打开异常原因录入的界面
          this.$confirm(data.resultMap.resultMsg, '提示', {
            confirmButtonText: '确认',
            celButtonText: '取消',
            type: 'warning'
          }).then(() => {
            //执行切换卷的操作
            this.switchRollOperation();
          });
        } else { //执行切换卷的操作
          this.switchRollOperation();
        }
      });
    },

    /*执行切换卷的操作*/
    switchRollOperation() {
      //处理信息
      switchSfdcRoll(this.pageData).then(({data}) => {
        //判断操作是否成功
        if (data.code == 500) {
          this.$message.error(data.msg);
        } else {
          //关闭当前的页面
          this.pageData.newRollNo = '';
          this.closeDialog();
        }
      })
    },
  },
  created() {
    // this.factoryList()
    // this.getLanguageList()
  }
}

</script>

<style scoped lang="scss">
/*调节页面button和input的上下间距*/
.customer-css .customer-button{
  margin-top: 25px;
}

/*调节fieldset下的样式*/
.customer-fieldset .customer-item{
  margin-top: -15px;
}

/*fieldset下table的样式*/
.customer-fieldset /deep/ .el-table__header th.is-leaf{
  line-height: 16px;
}

/deep/ .customer-tab .el-tabs__content{
  padding: 0px !important;
}

</style>
