<template>
  <div class="common-page-shadow">
    <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
            v-model="searchForm.matOrgName"
            size="small"
            clearable
            placeholder="请输入需求企业"
          ></el-input>
        </el-form-item>
        <el-form-item label="违约企业">
          <el-input
            size="small"
            v-model="searchForm.supplierOrgName"
            clearable
            placeholder="请输入违约企业"
          ></el-input>
        </el-form-item>
        <el-form-item label="处理状态">
          <el-select
            clearable
            size="small"
            v-model="searchForm.handleStatus"
            placeholder="请选择处理状态"
          >
            <el-option
              v-for="item in statusList"
              :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-view"
            type="primary"
            class="btn btn-plus"
            @click="handleQuery"
          >
            明细查询
          </el-button>
          <!-- <el-button
            size="small"
            icon="el-icon-bottom"
            type="primary"
            plain
            class="btn btn-delete"
            @click="handleDownload"
          >
            导出数据
          </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"
            :data="tableData"
            @selection-change="handleSelectionChange"
          >
            <el-table-column
              type="selection"
              min-width="50px"
              align="center"
            ></el-table-column>
            <el-table-column
              type="index"
              label="序号"
              min-width="50"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="noticeCode"
              min-width="110px"
              show-overflow-tooltip
              label="项目编号"
              align="center"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="noticeTitle"
              min-width="120px"
              show-overflow-tooltip
              label="项目名称"
              align="center"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="noticeType"
              min-width="90px"
              show-overflow-tooltip
              label="项目类型"
              align="center"
              resizable
            >
              <template v-slot="{row}">
                <div v-if="row.noticeType == 1">物资</div>
                <div v-if="row.noticeType == 2">项目</div>
              </template>
            </el-table-column>
            <el-table-column
              prop="matOrgName"
              min-width="130px"
              show-overflow-tooltip
              label="需求单位"
              align="center"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="supplierOrgName"
              show-overflow-tooltip
              min-width="130px"
              align="center"
              label="违约企业"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="userName"
              show-overflow-tooltip
              min-width="100px"
              align="center"
              label="违约联系人"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="userMobile"
              show-overflow-tooltip
              min-width="100px"
              align="center"
              label="违约人联系方式"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="violateTime"
              show-overflow-tooltip
              min-width="110px"
              align="center"
              label="违约日期"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="violatePrice"
              show-overflow-tooltip
              min-width="90px"
              align="center"
              label="违约金额(元)"
              resizable
            >
            </el-table-column>

            <el-table-column min-width="200px" align="center" label="操作">
              <template v-slot="{row}">
                <template>
                  <el-button
                    icon="el-icon-thumb"
                    plain
                    @click="handleDetails(row)"
                    type="primary"
                    size="small"
                  >
                    没收保证金
                  </el-button>
                  <el-button
                    icon="el-icon-thumb"
                    plain
                    type="primary"
                    size="small"
                  >
                    流标
                  </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: 'create_time_',
          },
        ],
      },
      statusList: [
        {label: '未收取', value: '1'},
        {label: '已收取', value: '2'},
        {label: '流标', value: '3'},
      ],
      searchForm: {}, // 顶部搜索对象
      canpanmyList: [],
    }
  },
  mounted() {},
  created() {
    this.handleSearch()
  },
  methods: {
    getDictName(code, value) {
      return utils.getDictName(code, value)
    },
    //获取数据
    loadData() {
      this.tableLoading = true
      this.$http
        .post('${portal}/bizViolateRecord/v1/page', this.params)
        .then((res) => {
          console.log(res, 'res')
          this.tableLoading = false
          const data = (res && res.data) || {}
          this.tableData = data.value.rows || []
          console.log('返回的表格数据', this.tableData)
          this.params.pageBean = {
            page: data.value.page,
            pageSize: data.value.pageSize,
            total: data.value.total,
          }
        })
    },
    // 顶部搜索
    handleSearch() {
      let obj = this.searchForm
      let querys = []
      for (let i in obj) {
        if (obj[i]) {
          querys.push({
            group: 'main',
            operation:
              i == 'matOrgName' || i == 'supplierOrgName' || i == 'companyName'
                ? 'LIKE'
                : 'EQUAL',
            parentGroup: '',
            property: i,
            relation: 'AND',
            value: obj[i],
          })
        }
      }
      this.params.querys = querys
      this.loadData()
    },
    // 明细查询
    handleQuery() {
      if (this.currentDataDel.length > 1) {
        this.$message.warning('请选择单条数据查看')
      } else {
        this.$router.push({
          name: 'defaultWinningBidGoodsDetail',
          query: {id: this.currentDataDel[0].id},
        })
      }
    },
    handleSelectionChange(currentData) {
      this.currentDataDel = currentData
    },
    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% - 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>
