<template>
  <div class="fullHeight whiteBlock">
    <div style="padding: 15px 15px 0">
      <p class="pageTitle">招标管理</p>
      <el-form
        :inline="true"
        ref="searchForm"
        :model="searchForm"
        size="medium"
      >
        <el-form-item label="招标名称">
          <el-input
            v-model="searchForm.tenderName"
            placeholder="请输入"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" plain @click="getList">{{
            $t('message.energyManage.waybill.query')
          }}</el-button>
          <el-button type="warning" plain @click="refresh">{{
            $t('message.deviceManage.refresh')
          }}</el-button>
          <el-button type="primary" size="medium" @click="add">新增</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="table_wrap whiteBlock">
      <el-table class="tables" :data="List" @row-click="showDetailFn">
        <el-table-column
          prop="tenderName"
          label="招标名称"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="tenderUnit"
          align="center"
          label="招标单位"
        ></el-table-column>
        <el-table-column
          prop="purchasingMethod"
          align="center"
          label="采购方式"
        >
          <template slot-scope="scope">{{
            scope.row.purchasingMethod == 1
              ? '询价'
              : scope.row.purchasingMethod == 2
              ? '竞争性谈判'
              : scope.row.purchasingMethod == 3
              ? '直接委托'
              : scope.row.purchasingMethod == 4
              ? '单一来源'
              : scope.row.purchasingMethod == 5
              ? '其他合法采购方式'
              : ''
          }}</template>
        </el-table-column>
        <el-table-column
          prop="tenderType"
          align="center"
          label="招标类型"
        ></el-table-column>
        <el-table-column
          prop="tenderDay"
          align="center"
          label="招采时间（天）"
        ></el-table-column>
        <el-table-column
          prop="releaseTime"
          align="center"
          label="发布时间"
        ></el-table-column>
        <el-table-column
          prop="planContractAmount"
          align="center"
          label="计划合同金额（元）"
        ></el-table-column>
        <el-table-column
          prop="state"
          align="center"
          label="状态"
        ></el-table-column>
        <el-table-column prop="remark" label="备注" align="center">
        </el-table-column>
        <el-table-column prop="annex" align="center" label="附件">
          <template slot-scope="scope">
            <el-button
              @click.stop="download(scope.row.annex)"
              type="text"
              size="small"
              >下载附件</el-button
            >
          </template>
        </el-table-column>

        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <div class="tableBtns" style="margin-left: 10px !important">
              <div @click.stop="edit(scope.row)" class="operationText">
                <img
                  src="@/assets/images/icon-edit.png"
                  width="15px"
                  height="15px"
                />
                <span>编辑</span>
              </div>
              <div @click.stop="deleteDev(scope.row)" class="operationText">
                <img
                  src="@/assets/images/icon-delete.png"
                  width="15px"
                  height="15px"
                />
                <span>删除</span>
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        class="pagerBox"
        @size-change="SizeChange"
        @current-change="CurrentChange"
        :current-page="pagInfo.pageNo"
        :page-sizes="$store.state.PAGESIZRS"
        :page-size="pagInfo.pageSize"
        layout="total, sizes, prev, pager, next"
        :total="Number(pagInfo.total)"
        background
      ></el-pagination>
    </div>
    <!-- 新增弹框 -->
    <el-dialog
      :modal-append-to-body="false"
      @close="close"
      :title="title"
      :visible.sync="dialogShow"
      width="667px"
    >
      <div class="dialog_content">
        <el-form
          size="medium"
          ref="addInviteForm"
          :model="addInviteForm"
          :rules="addInviteFormRules"
          label-width="120px"
          class="dialogFormBox"
        >
          <el-form-item label="招标名称" prop="tenderName">
            <el-input
              v-model="addInviteForm.tenderName"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="招标单位" prop="tenderUnit">
            <el-input
              v-model="addInviteForm.tenderUnit"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="采购方式" prop="purchasingMethod">
            <el-select v-model="addInviteForm.purchasingMethod">
              <el-option
                v-for="(item, index) in resultList"
                :key="index"
                :value="item.value"
                :label="item.purchasingMethod"
              ></el-option>
            </el-select>
            <!-- <el-input
              v-model="addInviteForm.purchasingMethod"
              placeholder="请输入"
            ></el-input> -->
          </el-form-item>
          <el-form-item label="招标类型" prop="tenderType">
            <el-input
              v-model="addInviteForm.tenderType"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="招采时间（天）" prop="tenderDay">
            <el-input
              type="number"
              v-model="addInviteForm.tenderDay"
              placeholder="请输入数字类型"
            ></el-input>
          </el-form-item>
          <el-form-item label="发布时间" prop="remreleaseTimeark">
            <el-date-picker
              v-model="addInviteForm.releaseTime"
              type="date"
              placeholder="选择日期"
              value-format="yyyy-MM-dd"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item
            label="计划合同金额（元）"
            prop="planContractAmount"
            label-width="140px"
            style="margin-left: -20px"
          >
            <el-input
              type="number"
              @change="checkValue()"
              v-model="addInviteForm.planContractAmount"
              placeholder="请输入数字类型"
            ></el-input>
          </el-form-item>
          <el-form-item label="状态" prop="state">
            <el-input
              v-model="addInviteForm.state"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <el-input
              v-model="addInviteForm.remark"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="附件">
            <el-upload
              class="upload-demo"
              name="files"
              :action="$store.state.UPLOADURL"
              :on-remove="(file, fileList) => handleRemove(file, fileList, 1)"
              :multiple="false"
              :on-success="(res, file) => handleSuccess(res, file, 1)"
              :file-list="surveySchemeList"
              accept=".doc, .docx, .xls, .xlsx, .ppt, .pptx, .pdf"
            >
              <el-button size="medium" type="primary" plain>
                上传附件
              </el-button>
            </el-upload>
          </el-form-item>

          <div class="dialog-footer">
            <el-button
              class="cancleBtn"
              @click="dialogShow = false"
              icon="el-icon-circle-close"
              size="medium"
              >{{ $t('message.deviceManage.cancel') }}
            </el-button>
            <el-button
              type="primary"
              icon="el-icon-circle-check"
              @click="submitOne"
              size="medium"
              >{{ $t('message.deviceManage.save') }}
            </el-button>
          </div>
        </el-form>
      </div>
    </el-dialog>
    <!-- 详情弹框 -->
    <el-dialog
      :modal-append-to-body="false"
      title="详情"
      :visible.sync="addOrEditDialog"
      width="1490px"
    >
      <div class="dialog_content">
        <el-form
          size="medium"
          :model="contractForm"
          ref="contractForm"
          :rules="contractFormRules"
          label-width="70px"
          :inline="true"
        >
          <el-form-item label="招标名称" prop="orderNumber">
            <el-input disabled v-model="detailData.tenderName"></el-input>
          </el-form-item>
          <el-form-item label="招标单位" prop="orderNumber">
            <el-input disabled v-model="detailData.tenderUnit"></el-input>
          </el-form-item>
          <el-form-item label="采购方式" prop="buyerName">
            <template>
              <div
                style="
                  width: 200px;
                  height: 34px;
                  border: 1px solid #f5f7fa;
                  border-radius: 5px;
                  line-height: 33px;
                  background-color: #f5f7fa;
                  color: #aeb0bb;
                "
              >
                <span style="margin-left: 10px">{{
                  detailData.purchasingMethod == 1
                    ? '询价'
                    : detailData.purchasingMethod == 2
                    ? '竞争性谈判'
                    : detailData.purchasingMethod == 3
                    ? '直接委托'
                    : detailData.purchasingMethod == 4
                    ? '单一来源'
                    : detailData.purchasingMethod == 5
                    ? '其他合法采购方式'
                    : ''
                }}</span>
              </div>
            </template>
            <!-- <el-input disabled v-model="detailData.purchasingMethod"> -->
            <!-- </el-input> -->
          </el-form-item>
          <el-form-item label="招标类型" prop="receivingAddr">
            <el-input disabled v-model="detailData.tenderType"></el-input>
          </el-form-item>
          <el-form-item
            label="招采时间（天）"
            prop="receivingAddr"
            label-width="110px"
          >
            <el-input disabled v-model="detailData.tenderDay"></el-input>
          </el-form-item>

          <el-form-item label="发布时间" prop="remarks">
            <el-input disabled v-model="detailData.releaseTime"></el-input>
          </el-form-item>

          <el-form-item label="状态" prop="remarks">
            <el-input disabled v-model="detailData.state"></el-input>
          </el-form-item>
          <el-form-item label="备注" prop="remarks">
            <el-input disabled v-model="detailData.remark"></el-input>
          </el-form-item>
          <el-form-item
            label="计划合同金额（元）"
            prop="remarks"
            label-width="140px"
          >
            <el-input
              disabled
              v-model="detailData.planContractAmount"
            ></el-input>
          </el-form-item>
          <el-form-item label="附件" prop="remarks">
            <!-- 下载附件 -->
            <el-button
              @click.stop="download(detailData.annex, 4)"
              type="primary"
              plain
              size="small"
              >下载附件</el-button
            >
          </el-form-item>
        </el-form>
        <div class="btnAdd">
          <el-button type="primary" size="medium" @click="addDetails"
            >新增</el-button
          >
        </div>
        <el-tabs
          style="margin-bottom: 5px; width: 196px"
          v-model="dialogSteps"
          type="card"
        >
          <el-tab-pane label="投标记录" name="0"></el-tab-pane>
          <el-tab-pane label="招标清单" name="1"></el-tab-pane>
        </el-tabs>

        <div class="importMaterialBox" v-show="dialogSteps == 0">
          <el-table
            class="tables"
            :data="ListRecord"
            height="360"
            style="min-height: auto"
          >
            <el-table-column
              label="投标单位"
              prop="tenderUnit"
              align="center"
            ></el-table-column>
            <el-table-column
              label="商务文件"
              prop="businessDocument"
              align="center"
            >
              <template slot-scope="scope">
                <el-button
                  @click.stop="download(scope.row.businessDocument, 1)"
                  type="text"
                  size="small"
                  >下载附件</el-button
                >
              </template>
            </el-table-column>
            <el-table-column
              label="技术文件"
              prop="technicalDocument"
              align="center"
            >
              <template slot-scope="scope">
                <el-button
                  @click="download(scope.row.technicalDocument, 2)"
                  type="text"
                  size="small"
                  >下载附件</el-button
                >
              </template>
            </el-table-column>
            <el-table-column
              label="价格文件"
              prop="technicalDocument"
              align="center"
            >
              <template slot-scope="scope">
                <el-button
                  @click="download(scope.row.priceFile, 3)"
                  type="text"
                  size="small"
                  >下载附件</el-button
                >
              </template>
            </el-table-column>
            <el-table-column label="上传时间" prop="uploadTime" align="center">
            </el-table-column>
            <el-table-column label="状态" prop="state" align="center">
            </el-table-column>
            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <div class="tableBtns" style="margin-left: -5px !important">
                  <div @click="editComponent(scope.row)" class="operationText">
                    <img
                      src="@/assets/images/icon-edit.png"
                      width="15px"
                      height="15px"
                    />
                    <span>编辑</span>
                  </div>
                  <div @click="delet(scope.row)" class="operationText">
                    <img
                      src="@/assets/images/icon-delete.png"
                      width="15px"
                      height="15px"
                    />
                    <span>删除</span>
                  </div>
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="importMaterialBox" v-show="dialogSteps == 1">
          <el-table
            class="tables"
            :data="inventoryList"
            height="360"
            style="min-height: auto"
          >
            <el-table-column
              label="物品名称"
              prop="itemName"
              align="center"
            ></el-table-column>
            <el-table-column
              label="规格型号"
              prop="specificationAndModel"
              align="center"
            ></el-table-column>
            <el-table-column
              label="计量单位"
              prop="measureUnit"
              align="center"
            ></el-table-column>
            <el-table-column
              label="估算数量"
              prop="estimateQuantity"
              align="center"
            >
            </el-table-column>
            <el-table-column
              label="物资采购单位"
              prop="materialProcurementUnit"
              align="center"
            >
            </el-table-column>

            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <div class="tableBtns" style="margin-left: -5px !important">
                  <div @click="editComponent(scope.row)" class="operationText">
                    <img
                      src="@/assets/images/icon-edit.png"
                      width="15px"
                      height="15px"
                    />
                    <span>编辑</span>
                  </div>
                  <div @click="delet(scope.row)" class="operationText">
                    <img
                      src="@/assets/images/icon-delete.png"
                      width="15px"
                      height="15px"
                    />
                    <span>删除</span>
                  </div>
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>

        <div class="dialog-footer">
          <el-button
            type="primary"
            icon="el-icon-circle-check"
            @click="addOrEditDialog = false"
            size="medium"
            >确认
          </el-button>
        </div>
      </div>
    </el-dialog>
    <!-- 详情-投标记录新增 -->
    <el-dialog
      :modal-append-to-body="false"
      :title="tenderRecordStitle"
      :visible.sync="tenderRecordsShow"
      width="667px"
    >
      <div class="dialog_content">
        <el-form
          size="medium"
          ref="recordsForm"
          :model="recordsForm"
          :rules="recordsRules"
          label-width="120px"
          class="dialogFormBox"
        >
          <el-form-item label="投标单位" prop="tenderUnit">
            <el-input
              v-model="recordsForm.tenderUnit"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="上传时间" prop="uploadTime">
            <el-date-picker
              v-model="recordsForm.uploadTime"
              type="date"
              placeholder="选择日期"
              value-format="yyyy-MM-dd"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="状态" prop="state">
            <el-input
              v-model="recordsForm.state"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="商务文件" prop="businessDocument">
            <el-upload
              class="upload-demo"
              name="files"
              :action="$store.state.UPLOADURL"
              :on-remove="(file, fileList) => handleRemove(file, fileList, 2)"
              :multiple="false"
              :on-success="(res, file) => handleSuccess(res, file, 2)"
              :file-list="commercialAffairsList"
              accept=".doc, .docx, .xls, .xlsx, .ppt, .pptx, .pdf"
            >
              <el-button size="medium" type="primary" plain>
                上传附件
              </el-button>
            </el-upload>
          </el-form-item>
          <el-form-item label="技术文件" prop="technicalDocument">
            <el-upload
              class="upload-demo"
              name="files"
              :action="$store.state.UPLOADURL"
              :on-remove="(file, fileList) => handleRemove(file, fileList, 3)"
              :multiple="false"
              :on-success="(res, file) => handleSuccess(res, file, 3)"
              :file-list="technologyList"
              accept=".doc, .docx, .xls, .xlsx, .ppt, .pptx, .pdf"
            >
              <el-button size="medium" type="primary" plain>
                上传附件
              </el-button>
            </el-upload>
          </el-form-item>
          <el-form-item label="价格文件" prop="priceFile">
            <el-upload
              class="upload-demo"
              name="files"
              :action="$store.state.UPLOADURL"
              :on-remove="(file, fileList) => handleRemove(file, fileList, 4)"
              :multiple="false"
              :on-success="(res, file) => handleSuccess(res, file, 4)"
              :file-list="priceList"
              accept=".doc, .docx, .xls, .xlsx, .ppt, .pptx, .pdf"
            >
              <el-button size="medium" type="primary" plain>
                上传附件
              </el-button>
            </el-upload>
          </el-form-item>

          <div class="dialog-footer">
            <el-button
              class="cancleBtn"
              @click="tenderRecordsShow = false"
              icon="el-icon-circle-close"
              size="medium"
              >取消
            </el-button>
            <el-button
              type="primary"
              icon="el-icon-circle-check"
              size="medium"
              @click="saveBtn(1)"
              >保存
            </el-button>
          </div>
        </el-form>
      </div>
    </el-dialog>
    <!-- 详情-招标清单新增 -->
    <el-dialog
      :modal-append-to-body="false"
      @close="close"
      :title="tenderListShowtitle"
      :visible.sync="tenderListShow"
      width="667px"
    >
      <div class="dialog_content">
        <el-form
          size="medium"
          ref="tenderListForm"
          :model="tenderListForm"
          :rules="tenderListFormRules"
          label-width="120px"
          class="dialogFormBox"
        >
          <el-form-item label="物品名称" prop="itemName">
            <el-input
              v-model="tenderListForm.itemName"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="规格型号" prop="specificationAndModel">
            <el-input
              v-model="tenderListForm.specificationAndModel"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="计量单位" prop="measureUnit">
            <el-input
              v-model="tenderListForm.measureUnit"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="估算数量" prop="estimateQuantity">
            <el-input
              v-model="tenderListForm.estimateQuantity"
              placeholder="请输入"
            ></el-input>
          </el-form-item>

          <el-form-item label="物资采购单位" prop="materialProcurementUnit">
            <el-input
              v-model="tenderListForm.materialProcurementUnit"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <div class="dialog-footer">
            <el-button
              class="cancleBtn"
              @click="tenderListShow = false"
              icon="el-icon-circle-close"
              size="medium"
              >取消
            </el-button>
            <el-button
              type="primary"
              icon="el-icon-circle-check"
              size="medium"
              @click="saveBtn(2)"
              >保存
            </el-button>
          </div>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  addGtMaterialTenderApi,//招标管理
  deleGtMaterialTenderApi,
  editGtMaterialTenderApi,
  getTMaterialTenderApi,
  addGtMaterialTenderRecordApi,//招标管理_投标记录
  deletGtMaterialTenderRecordApi,
  editGtMaterialTenderRecordApi,
  getGtMaterialTenderRecordPageApi,
  addGtMaterialTenderBidApi,//招标管理_投标记录
  deletGtMaterialTenderBidApi,
  editGtMaterialTenderBidApi,
  getGtMaterialTenderBidPageApi
} from '@/assets/js/api/materialManagement.js'
export default {
  created() {
    this.getList()
    this.getRecordList()
    this.getTendersList()
  },
  data() {
    return {
      resultList: [
        {
          value: 1,
          purchasingMethod: '询价'
        },
        {
          value: 2,
          purchasingMethod: '竞争性谈判'
        },
        {
          value: 3,
          purchasingMethod: '直接委托'
        },
        {
          value: 4,
          purchasingMethod: '单一来源'
        },
        {
          value: 5,
          purchasingMethod: '其他合法采购方式'
        },
      ],

      uploadaurl: '',
      addInviteForm: {
        tenderName: "",
        tenderUnit: '',
        purchasingMethod: '',
        tenderType: '',
        tenderDay: '',
        releaseTime: '',
        planContractAmount: '',
        state: '',
        remark: '',
        annex: '',
        purchasingMethod: '',
      },//招标管理

      recordsForm: {
        tenderUnit: "",
        uploadTime: "",
        state: "",
        businessDocument: "",//商务文件
        technicalDocument: "",//技术文件
        priceFile: "",//技术文件
        gtMaterialTenderId: '',
      },//招标管理
      gtMaterialTenderId: '',//招标id

      surveySchemeList: [],
      addInviteFormRules: {
        tenderName: [
          { required: true, message: '必填', trigger: 'change' }

        ]
      },
      recordsRules: {},
      contractFormRules: {},
      searchForm: {
        tenderName: '',
      },
      pagInfo: {
        pageNo: 1, //页数
        pageSize: 10, //条数
        total: 0 //总条数
      },
      List: [],
      title: "",
      dialogShow: false,
      detailData: {},
      ListRecord: [],
      inventoryList: [],
      commercialAffairsList: [],
      technologyList: [],
      priceList: [],
      //----------------
      tenderListShowtitle: '',//详情-招标清单
      tenderListShow: false,//详情-招标清单
      tenderListForm: {
        itemName: '',
        specificationAndModel: '',
        estimateQuantity: '',
        measureUnit: '',
        materialProcurementUnit: '',
      },//详情-招标清单
      tenderListFormRules: {},
      tenderRecordStitle: '',//详情-投标记录
      tenderRecordsShow: false,//详情-投标记录
      tenderRecordsForm: {},//详情-投标记录
      tenderRecordsList: [],//详情-投标记录
      detailData: {},
      dialogSteps: 0,
      contractForm: {},
      contractFormRules: {},
      addOrEditDialog: false,

      value: '',
      id: '',
      options: [
        {
          label: '发标', value: 0
        },
        {
          label: '议标', value: 1
        },
        {
          label: '中标', value: 2
        },
      ],


      addEditForm: {
        warehouseName: '',//仓库名称
        warehousePos: '',//warehousePos
        header: '',//负责人
        headerPhone: '',//负责人电话
        remark: '',//备注
        fileName: '',//文件名
      },

    }
  },
  methods: {
    checkValue() {
      var value = '' + this.addInviteForm.planContractAmount.toString();
      value = value
        .replace(/[^\d.]/g, '') // 清除“数字”和“.”以外的字符
        .replace(/\.{2,}/g, '.') // 只保留第一个. 清除多余的
        .replace(/^\./g, '')    //保证第一个为数字而不是.
        .replace('.', '$#$')
        .replace(/\./g, '')
        .replace('$#$', '.')
        .replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); // 只能输入两个小数
      if (value.indexOf('.') < 0 && value != '') {
        // 以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
        value = parseFloat(value);

      }
      value = Number(value).toFixed(2); //不足补位
      this.addInviteForm.planContractAmount = value;

    },
    add() {
      this.title = '新增招标'
      this.dialogShow = true
      this.surveySchemeList = []
      this.close()
    },

    edit(obj) {
      this.title = '编辑招标'
      this.dialogShow = true
      this.addInviteForm = JSON.parse(JSON.stringify(obj))
      this.surveySchemeList = obj.annex == '' ? obj.annex : []
      if (typeof obj.annex === 'string') {
        this.addInviteForm.annex = JSON.parse(obj.annex)
        this.surveySchemeList = this.addInviteForm.annex

      }

    },
    //招标新增/编辑提交
    submitOne() {
      let params = JSON.parse(JSON.stringify(this.addInviteForm))
      params.annex = JSON.stringify(this.surveySchemeList)
      params.projectSn = this.$store.state.projectSn
      this.$refs.addInviteForm.validate((valid) => {
        if (valid) {
          if (this.title == '新增招标') {
            addGtMaterialTenderApi(params).then((result) => {
              if (result.success) {
                this.$message.success(result.message)
                this.getList()
              }
            })
          } else if (this.title === '编辑招标') {
            editGtMaterialTenderApi(params).then((result) => {
              if (result.success) {
                this.$message.success(result.message)
                this.getList()
              }
            })
          }
          this.dialogShow = false
        } else {
          return false
        }
      })
    },
    deleteDev(obj) {
      this.$confirm("此操作将永久删除, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          deleGtMaterialTenderApi({ id: obj.id }).then((res) => {
            if (res.success) {
              this.getList()
              this.$message({
                type: "success",
                message: "删除成功!",
              });
            } else {
              this.$message({
                type: "error",
                message: res.message,
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    //查询招标列表
    getList() {
      getTMaterialTenderApi({
        pageNo: this.pagInfo.pageNo,
        pageSize: this.pagInfo.pageSize,
        projectSn: this.$store.state.projectSn,
        tenderName: this.searchForm.tenderName,
      }).then((result) => {
        if (result.success) {
          this.List = result.result.records
          this.pagInfo.total = result.result.total
        }
      })
    },

    close() {
      this.addInviteForm = {}
      this.surveySchemeList = []
      this.recordsForm = {}
      this.tenderListForm = {}
      this.commercialAffairsList = []
      this.technologyList = []
      this.priceList = []
      this.$nextTick(() => {
        this.$refs.addInviteForm.clearValidate()
      })

    },
    //显示检查详细弹框
    showDetailFn(row) {
      console.log('row==========', row);
      this.detailData = row
      this.gtMaterialTenderId = this.detailData.id
      this.addOrEditDialog = true
      this.getRecordList()
      this.getTendersList()
    },
    //查询投标记录
    getRecordList() {
      getGtMaterialTenderRecordPageApi({
        pageNo: this.pagInfo.pageNo,
        pageSize: this.pagInfo.pageSize,
        projectSn: this.$store.state.projectSn,
        gtMaterialTenderId: this.gtMaterialTenderId
      }).then((result) => {
        if (result.success) {
          this.ListRecord = result.result.records
          this.pagInfo.total = result.result.total
        }
      })
    },
    //查询招标清单
    getTendersList() {
      getGtMaterialTenderBidPageApi({
        pageNo: this.pagInfo.pageNo,
        pageSize: this.pagInfo.pageSize,
        projectSn: this.$store.state.projectSn,
        gtMaterialTenderId: this.gtMaterialTenderId
      }).then((result) => {
        if (result.success) {
          this.inventoryList = result.result.records
          this.pagInfo.total = result.result.total
        }
      })
    },
    //记录详情新增弹框
    addDetails() {
      if (this.dialogSteps == 0) {
        this.tenderRecordStitle = '新增记录'
        this.tenderRecordsShow = true
        this.close()
      } else {
        this.tenderListShow = true
        this.tenderListShowtitle = '新增清单'

      }
    },
    //记录详情编辑弹框
    editComponent(obj) {
      if (this.dialogSteps == 0) {
        this.tenderRecordStitle = '编辑记录'
        this.tenderRecordsShow = true
        this.recordsForm = JSON.parse(JSON.stringify(obj))
        this.commercialAffairsList = obj.businessDocument

        this.technologyList = obj.technicalDocument
        this.priceList = obj.priceFile

        if (typeof obj.businessDocument === 'string') {
          this.recordsForm.businessDocument = JSON.parse(obj.businessDocument)
          this.commercialAffairsList = this.recordsForm.businessDocument
        }
        if (typeof obj.technicalDocument === 'string') {
          this.recordsForm.technicalDocument = JSON.parse(obj.technicalDocument)
          this.technologyList = this.recordsForm.technicalDocument
        }
        if (typeof obj.priceFile === 'string') {
          this.recordsForm.priceFile = JSON.parse(obj.priceFile)
          this.priceList = this.recordsForm.priceFile
        }

      } else {
        this.tenderListShow = true
        this.tenderListShowtitle = '编辑清单'
        this.tenderListForm = JSON.parse(JSON.stringify(obj))
      }
    },
    //新增/编辑提交
    saveBtn(type) {
      if (type == 1) {
        let params = JSON.parse(JSON.stringify(this.recordsForm))
        params.projectSn = this.$store.state.projectSn
        params.gtMaterialTenderId = this.gtMaterialTenderId
        params.businessDocument = JSON.stringify(this.commercialAffairsList)
        params.technicalDocument = JSON.stringify(this.technologyList)
        params.priceFile = JSON.stringify(this.priceList)
        this.$refs.recordsForm.validate((valid) => {
          if (valid) {
            if (this.tenderRecordStitle == '新增记录') {
              addGtMaterialTenderRecordApi(params).then((result) => {
                if (result.success) {
                  this.$message.success(result.message)
                  this.getRecordList()

                }
              })
            } else if (this.tenderRecordStitle == '编辑记录') {
              editGtMaterialTenderRecordApi(params).then((result) => {
                if (result.success) {
                  this.$message.success(result.message)
                  this.getRecordList()

                }
              })
            }
            this.tenderRecordsShow = false
          } else {
            return false
          }
        })
      } else {
        let params = JSON.parse(JSON.stringify(this.tenderListForm))
        params.projectSn = this.$store.state.projectSn
        params.gtMaterialTenderId = this.gtMaterialTenderId
        this.$refs.tenderListForm.validate((valid) => {
          if (valid) {
            if (this.tenderListShowtitle == '新增清单') {
              addGtMaterialTenderBidApi(params).then((result) => {
                if (result.success) {
                  this.$message.success(result.message)
                  this.getTendersList()

                }
              })
            } else if (this.tenderListShowtitle == '编辑清单') {
              editGtMaterialTenderBidApi(params).then((result) => {
                if (result.success) {
                  this.$message.success(result.message)
                  this.getTendersList()

                }
              })
            }
            this.tenderListShow = false
          } else {
            return false
          }
        })
      }

    },
    delet(obj) {
      if (this.dialogSteps == 0) {
        this.$confirm("此操作将永久删除, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            deletGtMaterialTenderRecordApi({ id: obj.id }).then((res) => {
              if (res.success) {
                this.getRecordList()
                this.$message({
                  type: "success",
                  message: "删除成功!",
                });
              } else {
                this.$message({
                  type: "error",
                  message: res.message,
                });
              }
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除",
            });
          });

      } else {
        this.$confirm("此操作将永久删除, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            deletGtMaterialTenderBidApi({ id: obj.id }).then((res) => {
              if (res.success) {
                this.getTendersList()()
                this.$message({
                  type: "success",
                  message: "删除成功!",
                });
              } else {
                this.$message({
                  type: "error",
                  message: res.message,
                });
              }
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除",
            });
          });
      }
    },
    //下载附件
    download(item) {
      console.log('下载的item', item);
      let downloadElement = document.createElement('a')
      if (item == '[]') {
        this.$message.error('未查询到附件')
      } else {
        let arr = []
        arr = JSON.parse(item)
        arr.forEach(element => {
          let url = this.$http.defaults.baseURL + 'xmgl/upload/getRenameFile?fileUrl=' + element.url + '&fileName=' + element.name
          window.location.href = url;
        });
      }


    },
    // 删除文件
    handleRemove(file, fileList, type) {
      if (type == 1) {
        this.surveySchemeList = fileList
      }
      else if (type == 2) {
        this.commercialAffairsList = fileList
      }
      else if (type == 3) {
        this.technologyList = fileList
      }
      else if (type == 4) {
        this.priceList = fileList
      }
    },
    handleSuccess(res, file, type) {
      if (res.status == 'SUCCESS') {
        if (type == 1) {
          this.surveySchemeList.push({
            name: file.name,
            url: this.$store.state.FILEURL + file.response.data[0].imageUrl
          })
        } else if (type == 2) {
          this.commercialAffairsList.push({
            name: file.name,
            url: this.$store.state.FILEURL + file.response.data[0].imageUrl
          })
        }
        else if (type == 3) {
          this.technologyList.push({
            name: file.name,
            url: this.$store.state.FILEURL + file.response.data[0].imageUrl
          })
        }
        else if (type == 4) {
          this.priceList.push({
            name: file.name,
            url: this.$store.state.FILEURL + file.response.data[0].imageUrl
          })
        }
        this.fileName = file.name
      }
      this.$message.success(this.$t('message.deepFoundConfig.uploadSuccess'))
    },
    SizeChange(val) {
      this.pagInfo.pageSize = val
      this.getList()
    },
    CurrentChange(val) {
      this.pagInfo.pageNo = val
      this.getList()
    },
    refresh() {
      this.searchForm = {}
      this.pagInfo.pageNo = 1 //页数
      this.pagInfo.pageSize = 10 //条数
      this.getList()
    },
  }
}
</script>
<style lang="less" scoped>
.tables2 {
  min-height: auto;
}

::v-deep .dialog_content {
  padding: 0 0px;
}

.btnAdd {
  position: absolute;
  right: 20px;
}
</style>