<template>
  <div class="customer-css">
    <el-dialog :title="titleCon" v-drag v-bind="$attrs" v-on="$listeners"
               :visible.sync="visible"
               width="200px" style="height: 680px;" class="customer-dialog">
      <el-form :inline="true" label-position="top" style="height: 100px;"
               label-width="80px">
        <!-- 半成品卷卷号 -->
        <el-row>
          <el-col :span="24" style="margin-top: -5px;">
            <el-form-item :label=labels.rollQty>
              <el-input ref="rollQty" v-model="pageData.rollQty" style="width: 180px;" ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24" style="margin-top: -5px;">
            <el-form-item :label=labels.rollNums>
              <el-input v-model="pageData.rollNums" style="width: 180px;" ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="createSeparateRollFun">{{ buttons.confirmButton }}</el-button>
        <el-button type="primary" @click="closeDialog">{{ buttons.closeButton }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  getSeqStandardRollQty,
  createSeparateRoll,/*执行创建分卷的操作*/
} from '@/api/scheduleReport/com_separate_roll.js';

/*打印标签专用的js*/
import {
  printSfdcLabel,
} from "@/views/modules/scheduleReport/print_roll_label.js";

var functionId = 'C10000003';

export default {
  data() {
    return {
      titleCon: '创建分卷',
      visible: false,
      scheduleData: {
        site: this.$store.state.user.site,
        username: this.$store.state.user.name,
        seqNo: '',
        orderNo: '',
        itemNo: 0,
        partNo: '',
        workCenterNo: '',
        rollNo: '',
        functionName: '',
        currentRollFlag: false
      },
      pageData: {
        site: this.$store.state.user.site,
        username: this.$store.state.user.name,
        orderNo: '',
        itemNo: '',
        seqNo: '',
        rollNo: '',
        reportDate: '',
        reportTime: '',
        rollQty: 0,
        standardRollQty: 0,
        rollNums: 1
      },
      buttons: {
        confirmButton: '确定',
        closeButton: '关闭',
      },
      buttonList: [
        {
          functionId: functionId,
          languageValue: '确定',
          objectId: 'confirmButton',
          objectType: 'button',
          tableId: '*'
        }, {
          functionId: functionId,
          languageValue: '关闭',
          objectId: 'closeButton',
          objectType: 'button',
          tableId: '*'
        },
      ],
      queryButton: {
        functionId: functionId,
        table_id: '*',
        languageCode: this.$i18n.locale,
        objectType: 'button'
      },
      labels: {
        titleCon: '创建分卷',
        rollQty: '良品数量:',
        rollNums: '卷数:',
        confirmLabel: '确认',
        cancelLabel: '取消',
      },
      labelsList: [
        {
          functionId: functionId,
          languageValue: '创建分卷',
          objectId: 'titleCon',
          objectType: 'label',
          tableId: '*'
        }, {
          functionId: functionId,
          languageValue: '当前时间:',
          objectId: 'currentTime',
          objectType: 'label',
          tableId: '*'
        }, {
          functionId: functionId,
          languageValue: '良品数量:',
          objectId: 'rollQty',
          objectType: 'label',
          tableId: '*'
        }, {
          functionId: functionId,
          languageValue: '卷数:',
          objectId: 'rollNums',
          objectType: 'label',
          tableId: '*'
        }, {
          functionId: functionId,
          languageValue: '良品数量必须是正整数!',
          objectId: 'approvedQtyMustBeInteger',
          objectType: 'label',
          tableId: '*'
        }, {
          functionId: functionId,
          languageValue: '卷数必须是正整数!',
          objectId: 'rollQtyMustBeInteger',
          objectType: 'label',
          tableId: '*'
        }, {
          functionId: functionId,
          languageValue: '良品数量必须大于零且是整数!',
          objectId: 'approvedQtyMustMoreTanZeroAndBeInteger',
          objectType: 'label',
          tableId: '*'
        }, {
          functionId: functionId,
          languageValue: '卷数必须大于零且是整数!',
          objectId: 'rollQtyMustMoreTanZeroAndBeInteger',
          objectType: 'label',
          tableId: '*'
        }, {
          functionId: functionId,
          languageValue: '请先切换人员!',
          objectId: 'pleaseSwitchOperator',
          objectType: 'label',
          tableId: '*'
        }, {
          functionId: functionId,
          languageValue: '确认',
          objectId: 'confirmLabel',
          objectType: 'label',
          tableId: '*'
        }, {
          functionId: functionId,
          languageValue: '取消',
          objectId: 'cancelLabel',
          objectType: 'label',
          tableId: '*'
        },
      ],
      queryLabel: {
        functionId: functionId,
        table_id: '*',
        languageCode: this.$i18n.locale,
        objectType: 'label'
      },
    }
  },
  methods: {
    //页面初始化是的方法
    init(scheduleData) {
      //初始化参数
      this.scheduleData = scheduleData;
      //设置参数
      this.pageData.orderNo = scheduleData.orderNo;
      this.pageData.itemNo = scheduleData.itemNo;
      this.pageData.seqNo = scheduleData.seqNo;
      //调用方法  获取标准卷的数量
      this.getSeqStandardRollQtyFun();
      //清空参数
      this.pageData.rollNums = 1;
      this.visible = true;
      //获取焦点
      this.$nextTick(() => {
        this.$refs.rollQty.focus();
      });
      this.titleCon = this.labels.titleCon;//重置标题
    },

    //调用方法  获取标准卷的数量
    getSeqStandardRollQtyFun() {
      // 获取标准卷的数量
      getSeqStandardRollQty(this.pageData).then(({data}) => {
        if (data.code == 200) {
          this.pageData.standardRollQty = data.standardRollQty;
          this.pageData.rollQty = data.standardRollQty;
        }else{
          this.$message.error(data.msg);
        }
      })
    },

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

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

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

    //检查创建
    createSeparateRollFun() {
      //获取当前是的数量
      let rollQty = parseInt(this.pageData.rollQty);
      //判断是否可以修改
      if (rollQty <= 0 || !Number.isInteger(rollQty)){
        this.$message.error('卷数量无效!');
        return false;
      }

      //判断是否是尾数卷
      if(rollQty < this.pageData.standardRollQty){
        let rollNums = parseInt(this.pageData.rollNums);
        if(rollNums > 1){
          this.$message.error('当前的工单得尾数卷只能有一卷!');
          return false;
        }
      }

      //获取当前是的数量
      let rollNums = parseFloat(this.pageData.rollNums);
      //判断是否是正整数
      if (rollNums <= 0 || !Number.isInteger(rollNums)){
        this.$message.error('当前卷数无效!');
        return false;
      }
      //校验是否继续
      createSeparateRoll(this.pageData).then(({data}) => {
        //判断是否成功
        if (data.code == 200) {
          this.$message.success(data.msg);
          //this.closeDialog();
          //清空卷数  重置数据量
          this.pageData.rollQty = this.pageData.standardRollQty;
          this.pageData.rollNums = 1;
        } else {
          this.$message.error(data.msg);
        }
      });
    },

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