<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-select
            clearable
            v-model="searchForm.com"
            filterable
            placeholder="请选择销售企业"
          >
            <el-option
              v-for="item in canpanmyList"
              :key="item.affiliatedCompanyId"
              :label="item.affiliatedCompanyName"
              :value="item.affiliatedCompanyName"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="违约企业">
          <el-input
            size="small"
            v-model="searchForm.name"
            clearable
            placeholder="请输入违约企业"
          ></el-input>
        </el-form-item>
        <el-form-item label="没收状态">
          <el-select
            clearable
            v-model="searchForm.state"
            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">
        <!-- 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"
            @row-dblclick="handleDetail"
          >
            <el-table-column type="selection" align="center"> </el-table-column>
            <el-table-column
              prop="noticeCode"
              label="项目编号"
              align="center"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="noticeTitle"
              label="项目名称"
              align="center"
              min-width="180"
              show-overflow-tooltip
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="create"
              show-overflow-tooltip
              align="center"
              label="违约企业"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="createName"
              show-overflow-tooltip
              align="center"
              label="联系人"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="auctionMethod"
              show-overflow-tooltip
              align="center"
              label="联系方式"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="noticeReleaseTime"
              show-overflow-tooltip
              align="center"
              label="违约金额(元)"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="noticeReleaseTime"
              show-overflow-tooltip
              align="center"
              label="物料编号"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="noticeReleaseTime"
              show-overflow-tooltip
              align="center"
              label="物料名称"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="noticeReleaseTime"
              show-overflow-tooltip
              align="center"
              label="计量单位"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="noticeReleaseTime"
              show-overflow-tooltip
              align="center"
              label="预计数量"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="noticeReleaseTime"
              show-overflow-tooltip
              align="center"
              label="单价(元)"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="noticeReleaseTime"
              show-overflow-tooltip
              align="center"
              label="总价(元)"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="noticeReleaseTime"
              show-overflow-tooltip
              align="center"
              label="违约原因"
              resizable
            >
            </el-table-column>

            <el-table-column align="center" width="120" label="操作">
              <template v-slot="{row}">
                <template>
                  <el-button
                    icon="el-icon-thumb"
                    plain
                    type="primary"
                    size="small"
                    @click="handleConfiscate(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: [
        {
          id: 1,
          createName: '倪小莉',
          noticeTitle: '2022年4季度废旧物资及存货竞价'
        },
        {
          id: 2,
          createName: '倪小莉',
          noticeTitle: '2022年4季度废旧物资及存货竞价'
        },
        {
          id: 3,
          createName: '倪小莉',
          noticeTitle: '2022年4季度废旧物资及存货竞价'
        },
        {
          id: 4,
          createName: '倪小莉',
          noticeTitle: '2022年4季度废旧物资及存货竞价'
        }
      ],

      multipleSelection: [],

      params: {
        pageBean: {
          page: 1,
          pageSize: 20,
          total: 0
        }
      },

      searchForm: {}, // 顶部搜索对象
      deleteIds: '', // 是否选中列表解锁删除按钮
      activeCollapse1: ['1', '2'],
      fileList: [], // 文件上传
      edit: false, // 是否是修改功能
      currentDataDel: [], // 删除时排查是否有在审核的数据
      statusList: [
        {label: '未收取', value: '1'},
        {label: '已收取', value: '2'}
      ],
      canpanmyList: []
    }
  },
  mounted() {},
  created() {
    if (this.$route.params.pageBean) {
      this.params = this.$route.params.pageBean
      this.pageResult = this.$route.params.pageBean.pageBean
    }
    // this.getInitiatedCompany()
    // this.loadData(this.params)
  },
  methods: {
    //获取发起企业
    getInitiatedCompany() {
      let queryParam = {
        pageBean: {
          page: -1,
          pageSize: -1
        }
      }
      this.$http
        .post('${portal}/bizHandleNotice/v1/getInitiatedCompany', queryParam)
        .then(res => {
          if (res.data.state) {
            this.canpanmyList = res.data.value.rows
          }
        })
    },
    handleDetail(rows) {
      this.$router.push({
        name: 'recordDefaultPorjectDetail',
        query: {id: rows.id, name: this.$route.query.name}
      })
    },
    // 没收保证金
    handleConfiscate(rows) {
      this.$confirm('确定要没收保证金吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message.success('没收保证金成功！')
      })
    },
    // 撤回
    handleWithdraw(rows) {
      this.$confirm('确定要撤回吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message.success('撤回成功！')
      })
    },
    // 查看成交通知(列表按钮回调)
    handleNotifcation(rows) {
      this.$router.push({
        name: 'confirmationWinningBidView',
        query: {id: rows.id, name: rows.noticeTitle}
      })
    },
    getDictName(code, value) {
      return utils.getDictName(code, value)
    },
    //获取数据
    loadData(params) {
      this.tableLoading = true
      routerManagement.queryEventsList(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.pageResult = {
          page: data.value.page,
          pageSize: data.value.pageSize,
          total: data.value.total
        }
      })
    },
    // 顶部搜索
    handleSearch(searchForm) {
      debugger
      let obj = searchForm
      console.log(obj)
      let querys = []
      for (let i in obj) {
        if (obj[i]) {
          querys.push({
            group: 'main',
            operation:
              i == 'name' || i == 'code' || i == 'companyName'
                ? 'LIKE'
                : 'EQUAL',
            parentGroup: '',
            property: i,
            relation: 'AND',
            value: obj[i]
          })
        }
      }
      console.log(querys, 'querys')
      this.params.querys = querys
      console.log(this.params, 'params')
      this.loadData(this.params)
    },
    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;
  }
  // &: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>
