<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="收件人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="recipientName">
              <a-input v-model="model.recipientName" placeholder="请输入收件人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收件人电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="recipientTel">
              <a-input v-model="model.recipientTel" placeholder="请输入收件人电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收件地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deliveryAddress">
              <a-input v-model="model.deliveryAddress" placeholder="请输入收件地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="品类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="category">
              <a-input v-model="model.category" placeholder="请输入品类"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="快递单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="trackingNumber">
              <a-input v-model="model.trackingNumber" placeholder="请输入快递单号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="供应商" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplierName">
              <a-input v-model="model.supplierName" placeholder="请输入供应商"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customer">
              <a-input v-model="model.customer" placeholder="请输入客户"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="出厂价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="factoryPrice">
              <a-input-number v-model="model.factoryPrice" placeholder="请输入出厂价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="进货单价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseUnitPrice">
              <a-input-number v-model="model.purchaseUnitPrice" placeholder="请输入进货单价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="进货总价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalPurchasePrice">
              <a-input-number v-model="model.totalPurchasePrice" placeholder="请输入进货总价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="供货单价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplyUnitPrice">
              <a-input-number v-model="model.supplyUnitPrice" placeholder="请输入供货单价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="供货总价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalSupplyPrice">
              <a-input-number v-model="model.totalSupplyPrice" placeholder="请输入供货总价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="快递费用" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="courierFee">
              <a-input-number v-model="model.courierFee" placeholder="请输入快递费用" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="净利润" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="netProfit">
              <a-input-number v-model="model.netProfit" placeholder="请输入净利润" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="业务员" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="salesman">
              <a-input v-model="model.salesman" placeholder="请输入业务员"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收款日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receivePaymentDate">
              <j-date placeholder="请选择收款日期" v-model="model.receivePaymentDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="付款日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paymentDate">
              <j-date placeholder="请选择付款日期" v-model="model.paymentDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="进项票开具日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inputTicketDate">
              <j-date placeholder="请选择进项票开具日期" v-model="model.inputTicketDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="销项票开具日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="outputTicketDate">
              <a-input v-model="model.outputTicketDate" placeholder="请输入销项票开具日期"  ></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: 'TbOrderForm',
    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: "/tborder/tbOrder/add",
          edit: "/tborder/tbOrder/edit",
          queryById: "/tborder/tbOrder/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>