<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="querys[2].value"
            clearable
            placeholder="请输入采购单位"
          ></el-input>
        </el-form-item>
        <el-form-item label="结束时间">
          <el-date-picker
            size="small"
            v-model="searchForm.date"
            type="datetimerange"
            @change="changeTime"
            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">
        <div class="common-btn-group">
            <el-button
              size="small"
              icon="el-icon-bottom"
              type="primary"
              plain
              :loading="exporting"
              :disabled="!currentDataDel.length"
              class="btn btn-plus"
              @click="dataExport"
            >
              导出报价明细
            </el-button>
          </div>
        <!-- LJ：表格高度自适应需配合样式  btn-pagenation 有按钮有分页  btngroup只有按钮  pagenation只有分页 -->
        <div class="common-table-content btn-pagenation">
          <el-table
            :border="true"
            stripe
            fit
            height="100%"
            size="mini"
            v-loading="tableLoading"
            ref="multipleSelection"
            :data="tableData"
            @selection-change="handleSelectionChange"
          >
          <el-table-column
              type="selection"
              min-width="50px"
              align="center"
            ></el-table-column>
            <el-table-column
              type="index"
              width="55"
              align="center"
              label="序号"
            >
            </el-table-column>
            <el-table-column
              prop="projectNumber"
              min-width="100px"
              label="项目编号"
              align="center"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="noticeTitle"
              show-overflow-tooltip
              min-width="120px"
              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
              show-overflow-tooltip
              min-width="100px"
              prop="procureType"
              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="quotationRoundsNum"
              show-overflow-tooltip
              min-width="100px"
              align="center"
              label="报价轮次"
              resizable
            >
            </el-table-column>
            <el-table-column min-width="120px" align="center" label="操作">
              <template v-slot="{row}">
                <template>
                  <el-button
                    type="primary"
                    plain
                    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 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: [],
      queryParam: {
        pageBean: {
          page: 1,
          pageSize: 20,
          total: 0,
        },
        sorter:[{
          direction: 'DESC',
          property: 'create_time_',
        }]
      },
      searchForm: {
        date:''
      }, // 顶部搜索对象
      exporting:false,
      deleteIds: '', // 是否选中列表解锁删除按钮
      fileList: [], // 文件上传
      edit: false, // 是否是修改功能
      currentDataDel: [], // 删除时排查是否有在审核的数据
      querys: [
        {
          group: 'main',
          operation: 'GREAT_EQUAL',
          parentGroup: '',
          property: 'bidStatus',
          relation: 'AND',
          value: '5',
        },
        {
          group: 'main',
          operation: 'BETWEEN',
          parentGroup: '',
          property: 'biddingEndTime',
          relation: 'AND',
          value: '',
        },
        {
          group: 'main',
          operation: 'LIKE',
          parentGroup: '',
          property: 'procureOrgName',
          relation: 'AND',
          value: '',
        }
      ],
      currentUser:{}
    }
  },
  mounted() {
    
  },
  created() {
    this.currentUser = JSON.parse(sessionStorage.getItem('currentUserDetail'))
    const moment = require('moment')
    this.querys[1].value = ''
    this.loadData()
  },
  methods: {
    //获取数据
    loadData() {
      this.tableLoading = true
      this.queryParam.querys = []
      if (this.querys[0].value) {
        this.queryParam.querys.push(this.querys[0])
      }
      if (this.querys[1].value) {
        this.queryParam.querys.push(this.querys[1])
      }
      if (this.querys[2].value) {
        this.queryParam.querys.push(this.querys[2])
      }
      this.$http
        .post('${portal}/matApproval/v1/quoManageData', 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.date =''
      this.querys[0].value = 5
      this.querys[1].value = ''
      this.querys[2].value = ''
      this.loadData()
    },
    //导出数据
    dataExport() {
      if(this.currentDataDel.length>1){
        this.$message.warning('请选择单条数据导出')
        return
      }
      let queryParam={
        querys:[]
      }
      queryParam.pageBean={
        page:-1,
        pageSize:-1,
        showTotal:false,
      }
      queryParam.querys.push({
        group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'quo.NOTICE_ID_',
          relation: 'AND',
          value: this.currentDataDel[0].id,
      })
    if(this.currentDataDel[0].affiliatedOrgId != this.currentUser.org[0].orgId || this.currentDataDel[0].procureOrgId != this.currentUser.org[0].orgId){
      queryParam.querys.push({
        group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'QUOTATION_COMPANY_ID_',
          relation: 'AND',
          value: this.currentUser.org[0].orgId,
      })
    }
      let portal = window.context.portal
      let query = {
        url: `${portal}/bizBiddingQuotation/v1/exportDataToExcel`,
        method: 'post',
        data: queryParam,
        headers: {
          'Content-type': 'application/json',
        },
        responseType: 'blob', //将文件流转成blob对象
        noErrorMsg: true,
      }
      this.exporting = true
      this.$http
        .request(query)
        .then((res) => {
          if (res.status == 200) {
            this.$message.success('导出成功')
            this.exporting = false
          } else {
            this.$message.error('导出失败')
            this.exporting = false
          }
        })
        .catch(() => {
          this.exporting = false
        })
    },
    changeTime(val){
      console.log(val);
      this.searchForm.date = val
      this.querys[1].value = this.searchForm.date
    },
    //查看报价
    quoteBtn(rows) {
      if(rows.evaluationMethod == 2&& rows.evaluationMode==2){
        this.$router.push({
        path: `/tendeSiteRecording/${rows.id}`,
        query:{rows}
      })
      }
      if(rows.evaluationMode == 1&& (rows.evaluationMethod==2||rows.evaluationMethod==1)){
        this.$router.push({
        path: `/tendeSiteQuote/${rows.id}`,
        query:{rows}
      })
      }
    },
    // 顶部搜索
    handleSearch() {
      this.loadData(this.queryParam)
    },
    handleSelectionChange(currentData) {
      this.currentDataDel = currentData
      if (currentData.length === 0) return (this.deleteIds = '')
      let ids = []
      currentData.forEach((item) => {
        ids.push(item.id)
      })
      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% - 100px);
}
.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>
