<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="项目编码" prop="investProjectName">
        <el-input
          v-model="queryParams.data.projectCode"
          placeholder="请输入项目编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          type="cyan"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['earlyStage:bidNotice:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['earlyStage:bidNotice:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['earlyStage:bidNotice:remove']"
          >删除</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="bidNoticeList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" fixed />
      <el-table-column
        label="序号"
        type="index"
        width="50"
        align="center"
        fixed
      />

      <el-table-column
        label="招标项目名称"
        align="center"
        prop="bidProjectName"
        :formatter="projectNameFormat"
        min-width="150"
      />
      <el-table-column
        label="招标项目编码"
        align="center"
        prop="projectCode"
        min-width="120"
      />
      <el-table-column label="标段" align="center" prop="lotName" width="180" />
      <el-table-column
        label="公告性质"
        align="center"
        prop="noticeNature"
        min-width="150"
      />
      <el-table-column
        label="资格审查方式"
        align="center"
        prop="reviewQualificationMethod"
        min-width="150"
      />
      <el-table-column
        label="招标项目地点"
        align="center"
        prop="bidProjectLocation"
        min-width="150"
      />
      <el-table-column
        label="资金来源"
        align="center"
        prop="fundingSource"
        min-width="150"
      />
      <el-table-column
        label="资金来源构成"
        align="center"
        prop="fundingSourceConstitute"
        min-width="150"
      />
      <el-table-column
        label="招标范围及规模"
        align="center"
        prop="bidScope"
        min-width="150"
      />
      <el-table-column
        label="招标内容"
        align="center"
        prop="bidContent"
        min-width="180"
      />
      <el-table-column
        label="工期"
        align="center"
        prop="deliveryTime"
        min-width="150"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deliveryTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最高投标限价" align="center" prop="maxPriceBid" />
      <el-table-column
        label="是否接受联合体投标"
        align="center"
        prop="isConsortiumInvestment"
        :formatter="isConsortiumInvestmentFormat"
        min-width="180"
      />
      <el-table-column
        label="投标资格能力要求"
        align="center"
        prop="bidCapabilityRequirements"
        min-width="150"
      />
      <el-table-column
        label="是否采用电子招标投标方式"
        align="center"
        prop="isElectronicBidding"
        :formatter="isElectronicBiddingFormat"
        min-width="180"
      />
      <el-table-column
        label="获取招标文件的方式"
        align="center"
        prop="gainBidFileMethod"
        min-width="150"
      />
      <el-table-column
        label="获取招标文件开始时间"
        align="center"
        prop="gainFileStartTime"
        min-width="150"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.gainFileStartTime, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="获取招标文件截止时间"
        align="center"
        prop="gainFileEndTime"
        min-width="150"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gainFileEndTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="递交投标文件截止时间"
        align="center"
        prop="deliveryEndTime"
        min-width="150"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deliveryEndTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="投标文件递交方式"
        align="center"
        prop="bidDeliveryFileMethod"
        min-width="150"
      />
      <el-table-column
        label="开标方式"
        align="center"
        prop="bidOpeningMethod"
        min-width="150"
      />
      <el-table-column
        label="开标时间及地点"
        align="center"
        prop="bidTimeLocation"
        min-width="150"
      />
      <el-table-column
        label="公告发布媒介"
        align="center"
        prop="announcementReleaseMedia"
        min-width="150"
      />
      <el-table-column
        label="招标人"
        align="center"
        prop="tendererName"
        min-width="150"
      />
      <el-table-column
        label="办公地址"
        align="center"
        prop="officeAddress"
        min-width="150"
      />
      <el-table-column
        label="招标人联系人"
        align="center"
        prop="bidderContacts"
        min-width="150"
      />
      <el-table-column
        label="联系电话"
        align="center"
        prop="contactsPhone"
        min-width="150"
      />
      <el-table-column
        label="招标代理机构"
        align="center"
        prop="biddingAgency"
        min-width="150"
      />
      <el-table-column
        label="招标代理机构办公地址"
        align="center"
        prop="agencyOfficeAddress"
        min-width="150"
      />
      <el-table-column
        label="招标代理联系人"
        align="center"
        prop="bidAgencyContacts"
        min-width="150"
      />
      <el-table-column
        label="招标代理联系人联系电话"
        align="center"
        prop="agencyPhone"
        min-width="180"
      />
      <el-table-column
        label="招标监督机构"
        align="center"
        prop="tenderingSupervisionAgency"
        min-width="150"
      />
      <el-table-column
        label="联系电话"
        align="center"
        prop="supervisionPhone"
        min-width="150"
      />
      <el-table-column
        label="发布责任人"
        align="center"
        prop="releaseResponsiblePerson"
        min-width="150"
      />
      <el-table-column
        label="其他依法应当载明的内容"
        align="center"
        prop="otherLawContents"
        min-width="180"
      />
      <el-table-column
        label="附件"
        align="center"
        prop="attachment"
        min-width="150"
      >
        <template slot-scope="scope">
          <div
            v-for="(item, index) in JSON.parse(scope.row.attachment)"
            :key="item + index"
          >
            <i class="el-icon-document"></i>
            {{ item.name }}
            <i
              class="el-icon-download"
              @click="downloadFile(scope, index)"
              style="cursor: pointer"
            ></i>
          </div>
        </template>
      </el-table-column>

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        min-width="120"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['earlyStage:bidNotice:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['earlyStage:bidNotice:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改招标公告对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1500px"
      append-to-body
      @close="close"
    >
      <el-row :gutter="15">
        <el-form ref="form" :model="form" :rules="rules" label-width="180px">
          <el-col :span="8">
            <el-form-item label="招标项目名称" prop="bidProjectName">
              <!-- <el-input
                v-model="form.bidProjectName"
                placeholder="请输入招标项目名称"
              /> -->
              <el-select
                v-model="form.bidProjectName"
                placeholder="招标项目名称"
                filterable
                clearable
                size="small"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in bidProjectNameOptions"
                  :key="dict.projectName + dict.id"
                  :label="dict.projectName + '[' + dict.projectCode + ']'"
                  :value="dict.projectName + '[' + dict.projectCode + ']'"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="标段" prop="lotName">
              <el-input v-model="form.lotName" placeholder="请输入标段" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="公告性质" prop="noticeNature">
              <el-input
                v-model="form.noticeNature"
                placeholder="请输入公告性质"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="资格审查方式" prop="reviewQualificationMethod">
              <el-input
                v-model="form.reviewQualificationMethod"
                placeholder="请输入资格审查方式"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="招标项目地点" prop="bidProjectLocation">
              <el-input
                v-model="form.bidProjectLocation"
                placeholder="请输入招标项目地点"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="资金来源" prop="fundingSource">
              <el-input
                v-model="form.fundingSource"
                placeholder="请输入资金来源"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="资金来源构成" prop="fundingSourceConstitute">
              <el-input
                v-model="form.fundingSourceConstitute"
                placeholder="请输入资金来源构成"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="招标范围及规模" prop="bidScope">
              <el-input
                v-model="form.bidScope"
                placeholder="请输入招标范围及规模"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="招标内容" prop="bidContent">
              <el-input
                v-model="form.bidContent"
                placeholder="请输入招标内容"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="工期" prop="deliveryTime">
              <!-- <el-date-picker
                clearable
                size="small"
                style="width: 100%"
                v-model="form.deliveryTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择工期"
              >
              
              </el-date-picker> -->
              <el-input
                clearable
                size="small"
                v-model="form.deliveryTime"
                placeholder="请输入工期"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="最高投标限价" prop="maxPriceBid">
              <el-input
                v-model="form.maxPriceBid"
                placeholder="请输入最高投标限价"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="是否接受联合体投标"
              prop="isConsortiumInvestment"
            >
              <el-select
                v-model="form.isConsortiumInvestment"
                placeholder="请选择是否接受联合体投标"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in isConsortiumInvestmentOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="投标资格能力要求"
              prop="bidCapabilityRequirements"
            >
              <el-input
                v-model="form.bidCapabilityRequirements"
                placeholder="请输入投标资格能力要求"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="是否采用电子招标投标方式"
              prop="isElectronicBidding"
            >
              <el-select
                v-model="form.isElectronicBidding"
                placeholder="请选择是否采用电子招标投标方式"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in isElectronicBiddingOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="获取招标文件的方式" prop="gainBidFileMethod">
              <el-input
                v-model="form.gainBidFileMethod"
                placeholder="请输入获取招标文件的方式"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="获取招标文件开始时间" prop="gainFileStartTime">
              <el-date-picker
                clearable
                size="small"
                style="width: 100%"
                v-model="form.gainFileStartTime"
                type="datetime"
                value-format="yyyy-MM-dd"
                placeholder="选择获取招标文件开始时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="获取招标文件截止时间" prop="gainFileEndTime">
              <el-date-picker
                clearable
                size="small"
                style="width: 100%"
                v-model="form.gainFileEndTime"
                type="datetime"
                value-format="yyyy-MM-dd"
                placeholder="选择获取招标文件截止时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="递交投标文件截止时间" prop="deliveryEndTime">
              <el-date-picker
                clearable
                size="small"
                style="width: 100%"
                v-model="form.deliveryEndTime"
                type="datetime"
                value-format="yyyy-MM-dd"
                placeholder="选择递交投标文件截止时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="投标文件递交方式" prop="bidDeliveryFileMethod">
              <el-input
                v-model="form.bidDeliveryFileMethod"
                placeholder="请输入投标文件递交方式"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="开标方式" prop="bidOpeningMethod">
              <el-input
                v-model="form.bidOpeningMethod"
                placeholder="请输入开标方式"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="开标时间及地点" prop="bidTimeLocation">
              <el-input
                v-model="form.bidTimeLocation"
                placeholder="请输入开标时间及地点"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="公告发布媒介" prop="announcementReleaseMedia">
              <el-input
                v-model="form.announcementReleaseMedia"
                placeholder="请输入公告发布媒介"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="招标人" prop="tendererName">
              <el-input
                v-model="form.tendererName"
                placeholder="请输入招标人"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="办公地址" prop="officeAddress">
              <el-input
                v-model="form.officeAddress"
                placeholder="请输入办公地址"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="招标人联系人" prop="bidderContacts">
              <el-input
                v-model="form.bidderContacts"
                placeholder="请输入招标人联系人"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话" prop="contactsPhone">
              <el-input
                v-model="form.contactsPhone"
                placeholder="请输入联系电话"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="招标代理机构" prop="biddingAgency">
              <el-input
                v-model="form.biddingAgency"
                placeholder="请输入招标代理机构"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="招标代理机构办公地址"
              prop="agencyOfficeAddress"
            >
              <el-input
                v-model="form.agencyOfficeAddress"
                placeholder="请输入招标代理机构办公地址"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="招标代理联系人" prop="bidAgencyContacts">
              <el-input
                v-model="form.bidAgencyContacts"
                placeholder="请输入招标代理联系人"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="招标代理联系人联系电话" prop="agencyPhone">
              <el-input
                v-model="form.agencyPhone"
                placeholder="请输入招标代理联系人联系电话"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="招标监督机构"
              prop="tenderingSupervisionAgency"
            >
              <el-input
                v-model="form.tenderingSupervisionAgency"
                placeholder="请输入招标监督机构"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话" prop="supervisionPhone">
              <el-input
                v-model="form.supervisionPhone"
                placeholder="请输入联系电话"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="发布责任人" prop="releaseResponsiblePerson">
              <el-input
                v-model="form.releaseResponsiblePerson"
                placeholder="请输入发布责任人"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="其他依法应当载明的内容"
              prop="otherLawContents"
            >
              <el-input
                v-model="form.otherLawContents"
                placeholder="请输入其他依法应当载明的内容"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="附件" prop="attachment">
              <!-- <el-input v-model="form.attachment" placeholder="请输入附件" /> -->
              <el-upload
                class="upload-demo"
                action="thinking/common/upload"
                :headers="headers"
                :on-preview="handlePreview"
                :on-remove="handleRemove"
                :before-remove="beforeRemove"
                multiple
                :on-exceed="handleExceed"
                :on-success="submitUpload"
                :file-list="fileList"
              >
                <el-button size="small" type="primary" plain>
                  <i class="el-icon-upload el-icon--right"></i>
                  点击上传
                </el-button>
                <div slot="tip" class="el-upload__tip">
                  支持jpg/png/pdf/word/excel文件等，不超过100M
                </div>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listBidNotice,
  getBidNotice,
  delBidNotice,
  addBidNotice,
  updateBidNotice,
  exportBidNotice,
} from "@/api/earlyStage/bidNotice";
import { listProposal } from "@/api/earlyStage/proposal";
import { getToken } from "@/utils/auth";
import { getFileStream } from "@/api/system/upload";

