<template>
  <div class="edit-add-detail">
    <div class="crumbs">
      <Breadcrumb
        :breadcrumbOpt="breadcrumbOpt"
        svg-name="#icon-roleEdit"
        @breadcrumb-click="handleClose"
      />
    </div>
    <div class="common-page-shadow">
      <div class="common-table-container flex searchPanel">
        <div class="common-table-wrapper">
          <div
            class="common-btn-group"
            style="display: flex; align-items: center; margin-top: 10px"
          >
            <!-- <el-button
              type="primary"
              icon="el-icon-download"
              :loading="exporting"
              size="small"
              plain
              @click="handleDown"
              >下载报价模板</el-button
            >
            <import-file
              :importData="importData"
              @load="load"
              
            ></import-file> -->
          </div>
          <!-- LJ：表格高度自适应需配合样式  btn-pagenation 有按钮有分页  btngroup只有按钮  pagenation只有分页 -->
          <div class="common-table-content btn-pagenation">
            <el-table
              :border="true"
              stripe
              fit
              size="mini"
              v-loading="tableLoading"
              ref="multiple"
              :data="tableData"
              @cell-mouse-enter="handleCellEnter"
              @cell-mouse-leave="handleCellLeave"
              @row-click="handleBtn"
              @select="(selection, row) => handleBtn(row)"
              @selection-change="handleSelectionChange"
              @select-all="selectAll"
              height="100%"
            >
              <el-table-column
                type="selection"
                min-width="50px"
                align="center"
                fixed="left"
              ></el-table-column>
              <!-- <el-table-column
                type="index"
                width="55"
                align="center"
                label="序号"
              >
              </el-table-column> -->
              <el-table-column
                prop="matName"
                min-width="90px"
                label="物料名称"
                align="center"
                show-overflow-tooltip
                resizable
              >
              </el-table-column>
              <el-table-column
                  prop="matMaterial"
                  min-width="90px"
                  label="物料牌号"
                  align="center"
                  resizable
                >
                </el-table-column>
              <el-table-column
                prop="matSpec"
                min-width="90px"
                label="规格型号"
                show-overflow-tooltip
                align="center"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="matNum"
                show-overflow-tooltip
                min-width="80px"
                align="center"
                label="数量"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="matUnit"
                show-overflow-tooltip
                min-width="80px"
                align="center"
                label="计量单位"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="maximumPriceLimit"
                show-overflow-tooltip
                min-width="90px"
                align="center"
                label="最高限价"
                resizable
              >
              <template slot="header">
              <div style="display: flex; align-items: center">
                  <span>最高限价</span>
                  <el-tooltip class="item" effect="dark" placement="top">
                    <i class="el-icon-question" style="font-size: 16px"></i>
                    <!-- 悬停提示内容 -->
                    <div slot="content">
                      <div>单价最高限价，为0表示不限价</div>
                    </div>
                  </el-tooltip>
                </div>
              </template>
                <template slot-scope="scope">
                  <div>{{ scope.row.maximumPriceLimit }}</div>
                </template>
              </el-table-column>
              <el-table-column
                prop="rank"
                show-overflow-tooltip
                min-width="90px"
                align="center"
                label="当前排名"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="minQuoPrice"
                show-overflow-tooltip
                min-width="90px"
                align="center"
                label="当前最低报价"
                resizable
              >
              </el-table-column>
              <el-table-column
                header-align="center"
                align="center"
                v-for="(item, index) in tableHeadData"
                :key="index"
                :prop="item.prop"
                :min-width="item.width"
                :label="item.label"
              >
                <template slot-scope="scope">
                  <el-input-number
                    size="small"
                    :min="0"
                    v-if="item.prop != 'amount'"
                    v-model="scope.row.quoArrange"
                    :step="1"
                    :precision="4"
                    @change="changeQuoArrange(scope.row)"
                  ></el-input-number>
                  <div v-else-if="scope.row.quoArrange != ''">
                    {{
                      (scope.row.quoArrange * scope.row.matNum).toFixed(2) || ''
                    }}
                  </div>
                  <div v-else></div>
                </template>
              </el-table-column>
              <el-table-column
                prop="amount"
                show-overflow-tooltip
                min-width="80px"
                align="center"
                label="合计金额(元)"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="quotationMethod"
                show-overflow-tooltip
                min-width="80px"
                align="center"
                label="付款方式"
                resizable
              >
                <template v-slot="{row}">
                  {{ getDictName('cglx-fkfs', row.quotationMethod) }}
                </template>
              </el-table-column>
              <el-table-column
                prop="pendingTime"
                show-overflow-tooltip
                min-width="100px"
                align="center"
                label="挂账时间(月)"
                resizable
              >
                <template>
                  <!-- 表头名称 -->
                  <div style="display: flex; align-items: center">
                    <span>挂账时间(月)</span>
                    <el-tooltip class="item" effect="dark" placement="top">
                      <i class="el-icon-question" style="font-size: 16px"></i>
                      <!-- 悬停提示内容 -->
                      <div slot="content">
                        <div>为0表示不限制挂账时间</div>
                      </div>
                    </el-tooltip>
                  </div>
                </template>
                <template slot-scope="scope">
                  <div>{{ scope.row.pendingTime }}</div>
                </template>
              </el-table-column>
              <el-table-column
                prop="acceptanceTime"
                show-overflow-tooltip
                min-width="100px"
                align="center"
                v-if="$route.query.rows.quotationMethod==2"
                label="承兑时间(月)"
                resizable
              >
                <template>
                  <!-- 表头名称 -->
                  <div style="display: flex; align-items: center">
                    <span>承兑时间(月)</span>
                    <el-tooltip class="item" effect="dark" placement="top">
                      <i class="el-icon-question" style="font-size: 16px"></i>
                      <!-- 悬停提示内容 -->
                      <div slot="content">
                        <div>为0表示不限制承兑时间</div>
                      </div>
                    </el-tooltip>
                  </div>
                </template>
                <template slot-scope="scope">
                  <div>{{ scope.row.acceptanceTime }}</div>
                </template>
              </el-table-column>
              <el-table-column
                prop="matPlatcode"
                min-width="90px"
                label="平台物料编号"
                align="center"
                resizable
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="matCode"
                min-width="90px"
                label="企业物料编号"
                align="center"
                resizable
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="planCode"
                show-overflow-tooltip
                min-width="110px"
                align="center"
                label="计划编号"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="matBrand"
                show-overflow-tooltip
                min-width="100px"
                align="center"
                label="品牌"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="matBaseExt"
                show-overflow-tooltip
                min-width="80px"
                align="center"
                label="基础扩展"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="matOtherExt"
                show-overflow-tooltip
                min-width="80px"
                align="center"
                label="其他扩展"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="matCompanyName"
                show-overflow-tooltip
                min-width="100px"
                align="center"
                label="需求企业"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="demandDate"
                show-overflow-tooltip
                min-width="100px"
                align="center"
                label="需求日期"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="tenderExplain"
                show-overflow-tooltip
                min-width="100px"
                align="center"
                label="投标补充说明"
                resizable
              >
                <template slot-scope="scope">
                  <el-tooltip
                  width="250"
                  placement="top-start"
                  effect="light"
                  :content="scope.row.tenderExplain"
                >
                  <el-input
                    v-model="scope.row.tenderExplain"
                    placeholder="投标补充说明"
                  ></el-input>
                </el-tooltip>
                </template>
              </el-table-column>
              <el-table-column
                prop="unloadAddress"
                show-overflow-tooltip
                min-width="80px"
                align="center"
                label="送货地址"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="remarks"
                show-overflow-tooltip
                min-width="100px"
                align="center"
                label="企业补充说明"
                resizable
              >
              </el-table-column>
            </el-table>
          </div>
          <div class="common-pagenation">
            <div class="common-total">
              <div class="text">
                报价总额: <span>￥{{ totalValue }}</span>
              </div>
              <div class="btn">
                <el-button
                  type="primary"
                  size="small"
                  :disabled="show"
                  :loading="saveing"
                  @click="open"
                  >提交报价</el-button
                >
              </div>
            </div>
          </div>
        </div>
        <div class="common-table-quote">
          <div class="quote-content">
            <div class="rows">
              <div class="rows-left">
                <div class="rows-hr"></div>
              </div>
              <div class="rows-title">
                <div class="text-overflow">报价截止时间</div>
              </div>
            </div>
            <div class="auction">
              <div id="box">
                <div id="time">
                  <div
                    id="time"
                    style="text-align: center"
                    v-if="
                      time > 0 &&
                      Date.now() -
                        new Date(this.params.biddingStartTime).getTime() >
                        0
                    "
                  >
                    <strong>
                      <span id="day"> {{ dateTime.days }}天 </span>
                    </strong>
                    <strong>
                      <span id="hour"> {{ dateTime.hours }}时 </span>
                    </strong>
                    <strong>
                      <span id="minute"> {{ dateTime.minutes }}分 </span>
                    </strong>
                    <strong>
                      <span id="second"> {{ dateTime.seconds }}秒 </span>
                    </strong>
                  </div>
                  <div style="text-align: center; color: red" v-else>
                    {{ countDown }}
                  </div>
                </div>
              </div>
            </div>
            <div class="rows">
              <div class="rows-left">
                <div class="rows-hr"></div>
              </div>
              <div class="rows-title">
                <div class="text-overflow">
                  <el-tabs v-model="activeName" @tab-click="handleClick">
                    <el-tab-pane name="0" label="招标文件"></el-tab-pane>
                    <el-tab-pane name="1" label="澄清提问"></el-tab-pane>
                    <el-tab-pane name="2" label="投标文件"></el-tab-pane>
                    <el-tab-pane name="3" label="补遗文件"></el-tab-pane>
                    <el-tab-pane
                      name="4"
                      label="评分标准"
                      v-if="activeName == 4 && method != 1"
                    ></el-tab-pane>
                  </el-tabs>
                </div>
              </div>
            </div>
            <div class="content" v-if="activeName == 0">
              <el-table
                class="down"
                :data="dataList"
                size="mini"
                border
                v-loading="tableLoading"
                stripe
                style="width: 100%; margin-top: 20px"
              >
                <el-table-column prop="name" label="文件名称"></el-table-column>
                <el-table-column width="150px" label="操作">
                  <template slot-scope="scope">
                    <el-button size="small" type="text">
                      <a @click="downloadFile(scope.row.name, scope.row.url)"
                        >下载</a
                      >
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div class="content" v-if="activeName == 1">
              <el-table
                class="down"
                :data="clarifyList"
                size="mini"
                border
                :key="activeName == 1"
                stripe
                v-loading="tendering"
                style="width: 100%; margin-top: 20px"
              >
              <el-table-column type="expand">
                    <template slot-scope="props">
                      <el-table
                        :key="'childTable' + props.row.id"
                        header-cell-class-name="selectAllbtnDis"
                        :ref="'childTable' + props.row.id"
                        :data="props.row.answerList"
                        style="width: 100%; margin-left: 25px"
                      >
                        <el-table-column label="澄清企业" prop="operateOrgName">
                        </el-table-column>
                        <el-table-column label="澄清描述" prop="describe">
                        </el-table-column>
                        <el-table-column label="澄清时间" prop="operateTime">
                        </el-table-column>
                        <el-table-column
                          prop="name"
                          label="附件"
                        ></el-table-column>
                        <el-table-column width="120px" label="操作">
                          <template slot-scope="scope">
                            <el-button
                              size="small"
                              v-if="scope.row.accessoryList.length != 0"
                              type="text"
                            >
                              <a
                                @click="
                                  downloadFile(scope.row.name, scope.row.url)
                                "
                                >下载</a
                              >
                            </el-button>
                          </template>
                        </el-table-column>
                      </el-table>
                    </template>
                  </el-table-column>
                <el-table-column
                  prop="operateOrgName"
                  label="提问企业"
                  min-width="100px"
                  show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                  prop="describe"
                  label="描述"
                  min-width="100px"
                  show-overflow-tooltip
                ></el-table-column>

                <el-table-column
                  prop="operateTime"
                  label="提出时间"
                  min-width="100px"
                  show-overflow-tooltip
                ></el-table-column>
                <el-table-column prop="name" show-overflow-tooltip label="文件名称"></el-table-column>
                <el-table-column min-width="80px" label="操作">
                  <template slot-scope="scope">
                    <el-button size="small" type="text">
                      <a @click="downloadFile(scope.row.name, scope.row.url)"
                        >下载</a
                      >
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div class="content" v-if="activeName == 2">
              <el-table
                class="down"
                :data="tenderList"
                size="mini"
                border
                stripe
                v-loading="tendering"
                style="width: 100%; margin-top: 20px"
              >
                <el-table-column prop="name" label="文件名称"></el-table-column>
                <el-table-column width="150px" label="操作">
                  <template slot-scope="scope">
                    <el-button size="small" type="text">
                      <a @click="downloadFile(scope.row.name, scope.row.url)"
                        >下载</a
                      >
                    </el-button>
                    <el-button
                      size="small"
                      type="text"
                      @click="deleteHandle(scope.row.id, scope.$index)"
                      >删除</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div class="content" v-if="activeName == 3">
              <el-table
                class="down"
                :data="addendumList"
                size="mini"
                border
                v-loading="tendering"
                stripe
                style="width: 100%; margin-top: 20px"
              >
                <el-table-column
                  prop="describe"
                  show-overflow-tooltip
                  label="描述"
                ></el-table-column>
                <el-table-column
                  prop="name"
                  label="文件名称"
                  key="3"
                ></el-table-column>
                <el-table-column width="100px" label="操作">
                  <template slot-scope="scope">
                    <el-button size="small" type="text">
                      <a @click="downloadFile(scope.row.name, scope.row.url)"
                        >下载</a
                      >
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div class="content" v-if="activeName == 4">
              <el-table
                :border="true"
                stripe
                fit
                size="mini"
                :key="params.evaluationMethod"
                row-key="id"
                ref="multipleSelection"
                default-expand-all
                v-loading="tendering"
                :data="scoreData"
                :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
              >
                <el-table-column
                  prop="evaluationItemPname"
                  min-width="100px"
                  label="评分大项"
                  align="center"
                  resizable
                >
                </el-table-column>
                <el-table-column
                  label="评分细项"
                  min-width="150px"
                  prop="evaluationItemCode"
                >
                  <template slot-scope="scope">
                    <div>
                      {{ scope.row.evaluationItemCode }}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column
                  label="评分标准"
                  min-width="150px"
                  prop="evaluationStandard"
                >
                  <template slot-scope="scope">
                    <div>
                      {{ scope.row.evaluationStandard }}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column
                  label="分值"
                  min-width="120px"
                  prop="evaluationScore"
                >
                </el-table-column>
              </el-table>
            </div>
            <div class="btn">
              <el-button
                icon="el-icon-upload"
                @click="openBid"
                v-if="this.activeName == 2"
                size="small"
                :disabled="show"
                type="primary"
                >添加文件</el-button
              >
              <el-button
                icon="el-icon-upload"
                @click="openQuestion"
                v-if="this.activeName == 1"
                size="small"
                :disabled="show"
                type="primary"
                >添加提问</el-button
              >
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 投标文件上传 -->
    <el-dialog
      title="投标文件上传"
      :visible.sync="dialogVisible"
      width="60%"
      :before-close="dialogBeforeClose"
    >
      <div>
        <el-form label-width="80px">
          <el-form-item label="投标文件">
            <el-upload
              class="upload-demo"
              ref="upload"
              :headers="headers"
              :action="action"
              :file-list="bidFileList"
              style="text-align: left"
              :multiple="false"
              accept=".png,.jpg,.jpeg,.xlsx,.xls,.pdf,.docx,.doc,.zip,.rar"
              :show-file-list="false"
              :before-upload="beforeUpload"
              :on-success="handleSuccess"
            >
              <el-button
                icon="el-icon-upload"
                slot="trigger"
                style="width: 100% !important"
                size="small"
                type="primary"
                >上传文件</el-button
              >
            </el-upload>
          </el-form-item>
        </el-form>
        <el-table
          class="down"
          :data="bidFileList"
          border
          stripe
          style="width: 100%; margin-top: 20px"
        >
          <el-table-column prop="name" label="文件名称"></el-table-column>
          <el-table-column prop="size" label="文件大小">
            <template slot-scope="scope">
              <span>{{ scope.row.fileSize }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="createTime" label="上传时间">
            <template slot-scope="scope">
              <div>
                {{ scope.row.createTime }}
              </div>
            </template>
          </el-table-column>
          <el-table-column width="150px" label="操作">
            <template slot-scope="scope">
              <el-button size="small" type="text">
                <a
                  target="_blank"
                  @click="downloadFile(scope.row.name, scope.row.url)"
                  >下载</a
                >
              </el-button>
              <el-button
                size="small"
                type="text"
                @click="deleteFile(scope.$index)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div slot="footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" :loading="biding" @click="saveBid"
          >确 定</el-button
        >
      </div>
    </el-dialog>
    <!-- 提问 -->
    <el-dialog
      title="澄清提问"
      :visible.sync="visible"
      width="width"
      :before-close="dialogBeforeClose"
    >
      <el-form :model="form">
        <el-form-item label="问题描述" label-width="90px" prop="describe">
          <el-input
            type="textarea"
            autosize
            placeholder="请输入问题描述"
            v-model="form.describe"
          ></el-input>
        </el-form-item>
        <el-form-item label="附件上传" label-width="90px">
          <el-upload
            class="upload-demo"
            ref="upload"
            :headers="headers"
            :action="action"
            :file-list="form.accessoryList"
            :multiple="false"
            style="text-align: left"
            accept=".png,.jpg,.jpeg,.xlsx,.xls,.pdf,.docx,.doc,.zip,.rar"
            :show-file-list="false"
            :before-upload="beforeUpload"
            :on-success="handleSuccess"
          >
            <el-button slot="trigger" size="small" type="primary"
              >上传文件</el-button
            >
          </el-upload>
        </el-form-item>
      </el-form>
      <el-table
        class="down"
        :data="form.accessoryList"
        border
        stripe
        style="width: 100%; margin-top: 20px"
      >
        <el-table-column prop="name" label="文件名称"></el-table-column>
        <el-table-column prop="size" label="文件大小">
          <template slot-scope="scope">
            <span>{{ scope.row.fileSize }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="上传时间">
          <template slot-scope="scope">
            <div>
              {{ scope.row.createTime }}
            </div>
          </template>
        </el-table-column>
        <el-table-column width="150px" label="操作">
          <template slot-scope="scope">
            <el-button size="small" type="text">
              <a
                target="_blank"
                @click="downloadFile(scope.row.name, scope.row.url)"
                >下载</a
              >
            </el-button>
            <el-button
              size="small"
              type="text"
              @click="deleteHandle(scope.$index)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer">
        <el-button @click="visible = false">取 消</el-button>
        <el-button type="primary" :loading="quesing" @click="handleQuestion"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>
  
  <script>
import Breadcrumb from '@/components/Breadcrumb/index.vue'
import {mapState} from 'vuex'
import basicData from '@/api/basicData'
import utils from '@/utils.js'
export default {
  name: 'domesticDialog',
  components: {Breadcrumb},
  props: {
    editData: Object,
  },
  data() {
    return {
      form: {
        accessoryList:[],
        describe:''
      },
      totalValue: 0,
      importData: {
        title: '导入报价',
        templateName: '导入报价导入模板.xls',
        downloadUrl:
          window.context.portal +
          '/projectApprovalDetails/v1/exportTemplateToExcel',
        importUrl:
          window.context.portal + '/projectApprovalDetails/v1/excelTemplateToData',
        show: true,
        header: '报价导入',
      },
      dialogVisible: false,
      visible:false,
      breadcrumbOpt: [{breadcrumbName: '项目采购'}, {breadcrumbName: '报价'}],
      tableData: [],
      dataList: [],
      time: null,
      quesing:false,
      biding: false,
      addendumList: [], //补遗文件
      tenderList: [], //投标文件
      exporting: false,
      show: false,
      clarifyList: [], //澄清文件
      activeName: '0',
      tableLoading: false,
      id: '',
      method: '',
      params: {},
      objData: {},
      fileList: [],
      saveing: false,
      startTime: null,
      bidFileList: [],
      templateId: '',
      templateDetailId: '',
      endTime: null,
      selectArr: [],
      countDown: null,
      tendering: false,
      accecptData: false,
      dateTime: {
        days: '',
        hours: '',
        minutes: '',
        seconds: '',
      },
      currentUser: {},
      tableHeadData: [{label: '我的报价', width: 130, prop: 'quoArrange'}],
    }
  },
  created() {
    ;(this.tableHeadData = [
      {label: '我的报价', width: 130, prop: 'quoArrange'},
      // {label: '合计金额', width: 120, prop: 'amount'},
    ]),
      (this.currentUser = JSON.parse(
        sessionStorage.getItem('currentUserDetail')
      ))
    this.id = this.$route.params.id
    this.method = this.$route.params.method
    this.loadData()
    this.selectTree()
    this.getZbfile()
  },
  watch: {
    tableData: {
      handler: function (newVal, oldVal) {
        let sum = 0
        newVal.forEach((item) => {
          if (item.quoArrange != undefined) {
            sum += item.quoArrange * item.matNum
            item.amount = (item.quoArrange * item.matNum).toFixed(2)
            this.totalValue = sum.toFixed(2)
          }
        })
      },
      deep: true,
    },
  },
  beforeDestroy() {
    this.accecptData = false
    // clearInterval(this.timer)
  },
  mounted() {
    this.accecptData = true
    this.getBidFiles()
    this.$bus.$on('quo', (data) => {
      if (this.accecptData) {
        this.changeData(data)
      }
    })
  },
  computed: {
    uploadHeaders: function () {
      return {
        Authorization:
          this.$store.state.login.currentUser &&
          'Bearer ' + this.$store.state.login.currentUser.token,
      }
    },
    ...mapState({
      headers: (state) => {
        return {Authorization: `Bearer ${state.login.currentUser.token}`}
      },
      action: function () {
        return window.context.portal + '/biz/universal/v1/minioUpload'
      },
    }),
  },
  methods: {
    changeData(data) {
      this.tableData.forEach((item) => {
        if (data.quo) {
          data.quo.detailsList.forEach((val) => {
            if (item.matId == val.matId) {
              item.minQuoPrice = val.myPrice
              this.$forceUpdate()
            }
          })
        }
      })
    },
    handleClick() {
      if (this.activeName == 0) {
        this.getZbfile()
      }
      if (this.activeName == 2) {
        this.getBidFiles()
      }
      if (this.activeName == 1) {
        this.getQuestion()
      }
      if (this.activeName == 3) {
        let parmas = {
          pageBean: {
            pageSize: -1,
            page: -1,
          },
          querys: [],
        }
        parmas.querys.push(
          {
            group: 'main',
            operation: 'EQUAL',
            parentGroup: '',
            property: 'projectApprovalId',
            relation: 'AND',
            value: this.id,
          },
          {
            group: 'main',
            operation: 'EQUAL',
            parentGroup: '',
            property: 'releaseStatus',
            relation: 'AND',
            value: 2,
          },
          {
            group: 'main',
            operation: 'EQUAL',
            parentGroup: '',
            property: 'type',
            relation: 'AND',
            value: 2,
          }
        )
        this.dataing = true
        this.$http
          .post('${portal}/tenderDocument/v1/pageAccessory', parmas)
          .then((res) => {
            this.dataing = false
            this.addendumList = []
            let data = res.data.value.rows
            data.forEach((item) => {
              if (item.accessoryList && item.accessoryList.length != 0) {
                item.accessoryList.forEach((val) => {
                  if (item.id == val.sourceId) {
                    val.describe = item.describe
                    this.addendumList.push(val)
                  }
                })
              }
            })
          })
      }
      if (this.activeName == 4) {
        this.selectTree()
        let parmas = {
          pageBean: {
            pageSize: -1,
            page: -1,
          },
          querys: [],
        }
        parmas.querys.push(
          {
            group: 'main',
            operation: 'EQUAL',
            parentGroup: '',
            property: 'noticeId',
            relation: 'AND',
            value: this.id,
          },
          {
            group: 'main',
            operation: 'EQUAL',
            parentGroup: '',
            property: 'noticeType',
            relation: 'AND',
            value: 2,
          }
        )
        this.$http
          .post('${portal}/bizEvaluationSystem/v1/pageDetail', parmas)
          .then((res) => {
            let data = res.data.value.rows
            this.scoreData.forEach((item) => {
              data.forEach((val) => {
                val.descriptionList.forEach((e) => {
                  if (e.evaluationItemPid == item.id) {
                    item.evaluationScore = 0
                    item.evaluationItemPname = item.subjectName
                    item.evaluationScore += e.evaluationScore
                    item.children.push(e)
                  }
                })
              })
            })
          })
      }
    },
    // 获取提问文件
    getQuestion(){
      let parmas = {
          pageBean: {
            pageSize: -1,
            page: -1,
          },
          querys: [],
        }
        parmas.querys.push({
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'projectApprovalId',
          relation: 'AND',
          value: this.id,
        })
        this.tendering = true
        this.$http
          .post('${portal}/clarifyQuestions/v1/pageAndAnswer', parmas)
          .then((res) => {
            this.tendering = false
            this.clarifyList = []
            if (res.data.state) {
              this.clarifyList = res.data.value.rows
              this.clarifyList.forEach((item) => {
                if (item.accessoryList && item.accessoryList.length) {
                  item.accessoryList.forEach((val) => {
                    item.name = val.name
                    item.url = val.url
                  })
                }
                if (item.answerList.length != 0) {
                  item.answerList.forEach((e) => {
                    if (e.accessoryList && e.accessoryList.length) {
                      e.accessoryList.forEach((key) => {
                        e.name = key.name
                        e.url = key.url
                      })
                    }
                  })
                }
              })
            }
          })
    },
    // 获取招标文件
    getZbfile() {
      let parmas = {
        pageBean: {
          pageSize: -1,
          page: -1,
        },
        querys: [],
      }
      parmas.querys.push(
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'projectApprovalId',
          relation: 'AND',
          value: this.id,
        },
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'type',
          relation: 'AND',
          value: 1,
        }
      )
      this.dataing = true
      this.$http
        .post('${portal}/tenderDocument/v1/pageAccessory', parmas)
        .then((res) => {
          this.dataing = false
          this.dataList = []
          let data = res.data.value.rows
          data.forEach((item) => {
            if (item.accessoryList && item.accessoryList.length != 0) {
              item.accessoryList.forEach((val) => {
                if (item.id == val.sourceId) {
                  val.describe = item.describe
                  this.dataList.push(val)
                  this.$forceUpdate()
                }
              })
            }
          })
        })
    },
    //查询评标分类树结构
    selectTree() {
      this.scoreData = []
      basicData.bizEvaluationItemSelectTree().then((res) => {
        this.scoreData = res.value[0].children
        this.scoreData.forEach((item) => {
          this.$set(item, 'evaluationScore', 0)
        })
      })
    },
    //报价总额
    totalChange() {
      this.totalValue = 0
      let sum = 0
      this.tableData.forEach((item) => {
        if (item.quoArrange != undefined) {
          sum += item.quoArrange * item.matNum
          this.totalValue = sum.toFixed(2)
        }
      })
    },
    // handleDown() {
    //   this.exporting = true
    //   let data = {
    //     querys: [],
    //   }
    //   data.querys.push({
    //     group: 'main',
    //     operation: 'EQUAL',
    //     parentGroup: '',
    //     property: 'noticeId',
    //     relation: 'AND',
    //     value: this.params.id,
    //   })
    //   let portal = window.context.portal
    //   let query = {
    //     url: `${portal}/projectApprovalDetails/v1/exportTemplateToExcel`,
    //     method: 'post',
    //     data: data,
    //     headers: {
    //       'Content-type': 'application/json',
    //     },
    //     responseType: 'blob', //将文件流转成blob对象
    //     noErrorMsg: true,
    //   }
    //   this.$http.request(query).then((res) => {
    //     if (res.status == 200) {
    //       this.$message.success('导出成功')
    //       this.exporting = false
    //     } else {
    //       this.$message.error('导出失败')
    //       this.exporting = false
    //     }
    //   })
    // },
    //下载文件
    downloadFile(name, url) {
      console.log(name, 'name')
      const link = document.createElement('a')
      link.style.display = 'none'
      link.target = '_blank'
      // 设置下载地址
      link.setAttribute('href', url)
      // 设置文件名
      link.setAttribute('download', name)
      link.download = name
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    },
    /** 鼠标移入cell */
    handleCellEnter(row, column, cell, event) {
      row.isEdit = true
    },
    /** 鼠标移出cell */
    handleCellLeave(row, column, cell, event) {
      row.isEdit = false
    },
    // 表格行点击
    handleBtn(rows) {
      this.objData = rows
      this.selectArr = []
      this.$refs.multiple.clearSelection()
      this.selectArr.push(rows)
      this.$refs.multiple.toggleRowSelection(rows)
    },
    selectAll(selection, row) {
      this.$refs.multiple.clearSelection()
      this.selectArr = []
    },
    handleSelectionChange(val) {
      this.selectArr = val
    },
    load(data) {
      console.log(data, 'ress')
      let sum = 0
      this.tableData.forEach((item) => {
        data.forEach((val) => {
          if (item.id == val['标的ID']) {
            item.quoArrange = Number(val['含税单价(元)'])
            item.tenderExplain = val['投标补充说明']
            item.quotationTemplateDetailList.forEach((i) => {
              if (item.quotationTemplateDetailDataList) {
                item.quotationTemplateDetailDataList.push({
                  noticeDetailedId: item.id,
                  noticeId: this.id,
                  noticeType: 1,
                  templateId: i.templateId,
                  templateDetailId: i.id,
                  value: item.quoArrange,
                  quoArrange: i.quoArrange,
                })
                item.quotationTemplateDetailDataList.forEach((val) => {
                  if (val.quoArrange == '合计金额(元)') {
                    val.priceEntry = 2
                    val['value'] = item.quoArrange * item.matNum
                  } else {
                    val.priceEntry = 1
                  }
                })
              }
            })
            sum += item.quoArrange * item.matNum
          }
        })
      })
    },
    loadData() {
      this.tableLoading = true
      let params = {
        pageBean: {
          page: -1,
          pageSize: -1,
        },
        querys: [
          {
            group: 'main',
            operation: 'EQUAL',
            parentGroup: '',
            property: 'noticeId',
            relation: 'AND',
            value: this.id,
          },
        ],
      }
      this.$http
        .post('${portal}/projectApprovalDetails/v1/quoData', params)
        .then((res) => {
          console.log(res, 'res')
          if (res.data.state) {
            this.params = res.data.value
            this.time =
              new Date(this.params.biddingEndTime).getTime() - Date.now()
            if (new Date(this.params.biddingStartTime).getTime() > Date.now()) {
              this.show = false
            }
            this.tableData = res.data.value.detailsList
            this.countDownMethod(this.params)
            this.addendumList = []
            if (
              res.data.value.byDocument != undefined &&
              res.data.value.byDocument.length != 0
            ) {
              res.data.value.byDocument.forEach((item) => {
                if (item.accessoryList && item.accessoryList.length != 0) {
                  item.accessoryList.forEach((val) => {
                    if (item.id == val.sourceId) {
                      val.describe = item.describe
                      this.addendumList.push(val)
                    }
                  })
                }
              })
            }
          }
          this.tableData.forEach((item, index) => {
            this.$set(
              item,
              'quotationMethod',
              this.$route.query.rows.quotationMethod
            )
            if (item.quotationTemplateDetailDataList == undefined) {
              item.quotationTemplateDetailDataList = []
            }
            if (item.quoArrange == undefined) {
              this.$set(item, 'quoArrange', 0)
            }

            if (
              item.quotationTemplateDetailList &&
              item.quotationTemplateDetailList.length != 0
            ) {
              if (item.quotationTemplateDetailList[0].value == undefined) {
                item.quoArrange = 0
              } else {
                item.quoArrange = item.quotationTemplateDetailList[0].value
              }
              item.quotationTemplateDetailList.forEach((object) => {
                let arr = []
                arr = Object.keys(item.quotationTemplateDetailList[0])
                this.tableHeadData.forEach((val) => {
                  arr.forEach((e) => {
                    if (e == val.prop && object.quoArrange != '') {
                      val.label = item.quotationTemplateDetailList[0].quoArrange
                    }
                  })
                })
              })
            }
            this.$set(item, 'isEdit', true)
          })
          console.log(this.tableData, 'tableData')
          this.tableLoading = false
        })
    },
    // 倒计时定时器
    countDownMethod(row) {
      this.countDown = setInterval(() => {
        const date =
          Date.parse(new Date(row.biddingEndTime)) - Date.parse(new Date())
        this.time = date
        if (
          Date.parse(new Date(row.biddingStartTime)) - Date.parse(new Date()) >
          0
        ) {
          this.countDown = '未开始'
          this.show = true
        } else if (date > 0) {
          this.dateTime = this.formatDate(date)
          this.show = false
        } else {
          this.countDown = '已结束'
          this.show = true
          // this.handleClose()
          this.tableData = []
          this.totalValue = 0
          clearInterval(this.countDown)
        }
      }, 1000)
    },
    formatDate(time) {
      let days = this.addZero(Math.floor(time / 1000 / 60 / 60 / 24)) //天
      let hours = this.addZero(Math.floor((time / 1000 / 60 / 60) % 24)) //时
      let minutes = this.addZero(Math.floor((time / 1000 / 60) % 60)) //分
      let seconds = this.addZero(Math.floor((time / 1000) % 60)) //秒
      return {
        days,
        hours,
        minutes,
        seconds,
      }
    },
    addZero(d) {
      return parseInt(d) < 10 ? '0' + d : d
    },
    // 获取投标文件
    getBidFiles() {
      this.tendering = true
      this.tenderList = []
      let parmas = {
        pageBean: {
          pageSize: -1,
          page: -1,
        },
        querys: [],
      }
      parmas.querys.push(
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'projectApprovalId',
          relation: 'AND',
          value: this.id,
        },
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'projectApprovalType',
          relation: 'AND',
          value: 2,
        },
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'supplierId',
          relation: 'AND',
          value: this.currentUser.org[0].orgId,
        }
      )
      this.$http.post('${portal}/bidDocuments/v1/page', parmas).then((res) => {
        let data = res.data.value.rows
        this.tendering = false
        data.forEach((item) => {
          if (item.accessoryList && item.accessoryList.length != 0) {
            item.accessoryList.forEach((val) => {
              this.tenderList.push(val)
            })
          }
        })
      })
    },
    // 关闭//面包屑点击
    handleClose() {
      this.$router.push({
        name: 'quotesMy',
        params: {
          tabsActiveName: 'CompetitiveNegotiation',
        },
      })
    },
    // 删除
    deleteFile(index) {
      this.$confirm('是否确认删除该附件', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        this.bidFileList.splice(index, 1)
      })
    },
    changeQuoArrange(row) {
      console.log(row, 22222222)
      if (row.maximumPriceLimit != undefined && row.maximumPriceLimit != 0) {
        if (row.quoArrange > row.maximumPriceLimit) {
          this.$message.error('当前项报价已超过最高限价，请重新报价！')
          return
        }
      }
      if (row.minQuoPrice != undefined && row.minQuoPrice != 0) {
        if (
          row.quoArrange > row.minQuoPrice ||
          row.quoArrange == row.minQuoPrice
        ) {
          this.$message.error('请输入低于当前最低价的报价，请重新报价！')
          return
        }
      }
      if (row.quoArrange == '' || row.quoArrange == undefined) {
        row.amount = ''
      }
      row.myPrice = row.quoArrange
      row.quotationTemplateDetailDataList = []
      row.quotationTemplateDetailList.forEach((item) => {
        row.quotationTemplateDetailDataList.push({
          noticeDetailedId: row.id,
          noticeId: this.id,
          noticeType: 1,
          templateId: item.templateId,
          templateDetailId: item.id,
          value: row.quoArrange,
          quoArrange: item.quoArrange,
        })
      })
      this.tableData.forEach((e) => {
        if (e.quotationTemplateDetailDataList.length != 0) {
          e.quotationTemplateDetailDataList.forEach((val) => {
            if (e.id == val.noticeDetailedId && val.quoArrange == '合计金额(元)') {
              val.priceEntry = 2
              val['value'] = e.quoArrange * e.matNum
            } else {
              val.priceEntry = 1
            }
          })
        } else {
          e.quotationTemplateDetailList.forEach((i) => {
            if (i.quoArrange == '合计金额(元)') {
              i.priceEntry = 2
            }
            e.quotationTemplateDetailDataList.push({
              noticeDetailedId: e.id,
              noticeId: this.id,
              noticeType: 1,
              templateId: i.templateId,
              templateDetailId: i.id,
              value: e.quoArrange,
              priceEntry: i.priceEntry,
              quoArrange: i.quoArrange,
            })
          })
        }
      })
    },
    // 报价
    open() {
      console.log(this.tenderList, '/bidDocuments/v1/removeByIds')
      if (
        this.tenderList.length == 0 &&
        this.params.isBidDocumentsUpload == 1
      ) {
        this.$message.warning('请上传投标文件')
        this.show = true
        return
      } else {
        this.show = false
      }
      let quoVo = {
        projectApproval: {
          detailsList: [],
        },
      }
      if (this.tableData[0].quoArrange == 0) {
        this.$message.error('请输入报价')
        this.saveing = false
        return false
      }
      this.tableData.forEach((item) => {
        if (
          item.quoArrange > 0 &&
          item.quoArrange != undefined &&
          item.quoArrange != 0
        ) {
          quoVo.projectApproval.detailsList.push(item)
        }
      })
      delete this.params.detailsList
      quoVo.projectApproval = {...quoVo.projectApproval, ...this.params}
      quoVo.projectApproval.detailsList.forEach(item=>{
        if(item.quotationTemplateDetailDataList&&item.quotationTemplateDetailDataList.length==0){
          item.quotationTemplateDetailList.forEach((i) => {
            item.quotationTemplateDetailDataList.push({
              noticeDetailedId: item.id,
              noticeId: this.id,
              noticeType: 1,
              templateId: i.templateId,
              templateDetailId: i.id,
              value: item.quoArrange,
              priceEntry: i.priceEntry,
              quoArrange: Number(i.quoArrange),
            })
          })
        }
      })
      console.log(quoVo)
      this.saveing = true
      this.$http
        .post('${portal}/bizBiddingQuotation/v1/quotationMat', quoVo)
        .then((res) => {
          this.saveing = false
          if (res.data.state) {
            this.$message.success(res.data.message)
          }
        })
    },
    // 文件状态改变时的钩子，添加文件、上传成功和上传失败时都会被调用,function(file, fileList)
    handleSuccess(res, file, fileList) {
      console.log(res, fileList)
      this.bidFileList.push(res.value)
      if (this.bidFileList.length != 0) {
        this.show = false
      }
      if(this.activeName == 1){
        this.form.accessoryList.push(res.value)
      }
    },
    beforeUpload(file) {
      let acceptList = ['xlsx', 'xls','png','jpg','jpeg','xlsx','xls','pdf','docx','doc','zip','rar']
      // 根据文件名获取文件的后缀名
      let fileType = file.name.split('.').pop().toLowerCase()
      // 判断文件格式是否符合要求
      if (acceptList.indexOf(fileType) === -1) {
        this.$message.error('请上传 .png,.jpg,.jpeg,.xlsx,.xls,pdf,.docx,.doc,.zip,.rar 格式的文件 !')
        return false
      }
    },
    //下载按钮回调
    downloadFile(name, url) {
      console.log(name, 'name')
      var a = document.createElement('a')
      var event = new MouseEvent('click')
      a.download = name
      a.target = '_blank'
      a.href = url
      a.dispatchEvent(event)
    },
    // 删除
    deleteHandle(id, index) {
      this.$confirm('是否确认删除该附件', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        if (this.activeName == 2 && id) {
          this.$http
            .post('${portal}/biz/universal/v1/delete?ids=' + id)
            .then((res) => {
              if (res.data.state) {
                this.$message.success('删除成功')
                this.getBidFiles()
              }
            })
        }
        this.$forceUpdate()
      })
    },
    dialogBeforeClose() {
      this.dialogVisible = false
    },
    // 打开投标文件
    openBid() {
      this.dialogVisible = true
    },
    // 打开提问弹窗
    openQuestion(){
      this.visible = true
    },
    // 提交提问
    handleQuestion() {
      let data = {
        projectApprovalId: this.id,
        describe: this.form.describe,
        accessoryList: this.form.accessoryList,
        projectApprovalType: 2,
      }
      this.quesing = true
      this.$http
        .post('${portal}/clarifyQuestions/v1/saveOrUpdate', data)
        .then((res) => {
          if (res.data.state) {
            this.getQuestion()
            this.visible = false
            this.form = {
              describe: '',
              accessoryList: [],
            }
          }
          this.quesing = false
        })
    },
    // 保存投标文件
    saveBid() {
      let data = {
        accessoryList: [],
        projectApprovalId: this.params.id,
        projectApprovalType: 2,
        quotationRounds: 1,
        supplierId: '',
      }
      data.supplierId = this.currentUser.org[0].orgId
      data.accessoryList = this.bidFileList
      this.biding = true
      this.$http
        .post('${portal}/bidDocuments/v1/saveOrUpdateEntity', data)
        .then((res) => {
          this.biding = false
          if (res.data.state) {
            this.handleClick()
            this.dialogBeforeClose()
            this.bidFileList = []
          }
        })
    },
    // 获取字典值翻译
    getDictName(code, value) {
      return utils.getDictName(code, value)
    },
  },
}
</script>
  
  <style lang="scss" scoped>
