<template>
  <div class="customer-css">
    <el-dialog :title="titleCon" v-drag v-bind="$attrs" v-on="$listeners"
               width="220px" style="height: 300px;" class="customer-dialog">
      <el-form :inline="true" label-position="top" style="height: 100px;"
               label-width="80px">
        <!-- 菜单信息 -->
        <el-row>
          <el-col :span="24" >
            <el-form-item :label="'排产数量:'">
              <el-input ref="scheduleQty" controls-position="right" v-model="pageData.scheduleQty" min="0"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer" style="margin-top: -20px;">
        <el-button type="primary" @click="addSplitSchedule">确 定</el-button>
        <el-button type="primary" @click="closeDialog">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "com_split_schedule",
  data() {
    return {
      titleCon: '分批排产',
      pageData: {
        site: this.$store.state.user.site,
        userName: this.$store.state.user.name,
        scheduleQty: 0,
        maxScheduleQty: 0
      },
    }
  },
  methods: {
    /*初始化页面参数*/
    init(scheduleRow) {
      this.titleCon = '分批排产';
      //初始化页面的数据
      this.pageData.scheduleQty = scheduleRow.qtyToSchedule;
      this.pageData.maxScheduleQty = scheduleRow.qtyToSchedule;
      //自动获取焦点
      this.$nextTick(() => {
        this.$refs.scheduleQty.focus();
      });
     //什么都不做
    },

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

    /*添加分批排产数据*/
    addSplitSchedule(){
      //判断排产的数量是否满足条件
      let scheduleQty = this.pageData.scheduleQty;
      if(scheduleQty <= 0){
        this.$message.error('排产数量必须大于0!');
        return false;
      }

      /*判断是否超过最大可排产的数量*/
      if(this.pageData.maxScheduleQty < parseFloat(scheduleQty)){
        this.$message.error('该订单累计排产数量超过订单数量!');
        return false;
      }
      //关闭当前的组件
      this.closeDialog();
      //处理结束卷组件的方法
      this.$emit('initAddSplitSchedule', this.pageData.scheduleQty);
    },

  },
  created() {
    //
  }
}

</script>

<style scoped lang="scss">

</style>