export default {
  name: "BidNotice",
  props: ["proNo"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 招标公告表格数据
      bidNoticeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否接受联合体投标字典
      isConsortiumInvestmentOptions: [],
      // 是否采用电子招标投标方式字典
      isElectronicBiddingOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ids: null,
        data: {
          investProjectCode: null,
          investProjectName: null,
          bidProjectName: null,
          lotName: null,
          noticeNature: null,
          reviewQualificationMethod: null,
          bidProjectLocation: null,
          fundingSource: null,
          fundingSourceConstitute: null,
          bidScope: null,
          bidContent: null,
          deliveryTime: null,
          maxPriceBid: null,
          isConsortiumInvestment: null,
          bidCapabilityRequirements: null,
          isElectronicBidding: null,
          gainBidFileMethod: null,
          gainFileStartTime: null,
          gainFileEndTime: null,
          deliveryEndTime: null,
          bidDeliveryFileMethod: null,
          bidOpeningMethod: null,
          bidTimeLocation: null,
          announcementReleaseMedia: null,
          tendererName: null,
          officeAddress: null,
          bidderContacts: null,
          contactsPhone: null,
          biddingAgency: null,
          agencyOfficeAddress: null,
          bidAgencyContacts: null,
          agencyPhone: null,
          tenderingSupervisionAgency: null,
          supervisionPhone: null,
          releaseResponsiblePerson: null,
          otherLawContents: null,
          attachment: null,
          projectCode: null,
          proNo: null,
          createUid: null,
          createTime: null,
          updateUid: null,
          updateTime: null,
          owerDept: null,
          remark: null,
        },
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      // 附件
      fileList: [],
      // 请求头
      headers: {
        jianwei: "jwtech " + getToken(),
      },
      // 项目建议书的项目，同一个项目，有不同的项目编码
      bidProjectNameOptions: [],
    };
  },
  created() {
    this.getList();
    this.getDicts("yes_no").then((response) => {
      this.isConsortiumInvestmentOptions = response.data;
    });
    this.getDicts("yes_no").then((response) => {
      this.isElectronicBiddingOptions = response.data;
    });
  },
  // 父组件  利用axios请求得到的值  传送到子组件，要监听，否则初始渲染时为空
  watch: {
    proNo: function (n, o) {
      this.proNo = n;
      this.getList();
    },
  },
  methods: {
    /** 查询招标公告列表 */
    getList() {
      this.loading = true;
      this.queryParams.data.proNo = this.proNo;
      listBidNotice(this.queryParams).then((response) => {
        this.bidNoticeList = response.records;
        this.total = response.total;
        this.loading = false;
      });
      // 招标项目名称选项
      listProposal({ data: { proNo: this.proNo } }).then((response) => {
        // console.log("response55555555555", response);
        this.bidProjectNameOptions = response.records;
      });
    },
    // 是否接受联合体投标字典翻译
    isConsortiumInvestmentFormat(row, column) {
      return this.selectDictLabel(
        this.isConsortiumInvestmentOptions,
        row.isConsortiumInvestment
      );
    },
    // 是否采用电子招标投标方式字典翻译
    isElectronicBiddingFormat(row, column) {
      return this.selectDictLabel(
        this.isElectronicBiddingOptions,
        row.isElectronicBidding
      );
    },
    projectNameFormat(row) {
      if (row.bidProjectName) {
        return row.bidProjectName.slice(0, row.bidProjectName.indexOf("["));
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        investProjectCode: null,
        investProjectName: null,
        bidProjectName: null,
        lotName: null,
        noticeNature: null,
        reviewQualificationMethod: null,
        bidProjectLocation: null,
        fundingSource: null,
        fundingSourceConstitute: null,
        bidScope: null,
        bidContent: null,
        deliveryTime: null,
        maxPriceBid: null,
        isConsortiumInvestment: null,
        bidCapabilityRequirements: null,
        isElectronicBidding: null,
        gainBidFileMethod: null,
        gainFileStartTime: null,
        gainFileEndTime: null,
        deliveryEndTime: null,
        bidDeliveryFileMethod: null,
        bidOpeningMethod: null,
        bidTimeLocation: null,
        announcementReleaseMedia: null,
        tendererName: null,
        officeAddress: null,
        bidderContacts: null,
        contactsPhone: null,
        biddingAgency: null,
        agencyOfficeAddress: null,
        bidAgencyContacts: null,
        agencyPhone: null,
        tenderingSupervisionAgency: null,
        supervisionPhone: null,
        releaseResponsiblePerson: null,
        otherLawContents: null,
        attachment: null,
        projectCode: null,
        proNo: null,
        createUid: null,
        createTime: null,
        updateUid: null,
        updateTime: null,
        owerDept: null,
        remark: null,
      };
      this.fileList = [];
      this.resetForm("form");
    },
    // 查询表单重置
    resetQueryForm() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        data: {
          id: null,
          investProjectCode: null,
          investProjectName: null,
          bidProjectName: null,
          lotName: null,
          noticeNature: null,
          reviewQualificationMethod: null,
          bidProjectLocation: null,
          fundingSource: null,
          fundingSourceConstitute: null,
          bidScope: null,
          bidContent: null,
          deliveryTime: null,
          maxPriceBid: null,
          isConsortiumInvestment: null,
          bidCapabilityRequirements: null,
          isElectronicBidding: null,
          gainBidFileMethod: null,
          gainFileStartTime: null,
          gainFileEndTime: null,
          deliveryEndTime: null,
          bidDeliveryFileMethod: null,
          bidOpeningMethod: null,
          bidTimeLocation: null,
          announcementReleaseMedia: null,
          tendererName: null,
          officeAddress: null,
          bidderContacts: null,
          contactsPhone: null,
          biddingAgency: null,
          agencyOfficeAddress: null,
          bidAgencyContacts: null,
          agencyPhone: null,
          tenderingSupervisionAgency: null,
          supervisionPhone: null,
          releaseResponsiblePerson: null,
          otherLawContents: null,
          attachment: null,
          projectCode: null,
          proNo: null,
          createUid: null,
          createTime: null,
          updateUid: null,
          updateTime: null,
          owerDept: null,
          remark: null,
        },
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetQueryForm();
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加招标公告";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getBidNotice(id).then((response) => {
        this.form = response.data;
        if (response.data.attachment) {
          this.fileList = JSON.parse(response.data.attachment);
        }
        this.open = true;
        this.title = "修改招标公告";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        // 附件
        this.form.attachment = JSON.stringify(this.fileList);
        // 项目编码
        this.form.projectCode = this.form.bidProjectName.slice(
          this.form.bidProjectName.indexOf("[") + 1,
          this.form.bidProjectName.indexOf("]")
        );
        if (valid) {
          if (this.form.id != null) {
            updateBidNotice(this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            this.form.proNo = this.proNo;
            addBidNotice(this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    // 关闭弹窗
    close() {
      this.reset();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      if (ids) {
        this.$confirm("是否删除选中的数据？", "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(function () {
            return delBidNotice(ids);
          })
          .then(() => {
            this.getList();
            this.msgSuccess("删除成功");
          })
          .catch(function () {});
      } else {
        this.$message.warning("请选择要删除的数据！！");
      }
    },
    submitUpload(_, fileList) {
      console.log("fileList", fileList);
      this.fileList.push({
        name: fileList.name,
        fileName: fileList.response.fileName,
        url: fileList.response.url,
        uid: fileList.uid,
      });
    },
    handleRemove(file, fileList) {
      // console.log(file, fileList);
      let index = this.fileList.findIndex((item) => item.uid === file.uid);
      // 删除文件
      this.fileList.splice(index, 1);
    },
    // 表格中下载
    downloadFile(scope, index) {
      // console.log(scope);
      let file = JSON.parse(scope.row.attachment)[index];
      this.handlePreview(file);
    },
    // 点击预览下载文件
    handlePreview(file) {
      // console.log(file);
      getFileStream({ fileName: file.fileName }).then((res) => {
        const blob = new Blob([res], {
          // type类型后端返回来的数据中会有，根据自己实际进行修改
          // 表格下载为 application/xlsx，压缩包为 application/zip等，
          type: "application/xlsx",
        }); //excel,pdf等
        const href = URL.createObjectURL(blob); //创建新的URL表示指定的blob对象
        const a = document.createElement("a"); //创建a标签
        a.style.display = "none";
        a.href = href; // 指定下载链接
        a.download = file.name; //指定下载文件名
        a.click(); //触发下载
        URL.revokeObjectURL(a.href); //释放URL对象
      });
    },
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${
          files.length + fileList.length
        } 个文件`
      );
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep {
  .el-dialog {
    margin-top: 2vh !important;
    height: 90%;
    overflow-y: auto;
  }
}
</style>
