<template>
  <div class="layout-pd">
    <el-row>
      <!--操作-->
      <el-col :xs="24">
        <el-card class="mt8" shadow="hover">
          <el-form :model="Data.Filter" @submit.stop.prevent>
            <el-form-item prop="name" style="width: 100%">
              <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
                <el-form-item label="序列号">
                  <el-input v-model="Data.Filter.sn" placeholder="请输入序列号" clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
                <el-form-item label="在线状态">
                  <el-select v-model="Data.Filter.onlineStatus" placeholder="请选择在线状态">
                    <el-option v-for="(value, key) in selectList.Online" :key="key" :label="value" :value="key" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
                <el-form-item label="设备状态">
                  <el-select v-model="Data.Filter.deviceStatus" placeholder="请选择设备状态">
                    <el-option v-for="(value, key) in selectList.Device" :key="key" :label="value" :value="key" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
                <el-form-item label="报警级别">
                  <el-select v-model="Data.Filter.deviceAlarmLevel" placeholder="请选择报警级别">
                    <el-option v-for="(value, key) in selectList.Level" :key="key" :label="value" :value="key" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-form-item>
          </el-form>

          <hr>

          <!-- 按钮 -->
          <el-row justify="space-between" class="submit-button">
            <el-row>
              <el-button type="primary" icon="ele-Search" @click="onQuery"> 查询 </el-button>
              <el-button type="primary" icon="ele-RefreshRight" @click="onReset"> 重置 </el-button>
            </el-row>
          </el-row>
        </el-card>
      </el-col>
      <!--表格-->
      <el-col :xs="24">
        <el-card style="height: 70vh" class="my-fill mt8" shadow="hover">
          <el-table ref="multipleTableRef" v-loading="Data.loading" stripe :data="Data.tableModel" row-key="id"
            style="width: 100%">
            <el-table-column v-for="column in Data.dynamicColumns" :key="column.prop" :prop="column.prop"
              :label="column.label" />
          </el-table>
          <div class="my-flex my-flex-end" style="margin-top: 20px">
            <el-pagination v-model:currentPage="Data.pageInput.CurrentPage" v-model:page-size="Data.pageInput.PageSize"
              :total="Data.total" :page-sizes="[5, 10, 20, 50, 100]" small background @size-change="onSizeChange"
              @current-change="onCurrentChange" layout="total, sizes, prev, pager, next, jumper" />
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts" name="partsManagement/encScreen">
import { onMounted, reactive, ref, watch } from "vue";
import { encScreenFilterModel_SearchFilter, encScreenFilterModel, PageInputEncScreenFilterModel } from "/@/api/admin/reportManagement/encScreen/encScreenDto";
import { encScreenApi } from "/@/api/admin/reportManagement/encScreen/encScreenApi";

/** 页面对象 */
const Data = reactive({
  /**加载显示 */
  loading: false,
  /**条件查询模块 */
  Filter: {
    /**设备类型 */
    deviceType: "DisplayControls",
    /**在线状态 */
    onlineStatus: "",
    /**设备状态 */
    deviceStatus: "",
    /**序列号 */
    sn: "",
    /**设备报警级别 */
    deviceAlarmLevel: ""
  } as encScreenFilterModel_SearchFilter,
  /**表格信息 */
  tableModel: [] as Array<encScreenFilterModel>,
  /**动态表头 */
  dynamicColumns: [
    { prop: 'sn', label: '序列号' },
    { prop: 'companyName', label: '石油公司' },
    { prop: 'stationName', label: '加油站名称' },
    { prop: 'supplierName', label: '加油机厂商' },
    { prop: 'manufacturerName', label: '加密显示屏厂商' },
    { prop: 'nozzleconName', label: '油枪号' },
    { prop: 'uuid', label: '加密显示屏编号' },
    { prop: 'deviceStatus', label: '加密显示屏状态' },
    { prop: 'onlineStatus', label: '在线状态' },
    { prop: 'soldTime', label: '安装时间' },
    { prop: 'productTime', label: '出厂时间' },
  ],
  /**分页标识 */
  pageInput: {
    CurrentPage: 1,
    PageSize: 10,
  } as PageInputEncScreenFilterModel,
  /**分页总数 */
  total: 0,
})

/** 选择框列表 */
const selectList = reactive({
  Online: ["在线", "离线"],
  Device: [
    "启用",
    "备案",
    "维修",
    "出厂注册"],
  Level: [1, 2, 3, 4, 5]

})

/**初始化 */
const init = async () => {
  Data.loading = true
  const res: any = await new encScreenApi().getPage({ ...Data.pageInput, filter: Data.Filter }).catch(() => {
    Data.loading = false
  })
  Data.tableModel = res?.data ?? []
  Data.total = res?.data?.length ?? 0
  Data.loading = false
}

onMounted(() => {
  init()
})

/**条件查询 */
const onQuery = () => {
  init()
}

/**重置查询条件 */
const resetQuery = () => {
  Data.Filter.onlineStatus = ''
  Data.Filter.deviceStatus = ''
  Data.Filter.sn = ''
  Data.Filter.deviceAlarmLevel = ''
  Data.pageInput.CurrentPage = 1
  Data.pageInput.PageSize = 10
}

/**重置 */
const onReset = () => {
  resetQuery()
  init()
}

/**
* 页条变化
* @param val
*/
const onSizeChange = (val: number) => {
  Data.pageInput.PageSize = val
  init()
}

/**
 * 页数 变化
 * @param val
 */
const onCurrentChange = (val: number) => {
  Data.pageInput.CurrentPage = val
  init()
}

</script>

<style scoped lang="scss">
.el-input,
.el-select {
  width: 240px;
}

/* 输入框标签固定四个字符宽度 */
::v-deep .el-form-item__label {
  // 字体大小14，4个字符，12px右间距
  width: 14*4px+12px;
  justify-content: start;
}

/* 数据表头 设置灰色样式 */
::v-deep .el-table th.el-table__cell {
  background-color: #F6F6F6;
}
</style>