<template>
  <div class="common-page-shadow">
    <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[1].value"
            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">
        <div class="common-btn-group">
          <el-button
            size="small"
            icon="el-icon-plus"
            type="primary"
            class="btn btn-plus"
            @click="handleAdd"
          >
            新增
          </el-button>
          <el-button
            :disabled="handleDeleteActive"
            size="small"
            type="danger"
            icon="el-icon-delete"
            @click="handleDelete"
          >
            删除
          </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="tableMaxHeight"
            v-loading="tableLoading"
            ref="multipleSelection"
            :data="tableData"
            @selection-change="handleSelectionChange"
            @row-dblclick="handleDetail"
          >
            <el-table-column type="selection" min-width="5%" align="center">
            </el-table-column>
            <el-table-column
              prop="code"
              min-width="10%"
              label="资质类型编码"
              align="center"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="name"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="资质类型名称"
              resizable
            >
            </el-table-column>
            <el-table-column
              prop="fileSize"
              show-overflow-tooltip
              min-width="15%"
              align="center"
              label="限制文件大小(MB)"
              resizable
            >
            </el-table-column>
            <!-- <el-table-column
              prop="expirationProcessingMethod"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="到期处理方式"
              resizable
            >
              <template v-slot="{row}">
                {{ row.expirationProcessingMethod == 0 ? '冻结' : '提醒' }}
              </template>
            </el-table-column>
            <el-table-column
              prop="changeApproval"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="是否需要审批"
              resizable
            >
              <template v-slot="{row}">
                {{ row.changeApproval == 0 ? '不需要审批' : '需要审批' }}
              </template>
            </el-table-column>
            <el-table-column
              prop="changeApprovalMethod"
              show-overflow-tooltip
              min-width="10%"
              align="center"
              label="审批方式"
              resizable
            >
              <template v-slot="{row}">
                {{ row.changeApprovalMethod == 0 ? '企业审批' : '平台审批' }}
              </template>
            </el-table-column> -->
            <el-table-column min-width="10%" align="center" label="操作">
              <template v-slot="{row}">
                <template>
                  <el-button
                    icon="el-icon-edit"
                    type="primary"
                    plain
                    size="small"
                    @click="handleEdit(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 basicData from '@/api/basicData'
export default {
  name: 'DemandEntry',
  components: {
    pagination
  },
  mixins: [TableMixin],
  data() {
    return {
      tableMaxHeight: 550,
      handleDeleteActive: true,
      handleDeleteId: [],
      tableLoading: false,
      tableData: [],
      expirationProcessingMethodList: [
        {
          label: '冻结',
          value: '0'
        },
        {
          label: '提醒',
          value: '1'
        }
      ],
      changeApprovalList: [
        {
          label: '不需要审批',
          value: '0'
        },
        {
          label: '需要审批',
          value: '1'
        }
      ],
      multipleSelection: [],
      queryParam: {
        pageBean: {
          page: 1,
          pageSize: 20,
          total: 0
        },
        sorter: [
          {
            direction: 'DESC',
            property: 'create_time_'
          }
        ]
      },

      querys: [
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'expirationProcessingMethod',
          relation: 'AND',
          value: ''
        },
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'name',
          relation: 'AND',
          value: ''
        }
      ],
      fileList: [] // 文件上传
    }
  },
  mounted() {
    this.calcTableHeight()
    //页面缩放从新计算表格的高度
    window.addEventListener('resize', this.calcTableHeight)
  },
  created() {
    this.loadData()
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.calcTableHeight)
  },
  methods: {
    // 动态计算表格的高度，自适应当前容器
    calcTableHeight() {
      this.tableHeight = this.$refs.tableContent.offsetHeight
    },
    getDictName(code, value) {
      return utils.getDictName(code, value)
    },
    //获取数据
    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])
      }
      basicData.bizQualificationCategoryQuery(this.queryParam).then(res => {
        this.queryParam.pageBean.total = res.value.total
        this.queryParam.pageBean.page = res.value.page
        this.queryParam.pageBean.pageSize = res.value.pageSize
        this.tableLoading = false
        this.tableData = res.value.rows
      })
    },
    //添加
    handleAdd() {
      this.$router.push('qualificationAddDialog')
    },
    // 编辑
    handleEdit(rows) {
      this.$refs.form.clearValidate()
      this.$router.push({
        name: 'qualificationAddDialog',
        query: {editRows: rows, pageBean: this.queryParam}
      })
    },
    // 详情
    handleDetail(rows) {
      this.$router.push({
        name: 'qualificationDetail',
        query: {detailRows: rows, pageBean: this.queryParam}
      })
    },
    // 删除
    handleDelete() {
      this.$confirm('确定删除选中数据？', '提示', {
        confirmButtonText: '确 定',
        cancelButtonText: '取 消',
        type: 'warning'
      })
        .then(() => {
          basicData
            .bizQualificationSaveRemove(this.handleDeleteId)
            .then(res => {
              if (res.state) {
                this.$notify({
                  type: 'success',
                  message: '删除成功',
                  duration: 2000
                })
                this.loadData()
              }
            })
            .catch(res => {
              this.$notify({
                type: 'error',
                message: res.message,
                duration: 2000,
                offset: 80
              })
            })
        })
        .catch(() => {})
    },
    //重置
    clearSearchForm() {
      this.querys[0].value = ''
      this.querys[1].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>
.common-page-shadow{
  height: calc(100% - 80px);
}
.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>
