<template>
  <div class="customer-css">
    <el-dialog :title="titleCon" v-drag v-bind="$attrs" v-on="$listeners"
               width="270px" style="height: 680px;" class="customer-dialog">
      <el-form :inline="true" label-position="top" style="height: 100px;"
               label-width="80px">
        <!-- 时间 -->
        <el-row style="margin-top: -10px;">
          <el-col :span="8">
            <el-form-item :label="'当前时间:'">
              <el-date-picker style="width: 100px;"
                              v-model="pageData.reportDate"
                              format="yyyy-MM-dd"
                              value-format="yyyy-MM-dd"
                              placeholder="">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8" style="margin-left: 20px; margin-top: 27px;">
            <el-form-item :label="''">
              <el-form-item :label="''">
                <el-time-picker style="width: 80px;"
                                v-model="pageData.reportTime"
                                format="HH:mm:ss"
                                value-format="HH:mm:ss"
                                placeholder="">
                </el-time-picker>
              </el-form-item>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 半成品卷卷号 -->
        <el-row>
          <el-col :span="12" style="margin-top: -5px;">
            <el-form-item :label="'良品数量:'">
              <el-input ref="rollQty" v-model="pageData.rollQty" style="width: 120px;" ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" style="margin-top: -5px;">
            <el-form-item :label="'卷数:'">
              <el-input v-model="pageData.rollNums" 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="">确 定</el-button>
        <el-button type="primary" @click="closeDialog">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import {
    checkCreateSplitSfdcRoll,/*校验是否可以创建分卷*/
    createSplitSfdcRoll,/*执行创建分卷的操作*/
  } from '@/api/yieldReport/com_separate_roll.js'
export default {
  name: "com_separate_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,
        orderNo: '',
        itemNo: '',
        seqNo: '',
        rollNo: '',
        reportDate: '',
        reportTime: '',
        rollQty: 0,
        rollNums: 1
      },
      operatorData: {
        site: this.$store.state.user.site,
        username: this.$store.state.user.name,
        operatorId: '',
        operatorName: '',
        status: '',
        seqNo: '',
        showFlag: false
      },
    }
  },
  methods: {
    //页面初始化是的方法
    init(scheduleData, operatorData) {
      //初始化参数
      this.scheduleData = scheduleData;
      //初始化操作员对象
      this.operatorData = JSON.parse(JSON.stringify(operatorData));
      //重置时间
      this.pageData.reportDate = this.dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss');
      this.pageData.reportTime = this.dayjs(new Date()).format('HH:mm:ss');
      //设置参数
      this.pageData.orderNo = scheduleData.orderNo;
      this.pageData.itemNo = scheduleData.itemNo;
      this.pageData.seqNo = scheduleData.seqNo;
      this.pageData.rollNo = scheduleData.rollNo;
      //清空参数
      this.pageData.rollQty = 0;
      this.pageData.rollNums = 1;
      //获取焦点
      this.$nextTick(() => {
        this.$refs.rollQty.focus();
      });
    },

    /*关闭modal*/
    closeDialog(){
      this.$emit('update:visible', false);
    },

    /*检查材料卷号的数据*/
    checkValidQty() {
      //获取当前是的数量
      let rollQty = this.pageData.rollQty;
      //判断是否可以修改
      if (rollQty <= 0 || !Number.isInteger(rollQty)){
        this.$message.error('良品数量必须是正整数!');
        return false;
      }
    },

    /*检查材料卷号的数据*/
    checkRollNums() {
      //获取当前是的数量
      let rollNums = this.pageData.rollNums;
      //判断是否是正整数
      if (rollNums <= 0 || !Number.isInteger(rollNums)){
        this.$message.error('卷数必须是正整数!');
        return false;
      }
    },

    checkCreateSeparateRolllBun() {
      //人员判断
      if (this.pageData.operatorId == '' || this.pageData.operatorId == null) {
        this.$message.error('请先切换人员!');
        return false;
      }

      //获取当前是的数量
      let rollQty = this.pageData.rollQty;
      //判断是否可以修改
      if (rollQty <= 0 || !Number.isInteger(rollQty)){
        this.$message.error('良品数量必须大于零且是整数!');
        return false;
      }

      //获取当前是的数量
      let rollNums = this.pageData.rollNums;
      //判断是否是正整数
      if (rollNums <= 0 || !Number.isInteger(rollNums)){
        this.$message.error('卷数必须大于零且是整数!');
        return false;
      }
      //校验是否继续
      checkCreateSplitSfdcRoll(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.createSeparateRolllOperation();
          });
        } else { //执行切换卷的操作
          this.createSeparateRolllOperation();
        }
      });
    },

    /*执行创建分卷的操作*/
    createSeparateRolllOperation() {
      //处理信息
      createSplitSfdcRoll(this.pageData).then(({data}) => {
        //判断操作是否成功
        if (data.code == 500) {
          this.$message.error(data.msg);
        } else {
          //刷新报工的页面
          this.$emit('refreshPageData');
          //关闭当前的页面
          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>
