<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper" style="background: #f0f2f5; padding: 16px; margin-bottom: 16px; border-radius: 4px;">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="24">
            <a-form-item label="查询类型">
              <a-select v-model="queryType" placeholder="请选择查询类型" @change="handleQueryTypeChange">
                <a-select-option value="online">在线数据</a-select-option>
                <a-select-option value="history">历史数据</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="车型">
              <a-select v-model="selectedVehicleType" placeholder="请选择车型" allowClear @change="handleVehicleTypeChange">
                <a-select-option value="G2701内燃工程车">G2701内燃工程车</a-select-option>
                <a-select-option value="G2702内燃工程车">G2702内燃工程车</a-select-option>
                <a-select-option value="G2703内燃工程车">G2703内燃工程车</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <template v-if="queryType === 'history'">
            <a-col :md="6" :sm="24">
              <a-form-item label="开始时间">
                <a-date-picker v-model="startTime" placeholder="请选择开始时间" show-time valueFormat="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="结束时间">
                <a-date-picker v-model="endTime" placeholder="请选择结束时间" show-time valueFormat="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="24">
            <div style="margin-top: 4px;">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button v-if="queryType === 'history'" type="primary" @click="switchToOnline" style="margin-left: 8px">返回在线数据</a-button>
              <a-button v-else type="primary" @click="switchToHistory" style="margin-left: 8px">查询历史数据</a-button>
            </div>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('bu_zy_nrgcc_online')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <bu-zy-nrgcc-online-modal ref="modalForm" @ok="modalFormOk"></bu-zy-nrgcc-online-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import BuZyNrgccOnlineModal from './modules/BuZyNrgccOnlineModal'

  export default {
    name: 'BuZyNrgccOnlineList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      BuZyNrgccOnlineModal
    },
    data () {
      return {
        description: 'bu_zy_nrgcc_online管理页面',
        // 查询类型: online/history
        queryType: 'online',
        // 选中的车型类型
        selectedVehicleType: undefined,
        // 历史数据查询开始时间
        startTime: undefined,
        // 历史数据查询结束时间
        endTime: undefined,
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'上传服务器名',
            align:"center",
            dataIndex: 'serverName'
          },
          {
            title:'车型',
            align:"center",
            dataIndex: 'sensorId_dictText'
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'status'
          },
          {
            title:'报警字段名',
            align:"center",
            dataIndex: 'statusname'
          },
          {
            title:'机车里程',
            align:"center",
            dataIndex: 'vw4550',
            customRender: (text) => {
              if (text === null || text === undefined) return '-'
              let meters = Number(text)
              if (isNaN(meters)) return text
              let km = meters / 1000
              // 保留两位小数
              return km.toFixed(2)
            }
          },
          {
            title:'机车速度',
            align:"center",
            dataIndex: 'vw4500'
          },
          {
            title:'传动箱子转速',
            align:"center",
            dataIndex: 'vw4502'
          },
          {
            title:'蓄电池电流',
            align:"center",
            dataIndex: 'vw4504'
          },
          {
            title:'蓄电池电压',
            align:"center",
            dataIndex: 'vw4506'
          },
          {
            title:'柴油机转速',
            align:"center",
            dataIndex: 'vw4508'
          },
          {
            title:'蓄电池电压',
            align:"center",
            dataIndex: 'vw4510'
          },
          {
            title:'传动箱油温',
            align:"center",
            dataIndex: 'vw4512'
          },
          {
            title:'传动箱压力',
            align:"center",
            dataIndex: 'vw4514'
          },
          {
            title:'冷却水温度',
            align:"center",
            dataIndex: 'vw4516'
          },
          {
            title:'滑油压力',
            align:"center",
            dataIndex: 'vw4518'
          },
          {
            title:'滑油温度',
            align:"center",
            dataIndex: 'vw4520'
          },
          {
            title:'负载反馈',
            align:"center",
            dataIndex: 'vw4522'
          },
          {
            title:'柴油机工作计时',
            align:"center",
            dataIndex: 'vw4526',
            customRender: (text) => this.formatSeconds(text)
          },
          {
            title:'燃料温度',
            align:"center",
            dataIndex: 'vw4530'
          },
          {
            title:'燃油压力',
            align:"center",
            dataIndex: 'vw4532'
          },
          {
            title:'前进输入',
            align:"center",
            dataIndex: 'v45345'
          },
          {
            title:'后退输入',
            align:"center",
            dataIndex: 'v45346'
          },
          {
            title:'加载0位输入',
            align:"center",
            dataIndex: 'v45347'
          },
          {
            title:'加载1位输入',
            align:"center",
            dataIndex: 'v45350'
          },
          {
            title:'升输入',
            align:"center",
            dataIndex: 'v45351'
          },
          {
            title:'保输入',
            align:"center",
            dataIndex: 'v45352'
          },
          {
            title:'降输入',
            align:"center",
            dataIndex: 'v45353'
          },
          {
            title:'自动换档输入',
            align:"center",
            dataIndex: 'v45354'
          },
          {
            title:'手动1档输入',
            align:"center",
            dataIndex: 'v45355'
          },
          {
            title:'手动2档输入',
            align:"center",
            dataIndex: 'v45356'
          },
          {
            title:'手动3档输入',
            align:"center",
            dataIndex: 'v45357'
          },
          {
            title:'手动4档输入',
            align:"center",
            dataIndex: 'v45360'
          },
          {
            title:'柴油机起动按钮输入',
            align:"center",
            dataIndex: 'v45361'
          },
          {
            title:'紧急制动按钮输入',
            align:"center",
            dataIndex: 'v45362'
          },
          {
            title:'停放制动继电器反馈',
            align:"center",
            dataIndex: 'v45363'
          },
          {
            title:'加载保护继电器反馈',
            align:"center",
            dataIndex: 'v45364'
          },
          {
            title:'撒砂输入',
            align:"center",
            dataIndex: 'v45367'
          },
          {
            title:'柴油机报警输入',
            align:"center",
            dataIndex: 'v45370'
          },
          {
            title:'总风缸压力开关输入',
            align:"center",
            dataIndex: 'v45371'
          },
          {
            title:'空压机过温输入',
            align:"center",
            dataIndex: 'v45373'
          },
          {
            title:'3km低恒速',
            align:"center",
            dataIndex: 'v45374'
          },
          {
            title:'5km低恒速',
            align:"center",
            dataIndex: 'v45375'
          },
          {
            title:'8km低恒速',
            align:"center",
            dataIndex: 'v45376'
          },
          {
            title:'紧急停机',
            align:"center",
            dataIndex: 'v45377'
          },
          {
            title:'通风',
            align:"center",
            dataIndex: 'v45380'
          },
          {
            title:'启动',
            align:"center",
            dataIndex: 'v45381'
          },
          {
            title:'制冷',
            align:"center",
            dataIndex: 'v45382'
          },
          {
            title:'制热',
            align:"center",
            dataIndex: 'v45383'
          },
          {
            title:'他车主机信号入',
            align:"center",
            dataIndex: 'v45384'
          },
          {
            title:'补车柴油机起动按钮',
            align:"center",
            dataIndex: 'v45385'
          },
          {
            title:'检测车停放制动重联',
            align:"center",
            dataIndex: 'v45386'
          },
          {
            title:'他车柴油机停机按钮',
            align:"center",
            dataIndex: 'v45387'
          },
          {
            title:'空调电机启动器反馈',
            align:"center",
            dataIndex: 'v45390'
          },
          {
            title:'相序继电器反馈',
            align:"center",
            dataIndex: 'v45392'
          },
          {
            title:'高压压力保护',
            align:"center",
            dataIndex: 'v45393'
          },
          {
            title:'低压压力保护',
            align:"center",
            dataIndex: 'v45394'
          },
          {
            title:'过热保护',
            align:"center",
            dataIndex: 'v45395'
          },
          {
            title:'后向电磁阀输出',
            align:"center",
            dataIndex: 'v45402'
          },
          {
            title:'前向电磁阀输出',
            align:"center",
            dataIndex: 'v45403'
          },
          {
            title:'四档电磁阀输出',
            align:"center",
            dataIndex: 'v45404'
          },
          {
            title:'三档电磁阀输出',
            align:"center",
            dataIndex: 'v45405'
          },
          {
            title:'二档电磁阀输出',
            align:"center",
            dataIndex: 'v45406'
          },
          {
            title:'一档电磁阀输出',
            align:"center",
            dataIndex: 'v45407'
          },
          {
            title:'蜂鸣器输出',
            align:"center",
            dataIndex: 'v45410'
          },
          {
            title:'前向撒砂输出',
            align:"center",
            dataIndex: 'v45411'
          },
          {
            title:'后向撒砂输出',
            align:"center",
            dataIndex: 'v45412'
          },
          {
            title:'排水阀输出',
            align:"center",
            dataIndex: 'v45414'
          },
          {
            title:'空压机进气输出',
            align:"center",
            dataIndex: 'v45415'
          },
          {
            title:'放风阀输出',
            align:"center",
            dataIndex: 'v45416'
          },
          {
            title:'柴油机起动输出',
            align:"center",
            dataIndex: 'v45424'
          },
          {
            title:'柴油机停机输出',
            align:"center",
            dataIndex: 'v45425'
          },
          {
            title:'PTO允许输出',
            align:"center",
            dataIndex: 'v45426'
          },
          {
            title:'PTO升速输出',
            align:"center",
            dataIndex: 'v45427'
          },
          {
            title:'PTO降速输出',
            align:"center",
            dataIndex: 'v45430'
          },
          {
            title:'干燥器',
            align:"center",
            dataIndex: 'v45432'
          },
          {
            title:'前向风笛10K输出',
            align:"center",
            dataIndex: 'v45433'
          },
          {
            title:'后向风笛9K输出',
            align:"center",
            dataIndex: 'v45434'
          },
          {
            title:'本车从机确认',
            align:"center",
            dataIndex: 'v45435'
          },
          {
            title:'柴油机工作',
            align:"center",
            dataIndex: 'v45436'
          },
          {
            title:'空调电源相序错误报警',
            align:"center",
            dataIndex: 'v45440'
          },
          {
            title:'滑油液位低禁止启机',
            align:"center",
            dataIndex: 'v45441'
          },
          {
            title:'列车管风压低报警卸载',
            align:"center",
            dataIndex: 'v45442'
          },
          {
            title:'紧急制动报警卸载',
            align:"center",
            dataIndex: 'v45443'
          },
          {
            title:'停放制动报警卸载',
            align:"center",
            dataIndex: 'v45444'
          },
          {
            title:'紧急停机报警',
            align:"center",
            dataIndex: 'v45447'
          },
          {
            title:'传动箱油温高报警',
            align:"center",
            dataIndex: 'v45450'
          },
          {
            title:'传动箱油温高报警卸载',
            align:"center",
            dataIndex: 'v45451'
          },
          {
            title:'传动箱油压高报警',
            align:"center",
            dataIndex: 'v45452'
          },
          {
            title:'传动箱油压高报警卸载',
            align:"center",
            dataIndex: 'v45453'
          },
          {
            title:'冷却水水温高报警',
            align:"center",
            dataIndex: 'v45454'
          },
          {
            title:'冷却水水温高报警卸载',
            align:"center",
            dataIndex: 'v45455'
          },
          {
            title:'滑油压力低报警',
            align:"center",
            dataIndex: 'v45456'
          },
          {
            title:'滑油温度高报警',
            align:"center",
            dataIndex: 'v45457'
          },
          {
            title:'传动箱油温高卸载停机',
            align:"center",
            dataIndex: 'v45460'
          },
          {
            title:'柴油机超速卸停机',
            align:"center",
            dataIndex: 'v45461'
          },
          {
            title:'柴油机硬线报警',
            align:"center",
            dataIndex: 'v45462'
          },
          {
            title:'机车超速报警',
            align:"center",
            dataIndex: 'v45463'
          },
          {
            title:'机车超速卸载',
            align:"center",
            dataIndex: 'v45464'
          },
          {
            title:'冷却水液位低报警',
            align:"center",
            dataIndex: 'v45465'
          },
          {
            title:'换向降柴油机转速',
            align:"center",
            dataIndex: 'v45466'
          },
          {
            title:'空调电机过载',
            align:"center",
            dataIndex: 'v45467'
          },
          {
            title:'空调过热保护',
            align:"center",
            dataIndex: 'v45471'
          },
          {
            title:'空调高压故障锁死',
            align:"center",
            dataIndex: 'v45473'
          },
          {
            title:'空调高压故障',
            align:"center",
            dataIndex: 'v45474'
          },
          {
            title:'空档',
            align:"center",
            dataIndex: 'v45480'
          },
          {
            title:'换挡1档',
            align:"center",
            dataIndex: 'v45481'
          },
          {
            title:'换挡2档',
            align:"center",
            dataIndex: 'v45482'
          },
          {
            title:'换挡3档',
            align:"center",
            dataIndex: 'v45483'
          },
          {
            title:'换挡4档',
            align:"center",
            dataIndex: 'v45484'
          },
          {
            title:'机车前向',
            align:"center",
            dataIndex: 'v45485'
          },
          {
            title:'机车后向',
            align:"center",
            dataIndex: 'v45486'
          },
          {
            title:'机车前向加载',
            align:"center",
            dataIndex: 'v45487'
          },
          {
            title:'机车后向加载',
            align:"center",
            dataIndex: 'v45490'
          },
          {
            title:'空调低压故障锁死',
            align:"center",
            dataIndex: 'v45491'
          },
          {
            title:'空调低压故障',
            align:"center",
            dataIndex: 'v45492'
          },
          {
            title:'机车超速紧急制动',
            align:"center",
            dataIndex: 'v45495'
          },
          {
            title:'柴油机停机硬线',
            align:"center",
            dataIndex: 'v45496'
          },
          {
            title:'燃油压力低报警',
            align:"center",
            dataIndex: 'v45497'
          },
          {
            title:'机车程序版本号',
            align:"center",
            dataIndex: 'vw4554'
          },
          {
            title:'理论换档速度升',
            align:"center",
            dataIndex: 'vw4556'
          },
          {
            title:'理论换档速度降',
            align:"center",
            dataIndex: 'vw4558'
          },
          {
            title:'柴油机停机',
            align:"center",
            dataIndex: 'v45601'
          },
          {
            title:'他车从机',
            align:"center",
            dataIndex: 'v45602'
          },
          {
            title:'低水位报警',
            align:"center",
            dataIndex: 'v45603'
          },
          {
            title:'柴油机停机报警',
            align:"center",
            dataIndex: 'v45604'
          },
          {
            title:'风笛按钮输入',
            align:"center",
            dataIndex: 'v45605'
          },
          {
            title:'旁路制动按钮输入',
            align:"center",
            dataIndex: 'v45606'
          },
          {
            title:'电加热器',
            align:"center",
            dataIndex: 'v45624'
          },
          {
            title:'室内风机',
            align:"center",
            dataIndex: 'v45625'
          },
          {
            title:'室外风机',
            align:"center",
            dataIndex: 'v45626'
          },
          {
            title:'压缩机',
            align:"center",
            dataIndex: 'v45627'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/ZyNrgcc/buZyNrgccOnline/list",
          historyList: "/ZyNrgcc/buZyNrgccOnline/historyListByTimeRange", // 修改为按时间范围查询
          delete: "/ZyNrgcc/buZyNrgccOnline/delete",
          deleteBatch: "/ZyNrgcc/buZyNrgccOnline/deleteBatch",
          exportXlsUrl: "/ZyNrgcc/buZyNrgccOnline/exportXls",
          importExcelUrl: "ZyNrgcc/buZyNrgccOnline/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'serverName',text:'上传服务器名',dictCode:''})
        fieldList.push({type:'string',value:'sensorId',text:'传感器ID',dictCode:''})
        fieldList.push({type:'int',value:'status',text:'状态',dictCode:''})
        fieldList.push({type:'Text',value:'statusname',text:'报警字段名',dictCode:''})
        fieldList.push({type:'double',value:'vw4500',text:'机车速度',dictCode:''})
        fieldList.push({type:'double',value:'vw4502',text:'传动箱子转速',dictCode:''})
        fieldList.push({type:'double',value:'vw4504',text:'蓄电池电流',dictCode:''})
        fieldList.push({type:'double',value:'vw4506',text:'蓄电池电压',dictCode:''})
        fieldList.push({type:'double',value:'vw4508',text:'柴油机转速',dictCode:''})
        fieldList.push({type:'double',value:'vw4510',text:'蓄电池电压',dictCode:''})
        fieldList.push({type:'double',value:'vw4512',text:'传动箱油温',dictCode:''})
        fieldList.push({type:'double',value:'vw4514',text:'传动箱压力',dictCode:''})
        fieldList.push({type:'double',value:'vw4516',text:'冷却水温度',dictCode:''})
        fieldList.push({type:'double',value:'vw4518',text:'滑油压力',dictCode:''})
        fieldList.push({type:'double',value:'vw4520',text:'滑油温度',dictCode:''})
        fieldList.push({type:'double',value:'vw4522',text:'负载反馈',dictCode:''})
        fieldList.push({type:'double',value:'vw4526',text:'柴油机工作计时',dictCode:''})
        fieldList.push({type:'double',value:'vw4530',text:'燃料温度',dictCode:''})
        fieldList.push({type:'double',value:'vw4532',text:'燃油压力',dictCode:''})
        fieldList.push({type:'int',value:'v45345',text:'前进输入',dictCode:''})
        fieldList.push({type:'int',value:'v45346',text:'后退输入',dictCode:''})
        fieldList.push({type:'int',value:'v45347',text:'加载0位输入',dictCode:''})
        fieldList.push({type:'int',value:'v45350',text:'加载1位输入',dictCode:''})
        fieldList.push({type:'int',value:'v45351',text:'升输入',dictCode:''})
        fieldList.push({type:'int',value:'v45352',text:'保输入',dictCode:''})
        fieldList.push({type:'int',value:'v45353',text:'降输入',dictCode:''})
        fieldList.push({type:'int',value:'v45354',text:'自动换档输入',dictCode:''})
        fieldList.push({type:'int',value:'v45355',text:'手动1档输入',dictCode:''})
        fieldList.push({type:'int',value:'v45356',text:'手动2档输入',dictCode:''})
        fieldList.push({type:'int',value:'v45357',text:'手动3档输入',dictCode:''})
        fieldList.push({type:'int',value:'v45360',text:'手动4档输入',dictCode:''})
        fieldList.push({type:'int',value:'v45361',text:'柴油机起动按钮输入',dictCode:''})
        fieldList.push({type:'int',value:'v45362',text:'紧急制动按钮输入',dictCode:''})
        fieldList.push({type:'int',value:'v45363',text:'停放制动继电器反馈',dictCode:''})
        fieldList.push({type:'int',value:'v45364',text:'加载保护继电器反馈',dictCode:''})
        fieldList.push({type:'int',value:'v45367',text:'撒砂输入',dictCode:''})
        fieldList.push({type:'int',value:'v45370',text:'柴油机报警输入',dictCode:''})
        fieldList.push({type:'int',value:'v45371',text:'总风缸压力开关输入',dictCode:''})
        fieldList.push({type:'int',value:'v45373',text:'空压机过温输入',dictCode:''})
        fieldList.push({type:'int',value:'v45374',text:'3km低恒速',dictCode:''})
        fieldList.push({type:'int',value:'v45375',text:'5km低恒速',dictCode:''})
        fieldList.push({type:'int',value:'v45376',text:'8km低恒速',dictCode:''})
        fieldList.push({type:'int',value:'v45377',text:'紧急停机',dictCode:''})
        fieldList.push({type:'int',value:'v45380',text:'通风',dictCode:''})
        fieldList.push({type:'int',value:'v45381',text:'启动',dictCode:''})
        fieldList.push({type:'int',value:'v45382',text:'制冷',dictCode:''})
        fieldList.push({type:'int',value:'v45383',text:'制热',dictCode:''})
        fieldList.push({type:'int',value:'v45384',text:'他车主机信号入',dictCode:''})
        fieldList.push({type:'int',value:'v45385',text:'补车柴油机起动按钮',dictCode:''})
        fieldList.push({type:'int',value:'v45386',text:'检测车停放制动重联',dictCode:''})
        fieldList.push({type:'int',value:'v45387',text:'他车柴油机停机按钮',dictCode:''})
        fieldList.push({type:'int',value:'v45390',text:'空调电机启动器反馈',dictCode:''})
        fieldList.push({type:'int',value:'v45392',text:'相序继电器反馈',dictCode:''})
        fieldList.push({type:'int',value:'v45393',text:'高压压力保护',dictCode:''})
        fieldList.push({type:'int',value:'v45394',text:'低压压力保护',dictCode:''})
        fieldList.push({type:'int',value:'v45395',text:'过热保护',dictCode:''})
        fieldList.push({type:'int',value:'v45402',text:'后向电磁阀输出',dictCode:''})
        fieldList.push({type:'int',value:'v45403',text:'前向电磁阀输出',dictCode:''})
        fieldList.push({type:'int',value:'v45404',text:'四档电磁阀输出',dictCode:''})
        fieldList.push({type:'int',value:'v45405',text:'三档电磁阀输出',dictCode:''})
        fieldList.push({type:'int',value:'v45406',text:'二档电磁阀输出',dictCode:''})
        fieldList.push({type:'int',value:'v45407',text:'一档电磁阀输出',dictCode:''})
        fieldList.push({type:'int',value:'v45410',text:'蜂鸣器输出',dictCode:''})
        fieldList.push({type:'int',value:'v45411',text:'前向撒砂输出',dictCode:''})
        fieldList.push({type:'int',value:'v45412',text:'后向撒砂输出',dictCode:''})
        fieldList.push({type:'int',value:'v45414',text:'排水阀输出',dictCode:''})
        fieldList.push({type:'int',value:'v45415',text:'空压机进气输出',dictCode:''})
        fieldList.push({type:'int',value:'v45416',text:'放风阀输出',dictCode:''})
        fieldList.push({type:'int',value:'v45424',text:'柴油机起动输出',dictCode:''})
        fieldList.push({type:'int',value:'v45425',text:'柴油机停机输出',dictCode:''})
        fieldList.push({type:'int',value:'v45426',text:'PTO允许输出',dictCode:''})
        fieldList.push({type:'int',value:'v45427',text:'PTO升速输出',dictCode:''})
        fieldList.push({type:'int',value:'v45430',text:'PTO降速输出',dictCode:''})
        fieldList.push({type:'int',value:'v45432',text:'干燥器',dictCode:''})
        fieldList.push({type:'int',value:'v45433',text:'前向风笛10K输出',dictCode:''})
        fieldList.push({type:'int',value:'v45434',text:'后向风笛9K输出',dictCode:''})
        fieldList.push({type:'int',value:'v45435',text:'本车从机确认',dictCode:''})
        fieldList.push({type:'int',value:'v45436',text:'柴油机工作',dictCode:''})
        fieldList.push({type:'int',value:'v45440',text:'空调电源相序错误报警',dictCode:''})
        fieldList.push({type:'int',value:'v45441',text:'滑油液位低禁止启机',dictCode:''})
        fieldList.push({type:'int',value:'v45442',text:'列车管风压低报警卸载',dictCode:''})
        fieldList.push({type:'int',value:'v45443',text:'紧急制动报警卸载',dictCode:''})
        fieldList.push({type:'int',value:'v45444',text:'停放制动报警卸载',dictCode:''})
        fieldList.push({type:'int',value:'v45447',text:'紧急停机报警',dictCode:''})
        fieldList.push({type:'int',value:'v45450',text:'传动箱油温高报警',dictCode:''})
        fieldList.push({type:'int',value:'v45451',text:'传动箱油温高报警卸载',dictCode:''})
        fieldList.push({type:'int',value:'v45452',text:'传动箱油压高报警',dictCode:''})
        fieldList.push({type:'int',value:'v45453',text:'传动箱油压高报警卸载',dictCode:''})
        fieldList.push({type:'int',value:'v45454',text:'冷却水水温高报警',dictCode:''})
        fieldList.push({type:'int',value:'v45455',text:'冷却水水温高报警卸载',dictCode:''})
        fieldList.push({type:'int',value:'v45456',text:'滑油压力低报警',dictCode:''})
        fieldList.push({type:'int',value:'v45457',text:'滑油温度高报警',dictCode:''})
        fieldList.push({type:'int',value:'v45460',text:'传动箱油温高卸载停机',dictCode:''})
        fieldList.push({type:'int',value:'v45461',text:'柴油机超速卸停机',dictCode:''})
        fieldList.push({type:'int',value:'v45462',text:'柴油机硬线报警',dictCode:''})
        fieldList.push({type:'int',value:'v45463',text:'机车超速报警',dictCode:''})
        fieldList.push({type:'int',value:'v45464',text:'机车超速卸载',dictCode:''})
        fieldList.push({type:'int',value:'v45465',text:'冷却水液位低报警',dictCode:''})
        fieldList.push({type:'int',value:'v45466',text:'换向降柴油机转速',dictCode:''})
        fieldList.push({type:'int',value:'v45467',text:'空调电机过载',dictCode:''})
        fieldList.push({type:'int',value:'v45471',text:'空调过热保护',dictCode:''})
        fieldList.push({type:'int',value:'v45473',text:'空调高压故障锁死',dictCode:''})
        fieldList.push({type:'int',value:'v45474',text:'空调高压故障',dictCode:''})
        fieldList.push({type:'int',value:'v45480',text:'空档',dictCode:''})
        fieldList.push({type:'int',value:'v45481',text:'换挡1档',dictCode:''})
        fieldList.push({type:'int',value:'v45482',text:'换挡2档',dictCode:''})
        fieldList.push({type:'int',value:'v45483',text:'换挡3档',dictCode:''})
        fieldList.push({type:'int',value:'v45484',text:'换挡4档',dictCode:''})
        fieldList.push({type:'int',value:'v45485',text:'机车前向',dictCode:''})
        fieldList.push({type:'int',value:'v45486',text:'机车后向',dictCode:''})
        fieldList.push({type:'int',value:'v45487',text:'机车前向加载',dictCode:''})
        fieldList.push({type:'int',value:'v45490',text:'机车后向加载',dictCode:''})
        fieldList.push({type:'int',value:'v45491',text:'空调低压故障锁死',dictCode:''})
        fieldList.push({type:'int',value:'v45492',text:'空调低压故障',dictCode:''})
        fieldList.push({type:'int',value:'v45495',text:'机车超速紧急制动',dictCode:''})
        fieldList.push({type:'int',value:'v45496',text:'柴油机停机硬线',dictCode:''})
        fieldList.push({type:'int',value:'v45497',text:'燃油压力低报警',dictCode:''})
        fieldList.push({type:'double',value:'vw4550',text:'机车里程',dictCode:''})
        fieldList.push({type:'double',value:'vw4554',text:'机车程序版本号',dictCode:''})
        fieldList.push({type:'double',value:'vw4556',text:'理论换档速度升',dictCode:''})
        fieldList.push({type:'double',value:'vw4558',text:'理论换档速度降',dictCode:''})
        fieldList.push({type:'int',value:'v45601',text:'柴油机停机',dictCode:''})
        fieldList.push({type:'int',value:'v45602',text:'他车从机',dictCode:''})
        fieldList.push({type:'int',value:'v45603',text:'低水位报警',dictCode:''})
        fieldList.push({type:'int',value:'v45604',text:'柴油机停机报警',dictCode:''})
        fieldList.push({type:'int',value:'v45605',text:'风笛按钮输入',dictCode:''})
        fieldList.push({type:'int',value:'v45606',text:'旁路制动按钮输入',dictCode:''})
        fieldList.push({type:'int',value:'v45624',text:'电加热器',dictCode:''})
        fieldList.push({type:'int',value:'v45625',text:'室内风机',dictCode:''})
        fieldList.push({type:'int',value:'v45626',text:'室外风机',dictCode:''})
        fieldList.push({type:'int',value:'v45627',text:'压缩机',dictCode:''})
        this.superFieldList = fieldList
      },
      // 车型选择变更
      handleVehicleTypeChange(value) {
        this.selectedVehicleType = value;
        this.loadData(1);
      },
      // 查询类型变更
      handleQueryTypeChange(value) {
        if (value === 'online') {
          // 切换到在线数据查询
          this.loadData(1)
        }
      },
      // 切换到历史数据查询
      switchToHistory() {
        this.queryType = 'history'
      },
      // 切换到在线数据查询
      switchToOnline() {
        this.queryType = 'online'
        this.startTime = undefined
        this.endTime = undefined
        this.loadData(1)
      },
      // 重写加载数据方法
      loadData(arg) {
        if (!this.url.list) {
          this.$message.error('请设置url.list属性!')
          return
        }
        // 加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1
        }
        let params = this.getQueryParams()// 查询条件
        // 添加车型筛选条件
        if (this.selectedVehicleType) {
          params.vehicleType = this.selectedVehicleType;
        }
        if (this.queryType === 'history') {
          // 历史数据查询
          if (!this.startTime || !this.endTime) {
            this.$message.warning('请选择完整的起止时间')
            return
          }

          if (this.startTime >= this.endTime) {
            this.$message.warning('开始时间必须小于结束时间')
            return
          }

          params.startTime = this.startTime
          params.endTime = this.endTime

          this.loading = true
          this.$http({
            url: this.url.historyList,
            method: 'get',
            params: params
          }).then((res) => {
            if (res.success) {
              this.dataSource = res.result.records
              this.ipagination.total = res.result.total
            } else {
              // 处理后端返回的错误信息
              this.$message.error(res.message)
              // 清空表格数据
              this.dataSource = []
              this.ipagination.total = 0
            }
            this.loading = false
          })
        } else {
          // 在线数据查询
          this.loading = true
          this.$http({
            url: this.url.list,
            method: 'get',
            params: params
          }).then((res) => {
            if (res.success) {
              this.dataSource = res.result.records
              this.ipagination.total = res.result.total
            } else {
              // 处理后端返回的错误信息
              this.$message.error(res.message)
              // 清空表格数据
              this.dataSource = []
              this.ipagination.total = 0
            }
            this.loading = false
          })
        }
      },
      handleEdit(record) {
        // 将查询类型和时间信息传递给编辑模态框
        this.$refs.modalForm.edit(record, this.queryType, this.startTime, this.endTime);
      },
      formatSeconds(seconds) {
        if (seconds === null || seconds === undefined) return '-'

        let totalSeconds = Number(seconds)
        if (isNaN(totalSeconds)) return seconds

        const day = Math.floor(totalSeconds / 86400)
        const hour = Math.floor((totalSeconds % 86400) / 3600)
        const minute = Math.floor((totalSeconds % 3600) / 60)
        const second = totalSeconds % 60

        if (day > 0) {
          return `${day}天 ${hour}小时 ${minute}分 ${second}秒`
        } else {
          return `${hour}小时 ${minute}分 ${second}秒`
        }
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>