<!-- 询价单报价 -->
<template>
  <div class="customer-css">
    <!-- 查询条件 -->
    <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 0px;">
      <el-row>
        <el-col :span="24">
          <el-form-item label="询价单号:">
            <el-input v-model="searchData.orderNo" style="width: 150px" clearable></el-input>
          </el-form-item>
          <el-form-item :label="'询价时间'">
            <el-date-picker
              style="width: 130px"
              v-model="searchData.startDate"
              type="date"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              placeholder="Start">
            </el-date-picker>
          </el-form-item>
          <el-form-item :label="'To'">
            <el-date-picker
              style="width: 130px"
              v-model="searchData.endDate"
              type="date"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              placeholder="End">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="状态:">
            <el-select v-model="searchData.status" placeholder="请选择" clearable style="width: 120px">
              <el-option label="全部" value=""></el-option>
              <el-option label="待报价" value="待报价"></el-option>
              <el-option label="已报价" value="已报价"></el-option>
              <el-option label="已接受" value="已接受"></el-option>
              <el-option label="未接受" value="未接受"></el-option>
              <el-option label="已拒绝" value="已拒绝"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label=" ">
            <el-button class="customer-bun-min" type="primary" @click="getMainData">查询</el-button>
            <el-button @click="resetSearch" style="margin-left: 2px">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <!-- 询价列表 -->
    <el-table
      :height="height"
      :data="mainDataList"
      border
      ref="mainTable"
      highlight-current-row
      @row-click="changeData"
      v-loading="dataListLoading"
      style="margin-top: 0px; width: 100%;">
      <el-table-column
        v-for="(item, index) in columnArray1"
        :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :show-overflow-tooltip="item.showOverflowTooltip"
        :align="item.align"
        :fixed="item.fixed"
        :min-width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="scope">
          <span v-if="!item.columnHidden">{{ scope.row[item.columnProp] }}</span>
        </template>
      </el-table-column>
      <!-- 操作列 -->
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="180"
        label="Action">
        <template slot-scope="scope">
          <el-link
            v-if="scope.row.status === '待报价'||scope.row.status === '未接受'"
            style="cursor: pointer"
            @click="openQuoteDialog(scope.row)">
            报价
          </el-link>
          <!-- <el-link style="cursor: pointer" @click="openQuoteDialog(scope.row)">报价</el-link> -->
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination
      style="margin-top: 0px"
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[20, 50, 100, 200]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <!-- 标签页 -->
    <el-tabs v-model="activeName" style="margin-top: 0px; width: 99%;" @tab-click="tabClick" class="customer-tab" type="border-card">
      <el-tab-pane label="报价记录" name="quotationList">
        <quotationList ref="quotationList" :height="tabHeight"></quotationList>
      </el-tab-pane>
      <el-tab-pane label="附件" name="attachments">
        <attachments ref="attachments" :height="tabHeight"></attachments>
      </el-tab-pane>
    </el-tabs>

    <!-- 报价信息新增弹出框 -->
    <el-dialog
      title="报价信息"
      :visible.sync="quoteDialogVisible"
      width="600px"
      top="3vh"
      :close-on-click-modal="false"
      class="part-dialog">
      <div class="dialog-content">
        <el-form
          :model="quoteForm"
          :rules="quoteRules"
          ref="quoteForm"
          label-position="top"
          class="part-form">

          <!-- 基础信息 -->
          <div class="form-section">
            <el-row :gutter="20">
              <el-col :span="6">
                <el-form-item label="物料编码" prop="partNo">
                  <el-input v-model="quoteForm.partNo" :disabled="true" placeholder="物料编码"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="18">
                <el-form-item label="物料名称" prop="partDesc">
                  <el-input v-model="quoteForm.partDesc" :disabled="true" placeholder="物料名称"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="18">
                <el-form-item label="规格型号" prop="spec">
                  <el-input v-model="quoteForm.spec" :disabled="true" placeholder="规格型号"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="询价数量" prop="qty">
                  <el-input-number v-model="quoteForm.qty" :disabled="true" :min="0" style="width: 100%"></el-input-number>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="其他要求" prop="otherCondition">
                  <el-input v-model="quoteForm.otherCondition" type="text" :disabled="true" :rows="1" placeholder="其他要求"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="计量单位" prop="umid">
                  <el-input v-model="quoteForm.umid" :disabled="true" placeholder="计量单位"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </div>

          <!-- 费用信息 -->
          <div class="form-section">
            <el-row :gutter="20">
              <el-col :span="6">
                <el-form-item label="材料费用" prop="materialCost">
                  <el-input-number v-model="quoteForm.materialCost" @change="calculatePrice" :precision="2" :min="0" style="width: 100%"></el-input-number>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="加工费" prop="produceFee">
                  <el-input-number v-model="quoteForm.produceFee" @change="calculatePrice" :precision="2" :min="0" style="width: 100%"></el-input-number>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="表面处理费" prop="surfaceFee">
                  <el-input-number v-model="quoteForm.surfaceFee" @change="calculatePrice" :precision="2" :min="0" style="width: 100%"></el-input-number>
                </el-form-item>
              </el-col>
                <el-col :span="6">
                <el-form-item label="利润" prop="profit">
                  <el-input-number v-model="quoteForm.profit" @change="calculatePrice" :precision="2" :min="0" style="width: 100%"></el-input-number>
                </el-form-item>
              </el-col>
            </el-row>

             <!-- 价格信息 -->
          <div class="form-section">
            <el-row :gutter="20">
              <el-col :span="6">
                <el-form-item label="未税单价" prop="price">
                  <el-input-number v-model="quoteForm.price"  :disabled="true" :precision="4" :min="0" style="width: 100%" @change="calculateTax"></el-input-number>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="税率(%)" prop="taxRate">
                  <el-input-number v-model="quoteForm.taxRate" :disabled="true" :precision="2" :min="0" :max="100" style="width: 100%" @change="calculateTax"></el-input-number>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="含税单价" prop="tax">
                  <el-input-number v-model="quoteForm.tax"  :disabled="true" :precision="4" :min="0" style="width: 100%"></el-input-number>
                </el-form-item>
              </el-col>
                <el-col :span="6">
                <el-form-item label="关税" prop="duty">
                  <el-input-number v-model="quoteForm.duty" :precision="2" :min="0" style="width: 100%"></el-input-number>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
            <el-row :gutter="20">
               <el-col :span="6">
                <el-form-item label="采购周期(天)" prop="purchaseCycle">
                  <el-input-number v-model="quoteForm.purchaseCycle" :min="0" :precision="0" style="width: 100%"></el-input-number>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="模具费" prop="mouldFee">
                  <el-input-number v-model="quoteForm.mouldFee" :precision="2" :min="0" style="width: 100%"></el-input-number>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="附加费用" prop="additionalCost">
                  <el-input-number v-model="quoteForm.additionalCost" :precision="2" :min="0" style="width: 100%"></el-input-number>
                </el-form-item>
              </el-col>
               <el-col :span="6">
                <el-form-item label="运费" prop="freight">
                  <el-input-number v-model="quoteForm.freight" :precision="2" :min="0" style="width: 100%"></el-input-number>
                </el-form-item>
              </el-col>
            </el-row>
          </div>

          <!-- 其他信息 -->
          <div class="form-section">
             <el-row :gutter="20">
              <el-col :span="24">
                <el-form-item label="特殊要求" prop="remark2">
                  <el-input v-model="quoteForm.remark2" type="textarea" :disabled="true" :rows="1" placeholder="请输入特殊要求"></el-input>
                </el-form-item>
              </el-col>
             </el-row>
            <el-row :gutter="20">
                <el-col :span="24">
                  <el-form-item label="备注" prop="remark">
                <el-input v-model="quoteForm.remark" type="textarea" :rows="1" placeholder="请输入备注"></el-input>
              </el-form-item>
            </el-col>
            </el-row>

          </div>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer" style="margin-top: 20px; text-align: center;">
        <el-button type="primary" @click="submitQuote">提交报价</el-button>
        <el-button @click="cancelQuote">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import {
  getQuoPurDetailPage
} from '@/api/supplier/purQuotation.js'

