<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="companyName">
              <a-input v-model="model.companyName" placeholder="请输入供应商名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="提货地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="address">
              <a-input v-model="model.address" placeholder="请输入提货地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报价照片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pic">
              <j-image-upload isMultiple  v-model="model.pic" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="单价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="price">
              <a-input-number v-model="model.price" placeholder="请输入单价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="暂定数量、" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="num">
              <a-input-number v-model="model.num" placeholder="请输入暂定数量、" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审核状态 0审核中 1 审核通过 2审核未通过" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditStatus">
              <j-dict-select-tag type="list" v-model="model.auditStatus" dictCode="audit_status" placeholder="请选择审核状态 0审核中 1 审核通过 2审核未通过" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="挂单状态 0挂单 1 已撤单" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="showStatus">
              <j-dict-select-tag type="list" v-model="model.showStatus" dictCode="show_status" placeholder="请选择挂单状态 0挂单 1 已撤单" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="期货现货 0期货 1 现货" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productType">
              <j-dict-select-tag type="list" v-model="model.productType" dictCode="product_type" placeholder="请选择期货现货 0期货 1 现货" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="交货时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="transactionTime">
              <j-date placeholder="请选择交货时间" v-model="model.transactionTime"  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: 'TbProductForm',
    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: {
           price: [
              { required: true, message: '请输入单价!'},
           ],
        },
        url: {
          add: "/product/tbProduct/add",
          edit: "/product/tbProduct/edit",
          queryById: "/product/tbProduct/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>