<template>
  <div class="common-page-content">
    <div class="common-search-container" ref="contentPanel">
      <el-form
        ref="form"
        :model="searchForm"
        label-width="auto"
        label-position="right "
        :inline="true"
        type="flex"
        justify="left"
      >
        <el-form-item label="项目名称">
          <el-input
            size="small"
            v-model="searchForm.noticeTitle"
            clearable
            placeholder="请输入项目名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="需求企业">
          <el-input
            v-model="searchForm.procureOrgName"
            clearable
            size="small"
            placeholder="请输入需求企业"
          ></el-input>
        </el-form-item>
        <el-form-item label="发布状态">
          <el-select v-model="searchForm.winNoticeStatus" clearable
            size="small"
            style="width: 100%" placeholder="请选择发布状态">
              <el-option
                  v-for="item in winNoticeStatusList"
                  :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">
        <div class="common-btn-group">
          <el-button
            size="small"
            icon="el-icon-thumb"
            type="primary"
            :disabled="!currentDataDel.length"
            class="btn btn-plus"
            v-if="searchForm.winNoticeStatus == 1"
            :loading="pushing"
            @click="handlePush"
          >
            发送中标通知
          </el-button>
        </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="multipleSelection"
            height="100%"
            :data="tableData"
            @selection-change="handleSelectionChange"
          >
            <el-table-column
              type="selection"
              min-width="50"
              align="center"
            ></el-table-column>
            <el-table-column
              type="index"
              label="序号"
              width="50"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="noticeCode"
              min-width="100px"
              label="项目编号"
              align="center"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="noticeTitle"
              min-width="120px"
              label="项目名称"
              align="center"
              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="evaluationMethod"
              show-overflow-tooltip
              min-width="100px"
              align="center"
              label="评标方法"
              resizable
            >
            <template slot-scope="scope">
                <span v-if="scope.row.evaluationMethod == 2"
                  >综合评标法</span
                >
                <span v-if="scope.row.evaluationMethod == 1"
                  >最低评标法</span
                >
              </template>
            </el-table-column>
            <el-table-column
              prop="biddingStartTime"
              show-overflow-tooltip
              min-width="100px"
              align="center"
              label="投标开始时间"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="biddingEndTime"
              show-overflow-tooltip
              min-width="100px"
              align="center"
              label="投标结束时间"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="winBidValidity"
              show-overflow-tooltip
              min-width="100px"
              align="center"
              label="中标有效期(天)"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="winNoticeStatus"
              show-overflow-tooltip
              min-width="100px"
              align="center"
              label="发布状态"
              resizable
            >
              <template slot-scope="scope">
                <el-tag v-if="scope.row.winNoticeStatus == 2" type="success"
                  >已发布</el-tag
                >
                <el-tag v-if="scope.row.winNoticeStatus == 3" type="warning"
                  >待确认</el-tag
                >
                <el-tag v-if="scope.row.winNoticeStatus == 1" type="info"
                  >未发布</el-tag
                >
                <el-tag v-if="scope.row.winNoticeStatus == 4" type="danger"
                  >不同意</el-tag
                >
              </template>
            </el-table-column>
            <el-table-column min-width="120px" align="center" label="操作">
              <template v-slot="{row}">
                <template>
                  <el-button
                    icon="el-icon-view"
                    type="primary"
                    plain
                    size="small"
                    @click="handleNotifcation(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'
const portal = window.context.portal
export default {
  name: 'DemandEntry',
  components: {
    pagination,
  },
  mixins: [TableMixin],
  data() {
    return {
      currentPage: 1,
      tableMaxHeight: 400,
      loading: false,
      tableLoading: false,
      pushing: false,
      tableData: [],
      multipleSelection: [],
      winNoticeStatusList:[{label:'未发布',value:'1'},{label:'待确认',value:'3'},{label:'已发布',value:'2'},{label:'不同意',value:'4'}], 
      queryParam: {
        pageBean: {
          page: 1,
          pageSize: 20,
          total: 0,
        },
        querys: [],
        sorter: [
          {
            direction: 'DESC',
            property: 'createTime',
          },
        ],
      },
      searchForm: {
        calibraStatus: '2',
        winNoticeStatus: '1',
      }, // 顶部搜索对象
      deleteIds: '', // 是否选中列表解锁删除按钮
      edit: false, // 是否是修改功能
      currentDataDel: [], // 删除时排查是否有在审核的数据
    }
  },
  mounted() {},
  created() {
    this.handleSearch()
  },
  methods: {
    // 管理成交通知(列表按钮回调)
    handleNotifcation(rows) {
      if (rows.evaluationMethod == 2 && rows.evaluationMode == 2) {
        this.$router.push({
          name: 'projectNoticeAdd',
          query: {rows},
        })
      }
      if (
        (rows.evaluationMethod == 1 || rows.evaluationMethod == 2) &&
        rows.evaluationMode != 2
      ) {
        this.$router.push({
          path: `/projectNoticeDetails/${rows.id}`,
          query: {evaluationMethod: rows.evaluationMethod, rows},
        })
      }
    },
    getDictName(code, value) {
      return utils.getDictName(code, value)
    },

    //获取数据
    loadData() {
      this.tableLoading = true
      this.$http
        .post('${portal}/projectApproval/v1/page', this.queryParam)
        .then((res) => {
          console.log(res, 'res')
          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,
            }
          }
          this.tableLoading = false
        })
    },
    clearSearchForm() {
      this.searchForm = {
        calibraStatus: '2',
        winNoticeStatus: '1',
      }
      this.handleSearch()
    },
    // 顶部搜索
    handleSearch() {
      let obj = this.searchForm
      let querys = []
      for (let i in obj) {
        if (obj[i]) {
          querys.push({
            group: 'main',
            operation:
              i == 'procureOrgName' || i == 'noticeTitle' ? 'LIKE' : 'EQUAL',
            parentGroup: '',
            property: i,
            relation: 'AND',
            value: obj[i],
          })
        }
      }
      this.queryParam.querys = querys
      this.loadData()
    },
    //   发布
    handlePush() {
      this.$confirm('是否发送成交通知？', '提示', {
        confirmButtonText: '确 定',
        cancelButtonText: '取 消',
        type: 'warning',
      }).then(() => {
        this.pushing = true
        let data = {
          noticeId: this.currentDataDel[0].id,
          noticeType:2
        }
        this.$http
          .post('${portal}/bizWinBiddingNotice/v1/pushWinBidNoticePro', data)
          .then((res) => {
            this.pushing = false
            if (res.data.state) {
              this.$message.success(res.data.message)
              this.handleSearch()
            }
          })
      })
    },
    handleSelectionChange(currentData) {
      this.currentDataDel = currentData
      if (this.currentDataDel.length > 1) {
        this.$refs.multipleSelection.toggleRowSelection(
          this.currentDataDel[0],
          false
        )
      }
    },
    handleCurrentChange(page) {
      this.queryParam.pageBean = {...this.queryParam.pageBean, page}
      this.loadData()
    },
    handleSizeChange(pageSize) {
      this.queryParam.pageBean = {...this.queryParam.pageBean, pageSize}
      this.loadData()
    },
  },
  computed: {
    SearchPanel() {
      return {
        '--searchPanel': this.searchPanel + 'px',
      }
    },
  },
}
</script>
  
  <style lang="scss" scoped>
.common-table-container {
  height: calc(100% - 90px);
}
.common-table-content {
  height: calc(100% - 110px);
}
.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;
  }
  /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>
  