import {
    createPurReplyHist
  } from '@/api/supplier/purReplyHist.js'

import quotationList from './com_inquiry_QuotationList'
import attachments from './com_inquiry_Attachments'

export default {
  name: 'InquiryQuery',
  components: {
    quotationList,
    attachments
  },
  data() {
    return {
      height: 200,
      tabHeight: 300,
      dataListLoading: false,
      mainDataList: [],
      pageIndex: 1,
      pageSize: 20,
      totalPage: 0,
      activeName: 'quotationList',
      currentRow: {},
      searchData: {
        orderNo: '',
        partNo: '',
        supplierId: '',
        supplierName: '',
        status: '待报价',
        startDate: '',
        endDate: '',
        site: this.$store.state.user.site,
        page: 1,
        limit: 20
      },
      // 表格列配置
      columnArray1: [
        { columnProp: 'status', columnLabel: '状态', columnWidth: '80', headerAlign: 'center', align: 'center', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'orderNo', columnLabel: '询价单号', columnWidth: '120', headerAlign: 'center', align: 'center', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'orderDate', columnLabel: '询价日期', columnWidth: '100', headerAlign: 'center', align: 'center', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'wantReplyDate', columnLabel: '要求报价日期', columnWidth: '100', headerAlign: 'center', align: 'center', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'itemNo', columnLabel: '序号', columnWidth: '60', headerAlign: 'center', align: 'center', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'partNo', columnLabel: '物料编码', columnWidth: '120', headerAlign: 'center', align: 'center', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'partDesc', columnLabel: '物料名称', columnWidth: '150', headerAlign: 'center', align: 'left', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'umid', columnLabel: '计量单位', columnWidth: '80', headerAlign: 'center', align: 'center', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'spec', columnLabel: '规格型号', columnWidth: '150', headerAlign: 'center', align: 'left', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'qty', columnLabel: '询价数量', columnWidth: '100', headerAlign: 'center', align: 'right', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'remark2', columnLabel: '特殊要求', columnWidth: '80', headerAlign: 'center', align: 'center', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },

        { columnProp: 'buyer', columnLabel: '采购员', columnWidth: '120', headerAlign: 'center', align: 'center', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'paymentTerm', columnLabel: '付款方式', columnWidth: '80', headerAlign: 'center', align: 'center', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'deliveryTerm', columnLabel: '交易条款', columnWidth: '120', headerAlign: 'center', align: 'center', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'otherCondition', columnLabel: '其他要求', columnWidth: '120', headerAlign: 'center', align: 'center', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'materialCost', columnLabel: '材料费用', columnWidth: '100', headerAlign: 'center', align: 'right', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'produceFee', columnLabel: '加工费', columnWidth: '100', headerAlign: 'center', align: 'right', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'surfaceFee', columnLabel: '表面处理费', columnWidth: '100', headerAlign: 'center', align: 'right', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'profit', columnLabel: '利润', columnWidth: '100', headerAlign: 'center', align: 'right', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'price', columnLabel: '未税单价', columnWidth: '100', headerAlign: 'center', align: 'right', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'taxRate', columnLabel: '税率(%)', columnWidth: '80', headerAlign: 'center', align: 'right', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'tax', columnLabel: '含税单价', columnWidth: '100', headerAlign: 'center', align: 'right', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'duty', columnLabel: '关税', columnWidth: '80', headerAlign: 'center', align: 'right', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'purchaseCycle', columnLabel: '采购周期', columnWidth: '90', headerAlign: 'center', align: 'center', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'mouldFee', columnLabel: '模具费', columnWidth: '100', headerAlign: 'center', align: 'right', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'additionalCost', columnLabel: '附加费用', columnWidth: '100', headerAlign: 'center', align: 'right', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'freight', columnLabel: '运费', columnWidth: '100', headerAlign: 'center', align: 'right', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'remark', columnLabel: '备注', columnWidth: '150', headerAlign: 'center', align: 'left', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'supplierId', columnLabel: '供应商编码', columnWidth: '120', headerAlign: 'center', align: 'center', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true },
        { columnProp: 'supplierName', columnLabel: '供应商名称', columnWidth: '150', headerAlign: 'center', align: 'left', fixed: false, columnHidden: false, columnSortable: false, showOverflowTooltip: true }
      ],
      // 报价对话框相关
      quoteDialogVisible: false,
      quoteForm: {
        // 基础信息
        partNo: '',
        partDesc: '',
        spec: '',
        qty: 0,
        umid: '',
        otherCondition: '',
        // 费用信息
        materialCost: 0,
        produceFee: 0,
        surfaceFee: 0,
        profit: 0,
        mouldFee: 0,
        additionalCost: 0,
        freight: 0,
        purchaseCycle: 0,
        duty: 0,
        // 价格信息
        price: 0,
        taxRate: 13,
        tax: 0,
        // 其他信息
        remark2: '',
        remark: '',
        // 关联信息
        orderNo: '',
        itemNo: '',
        supplierId: '',
        supplierName: '',
        site: this.$store.state.user.site,
        createdBy: this.$store.state.user.name
      },
      quoteRules: {
        price: [
          { required: true, message: '请输入未税单价', trigger: 'blur' },
          {
            validator: (rule, value, callback) => {
              if (value == null || Number(value) <= 0) {
                callback(new Error('未税单价必须大于0'))
              } else {
                callback()
              }
            },
            trigger: 'blur'
          }
        ],
        taxRate: [{ required: true, message: '请输入税率', trigger: 'blur' }]
      },
      // 上次填写的报价信息（用于残留功能）
      lastQuoteData: null
    }
  },
  created() {
    this.getMainData()
  },
  mounted() {
    this.$nextTick(() => {
      this.height = (window.innerHeight - 280) / 2
      this.tabHeight = this.height - 50
    })
    window.addEventListener('resize', this.handleResize)
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.handleResize)
  },
  methods: {
    handleResize() {
      this.height = (window.innerHeight - 280) / 2
      this.tabHeight = this.height - 50
      this.refreshCurrentTabTable()
    },
    resetSearch() {
      this.searchData = {
        orderNo: '',
        partNo: '',
        supplierId: '',
        supplierName: '',
        status: '待报价',
        startDate: '',
        endDate: '',
        site: this.$store.state.user.site,
        page: 1,
        limit: this.pageSize
      }
      this.getMainData()
    },
    getMainData() {
      this.dataListLoading = true
      this.searchData.limit = this.pageSize
      this.searchData.page = this.pageIndex
      getQuoPurDetailPage(this.searchData).then(({ data }) => {
        if (data.code === 0) {
          this.mainDataList = data.page.list
          this.pageIndex = data.page.currPage
          this.pageSize = data.page.pageSize
          this.totalPage = data.page.totalCount
          if (this.mainDataList.length > 0) {
            this.$refs.mainTable.setCurrentRow(this.mainDataList[0])
            this.changeData(this.mainDataList[0])
          } else {
            this.changeData(null)
          }
        }
        this.dataListLoading = false
      }).catch(() => {
        this.dataListLoading = false
      })
    },
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getMainData()
    },
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getMainData()
    },
    changeData(row) {
      this.currentRow = row ? JSON.parse(JSON.stringify(row)) : { site: '', orderNo: '', itemNo: '' }
      this.refreshCurrentTabTable()
    },


    tabClick() {
      this.refreshCurrentTabTable()
    },
    refreshCurrentTabTable() {
       if (this.currentRow === '' || this.currentRow === null) {
        this.currentRow = {site: '', orderNo: ''}
      }
      if (this.activeName === 'quotationList') {
        this.refreshQuotationList()
      }
      if (this.activeName === 'attachments') {
        this.refreshAttachments()
      }
    },

    refreshQuotationList(){
      let inData = {
          site: this.currentRow.site,
          orderNo: this.currentRow.orderNo,
          itemNo: this.currentRow.itemNo,
          partNo: this.currentRow.partNo,
          type: 'add',
          height: this.tabHeight
      }
       this.$refs.quotationList.init(inData)
    },

    refreshAttachments () {
      let inData = {
          orderRef1: this.currentRow.site,
          orderRef2: this.currentRow.orderNo,
          orderRef3: this.currentRow.partNo,
          orderReftype: 'purQuotationDetail',
          height: this.tabHeight
      }
      this.$refs.attachments.init(inData)
    },
    // 打开报价对话框
    openQuoteDialog(row) {
      if (!row) {
        this.$message.warning('请选择要报价的询价单')
        return
      }

      // 检查是否有上次填写的数据且是当前行的数据
      const hasLastData = this.lastQuoteData &&
                         this.lastQuoteData.orderNo === row.orderNo &&
                         this.lastQuoteData.itemNo === row.itemNo

      // 填充表单数据
      this.quoteForm = {
        // 基础信息
        partNo: row.partNo || '',
        partDesc: row.partDesc || '',
        spec: row.spec || '',
        qty: row.qty || 0,
        umid: row.umid || '',
        otherCondition: row.otherCondition || '',
        status: '已报价',
        // 费用信息 - 如果有上次填写的数据则使用，否则使用行数据或默认值
        materialCost: hasLastData ? this.lastQuoteData.materialCost : (row.materialCost || 0),
        produceFee: hasLastData ? this.lastQuoteData.produceFee : (row.produceFee || 0),
        surfaceFee: hasLastData ? this.lastQuoteData.surfaceFee : (row.surfaceFee || 0),
        profit: hasLastData ? this.lastQuoteData.profit : (row.profit || 0),
        mouldFee: hasLastData ? this.lastQuoteData.mouldFee : (row.mouldFee || 0),
        additionalCost: hasLastData ? this.lastQuoteData.additionalCost : (row.additionalCost || 0),
        freight: hasLastData ? this.lastQuoteData.freight : (row.freight || 0),
        purchaseCycle: hasLastData ? this.lastQuoteData.purchaseCycle : (row.purchaseCycle || 0),
        duty: hasLastData ? this.lastQuoteData.duty : (row.duty || 0),
        // 价格信息
        price: hasLastData ? this.lastQuoteData.price : (row.price || 0),
        taxRate: hasLastData ? this.lastQuoteData.taxRate : (row.taxRate || 13),
        tax: hasLastData ? this.lastQuoteData.tax : (row.tax || 0),
        // 其他信息
        remark2: row.remark2 || '',
        remark: hasLastData ? this.lastQuoteData.remark : (row.remark || ''),
        // 关联信息
        orderNo: row.orderNo,
        itemNo: row.itemNo,
        supplierId: row.supplierId || this.$store.state.user.supplierId,
        supplierName: row.supplierName || this.$store.state.user.supplierName,
        site: this.$store.state.user.site,
        createdBy: this.$store.state.user.name
      }

      // 计算含税单价
      this.calculatePrice()
      this.quoteDialogVisible = true
    },

    calculatePrice(){
      //未税单价=材料成本+加工费+表面费用+利润
      this.quoteForm.price = this.quoteForm.materialCost + this.quoteForm.produceFee +
                          this.quoteForm.surfaceFee + this.quoteForm.profit
       this.calculateTax()

    },
   // 计算含税单价
    calculateTax() {
      //含税单价=未税单价*(1+税率)
      if (this.quoteForm.price && this.quoteForm.taxRate) {
        this.quoteForm.tax = this.quoteForm.price * (1 + this.quoteForm.taxRate / 100)
      }
    },

    // 提交报价
    submitQuote() {
      this.calculatePrice()
      this.$refs.quoteForm.validate((valid) => {
        if (valid) {
          if (!this.quoteForm.price || Number(this.quoteForm.price) <= 0) {
            this.$message.error('未税单价必须大于0')
            return
          }
          // 计算总成本（可选）
          const totalCost = this.quoteForm.materialCost + this.quoteForm.produceFee +
                           this.quoteForm.surfaceFee + this.quoteForm.profit +
                           this.quoteForm.mouldFee + this.quoteForm.additionalCost +
                           this.quoteForm.freight + this.quoteForm.duty

          const submitData = {
            ...this.quoteForm,
            totalCost: totalCost
          }

          createPurReplyHist(submitData).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message.success('报价提交成功')
              // 提交成功后清除残留数据
              this.lastQuoteData = null
              this.quoteDialogVisible = false
              // 刷新报价记录列表
              this.refreshCurrentTabTable()
              // 刷新主列表状态
              this.getMainData()
            } else {
              this.$message.error(data.msg || '报价提交失败')
            }
          }).catch(error => {
            this.$message.error('报价提交失败: ' + error.message)
          })
        } else {
          this.$message.warning('请填写必填字段')
        }
      })
    },

    // 取消报价（保存当前填写的数据用于下次残留）
    cancelQuote() {
      // 保存当前填写的数据（只保存可编辑的字段）
      this.lastQuoteData = {
        orderNo: this.quoteForm.orderNo,
        itemNo: this.quoteForm.itemNo,
        // 费用信息
        materialCost: this.quoteForm.materialCost,
        produceFee: this.quoteForm.produceFee,
        surfaceFee: this.quoteForm.surfaceFee,
        profit: this.quoteForm.profit,
        mouldFee: this.quoteForm.mouldFee,
        additionalCost: this.quoteForm.additionalCost,
        freight: this.quoteForm.freight,
        purchaseCycle: this.quoteForm.purchaseCycle,
        duty: this.quoteForm.duty,
        // 价格信息
        price: this.quoteForm.price,
        taxRate: this.quoteForm.taxRate,
        tax: this.quoteForm.tax,
        // 备注
        remark: this.quoteForm.remark
      }
      this.quoteDialogVisible = false
    }
  }
}
</script>

