<template>
  <div class="common-page-shadow">
    <div class="common-search-container" ref="contentPanel">
      <el-form
        ref="form"
        :model="searchForm"
        label-position="right "
        :inline="true"
        type="flex"
        justify="left"
      >
        <el-form-item label="项目编号">
          <el-input
            size="small"
            v-model="searchForm.projectNumber"
            clearable
            placeholder="请输入项目编号"
          ></el-input>
        </el-form-item>
        <el-form-item label="采购单位">
          <el-input
            size="small"
            v-model="searchForm.procureOrgName"
            clearable
            placeholder="请输入采购单位"
          ></el-input>
        </el-form-item>
        <el-form-item label="评标状态">
          <el-select
            size="small"
            @change="changeStatus"
            clearable
            v-model="status"
            placeholder="请选择评标状态"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div class="container-btn">
        <el-button
          size="small"
          icon="el-icon-search"
          type="danger"
          class="btn btn-plus"
          @click="handleSearch"
        >
          搜索
        </el-button>
        <el-button
          size="small"
          icon="el-icon-refresh-right"
          class="btn btn-plus"
          @click="clearSearchForm"
        >
          重置
        </el-button>
      </div>
    </div>
    <el-row
      class="common-table-container flex searchPanel"
      :style="SearchPanel"
    >
      <el-col :span="24" class="common-table-wrapper">
        <!-- LJ：表格高度自适应需配合样式  btn-pagenation 有按钮有分页  btngroup只有按钮  pagenation只有分页 -->
        <div class="common-table-content btn-pagenation">
          <el-table
            :border="true"
            stripe
            fit
            size="mini"
            v-loading="tableLoading"
            ref="multipleSelection"
            height="100%"
            :data="tableData"
            @selection-change="handleSelectionChange"
          >
            <el-table-column
              type="index"
              width="55"
              align="center"
              label="序号"
            >
            </el-table-column>
            <el-table-column
              prop="projectNumber"
              min-width="110px"
              label="项目编号"
              align="center"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="noticeTitle"
              show-overflow-tooltip
              min-width="130px"
              align="center"
              label="项目名称"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="procureOrgName"
              show-overflow-tooltip
              min-width="130px"
              align="center"
              label="采购单位"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="procureType"
              show-overflow-tooltip
              min-width="100px"
              align="center"
              label="采购类型"
              resizable
            >
              <template v-slot="{row}">
                <div v-if="row.procureType != 6">
                  {{ getDictName('cglx-cglx', row.procureType) }}
                </div>
                <div v-else>谈判采购（多轮）</div>
              </template>
            </el-table-column>
            <el-table-column
              prop="biddingStartTime"
              show-overflow-tooltip
              min-width="120px"
              align="center"
              label="投标开始时间"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="biddingEndTime"
              show-overflow-tooltip
              min-width="120px"
              align="center"
              label="投标结束时间"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="evaluationStartTime"
              show-overflow-tooltip
              min-width="120px"
              align="center"
              label="评标开始时间"
              resizable
            >
            </el-table-column>
            <el-table-column
              show-overflow-tooltip
              min-width="120px"
              align="center"
              label="评标状态"
              resizable
            >
              <template slot-scope="scope">
                <el-tag type="danger" v-if="scope.row.bidStatus == 5">
                  未评标
                </el-tag>
                <el-tag v-else>已评标</el-tag>
              </template>
            </el-table-column>
            <el-table-column min-width="120px" align="center" label="操作">
              <template v-slot="{row}">
                <template>
                  <el-button
                    type="primary"
                    plain
                    v-if="row.calibraStatus==0"
                    size="small"
                    @click="quoteBtn(row)"
                    >评标</el-button
                  >
                </template>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="common-pagenation">
          <el-pagination
            ref="paginationPanel"
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="queryParam.pageBean.page"
            :page-sizes="[20, 30, 40, 50]"
            :page-size="queryParam.pageBean.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="queryParam.pageBean.total"
          >
          </el-pagination>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import pagination from '@/components/pagination'