.common-page-shadow {
  width: 100%;
  height: calc(100% - 50px);
  box-sizing: border-box;
  .flex {
    display: flex;
    flex-wrap: nowrap;
  }
  .common-search-container {
    height: 80px;
    div {
      display: flex;
      align-items: center;
    }
  }
  .common-table-container {
    height: calc(100% - 20px);
    .common-table-content.btn-pagenation {
      height: calc(100% - 130px);
    }
    .common-table-wrapper {
      width: 65%;
    }
    .common-table-quote {
      height: 100%;
      width: 35%;
      padding: 26px 20px 30px 20px;
      .quote-content {
        border: 1px solid #eee;
        border-radius: 10px;
        height: 100%;
        padding: 0 20px;
        position: relative;
        width: calc(100% - 60px);
        .content {
          height: calc(100% - 240px);
          overflow: auto;
        }
        .btn {
          width: 100%;
          position: absolute;
          bottom: 16px;
          display: flex;
          justify-content: center;
        }
      }
    }
  }
}

.rows {
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ebebeb;
  margin-bottom: 16px;
  padding: 10px 0;
  .rows-left {
    margin-right: 10px;
    .rows-hr {
      width: 3px;
      height: 18px;
      background-color: #0e6eff;
      border-radius: 2px;
    }
  }
  .rows-title {
    .text-overflow {
      width: 100%;
      font-size: 16px;
    }
  }
}
</style>
  