<style scoped lang="scss">

/deep/ .customer-tab .el-tabs__content {
  padding: 5px !important;
}

/* 产品对话框整体样式 */
.part-dialog {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.part-dialog .el-dialog {
  margin-top: 5vh !important;
  margin-bottom: 5vh !important;
}

.part-dialog .el-dialog__header {
  padding: 20px 25px 15px 25px;
  border-bottom: 1px solid #E4E7ED;
}

.part-dialog .el-dialog__body {
  padding: 25px 25px 25px 25px;
  max-height: 75vh;
  overflow-y: auto;
  min-height: 400px;
}

.dialog-content {
  width: 100%;
}
/* 产品表单样式 */
.part-form {
  width: 100%;
}

.part-form .el-form-item {
  margin-bottom: 1px;
}

.part-form .el-form-item__label {
  font-weight: 500;
  color: #303133;
  line-height: 32px;
  padding-right: 12px;
}

.part-form .el-form-item__content {
  line-height: normal;
}

/* 表单分组样式 */
.form-section {
  margin-bottom: 5px;
}

.form-section:last-child {
  margin-bottom: 5px;
}

/* 输入框样式 */
.part-form .el-input,
.part-form .el-textarea,
.part-form .el-date-editor {
  width: 100%;
}

/* 文本域样式优化 */
.part-form .el-textarea__inner {
  resize: none;
  font-family: inherit;
  line-height: 1.5;
}

/* 对话框底部按钮居中 */
.dialog-footer-center {
  text-align: center;
  padding: 15px 0 5px 0;
  border-top: 1px solid #E4E7ED;
  margin-top: 15px;
}

.dialog-footer-center .el-button {
  margin: 0 10px;
  min-width: 90px;
  height: 36px;
  padding: 0 20px;
  font-size: 14px;
}

/* 响应式调整 */
@media (max-width: 1200px) {
  .part-dialog {
    width: 95% !important;
  }

  .part-dialog .el-dialog__body {
    padding: 20px 20px 15px 20px;
  }
}

@media (max-width: 768px) {
  .part-form .el-col {
    margin-bottom: 20px;
  }

  .form-section {
    margin-bottom: 35px;
  }

  .part-form .el-form-item__label {
    line-height: 28px;
    height: 28px;
  }
}
</style>
