<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="96px"
    >
      <el-form-item label="招标计划名称" prop="bidPlanName">
        <el-input
          v-model="queryParams.cv.value"
          placeholder="请输入招标计划名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        >
          <el-button
            type="primary"
            slot="append"
            icon="el-icon-search"
            size="small"
            @click="handleQuery"
          ></el-button>
        </el-input>
      </el-form-item>
      <el-form-item label="是否合并招标" prop="isConsolidatedBidding">
        <el-select
          v-model="queryParams.data.isConsolidatedBidding"
          placeholder="请选择是否合并招标"
          clearable
          size="small"
          @change="handleQuery"
        >
          <el-option
            v-for="dict in isConsolidatedBiddingOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </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:bidInfo: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:bidInfo: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:bidInfo:remove']"
          >删除</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="bidInfoList"
      @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="bidPlanName"
        min-width="150"
      />
      <el-table-column
        label="是否合并招标"
        align="center"
        prop="isConsolidatedBidding"
        :formatter="isConsolidatedBiddingFormat"
        min-width="120"
      />
      <el-table-column
        label="招标性质"
        align="center"
        prop="bidNature"
        min-width="150"
      />

      <el-table-column
        label="招标计划发布人"
        align="center"
        prop="bidPlanPerson"
        min-width="150"
      />
      <el-table-column
        label="发布时间"
        align="center"
        prop="reportTime"
        min-width="120"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.reportTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="招标人名称"
        align="center"
        prop="tendererName"
        min-width="150"
      />
      <el-table-column
        label="招标人统一社会信用代码"
        align="center"
        prop="socialCreditCode"
        min-width="180"
      />

      <!-- <el-table-column
        label="附件"
        align="center"
        prop="bidAttachment"
        min-width="150"
      >
        <template slot-scope="scope">
          <div
            v-for="(item, index) in JSON.parse(scope.row.bidAttachment)"
            :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"
        prop="createTime"
        min-width="120"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        min-width="180"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="viewInfo(scope.row)"
            >查看</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['earlyStage:bidInfo:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['earlyStage:bidInfo: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="90%"
      append-to-body
      @close="close"
      :close-on-click-modal="false"
    >
      <!-- 招标计划基本信息 -->
      <el-divider content-position="left"> 招标计划基本信息 </el-divider>
      <el-row :gutter="15">
        <el-form
          ref="baseForm"
          :model="baseForm"
          :rules="baseRules"
          label-width="170px"
        >
          <el-col :span="12">
            <el-form-item label="招标项目名称" prop="bidProjectName">
              <!-- <el-input
                v-model="baseForm.bidProjectName"
                placeholder="请输入招标项目名称"
              /> -->
              <el-select
                v-model="baseForm.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="12">
            <el-form-item label="是否合并招标" prop="isConsolidatedBidding">
              <el-select
                v-model="baseForm.isConsolidatedBidding"
                placeholder="请选择是否合并招标"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in isConsolidatedBiddingOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="招标性质" prop="bidNature">
              <el-input
                v-model="baseForm.bidNature"
                placeholder="请输入招标性质"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="招标计划名称" prop="bidPlanName">
              <el-input
                v-model="baseForm.bidPlanName"
                placeholder="请输入招标计划名称"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="招标计划发布人" prop="bidPlanPerson">
              <el-input
                v-model="baseForm.bidPlanPerson"
                placeholder="请输入招标计划发布人"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发布时间" prop="reportTime">
              <el-date-picker
                clearable
                size="small"
                style="width: 100%"
                v-model="baseForm.reportTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择发布时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="招标人名称" prop="tendererName">
              <el-input
                v-model="baseForm.tendererName"
                placeholder="请输入招标人名称"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="招标人统一社会信用代码"
              prop="socialCreditCode"
            >
              <el-input
                v-model="baseForm.socialCreditCode"
                placeholder="请输入招标人统一社会信用代码"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input
                type="textarea"
                v-model="baseForm.remark"
                :rows="4"
                placeholder="请输入备注"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="附件" prop="bidAttachment">
              <!-- <el-input
                v-model="baseForm.bidAttachment"
                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>
      <!-- 计划明细内容 -->
      <el-divider content-position="left">计划明细内容</el-divider>
      <el-row :gutter="15">
        <el-form
          ref="detailsForm"
          :model="detailsForm"
          :rules="detailsRules"
          label-width="170px"
        >
          <el-col :span="12">
            <el-form-item label="是否依法必招项目" prop="isMustProject">
              <el-select
                v-model="detailsForm.isMustProject"
                placeholder="请输入是否依法必招项目"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in isMustProject"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="招标项目类型" prop="bidType">
              <el-select
                v-model="detailsForm.bidType"
                placeholder="请选择招标项目类型"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in bidType"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="招标方式" prop="bidMethod">
              <el-input
                v-model="detailsForm.bidMethod"
                placeholder="请输入招标方式"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="招标内容" prop="bidContent">
              <el-input
                v-model="detailsForm.bidContent"
                placeholder="请输入招标内容"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="预估发包价" prop="estimatedContractPrice">
              <el-input
                v-model="detailsForm.estimatedContractPrice"
                placeholder="请输入预估发包价"
              >
                <template slot="append">万元</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="招标项目建设地点"
              prop="bidConstructionLocation"
            >
              <el-input
                v-model="detailsForm.bidConstructionLocation"
                placeholder="请输入招标项目建设地点"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="招标公告预计发布时间" prop="bidNoticeTime">
              <el-date-picker
                clearable
                size="small"
                style="width: 100%"
                v-model="detailsForm.bidNoticeTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择招标公告预计发布时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="招标监管部门" prop="bidRegulator">
              <el-input
                v-model="detailsForm.bidRegulator"
                placeholder="请输入招标监管部门"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="项目概况" prop="projectOverview">
              <el-input
                v-model="detailsForm.projectOverview"
                type="textarea"
                :rows="4"
                placeholder="请输入项目概况"
              />
            </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>

    <!--查看 -->
    <el-dialog
      :title="viewTitle"
      :visible.sync="viewOpen"
      width="90%"
      append-to-body
      @close="closeView"
      :close-on-click-modal="false"
    >
      <!-- 计划信息 -->
      <div class="infoTitle">计划信息</div>
      <div class="draLine"></div>
      <div class="content">
        <!-- <table class="infoTable" border="1">
          <tbody>
            <tr class="ant-descriptions-row">
              <th
                class="ant-descriptions-item-label"
                colspan="1"
                style="width: 180px"
              >
                <span>合并招标</span>
              </th>
              <td
                class="ant-descriptions-item-content"
                colspan="1"
                style="max-width: 900px"
              >
                <span>{{ isConsolidatedBiddingFormat(this.infoMsg) }}</span>
              </td>
              <th
                class="ant-descriptions-item-label"
                colspan="1"
                style="width: 180px"
              >
                <span>性质</span>
              </th>
              <td
                class="ant-descriptions-item-content"
                colspan="1"
                style="max-width: 900px"
              >
                <span>{{ this.infoMsg.bidNature }}</span>
              </td>
            </tr>
            <tr class="ant-descriptions-row">
              <th
                class="ant-descriptions-item-label"
                colspan="1"
                style="width: 180px"
              >
                <span>招标计划名称</span>
              </th>
              <td
                class="ant-descriptions-item-content"
                colspan="3"
                style="max-width: 900px"
              >
                <span>{{ this.infoMsg.bidPlanName }}</span>
              </td>
            </tr>
            <tr class="ant-descriptions-row">
              <th
                class="ant-descriptions-item-label"
                colspan="1"
                style="width: 180px"
              >
                <span>招标计划发布人</span>
              </th>
              <td
                class="ant-descriptions-item-content"
                colspan="1"
                style="max-width: 900px"
              >
                <span>{{ this.infoMsg.bidPlanPerson }}</span>
              </td>
              <th
                class="ant-descriptions-item-label"
                colspan="1"
                style="width: 180px"
              >
                <span>发布时间</span>
              </th>
              <td
                class="ant-descriptions-item-content"
                colspan="1"
                style="max-width: 900px"
              >
                <span>{{ this.infoMsg.reportTime }}</span>
              </td>
            </tr>
            <tr class="ant-descriptions-row">
              <th
                class="ant-descriptions-item-label"
                colspan="1"
                style="width: 180px"
              >
                <span>招标人名称</span>
              </th>
              <td
                class="ant-descriptions-item-content"
                colspan="1"
                style="max-width: 900px"
              >
                <span>{{ this.infoMsg.tendererName }}</span>
              </td>
              <th
                class="ant-descriptions-item-label"
                colspan="1"
                style="width: 180px"
              >
                <span>招标人统一社会信用代码</span>
              </th>
              <td
                class="ant-descriptions-item-content"
                colspan="1"
                style="max-width: 900px"
              >
                <span>{{ this.infoMsg.socialCreditCode }}</span>
              </td>
            </tr>
            <tr class="ant-descriptions-row">
              <th
                class="ant-descriptions-item-label"
                colspan="1"
                style="width: 180px"
              >
                <span>备注</span>
              </th>
              <td
                class="ant-descriptions-item-content"
                colspan="3"
                style="max-width: 900px"
              >
                <span>{{ this.infoMsg.remark }}</span>
              </td>
            </tr>
            <tr class="ant-descriptions-row">
              <th
                class="ant-descriptions-item-label"
                colspan="1"
                style="width: 180px"
              >
                <span>招标计划附件</span>
              </th>
              <td
                class="ant-descriptions-item-content"
                colspan="3"
                style="max-width: 900px"
              >
                {{ this.infoMsg.length }}
                <template v-if="this.infoMsg.bidAttachment">
                  <div
                    v-for="(item, index) in JSON.parse(
                      this.infoMsg.bidAttachment
                    )"
                    :key="item + index"
                  >
                    {{ item.name }}

                    <i
                      class="el-icon-download"
                      @click="downloadFile2(item, index)"
                      style="cursor: pointer"
                    ></i>
                  </div>
                </template>
              </td>
            </tr>
          </tbody>
        </table> -->

        <el-descriptions
          class="margin-top"
          :column="2"
          border
          :labelStyle="{
            'text-align': 'left',
            width: '180px',
            height: '50px',
          }"
          :contentStyle="{}"
        >
          <el-descriptions-item>
            <template slot="label"> 合并招标 </template>
            {{ isConsolidatedBiddingFormat(this.infoMsg) }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 性质 </template>
            {{ this.infoMsg.bidNature }}
          </el-descriptions-item>
          <el-descriptions-item span="2">
            <template slot="label"> 招标计划名称 </template>
            {{ this.infoMsg.bidPlanName }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 招标计划发布人 </template>
            {{ this.infoMsg.bidPlanPerson }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 发布时间 </template>
            {{ this.infoMsg.reportTime }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 招标人名称 </template>
            {{ this.infoMsg.tendererName }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 招标人统一社会信用代码 </template>
            {{ this.infoMsg.socialCreditCode }}
          </el-descriptions-item>
          <el-descriptions-item span="2">
            <template slot="label"> 备注 </template>
            {{ this.infoMsg.remark }}
          </el-descriptions-item>
          <el-descriptions-item span="2">
            <template slot="label"> 招标计划附件 </template>
            <!-- {{ this.infoMsg.length }} -->
            <template v-if="this.infoMsg.bidAttachment">
              <div
                v-for="(item, index) in JSON.parse(this.infoMsg.bidAttachment)"
                :key="item + index"
              >
                {{ item.name }}

                <i
                  class="el-icon-download"
                  @click="downloadFile2(item, index)"
                  style="cursor: pointer"
                ></i>
              </div>
            </template>
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <!-- 明细内容 -->
      <div class="detailsTitle">明细内容</div>
      <div class="draLine"></div>
      <div class="content">
        <!-- <table class="detialsTable" border="1">
          <tbody>
            <tr class="ant-descriptions-row">
              <th
                class="ant-descriptions-item-label"
                colspan="1"
                style="width: 180px"
              >
                <span>招标项目名称</span>
              </th>
              <td
                class="ant-descriptions-item-content"
                colspan="3"
                style="width: 420px"
              >
                <span>{{ this.viewTitle }}</span>
              </td>
            </tr>
            <tr class="ant-descriptions-row">
              <th
                class="ant-descriptions-item-label"
                colspan="1"
                style="width: 180px"
              >
                <span>是否依法必招项目</span>
              </th>
              <td
                class="ant-descriptions-item-content"
                colspan="1"
                style="width: 420px"
              >
                <span>{{ this.isMustProjectFormat(this.detailsMsg) }}</span>
              </td>
              <th
                class="ant-descriptions-item-label"
                colspan="1"
                style="width: 180px"
              >
                <span>投资项目代码</span
                >
              </th>
              <td
                class="ant-descriptions-item-content"
                colspan="1"
                style="width: 420px"
              >
                <span>{{ this.detailsMsg.projectCode }}</span>
              </td>
            </tr>
            <tr class="ant-descriptions-row">
              <th
                class="ant-descriptions-item-label"
                colspan="1"
                style="width: 180px"
              >
                <span>招标项目类型</span
                >
              </th>
              <td
                class="ant-descriptions-item-content"
                colspan="1"
                style="width: 420px"
              >
                <span>{{ this.detailsMsg.bidType }}</span>
              </td>
              <th
                class="ant-descriptions-item-label"
                colspan="1"
                style="width: 180px"
              >
                <span>招标方式</span
                >
              </th>
              <td
                class="ant-descriptions-item-content"
                colspan="1"
                style="width: 420px"
              >
                <span>{{ this.detailsMsg.bidMethod }}</span>
              </td>
            </tr>
            <tr class="ant-descriptions-row">
              <th
                class="ant-descriptions-item-label"
                colspan="1"
                style="width: 180px"
              >
                <span>招标内容</span>
              </th>
              <td
                class="ant-descriptions-item-content"
                colspan="1"
                style="width: 420px"
              >
                <span>{{ this.detailsMsg.bidContent }}</span>
              </td>
              <th
                class="ant-descriptions-item-label"
                colspan="1"
                style="width: 180px"
              >
                <span>预估发包价（元）</span>
              </th>
              <td
                class="ant-descriptions-item-content"
                colspan="1"
                style="width: 420px"
              >
                <span>{{ this.detailsMsg.estimatedContractPrice }}</span>
              </td>
            </tr>
            <tr class="ant-descriptions-row">
              <th
                class="ant-descriptions-item-label"
                colspan="1"
                style="width: 180px"
              >
                <span>招标项目建设地点</span>
              </th>
              <td
                class="ant-descriptions-item-content"
                colspan="1"
                style="width: 420px"
              >
                <span>{{ this.detailsMsg.bidConstructionLocation }}</span>
              </td>
              <th
                class="ant-descriptions-item-label"
                colspan="1"
                style="width: 180px"
              >
                <span>招标公告预计发布时间</span
                >
              </th>
              <td
                class="ant-descriptions-item-content"
                colspan="1"
                style="width: 420px"
              >
                <span>{{ this.detailsMsg.bidNoticeTime }}</span>
              </td>
            </tr>
            <tr class="ant-descriptions-row">
              <th
                class="ant-descriptions-item-label"
                colspan="1"
                style="width: 180px"
              >
                <span>招标监督部门</span
                >
              </th>
              <td
                class="ant-descriptions-item-content"
                colspan="3"
                style="width: 420px"
              >
                <span>{{ this.detailsMsg.bidRegulator }}</span>
              </td>
            </tr>
            <tr class="ant-descriptions-row">
              <th
                class="ant-descriptions-item-label"
                colspan="1"
                style="width: 180px"
              >
                <span>项目概况</span
                >
              </th>
              <td
                class="ant-descriptions-item-content"
                colspan="3"
                style="width: 420px"
              >
                <span>{{ this.detailsMsg.projectOverview }}</span>
              </td>
            </tr>
          </tbody>
        </table> -->

        <el-descriptions
          class="margin-top"
          :column="2"
          border
          :labelStyle="{
            'text-align': 'left',
            width: '180px',
            height: '50px',
          }"
          :contentStyle="{}"
        >
          <el-descriptions-item span="2">
            <template slot="label"> 招标项目名称 </template>
            {{ this.viewTitle }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 是否依法必招项目 </template>
            {{ this.isMustProjectFormat(this.detailsMsg) }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 投资项目代码 </template>
            {{ this.detailsMsg.projectCode }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 招标项目类型 </template>
            {{ this.detailsMsg.bidType }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 招标方式 </template>
            {{ this.detailsMsg.bidMethod }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 招标内容 </template>
            {{ this.detailsMsg.bidContent }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 预估发包价（元） </template>
            {{ this.detailsMsg.estimatedContractPrice }}
            {{ this.detailsMsg.estimatedContractPrice ? " 万元" : "" }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 招标项目建设地点 </template>
            {{ this.detailsMsg.bidConstructionLocation }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 招标公告预计发布时间 </template>
            {{ this.detailsMsg.bidNoticeTime }}
          </el-descriptions-item>
          <el-descriptions-item span="2">
            <template slot="label"> 招标监督部门 </template>
            {{ this.detailsMsg.bidRegulator }} </el-descriptions-item
          ><el-descriptions-item span="2">
            <template slot="label"> 项目概况 </template>
            {{ this.detailsMsg.projectOverview }}
          </el-descriptions-item>
        </el-descriptions>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listBidInfo,
  getBidInfo,
  getBidInfoVO,
  delBidInfoVO,
  addBidInfoVO,
  updateBidInfoVO,
} from "@/api/earlyStage/bidInfoVO";
import { listProposal } from "@/api/earlyStage/proposal";
import { getToken } from "@/utils/auth";
import { getFileStream } from "@/api/system/upload";

export default {
  name: "BidInfo",
  props: ["proNo"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 招标计划基本信息表格数据
      bidInfoList: [],
      // 弹出层标题
      title: "",
      // 查看弹出层标题
      viewTitle: "",
      // 是否显示弹出层
      open: false,
      // 是否显示查看弹出层
      viewOpen: false,
      // 是否合并招标字典
      isConsolidatedBiddingOptions: [],
      // 是否依法必招项目字典
      isMustProject: [],
      // 招标项目类型字典
      bidType: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ids: null,
        data: {
          bidProjectName: null,
          isConsolidatedBidding: null,
          bidPlanName: null,
        },
        // 模糊查询
        cv: {
          type: null,
          name: null,
          value: null,
        },
        // 排序方式
        params: {
          // 按哪个字段排序
          orderBy: "create_time",
          // desc降序，升序asc
          sort: "desc",
        },
      },
      // // 查询参数
      detailQueryParams: {
        pageNum: 1,
        pageSize: 10,
        ids: null,
        data: {
          bidProjectName: null,
          isMustProject: null,
          investProjectCode: null,
          bidType: null,
          bidMethod: null,
          bidContent: null,
          estimatedContractPrice: null,
          bidConstructionLocation: null,
          bidNoticeTime: null,
          bidRegulator: null,
          projectOverview: null,
          bidId: null,
          projectCode: null,
          attachmentAddress: null,
          proNo: null,
          createUid: null,
          createTime: null,
          updateUid: null,
          updateTime: null,
          owerDept: null,
          remark: null,
        },
      },
      // form: {
      // 基本信息表单参数
      baseForm: {},
      // 明细内容表单参数
      detailsForm: {},
      // },
      // 表单校验
      baseRules: {},
      detailsRules: {
        estimatedContractPrice: [
          // { required: true, message: "请输入预估发包价", trigger: "blur" },
          {
            pattern:
              /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
            message: "请输入数字,可保留两位小数",
            trigger: "blur",
          },
        ],
      },
      // 附件
      fileList: [],
      // 请求头
      headers: {
        jianwei: "jwtech " + getToken(),
      },
      // 项目建议书的项目，同一个项目，有不同的项目编码
      bidProjectNameOptions: [],
      // 点击查看时的信息
      infoMsg: {},
      detailsMsg: {},
    };
  },
  created() {
    this.getList();
    this.getDicts("whether").then((response) => {
      // console.log("444444", response);
      this.isConsolidatedBiddingOptions = response.data;
      this.isMustProject = response.data;
    });
    this.getDicts("Bid_type").then((response) => {
      this.bidType = response.data;
    });
  },
  // 父组件  利用axios请求得到的值  传送到子组件，要监听，否则初始渲染时为空
  watch: {
    proNo: function (n, o) {
      this.proNo = n;
      this.getList();
    },
  },
  methods: {
    /** 查询招标计划基本信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.data.proNo = this.proNo;
      listBidInfo(this.queryParams).then((response) => {
        this.bidInfoList = response.records;
        this.total = response.total;
        setTimeout(() => {
          this.loading = false;
        }, 50);
      });
      // 招标项目选项
      listProposal({ data: { proNo: this.proNo } }).then((response) => {
        // console.log("response55555555555", response);
        this.bidProjectNameOptions = response.records;
      });
    },
    // 是否合并招标字典翻译
    isConsolidatedBiddingFormat(row, column) {
      return this.selectDictLabel(
        this.isConsolidatedBiddingOptions,
        row.isConsolidatedBidding
      );
    },
    isMustProjectFormat(row, column) {
      return this.selectDictLabel(this.isMustProject, row.isMustProject);
    },
    projectNameFormat(row) {
      return row.bidProjectName.slice(0, row.bidProjectName.indexOf("["));
    },
    // 表单重置
    reset() {
      this.baseForm = {
        id: null,
        isConsolidatedBidding: null,
        bidNature: null,
        bidPlanName: null,
        bidPlanPerson: null,
        reportTime: null,
        tendererName: null,
        socialCreditCode: null,
        remark: null,
        bidAttachment: null,
        projectCode: null,
        proNo: null,
        createUid: null,
        createTime: null,
        updateUid: null,
        updateTime: null,
        owerDept: null,
      };
      this.detailsForm = {
        id: null,
        bidProjectName: null,
        isMustProject: null,
        investProjectCode: null,
        bidType: null,
        bidMethod: null,
        bidContent: null,
        estimatedContractPrice: null,
        bidConstructionLocation: null,
        bidNoticeTime: null,
        bidRegulator: null,
        projectOverview: null,
        bidId: null,
        projectCode: null,
        attachmentAddress: null,
        proNo: null,
        createUid: null,
        createTime: null,
        updateUid: null,
        updateTime: null,
        owerDept: null,
        remark: null,
      };
      this.fileList = [];
      this.resetForm("baseForm");
      this.resetForm("detailsForm");
    },
    // 查询表单重置
    resetQueryForm() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        data: {
          id: null,
          isConsolidatedBidding: null,
          bidNature: null,
          bidPlanName: null,
          bidPlanPerson: null,
          reportTime: null,
          tendererName: null,
          socialCreditCode: null,
          remark: null,
          bidAttachment: null,
          projectCode: null,
          proNo: null,
          createUid: null,
          createTime: null,
          updateUid: null,
          updateTime: null,
          owerDept: null,
        },
        // 模糊查询
        cv: {
          type: null,
          name: null,
          value: null,
        },
        // 排序方式
        params: {
          // 按哪个字段排序
          orderBy: "create_time",
          // desc降序，升序asc
          sort: "desc",
        },
      };
      this.resetForm("baseForm");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.cv.type = "like";
      this.queryParams.cv.name = "bidPlanName";
      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.open = true;
      this.title = "添加招标计划基本信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getBidInfoVO(id).then((response) => {
        // console.log("666666666666", response);
        this.baseForm = response.data.specialProjectBidInfo;
        if (response.data.specialProjectBidInfo.bidAttachment) {
          this.fileList = JSON.parse(
            response.data.specialProjectBidInfo.bidAttachment
          );
        }
        this.detailsForm = response.data.projectBidDetails;
        this.open = true;
        this.title = "修改招标计划基本信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["baseForm"].validate((valid) => {
        this.$refs["detailsForm"].validate((valid2) => {
          // 附件
          this.baseForm.bidAttachment = JSON.stringify(this.fileList);
          // 项目编码
          this.baseForm.projectCode = this.baseForm.bidProjectName.slice(
            this.baseForm.bidProjectName.indexOf("[") + 1,
            this.baseForm.bidProjectName.indexOf("]")
          );
          this.detailsForm.projectCode = this.baseForm.projectCode;
          this.detailsForm.bidProjectName = this.baseForm.bidProjectName;
          if (valid && valid2) {
            if (this.baseForm.id != null) {
              updateBidInfoVO({
                specialProjectBidInfo: this.baseForm,
                projectBidDetails: this.detailsForm,
              }).then((response) => {
                if (response.code === 200) {
                  this.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                }
              });
            } else {
              this.baseForm.proNo = this.proNo;
              this.detailsForm.proNo = this.proNo;
              addBidInfoVO({
                specialProjectBidInfo: this.baseForm,
                projectBidDetails: this.detailsForm,
              }).then((response) => {
                if (response.code === 200) {
                  this.msgSuccess("新增成功");
                  this.open = false;
                  this.getList();
                }
              });
            }
          }
        });
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    // 关闭弹窗
    close() {
      this.reset();
    },
    // 查看信息
    viewInfo(row) {
      this.viewTitle = row.bidProjectName.slice(
        0,
        row.bidProjectName.indexOf("[")
      );
      this.infoMsg = row;
      console.log("infoMsg", row);
      getBidInfoVO(row.id).then((response) => {
        this.detailsMsg = response.data.projectBidDetails;
        console.log("detailsMsg", this.detailsMsg);
      });

      this.viewOpen = true;
    },
    // 关闭弹窗
    closeView() {
      this.infoMsg = {};
      this.detailsMsg = {};
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      if (ids) {
        this.$confirm("是否删除选中的数据？", "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(function () {
            return delBidInfoVO(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.bidAttachment)[index];
      this.handlePreview(file);
    },
    // 查看信息中, 下载
    downloadFile2(info, index) {
      console.log(info);
      this.handlePreview(info);
    },
    // 点击预览下载文件
    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: 1100px;
    // overflow-y: auto;
    .content {
      display: flex;
      flex-direction: column;
      align-items: center;
      .margin-top {
        width: 95%;
        border-left: 1px solid #f0f0f0;
        border-right: 1px solid #f0f0f0;
      }
    }
  }
  .el-dialog__title {
    font-weight: 700;
    font-size: 28px;
  }
  .el-divider {
    height: 4px;
    color: #000;
  }
  .el-divider__text {
    font-weight: 700;
    font-size: 20px;
  }
}
.draLine {
  width: 100%;
  border: 2px solid #000;
  margin: 10px 0 20px 0;
}
.infoTitle,
.detailsTitle {
  color: #000;
  font-size: 20px;
  font-weight: 700;
}
.detailsTitle {
  margin-top: 30px;
}
.infoTable,
.detialsTable {
  width: 100%;
  border-collapse: collapse;
  border-color: #ccc;
}
.infoTable th,
.infoTable tr,
.detialsTable th,
.detialsTable tr {
  padding: 20px 0;
  text-align: center;
}
</style>
