<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.noticeCode"
            clearable
            placeholder="请输入项目编号"
          ></el-input>
        </el-form-item>
        <el-form-item label="结束时间">
          <el-date-picker
            size="small"
            v-model="searchForm.sendTime"
            type="datetimerange"
            value-format="yyyy-MM-dd HH:mm:ss"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :default-time="['00:00:00', '23:59:59']"
          ></el-date-picker>
        </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"
              label="序号"
              width="50"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="noticeCode"
              min-width="110px"
              label="项目编号"
              align="center"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="noticeName"
              min-width="120px"
              label="项目名称"
              align="center"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="noticeType"
              min-width="90px"
              label="项目类型"
              align="center"
              resizable
            >
            <template slot-scope="scope">
              <div v-if="scope.row.noticeType==1">
                物资
              </div>
              <div v-if="scope.row.noticeType==2">
                项目
              </div>
            </template>
            </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="sendUserName"
              show-overflow-tooltip
              min-width="100px"
              align="center"
              label="发布人"
              resizable
            >
            </el-table-column>
            
            <el-table-column
              prop="sendTime"
              show-overflow-tooltip
              min-width="100px"
              align="center"
              label="发布时间"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="sendUserAccount"
              show-overflow-tooltip
              min-width="110px"
              align="center"
              label="联系方式"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="vendorName"
              show-overflow-tooltip
              min-width="110px"
              align="center"
              label="中标供应商"
              resizable
            >
            </el-table-column>  
            <el-table-column
              prop="status"
              show-overflow-tooltip
              min-width="110px"
              align="center"
              label="确认状态"
              resizable
            >
              <template slot-scope="scope">
                <div v-if="scope.row.status==1">已确认</div>
              </template>
            </el-table-column> 
            <el-table-column min-width="160px" 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="params.pageBean.page"
            :page-sizes="[20, 30, 40, 50]"
            :page-size="params.pageBean.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="params.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,
      tableData: [],
      multipleSelection: [],
      params: {
        pageBean: {
          page: 1,
          pageSize: 20,
          total: 0
        },
        querys:[],
        sorter: [
          {
            direction: 'DESC',
            property: 'sendTime',
          },
        ],
      },
      searchForm: {
    
      }, // 顶部搜索对象
      currentDataDel: [], // 删除时排查是否有在审核的数据
      canpanmyList: []
    }
  },
  mounted() {},
  created() {
    this.handleSearch()
  },
  methods: {
    // 查看成交通知(列表按钮回调)
    handleNotifcation(rows) {
      if(rows.noticeType==1){
        this.$router.push({
        name: 'confirmationWinningBidDetail',
        query: {noticeId: rows.noticeId, id: rows.id,rows}
      })
      }
      if(rows.noticeType==2){
        this.$router.push({
        name: 'confirmationWinningBidView',
        query: {noticeId: rows.noticeId, id: rows.id,rows}
      })
      }
    },
    getDictName(code, value) {
      return utils.getDictName(code, value)
    },
    //获取数据
    loadData(params) {
      this.tableLoading = true
      this.$http.post('${portal}/bizWinBiddingNotice/v1/vendorPage',this.params).then(res=>{
        console.log(res, 'res')
        this.tableLoading = false
        this.tableData = res.data.value.rows || []
        console.log('返回的表格数据', this.tableData)
        this.params.pageBean = {
          page:  res.data.value.page,
          pageSize:  res.data.value.pageSize,
          total:  res.data.value.total
        }
      })
    },
    // 顶部搜索
    handleSearch() {
      let obj = this.searchForm
      let querys = []
      for (let i in obj) {
        if(i=='sendTime'){
          querys.push({
            group: 'main',
            operation:'BETWEEN',
            parentGroup: '',
            property: i,
            relation: 'AND',
            value: obj[i]
          })
        }else{
          querys.push({
            group: 'main',
            operation:
             i == 'noticeCode' || i == 'companyName'
                ? 'LIKE'
                : 'EQUAL',
            parentGroup: '',
            property: i,
            relation: 'AND',
            value: obj[i]
          })
        }
      }
      this.params.querys = querys
      this.loadData()
    },
    clearSearchForm(){
      this.searchForm={
     
      }
      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.params.pageBean = {...this.params.pageBean, page}
      this.loadData(this.params)
    },
    handleSizeChange(pageSize) {
      this.params.pageBean = {...this.params.pageBean, pageSize}
      this.loadData(this.params)
    }
  },
  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;
  }
  /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>