import {TableMixin} from '@/mixins/tableMixin'
import routerManagement from '@/api/BasicDataManagement/routerManagement.js'
import req from '@/request.js'
import utils from '@/utils.js'
import {label} from 'three/examples/jsm/nodes/Nodes.js'
const portal = window.context.portal
export default {
  name: 'DemandEntry',
  components: {
    pagination,
  },
  mixins: [TableMixin],
  data() {
    return {
      currentPage: 1,
      tableMaxHeight: 400,
      loading: false,
      tableLoading: false,
      tableData: [],
      multipleSelection: [],
      status: '',
      queryParam: {
        pageBean: {
          page: 1,
          pageSize: 20,
          total: 0,
        },
        querys: [],
        sorter: [
          {
            direction: 'DESC',
            property: 'create_time_',
          },
        ],
      },
      searchForm: {
        bidStatus: ['5'],
      }, // 顶部搜索对象
      deleteIds: '', // 是否选中列表解锁删除按钮
      currentDataDel: [], // 删除时排查是否有在审核的数据
      options: [
        {
          label: '未评标',
          value: '0',
        },
        {
          label: '已评标',
          value: '1',
        },
      ],
      
    }
  },
  mounted() {},
  created() {
    this.handleSearch()
  },
  methods: {
    getDictName(code, value) {
      return utils.getDictName(code, value)
    },
    // 评标
    quoteBtn(rows) {
      if (rows.evaluationMethod == 1) {
        this.$router.push({
          path: `/minProcurementBid/${rows.id}`,
          query: {rows},
        })
      }
      if (rows.evaluationMethod == 2 && rows.evaluationMode == 2) {
        this.$router.push({
          path: `/procurementBid/${rows.id}`,
          query: {evaluationTemplateId: rows.evaluationTemplateId},
        })
      }
      if (rows.evaluationMethod == 2 && rows.evaluationMode == 1) {
        this.$router.push({
          name: `procurementDetails`,
          query: {evaluationTemplateId: rows.evaluationTemplateId, data: rows},
        })
      }
    },
    // 顶部搜索
    handleSearch() {
      console.log(this.status);
      let querys = []
      for (let i in this.searchForm) {
        if (i == 'bidStatus') {
          if (this.status == ''&&this.status.length == 0) {
            querys.push({
              group: 'main',
              operation: 'IN',
              property: i,
              relation: 'AND',
              value: ['5','6'],
            })
          }else
          if (this.status == '0') {
            querys.push({
              group: 'main',
              operation: 'IN',
              property: i,
              relation: 'AND',
              value: this.searchForm[i],
            })
          }else
          if (this.status == '1') {
            querys.push({
              group: 'main',
              operation: 'GREAT',
              property: i,
              relation: 'AND',
              value: '5',
            })
          }
        } else {
          querys.push({
            group: 'main',
            operation: 'LIKE',
            property: i,
            relation: 'AND',
            value: this.searchForm[i],
          })
        }
      }
      this.queryParam.querys = querys
      this.loadData()
    },
    //获取数据
    loadData() {
      this.tableLoading = true
      this.$http
        .post('${portal}/matApproval/v1/bidEvaData', this.queryParam)
        .then((res) => {
          console.log(res, 'res')
          this.tableLoading = false
          if (res.data.state) {
            this.tableData = res.data.value.rows
            console.log('返回的表格数据', this.tableData)
            this.queryParam.pageBean = {
              page: res.data.value.page,
              pageSize: res.data.value.pageSize,
              total: res.data.value.total,
            }
          }
        })
    },
    changeStatus(val) {
      this.status = val
      if(val=='0'){
        this.searchForm.bidStatus = ['5']
      }
      if(val=='1'){
        this.searchForm.bidStatus = ['5','6']
      }
      this.$forceUpdate()
    },
    clearSearchForm() {
      this.searchForm = {
        bidStatus:['5']
      }
      this.status = ''
      this.queryParam.pageBean.page = 1
      this.handleSearch()
    },
    handleSelectionChange(currentData) {
      this.currentDataDel = currentData
      if (currentData.length === 0) return (this.deleteIds = '')
      let ids = []
      currentData.forEach((item) => {
        ids.push(item.id)
      })
      // this.$message.error(`【${item.demandTopic}】已上报待审核不能删除！`)
      this.deleteIds = ids.join(',')
    },
    handleCurrentChange(page) {
      this.queryParam.pageBean = {...this.queryParam.pageBean, page}
      this.loadData(this.queryParam)
    },
    handleSizeChange(pageSize) {
      this.queryParam.pageBean = {...this.queryParam.pageBean, pageSize}
      this.loadData(this.queryParam)
    },
  },
  computed: {
    SearchPanel() {
      return {
        '--searchPanel': this.searchPanel + 'px',
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.common-table-content.btn-pagenation {
  height: calc(100% - 60px);
}
.cloumn-btn {
  border: 1px solid #2761ff;
  padding: 3px 10px;
  border-radius: 5px;
  &:nth-child(1) {
    margin-right: 5px;
  }
  &:nth-child(2) {
    margin-right: 5px;
  }
  &:nth-child(1):hover {
    background-color: #2761ff;
    color: #fff;
  }
  &:nth-child(2):hover {
    background-color: #2761ff;
    color: #fff;
  }
  // &:nth-child(2):hover {
  //   background-color: #f56c6c;
  //   color: #fff;
  //   border-color: #f56c6c;
  // }
  /deep/ i,
  span {
    font-size: 16px;
  }
}

/deep/ .el-tree-node__content {
  padding: 5px 0;
}

/deep/ .el-table thead tr th {
  background-color: #eee !important;
  border-right: 1px solid #dfe2e8 !important;
}
/deep/ .el-table {
  border-collapse: collapse !important;
}
</style>
