<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="4" class="mb20">
                <el-form-item label="石油公司">
                  <el-input v-model="Data.Filter.CompanyName" placeholder="请输入石油公司" clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="4" class="mb20">
                <el-form-item label="油枪号">
                  <el-input v-model="Data.Filter.name" placeholder="请输入油枪号" clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="4" class="mb20">
                <el-form-item label="加油站">
                  <el-input v-model="Data.Filter.StationName" placeholder="请输入加油站名称" clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="4" 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="value" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="4" class="mb20">
                <el-form-item label="出厂时间">
                  <el-date-picker v-model="Data.time1" type="datetimerange" value-format="YYYY-MM-DD HH:mm:ss"
                    range-separator="To" start-placeholder="Start date" end-placeholder="End date" />
                </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/oilGun">
import { onMounted, reactive, watch } from "vue";
import { oilGunFilterModel_SearchFilter, oilGunFilterModel, PageInputoilGunFilterModel } from "/@/api/admin/reportManagement/oilGun/oilGunDto";
import { OilGunApi } from "/@/api/admin/reportManagement/oilGun/oilGunApi";


/**页面对象 */
const Data = reactive({
  time1: '',
  /** 选择框列表 */
  statusList: [] as any,
  supplierList: [] as any,
  /**加载显示 */
  loading: false,
  /**条件查询模块 */
  Filter: {
    /**油枪号 */
    name: "",
    /**加油站名称 */
    StationName: "",
    /**石油公司 */
    CompanyName: "",
    /**在线状态 */
    onlineStatus: "",
    /**出厂开始的时间 */
    OutBeginTime: "",
    /**出厂结束的时间 */
    OutEndTime: "",
  } as oilGunFilterModel_SearchFilter,
  /**表格信息 */
  tableModel: [] as Array<oilGunFilterModel>,
  /**动态表头 */
  dynamicColumns: [
    { prop: 'name', label: '油枪号' },
    { prop: 'companyName', label: '石油公司' },
    { prop: 'stationName', label: '加油站名称' },
    { prop: 'fuelName', label: '油品' },
    { prop: 'code', label: '编码' },
    { prop: 'alarming', label: '自锁' },
    { prop: 'fuelId', label: '油机号' },
    { prop: 'supplierName', label: '加油机厂商' },
    { prop: 'onlineStatus', label: '在线状态' },
    { prop: 'cheatStatus', label: '作弊状态' },
    { prop: 'monitoringUUID', label: '监控微处理器编号' },
    { prop: 'displayControlsUUID', label: '加密显示屏编号' },
    { prop: 'encoderControlsUUID', label: '编码器编号' },
    { prop: 'productTime', label: '出厂时间' },
    { prop: 'soldTime', label: '安装时间' },
  ],
  /**分页总数 */
  total: 0,
  /**分页标识 */
  pageInput: {
    currentPage: 1,
    pageSize: 10,
  } as PageInputoilGunFilterModel,
})

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

})

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

// 条件查询
const init = async () => {
  Data.loading = true
  const res: any = await new OilGunApi().getPage({ ...Data.pageInput, filter: Data.Filter })
  console.log(res)
  Data.tableModel = res?.data ?? []
  Data.total = res?.data?.length ?? 0
  Data.loading = false
}

const onQuery = () => {
  init()
}

/**重置查询条件 */
const resetQuery = () => {
  Data.Filter.StationName = ''
  Data.Filter.CompanyName = ''
  Data.Filter.onlineStatus = ''
  Data.Filter.OutBeginTime = ''
  Data.Filter.OutEndTime = ''
  Data.Filter.name = ''
  Data.time1 = ''
  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()
}

/**
 * 监听时间变换
 */
watch(() => Data.time1, (newVal) => {
  if (newVal.length === 0) {
    return
  }
  Data.Filter.OutBeginTime = newVal[0]?.[0] ?? ''
  Data.Filter.OutEndTime = newVal[0]?.[1] ?? ''
})

</script>

<style scoped lang="scss">
@import '/@/theme/tableStyle.scss';




</style>