<!--
  Description: 报警管理页面
  Author: 李亚光
  Date: 2023-04-23
 -->
<script lang="ts" setup name="alarmlist">
import { reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
const $router = useRouter()
const { proxy } = getCurrentInstance() as any
const listQuery = reactive({
  beginTime: '',
  endTime: '',
  // logType: '业务日志',
  offset: 1,
  limit: 20,
})
const columns = ref([
  {
    text: '作业名称',
    value: '1',
    align: 'center',
    // width: 170,
  },
  {
    text: '作业道路',
    value: '2',
    align: 'center',
    // width: 100,
  },
  {
    text: '报警信息',
    value: '3',
    align: 'center',
  },
  {
    text: '责任人',
    value: '4',
    align: 'center',
  },
  {
    text: '责任人联系方式',
    value: '5',
    align: 'center',
  },
  {
    text: '报警时间',
    value: '6',
    align: 'center',
  },
  {
    text: '当前状态',
    value: '7',
    align: 'center',
  },
])
const list = ref([])
const total = ref(20)
const listLoading = ref(true)
// 获取日志数据
const fetchData = () => {
  listLoading.value = true
  // getBizLogList(listQuery).then((response) => {
  //   list.value = response.data.rows
  //   total.value = parseInt(response.data.total)
  //   listLoading.value = false
  // })
  list.value = [
    {
      1: '作业一',
      2: '永定路',
      3: 'xxx设备异常',
      4: '张三',
      5: '13700000000',
      6: '2023-01-01',
      7: '未处理',
    },
    {
      1: '作业二',
      2: '长安街',
      3: 'xxx设备异常',
      4: '李四',
      5: '13700000000',
      6: '2023-01-01',
      7: '已处理',
    },
  ]
  total.value = list.value.length
  listLoading.value = false
}

fetchData()

// 查询数据
const search = () => {
  fetchData()
}

// 消除报警
const eliminate = (row: any) => {
  // personRef.value.initDialog('update', {})
}

// 页数发生变化后的操作，可能是页码变化，可能是每页容量变化，此函数必写
const changePage = (val: { size: number; page: number }) => {
  if (val && val.size) {
    listQuery.limit = val.size
  }
  if (val && val.page) {
    listQuery.offset = val.page
  }
  fetchData()
}
// 表格被选中的行
const selectList = ref<any[]>([])
// 表格多选
const multiSelect = (row: any[]) => {
  selectList.value = row
}
</script>

<template>
  <div class="list-log">
    <!-- 布局 -->
    <app-container>
      <!-- <edit-person ref="personRef" /> -->
      <!-- 筛选条件 -->
      <search-area @search="search">
        <search-item>
          <el-input v-model.trim="listQuery.beginTime" placeholder="作业名称" clearable />
        </search-item>
        <search-item>
          <el-select v-model="listQuery.beginTime" clearable placeholder="当前状态">
            <el-option v-for="item in []" :key="item.id" :label="item.name" :value="item.value" />
          </el-select>
        </search-item>
        <search-item>
          <el-select v-model="listQuery.beginTime" clearable placeholder="报警类型">
            <el-option v-for="item in []" :key="item.id" :label="item.name" :value="item.value" />
          </el-select>
        </search-item>
        <search-item>
          <el-date-picker
            v-model="listQuery.beginTime" type="datetime" value-format="YYYY/MM/DD HH:mm:ss"
            placeholder="报警开始时间"
          />
        </search-item>
        <search-item>
          <el-date-picker
            v-model="listQuery.endTime" type="datetime" value-format="YYYY/MM/DD HH:mm:ss"
            placeholder="报警结束时间"
          />
        </search-item>
        <template #btns>
          <!-- <el-button class="search-btn" type="primary" @click="add">
            新增
          </el-button> -->
          <el-button v-if="proxy.hasPerm('/alarm/del')" class="search-btn" type="info">
            删除
          </el-button>
        </template>
      </search-area>
      <table-container>
        <!-- 查询结果Table显示 -->
        <normal-table
          :data="list" :total="total" :columns="columns" :query="listQuery" :is-showmulti-select="true"
          :is-multi="true" :list-loading="listLoading" @change="changePage" @multi-select="multiSelect"
        >
          <template #columns>
            <el-table-column v-if="proxy.hasPerm('/alarm/cancel')" label="消警" width="90" align="center">
              <template #default="scope">
                <el-button link type="primary" size="small" @click="eliminate(scope.row)">
                  消警
                </el-button>
              </template>
            </el-table-column>
          </template>
        </normal-table>
      </table-container>
    </app-container>
  </div>
</template>

