<!-- 质检报表查询 -->
<template>
  <div>
    <a-space class="header">
      <div class="input-box">
        <div class="silt-title">
          <span style="width: 110px; display: block">{{ '质检机构名称' }}</span>
          <a-input style="width: 260px" v-model:value="informationData.jydw" placeholder="请输入" />
        </div>
        <div class="silt-title">
          <span style="width: 80px; display: block">{{ '检验结果' }}</span>
          <a-select style="width: 260px" class="select-box" v-model:value="informationData.checkResult" placeholder="请选择">
            <a-select-option v-for="item in inspectionResults" :key="item.value" :value="item.value">
              {{ item.label }}
            </a-select-option>
          </a-select>
        </div>
        <div class="silt-title">
          <span style="width: 80px; display: block">{{ '检测时间' }}</span>
          <a-range-picker class="select-box" v-model:value="informationData.date" valueFormat="YYYY-MM-DD" />
        </div>
      </div>
      <div class="btnBox">
        <a-button style="margin-right: 16px" type="primary" @click="searchData">查询</a-button>
        <a-button style="margin-right: 16px" @click="reset">重置</a-button>
      </div>
    </a-space>
    <a-table :dataSource="dataSource" :row-key="(record) => record.key" :pagination="informationData"
      @change="onChangePage" :columns="columns">
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'checkResult'">
          <span>
            {{ record.checkResult == 0 ? '不合格' : '合格' }}
          </span>
        </template>
      </template>
    </a-table>
  </div>
</template>
<script setup>
import reserveDataApi from '@/api/reserveData.info/reserveDataApi'

const columns = [
  {
    title: '序号',
    dataIndex: 'Index',
    align: 'center',
    width: '80px',
    customRender: ({ text, record, index }) => {
      return `${index + 1}`
    }
  },
  {
    title: '质检机构名称',
    dataIndex: 'jydw',
    align: 'center',
    key: 'jydw'
  },
  {
    title: '库区名称',
    dataIndex: 'orgName',
    align: 'center',
    key: 'orgName',
  },
  {
    title: '仓房',
    dataIndex: 'storeHouseName',
    align: 'center',
    key: 'storeHouseName'
  },
  {
    title: '检验结果',
    dataIndex: 'checkResult',
    align: 'center',
    key: 'checkResult',
  },
  {
    title: '检测时间',
    dataIndex: 'jysj',
    align: 'center',
    key: 'jysj',
  }
]
const dataSource = ref([])
const inspectionResults = ref([{ value: 0, label: '不合格' }, { value: 1, label: '合格' }])
const informationData = ref({
  jydw: null,
  checkResult: null,
  date: [],
  current: 1,
  size: 10,
})
// 表格分页
const onChangePage = (ev) => {
  informationData.value = { ...ev }
  if (isShowName.value == '1') {
    informationData.value.jydw = null
    informationData.value.date = []
    informationData.value.checkResult = null
  }
  onSearch()
}
// 列表分页
const onSearch = () => {
  const [s, e] = informationData.value.date
  const fd = {
    current: informationData.value.current,
    size: informationData.value.size,
    jydw: informationData.value.jydw || null,
    checkResult: informationData.value.checkResult,
    jysjStart: s || null,
    jysjEnd: e || null,
  }
  reserveDataApi.reportPage(fd).then((res) => {
    dataSource.value = []
    informationData.value.total = res.total
    dataSource.value = res.records
  })
}
const isShowName = ref('1')
// 查询
const searchData = () => {
  informationData.value.current = 1
  if (informationData.value.total > 10) {
    isShowName.value = '2'
  } else {
    isShowName.value = '1'
  }
  onSearch()
}
// 重置
const reset = () => {
  informationData.value = {
    jydw: null,
    checkResult: null,
    date: [],
    current: 1,
    size: 10
  }
  onSearch()
}

onMounted(() => {
  onSearch()
})
</script>
<style scoped>
.header {
  display: flex;
  padding: 20px;
  width: 100%;
}

.input-box {
  display: flex;
  width: 100%;
}

.input-box-sle {
  width: 56%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-right: 24px;
}

.title-box {
  width: 68px;
}

.inputBoxContent {
  width: 400px;
}

.silt-title {
  /* width: 280px; */
  display: flex;
  align-items: center;
  margin-right: 32px;
}

.btnBox {
  display: flex;
}

.ant-input-group-addon {
  border: 0;
}

.ant-input,
.ant-btn {
  border-radius: 5px;
}

.ant-pagination {
  margin-top: 12px;
  float: right;
  margin-right: 16px;
}

.ant-space-item {
  width: 26%;
}

.add-btn {
  background-color: rgba(112, 125, 233);
}

.check {
  background-color: rgba(112, 125, 233);
  color: #fff;
  margin-left: 8px;
}

.edit {
  background-color: rgba(222, 186, 80);
  color: #fff;
  margin-left: 8px;
}

.flow {
  background-color: #22ce8d;
  color: #fff;
  margin-left: 8px;
}

.delete {
  background-color: rgba(255, 70, 70);
  color: #fff;
  margin-left: 8px;
}

.audit {
  background-color: rgba(83, 184, 36);
  color: #fff;
  margin-left: 8px;
}

.ant-table-thead>tr>th {
  text-align: center;
}

.ant-table-tbody>tr>td {
  text-align: center;
}

.ant-select-selector {
  display: none !important;
}

::v-deep .ant-pagination-options {
  display: none !important;
}
</style>
