<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="keyId" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="keyId">
              <a-input-number v-model="model.keyId" placeholder="请输入keyId" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="任务号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskno">
              <a-input v-model="model.taskno" placeholder="请输入任务号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wo">
              <a-input v-model="model.wo" placeholder="请输入工单号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="制令单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mo">
              <a-input v-model="model.mo" placeholder="请输入制令单号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生产条码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="serialNumber">
              <a-input v-model="model.serialNumber" placeholder="请输入生产条码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="出所编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="outNo">
              <a-input v-model="model.outNo" placeholder="请输入出所编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="产品代号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productNumber">
              <a-input v-model="model.productNumber" placeholder="请输入产品代号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="物料编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pnCode">
              <a-input v-model="model.pnCode" placeholder="请输入物料编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="物料名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pnName">
              <a-input v-model="model.pnName" placeholder="请输入物料名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="批次" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="batchNo">
              <a-input v-model="model.batchNo" placeholder="请输入批次"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="元器件编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="componentSn">
              <a-input v-model="model.componentSn" placeholder="请输入元器件编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="供应商" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplier">
              <a-input v-model="model.supplier" placeholder="请输入供应商"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="质量等级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qualitygrate">
              <a-input v-model="model.qualitygrate" placeholder="请输入质量等级"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="位号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pcbItem">
              <a-textarea v-model="model.pcbItem" rows="4" placeholder="请输入位号" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qty">
              <a-input-number v-model="model.qty" placeholder="请输入数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="有效期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="validDate">
              <j-date placeholder="请选择有效期" v-model="model.validDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="筛选情况" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="filter">
              <a-input v-model="model.filter" placeholder="请输入筛选情况"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remarks">
              <a-input v-model="model.remarks" placeholder="请输入备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="更新人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="updator">
              <a-input v-model="model.updator" placeholder="请输入更新人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="更新时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="updateDate">
              <j-date placeholder="请选择更新时间" v-model="model.updateDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="位号2" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pcbItem2">
              <a-input v-model="model.pcbItem2" placeholder="请输入位号2"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="型号规格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pnSpec">
              <a-input v-model="model.pnSpec" placeholder="请输入型号规格"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="物料条码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="iqcSn">
              <a-input v-model="model.iqcSn" placeholder="请输入物料条码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="操作者" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workMan">
              <a-input v-model="model.workMan" placeholder="请输入操作者"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="操作工序" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workLocat">
              <a-input v-model="model.workLocat" placeholder="请输入操作工序"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="检验者" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="checkMan">
              <a-input v-model="model.checkMan" placeholder="请输入检验者"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="j检验时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="checkDate">
              <j-date placeholder="请选择j检验时间" v-model="model.checkDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="原始位号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pcbItemS">
              <a-textarea v-model="model.pcbItemS" rows="4" placeholder="请输入原始位号" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="原始数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qtyS">
              <a-input-number v-model="model.qtyS" placeholder="请输入原始数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="拆除位号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pcbItemR">
              <a-textarea v-model="model.pcbItemR" rows="4" placeholder="请输入拆除位号" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="拆除数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qtyR">
              <a-input-number v-model="model.qtyR" placeholder="请输入拆除数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="呈现位号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pcbItemShow">
              <a-textarea v-model="model.pcbItemShow" rows="4" placeholder="请输入呈现位号" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="PID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pid">
              <a-input v-model="model.pid" placeholder="请输入PID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="dpano" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dpano">
              <a-input v-model="model.dpano" placeholder="请输入dpano"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="technicalstandard" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="technicalstandard">
              <a-input v-model="model.technicalstandard" placeholder="请输入technicalstandard"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="行号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="iqcIndex">
              <a-input v-model="model.iqcIndex" placeholder="请输入行号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="出库单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="outStockNo">
              <a-input v-model="model.outStockNo" placeholder="请输入出库单号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="印制板号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="boardNo">
              <a-input v-model="model.boardNo" placeholder="请输入印制板号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="入库批次号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inbatchno">
              <a-input v-model="model.inbatchno" placeholder="请输入入库批次号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="采购单价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseprice">
              <a-input-number v-model="model.purchaseprice" placeholder="请输入采购单价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="内部单价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="internalprice">
              <a-input-number v-model="model.internalprice" placeholder="请输入内部单价" style="width: 100%" />
            </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: 'MesInfoForm',
    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: {
           keyId: [
              { required: true, message: '请输入keyId!'},
           ],
        },
        url: {
          add: "/mesInfo/mesInfo/add",
          edit: "/mesInfo/mesInfo/edit",
          queryById: "/mesInfo/mesInfo/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>