<!-- 风险智能识别 -->
<template>
  <div>
    <a-space class="header">
      <div class="inputBox">
        <span class="title-box">{{ '风险类型' }}</span>
        <a-select class="select-box" v-model:value="informationData.riskType" style="width: 190px" placeholder="请选择">
          <a-select-option v-for="item in riskTypeList" :key="item.value" :value="item.value">
            {{ item.name }}
          </a-select-option>
        </a-select>
      </div>
      <div class="btnBox">
        <a-button style="margin-right: 16px" @click="searchData">查询</a-button>
        <a-button style="margin-right: 16px" @click="reset">重置</a-button>
      </div>
    </a-space>
    <a-table :dataSource="dataSource" @change="onChangePage" :row-key="(record) => record.id"
      :pagination="informationData" :columns="columns">
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <span>
            <a-button class="check" @click="check(record)">查看图片</a-button>
          </span>
        </template>
      </template>
    </a-table>
    <!-- 查看--编辑--新增等操作 -->
    <FromData :dataObj="dataObj" @isVisible="isVisible" />
  </div>
</template>
<script setup name="riskIntelligentIdentify">
import safetyProductionApi from '@/api/security.info/riskLedgerApi.js'
import FromData from './from.vue'
const columns = [
  {
    title: '序号',
    dataIndex: 'Index',
    align: 'center',
    customRender: ({ text, record, index }) => {
      return `${index + 1}`
    }
  },
  {
    title: '库区名称',
    dataIndex: 'orgName',
    align: 'center',
    key: 'orgName'
  },
  {
    title: '风险类型',
    dataIndex: 'riskType',
    align: 'center',
    key: 'riskType'
  },
  {
    title: '预警描述',
    dataIndex: 'warningDescription',
    align: 'center',
    key: 'warningDescription'
  },
  {
    title: '预警事件',
    dataIndex: 'warningEvent',
    align: 'center',
    key: 'warningEvent'
  },
  {
    title: '报警单位',
    dataIndex: 'alarmUnit',
    align: 'center',
    key: 'alarmUnit'
  },
  {
    title: '报警时间',
    dataIndex: 'alarmTime',
    align: 'center',
    key: 'alarmTime'
  },
  {
    title: '报警位置',
    dataIndex: 'alarmLocation',
    align: 'center',
    key: 'alarmLocation'
  },
  {
    title: '报警等级',
    dataIndex: 'alarmLevel',
    align: 'center',
    key: 'alarmLevel'
  },
  {
    title: '操作',
    dataIndex: 'action',
    align: 'center',
    key: 'action',
    width: '200px'
  }
]
const riskTypeList = ref([
  {
    name: '抽烟检测',
    value: 1
  },
  {
    name: '未带安全帽',
    value: 2
  },
  {
    name: '摄像头遮挡',
    value: 3
  },
  {
    name: '姿态识别',
    value: 4
  },
])
const dataSource = ref([])
const dataObj = ref({
  visible: false,
  titleText: '',
  showLock: false,
  isType: '',
  id: ''
})

const informationData = ref({
  riskType: undefined,
  current: 1,
  size: 10
})
// 表格分页
const onChangePage = (ev) => {
  informationData.value = { ...ev }
  if (isShowName.value == '1') {
    informationData.value.riskType = ''
  }
  onSearch()
}
// 列表分页
const onSearch = () => {
  const fd = { ...informationData.value }
  safetyProductionApi.recognizetPage(fd).then((res) => {
    dataSource.value = []
    dataSource.value = res.records
    dataSource.value.forEach(i => {
      switch (i.riskType) {
        case 1:
          i.riskType = '抽烟检测'
          break
        case 2:
          i.riskType = '未带安全帽'
          break
        case 3:
          i.riskType = '摄像头遮挡'
          break
        case 4:
          i.riskType = '姿态识别'
          break
        default:
          break
      }
    })
    informationData.value.total = res.total
  })
}
// 查询
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 = () => {
  dataObj.value.isType = ''
  informationData.value = {
    riskType: '',
    current: 1,
    size: 10
  }
  onSearch()
}
// 查看
const check = (row) => {
  dataObj.value.id = row.id
  dataObj.value.titleText = '查看图片'
  dataObj.value.visible = true
}
// 子组件传递
const isVisible = (val) => {
  dataObj.value.visible = false
  dataObj.value.titleText = ''
  informationData.value.riskType = ''
  onSearch()
}

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

.inputBox {
  display: flex;
}

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

.select-box {
  margin-left: 12px;
}

.title-box {
  margin-left: 20px;
  line-height: 30px;
}

.inputBoxContent {
  width: 400px;
}

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

.btnBox {
  width: 260px;
  margin-left: 20px;
  justify-content: start;
  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;
}

.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;
}

::v-deep .ant-pagination-options {
  display: none !important;
}

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