<template>
  <div>
    <SearchBoxVue :data="searchData" @search="handleSearch" @reset="handleReset" />
    <TableBoxVue :loading="loading" :data="tableData" :status="status" style="margin-top: -40px;" />
    <pagination
      :auto-scroll="false"
      :total="paginationData.total"
      :page="paginationData.page"
      :limit="paginationData.limit"
      @pagination="handlePagination"
    />
  </div>
</template>

<script>
import SearchBoxVue from '@/views/recordsRoom/qc/components/SearchBox.vue'
import TableBoxVue from '@/views/recordsRoom/qc/components/TableBox.vue'
import pagination from '@/components/Pagination/index2.vue'
import { getBlZkList, getQualityControlStatus } from '@/api/qc'

export default {
  components: {
    SearchBoxVue,
    TableBoxVue,
    pagination
  },
  data() {
    return {
      loading: false,
      status: 0,
      searchData: {
        BLZT: '',
        level: '',
        ZKYS: '',
        BLDJ: '',
        AAA28: '',
        AAA01: '',
        AAC11N: '',
        AAB01_START: '',
        AAB01_END: '',
        AAC01_START: '',
        AAC01_END: ''
      },
      tableData: [],
      paginationData: {
        total: 0,
        page: 1,
        limit: 10
      }
    }
  },
  created() {
    this.getQualityControlStatus()
  },
  activated() {
    this.getList()
  },
  methods: {
    getList() {
      const {
        BLZT,
        level,
        ZKYS,
        BLDJ,
        AAA28,
        AAA01,
        AAC11N,
        AAB01_START,
        AAB01_END,
        AAC01_START,
        AAC01_END
      } = this.searchData
      const { page, limit } = this.paginationData
      const params = {
        BLZT,
        level,
        ZKYS,
        BLDJ,
        AAA28,
        AAA01,
        AAC11N,
        AAB01_START,
        AAB01_END,
        AAC01_START,
        AAC01_END,
        page,
        page_size: limit
      }
      params.AAB01_START = AAB01_START ? AAB01_START / 1000 : ''
      params.AAB01_END = AAB01_END ? AAB01_END / 1000 : ''
      params.AAC01_START = AAC01_START ? AAC01_START / 1000 : ''
      params.AAC01_END = AAC01_END ? AAC01_END / 1000 : ''
      this.loading = true
      getBlZkList(params).then(res => {
        this.paginationData.total = res.data.count
        this.tableData = res.data.list
         // 切换选中状态
        Array.isArray(this.tableData) && this.tableData.map(item => {
          item.selected = (item.ZYH == localStorage.getItem('getData')) ? !item.selected : false
        })
      }).catch(error => {
        console.log(error)
      }).finally(() => {
        this.loading = false
      })
    },
    /**
     * 获取开关状态
     */
    getQualityControlStatus() {
      getQualityControlStatus().then(res => {
        this.status = Number(res.data.status);
      }).catch(error => {
        console.log(error);
      })
    },
    handlePagination(param) {
      this.paginationData.page = param.page
      this.paginationData.limit = param.limit
      this.getList()
    },
    handleSearch() {
      this.paginationData.page = 1
      this.getList()
    },
    handleReset() {
      this.searchData = {
        BLZT: '',
        level: '',
        ZKYS: '',
        BLDJ: '',
        AAA28: '',
        AAA01: '',
        AAC11N: '',
        AAB01_START: '',
        AAB01_END: '',
        AAC01_START: '',
        AAC01_END: ''
      }
      this.handleSearch()
    }
  }
}
</script>

<style lang="scss" scoped>
.pagination-container {
  background-color: rgba(244,244,244,1);
  padding: 0 20px;
  display: flex;
  justify-content: flex-end;
  .cus-total {
    float: none;
    line-height: 28px;
  }
  .el-pagination {
    float: none;
  }
}
</style>
