<template>
  <div class="common-page-content">
    <div class="common-search-container" ref="contentPanel">
      <el-form
        ref="form"
        label-width="auto"
        label-position="right "
        :inline="true"
        type="flex"
        justify="left"
      >
        <el-form-item label="项目名称">
          <el-input
            size="small"
            v-model="querys[0].value"
            clearable
            placeholder="请输入项目名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="项目负责人">
          <el-input
            size="small"
            v-model="querys[1].value"
            clearable
            placeholder="请输入项目负责人"
          ></el-input>
        </el-form-item>
        <el-form-item label="项目类型">
          <dict-select
            dictCode="xmlx"
            :hasDefaultOption="true"
            clearable
            size="small"
            v-model="querys[2].value"
            placeholder="请选择项目类型"
          />
        </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-plus"
            type="primary"
            class="btn btn-plus"
            @click="handleAdd"
          >
            提交申请
          </el-button>
        </div>
        <!-- LJ：表格高度自适应需配合样式  btn-pagenation 有按钮有分页  btngroup只有按钮  pagenation只有分页 -->
        <div class="common-table-content btn-pagenation" ref="tableContent">
          <el-table
            :border="true"
            stripe
            fit
            size="mini"
            :max-height="tableHeight"
            v-loading="tableLoading"
            ref="multipleSelection"
            :data="tableData"
            @selection-change="handleSelectionChange"
          >
            <el-table-column type="selection" min-width="5%" align="center">
            </el-table-column>
            <el-table-column
              prop="projectCode"
              min-width="10%"
              label="项目编号"
              align="center"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="projectName"
              min-width="10%"
              label="项目名称"
              align="center"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="projectUserName"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="项目负责人 "
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="purchasingOrgName"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="采购单位"
              resizable
            >
            </el-table-column>
            <el-table-column
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="项目类型"
              resizable
            >
              <template v-slot="{row}">
                {{ getDictName('xmlx', row.projectType) }}
              </template>
            </el-table-column>
            <el-table-column
              prop="constructionStartTime"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="建设开始时间"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="constructionCompletionTime"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="建设结束时间"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="investment"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="总投资（万元）"
              resizable
            >
            </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 dictUtils from '@/components/dict/DictSelectUtils.js'
import procurementManagement from '@/api/procurementManagement'
export default {
  name: 'DemandEntry',
  components: {
    pagination
  },
  mixins: [TableMixin],
  data() {
    return {
      tableHeight: 1000,
      tableData: [],
      handleDeleteActive: true,
      handleDeleteId: [],
      tableLoading: false,
      queryParam: {
        pageBean: {
          page: 1,
          pageSize: 20,
          total: 0
        },
        sorter: [
          {
            direction: 'DESC',
            property: 'create_time_'
          }
        ]
      },
      querys: [
        {
          group: 'main',
          operation: 'LIKE',
          parentGroup: '',
          property: 'projectName',
          relation: 'AND',
          value: ''
        },
        {
          group: 'main',
          operation: 'LIKE',
          parentGroup: '',
          property: 'projectUserName',
          relation: 'AND',
          value: ''
        },
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'projectType',
          relation: 'AND',
          value: ''
        }
      ]
    }
  },
  mounted() {
    //页面缩放从新计算表格的高度
    window.addEventListener('resize', this.calcTableHeight)
  },
  created() {
    this.loadData()
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.calcTableHeight)
  },
  methods: {
    // 动态计算表格的高度，自适应当前容器
    calcTableHeight() {
      this.tableHeight = this.$refs.tableContent.offsetHeight
    },
    //获取数据
    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])
      }
      procurementManagement.bizProjectInfoPage(this.queryParam).then(res => {
        this.queryParam.pageBean.total = res.value.total
        this.tableLoading = false
        this.tableData = res.value.rows
      })
    },
    //添加
    handleAdd() {
      
    },
    //重置
    clearSearchForm() {
      this.querys[0].value = ''
      this.querys[1].value = ''
      this.querys[2].value = ''
      this.loadData()
    },
    // 顶部搜索
    handleSearch() {
      this.loadData()
    },
    handleSelectionChange(val) {
      if (val.length !== 0) {
        this.handleDeleteActive = false
        this.handleDeleteId = val.map(item => {
          return item.id
        })
      } else {
        this.handleDeleteActive = true
      }
    },
    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>
.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>
