<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="Line" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="line">
              <a-input v-model="model.line" placeholder="请输入Line"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="Demand ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="demandId">
              <a-input v-model="model.demandId" placeholder="请输入Demand ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="Tool" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tool">
              <a-input v-model="model.tool" placeholder="请输入Tool"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="Model.Suffix" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="model">
              <a-input v-model="model.model" placeholder="请输入Model.Suffix"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="Bucket" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bucket">
              <a-input v-model="model.bucket" placeholder="请输入Bucket"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="PO" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="po">
              <a-input-number v-model="model.po" placeholder="请输入PO" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="PST" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pst">
              <j-date placeholder="请选择PST" v-model="model.pst"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="Due Date" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dueDate">
              <j-date placeholder="请选择Due Date" v-model="model.dueDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="Final Dest." :labelCol="labelCol" :wrapperCol="wrapperCol" prop="finalDest">
              <a-input v-model="model.finalDest" placeholder="请输入Final Dest."  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="Comment1" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="comment1">
              <a-input v-model="model.comment1" placeholder="请输入Comment1"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="Comment2" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="comment2">
              <a-input v-model="model.comment2" placeholder="请输入Comment2"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="Remark" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入Remark"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="Overdue Days" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="overdueDays">
              <a-input-number v-model="model.overdueDays" placeholder="请输入Overdue Days" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="Week" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="week">
              <a-input v-model="model.week" placeholder="请输入Week"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'DelayProductForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/ProdPlan/delayProduct/add",
          edit: "/ProdPlan/delayProduct/edit",
          queryById: "/ProdPlan/delayProduct/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>