TblTradBaseForm.vue 10.7 KB
<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="tenderNumber">
              <a-input
                v-model="model.tenderNumber"
                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="procurement">
              <a-input v-model="model.procurement" placeholder="请输入客户采购"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户料号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="partNumber">
              <a-input
                v-model="model.partNumber"
                placeholder="请输入客户料号"
                
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="物料描述" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="description">
              <a-input v-model="model.description" placeholder="请输入物料描述"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="品名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productname">
              <a-input v-model="model.productname" placeholder="请输入品名" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="规格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="specifications">
              <a-input v-model="model.specifications" placeholder="请输入规格"></a-input>
            </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="含税运单价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="baseShuiprice">
              <a-input-number v-model="model.baseShuiprice" placeholder="请输入含税运单价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="中标单价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="baseZhong">
              <a-input-number v-model="model.baseZhong" placeholder="请输入中标单价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="计量单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="danwei">
              <a-input v-model="model.danwei" placeholder="请输入计量单位"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户需求单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="company">
              <a-input v-model="model.company" placeholder="请输入客户需求单位"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="交货日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deliveryTime">
              <j-date placeholder="请选择交货日期" v-model="model.deliveryTime" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="品牌" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="brand">
              <a-input v-model="model.brand" placeholder="请输入品牌"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工作令" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workOrder">
              <a-input v-model="model.workOrder" placeholder="请输入工作令"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="进口国产标识" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="identification">
              <a-input v-model="model.identification" placeholder="请输入进口国产标识"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="WBS" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wbs">
              <a-input v-model="model.wbs" placeholder="请输入WBS"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="评审结果" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="result">
              <a-input v-model="model.result" placeholder="请输入评审结果"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="notes">
              <a-input v-model="model.notes" placeholder="请输入备注"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设计人员姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="design">
              <a-input v-model="model.design" placeholder="请输入设计人员姓名"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="phone">
              <a-input v-model="model.phone" placeholder="请输入联系方式"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="图纸" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="picture">
              <j-image-upload isMultiple v-model="model.picture"></j-image-upload>
            </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: 'TblTradBaseForm',

  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  data() {
    return {
      currentTenNumber:'',
      currentPartNumber:'',
      isBianhaoDisabled: true, // 添加一个额外的变量来控制合同编号输入框的禁用状态
      isBianhaoDisabled2: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
        tenderNumber: [{ required: true, message: '请输入招标号!' }, { validator: this.validateNumber }],
        customer: [{ required: true, message: '请输入客户!' }],
        procurement: [{ required: true, message: '请输入客户采购!' }],
        partNumber: [{ required: true, message: '请输入客户料号!' }, { validator: this.validateNumber }],
        description: [{ required: true, message: '请输入物料描述!' }],
        productname: [{ required: true, message: '请输入品名!' }],
        specifications: [{ required: true, message: '请输入规格!' }],
        num: [{ required: true, message: '请输入申请数量!' }],
        danwei: [{ required: true, message: '请输入计量单位!' }],
        company: [{ required: true, message: '请输入客户需求单位!' }],
        baseZhong: [{ required: true, message: '请输入中标单价!' }],
      },
      url: {
        add: '/trad/tblTradBase/add',
        edit: '/trad/tblTradBase/edit',
        queryById: '/trad/tblTradBase/queryById',
        queryBy: 'trad/tblTradBase/queryBy',
      },
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    validateNumber(rule, value, callback) {
      // console.log(this.currentTenNumber)
      // console.log(this.currentPartNumber)
      if (!value) {
        callback()
      } else {
          const param = { tenderNumber: this.model.tenderNumber, partNumber: this.model.partNumber}
          // 使用 Promise 或者 async/await 来等待异步请求完成
          getAction(this.url.queryBy, param)
            .then((res) => {
              if (this.model.tenderNumber === this.currentTenNumber && this.model.partNumber===this.currentPartNumber) {
                callback()
              }else if (res.result && res.result.length <= 0) {
                callback()
              } else {
                callback('招标信息已存在!')
              }
            })
            .catch((error) => {
              console.error('Error:', error)
              callback('网络请求失败,请稍后重试!')
            })
      }
    },
    
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.currentTenNumber=this.model.tenderNumber
      this.currentPartNumber=this.model.partNumber
      this.visible = true
       
      // this.isBianhaoDisabled2 = 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>