<template>
  <div class="common-page-content">
    <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-select
            size="small"
            clearable
            v-model="searchForm.status"
            placeholder="请选择"
          >
            <el-option
              v-for="item in publishList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="对账企业">
          <el-input
            size="small"
            v-model="searchForm.vendorName"
            clearable
            placeholder="请输入对账企业"
          ></el-input>
        </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"
            row-key="id"
            :data="tableData"
            @selection-change="handleSelectionChange"
            @row-dblclick="handleDetail"
          >
            <el-table-column type="selection" reserve-selection min-width="5%" align="center">
            </el-table-column>
            <el-table-column
              prop="isdCode"
              min-width="10%"
              label="对账单号"
              align="center"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="matCompanyName"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="发起企业 "
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="matUserName"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="发起人"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="matCompanyPhone"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="发起人联系方式"
              resizable
            >
            </el-table-column>

            <el-table-column
              prop="vendorName"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="对账单位"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="status"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="发布状态"
              resizable
            >
              <template v-slot="{row}">
                <el-tag v-if="row.status === 3" type="warning">未确认</el-tag>
                <el-tag v-if="row.status === 4" type="success">已确认</el-tag>
                <el-tag v-if="row.status === 2" type="">审核中</el-tag>
                <el-tag v-if="row.status === 5" type="danger">不同意</el-tag>
              </template>
            </el-table-column>
            <el-table-column min-width="10%" align="center" label="操作">
              <template v-slot="{row}">
                <template>
                  <el-button
                    type="primary"
                    plain
                    size="small"
                    @click="handleDetail(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 reconciliationManagement from '@/api/BasicDataManagement/reconciliationManagement.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,
      publishList: [
        {
          value: 3,
          label: '待确认',
        },
        {
          value: 4,
          label: '已确认',
        },
        {
          value: 5,
          label: '已反馈',
        },
      ],
      tableData: [],
      multipleSelection: [],
      params: {
        pageBean: {
          page: 1,
          pageSize: 20,
          total: 0,
        },
      },
      queryParam: {
        pageBean: {
          page: 1,
          pageSize: 20,
          total: 0,
        },
      },
      searchForm: {}, // 顶部搜索对象
      currentDataDel: [], // 删除时排查是否有在审核的数据
      currentUser: {},
      matCompanyId: '',
      vendorId: '',
    }
  },
  mounted() {},
  created() {
    this.currentUser = JSON.parse(sessionStorage.getItem('currentUserDetail'))
    this.matCompanyId = this.currentUser.org[0].orgId
    this.vendorId = this.currentUser.org[0].orgId
    this.handleSearch()
  },
  methods: {
    //售后翻译
    agreeName(val) {
      return this.publishList.filter((item) => item.value === val)[0].label
    },
    //获取数据
    loadData(params) {
      this.tableLoading = true
      this.tableData = []
      let data = []
      if (params) {
        data = params
      } else {
        this.params.querys = [
          {
            group: 'main',
            operation: 'IN',
            parentGroup: '',
            property: 'status',
            relation: 'AND',
            value: [2, 3, 4, 5],
          },
        ]
        data = this.params
      }
      reconciliationManagement.queryEventsList(data).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,
        }
      })
    },
    // 意见反馈
    feedbackBtn(rows) {
      this.$refs.form.clearValidate()
      this.$router.push({
        name: 'confirmationOpinion',
        query: {editRows: rows, pageBean: this.params},
      })
    },
    // 详情
    handleDetail(rows) {
      this.$router.push({
        name: 'inquiryStatementRecording',
        query: {detailRows: rows, pageBean: this.params},
      })
    },
    //重置
    clearSearchForm() {
      this.searchForm = {}
      this.handleSearch()
    },
    // 顶部搜索
    handleSearch() {
      let obj = this.searchForm
      console.log(obj)
      let querys = [
        {
          group: 'main',
          operation: 'IN',
          parentGroup: '',
          property: 'status',
          relation: 'AND',
          value: [2, 3, 4, 5],
        },
        {
          group: 'mains',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'vendorId',
          relation: 'AND',
          value: this.vendorId,
        },
        {
          group: 'mains',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'matCompanyId',
          relation: 'OR',
          value: this.matCompanyId,
        },
      ]
      for (let i in obj) {
        if (obj[i]) {
          querys.push({
            group: 'main',
            operation:
              i == 'name' || i == 'code' || i == 'vendorName'
                ? '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
    },
    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)
    },
    //确认
    handleconfrim() {
      this.$confirm('确定要确认吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        reconciliationManagement.batchconfrim(rows.id).then((res) => {
          if (res.data.state) {
            this.$message.success('确认成功！')
            this.loadData()
          }
        })
      })
    },
    //拒绝
    handlerefuse() {
      this.$confirm('确定要拒绝吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        reconciliationManagement.batchRefuset(rows.id).then((res) => {
          if (res.data.state) {
            this.$message.success('拒绝成功！')
            this.loadData()
          }
        })
      })
    },
    
  },
  computed: {
    SearchPanel() {
      return {
        '--searchPanel': this.searchPanel + 'px',
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.common-table-content {
  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;
  }
  /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>
