<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
<!--          <a-col :span="5">-->
<!--            <a-form-item label="设备名称">-->
<!--&lt;!&ndash;              <j-select-device placeholder="请选择设备名称" :multiple="false" v-model="queryParam.deviceId"/>&ndash;&gt;-->
<!--              <j-search-select-tag placeholder="请选择设备名称" v-model="queryParam.deviceId" dict="bu_device,device_name,id"/>-->
<!--            </a-form-item>-->
<!--          </a-col>-->

<!--&lt;!&ndash;          <a-col :span="5">&ndash;&gt;-->
<!--&lt;!&ndash;            <a-form-item label="编号">&ndash;&gt;-->
<!--&lt;!&ndash;              <a-input placeholder="请输入编号" v-model="queryParam.code"/>&ndash;&gt;-->
<!--&lt;!&ndash;            </a-form-item>&ndash;&gt;-->
<!--&lt;!&ndash;          </a-col>&ndash;&gt;-->

<!--          <a-col :span="4">-->
<!--            <a-form-item label="选择编号">-->
<!--              <j-dict-select-tag v-model="queryParam.status" placeholder="请选择查看状态" dict-code="remind_status" ></j-dict-select-tag>-->
<!--            </a-form-item>-->
<!--          </a-col>-->

<!--          <a-col :md="6" :sm="8" >-->
<!--            <a-form-item label="请选择日期">-->
<!--              <j-date v-model="queryParam.beginTime" style="width:280px" placeholder="开始时间" @change="onChange"-->
<!--                      :showTime=true dateFormat="YYYY-MM-DD" />-->
<!--            </a-form-item>-->
<!--          </a-col>-->
<!--          <a-col :span="5">-->
<!--            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">-->
<!--              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>-->
<!--              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>-->
<!--            </span>-->
<!--          </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_air_quality')" >导出</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="dataSource1"
        :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-air-quality-modal ref="modalForm" @ok="modalFormOk"></bu-air-quality-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin1'
  import BuAirQualityModal from './modules/BuAirQualityModal'
  import {getAction} from "@api/manage";

  export default {
    name: 'BuAirQualityList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      BuAirQualityModal
    },
    data () {
      return {
        description: 'bu_air_quality管理页面',
        // 表头
        columns: [
          // {
          //   title: '#',
          //   dataIndex: '',
          //   key:'rowIndex',
          //   width:60,
          //   align:"center",
          //   customRender:function (t,r,index) {
          //     return parseInt(index)+1;
          //   }
          // },
          {
            title:'采集时间',
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title:'传感器名称',
            align:"center",
            dataIndex: 'sensorId_dictText',
          },
          // {
          //   title:'上传服务名',
          //   align:"center",
          //   dataIndex: 'serverName'
          // },
          // {
          //   title:'编号',
          //   align:"center",
          //   dataIndex: 'code'
          // },
          // {
          //   title:'PM2.5(μm)',
          //   align:"center",
          //   dataIndex: 'pm25'
          // },
          // {
          //   title:'PM10',
          //   align:"center",
          //   dataIndex: 'pm10'
          // },
          // {
          //   title:'温度',
          //   align:"center",
          //   dataIndex: 'humidity'
          // },
          // {
          //   title:'湿度',
          //   align:"center",
          //   dataIndex: 'temperature'
          // },
          // {
          //   title:'大气压力',
          //   align:"center",
          //   dataIndex: 'pressure'
          // },
          // {
          //   title:'光照度',
          //   align:"center",
          //   dataIndex: 'illuminance'
          // },
          // {
          //   title:'UV线电压',
          //   align:"center",
          //   dataIndex: 'tvoc'
          // },
          // {
          //   title:'二氧化碳(ppm)',
          //   align:"center",
          //   dataIndex: 'co2'
          // },
          // {
          //   title:'甲醛(ppm)',
          //   align:"center",
          //   dataIndex: 'hcho'
          // },
          // {
          //   title:'臭氧(ppm)',
          //   align:"center",
          //   dataIndex: 'o3'
          // },
          {
            title:'氧气(%VOL)',
            align:"center",
            dataIndex: 'o2'
          },
          // {
          //   title:'硫化氢(ppm)',
          //   align:"center",
          //   dataIndex: 'h2s'
          // },
          {
            title:'一氧化碳(ppm)',
            align:"center",
            dataIndex: 'co'
          },
          {
            title:'可燃气体(%LEL)',
            align:"center",
            dataIndex: 'ch4'
          },
          {
            title:'硫化氢(ppm)',
            align:"center",
            dataIndex: 'h2s'
          },
          // {
          //   title:'二氧化碳',
          //   align:"center",
          //   dataIndex: 'no2'
          // },
          // {
          //   title:'二氧化硫',
          //   align:"center",
          //   dataIndex: 'so2'
          // },
          // {
          //   title:'氢气',
          //   align:"center",
          //   dataIndex: 'h2'
          // },
          // {
          //   title:'氨气',
          //   align:"center",
          //   dataIndex: 'nh3'
          // },
          // {
          //   title:'噪声',
          //   align:"center",
          //   dataIndex: 'noise'
          // },
          // {
          //   title:'异味',
          //   align:"center",
          //   dataIndex: 'odor'
          // },
          // {
          //   title:'TSP总悬浮微粒',
          //   align:"center",
          //   dataIndex: 'tsp'
          // },
          // {
          //   title:'烟雾',
          //   align:"center",
          //   dataIndex: 'smoke'
          // },
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align:"center",
          //   fixed:"right",
          //   width:147,
          //   scopedSlots: { customRender: 'action' }
          // }
        ],
        url: {
          list: "/energy/buAirQuality/list",
          airList: "/energy/buAirQuality/list",
          delete: "/energy/buAirQuality/delete",
          deleteBatch: "/energy/buAirQuality/deleteBatch",
          exportXlsUrl: "/energy/buAirQuality/exportXls",
          importExcelUrl: "energy/buAirQuality/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
        dataSource1:[],
      }
    },
    // created() {
    // this.getSuperFieldList();
    // },
    methods: {
      // initDictConfig(){
      // },
      onChange(data){
        this.queryParam.beginTime = data + " 00:00:00";
        this.queryParam.endTime = data + " 23:59:59";
      },
      loadData1(arg) {
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.airList, params).then((res) => {
          if (res.success) {
            this.dataSource1 = res.result.records||res.result;
            if(res.result.total)
            {
              this.ipagination.total = res.result.total;
            }
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
          this.loading = false;
        })
      },
      // getSuperFieldList(){
      //   let fieldList=[];
      //   fieldList.push({type:'string',value:'serverName',text:'上传服务名'})
      //   fieldList.push({type:'int',value:'code',text:'编号'})
      //   fieldList.push({type:'number',value:'pm25',text:'PM2.5'})
      //   fieldList.push({type:'number',value:'pm10',text:'PM10'})
      //   fieldList.push({type:'number',value:'humidity',text:'温度'})
      //   fieldList.push({type:'number',value:'temperature',text:'湿度'})
      //   fieldList.push({type:'number',value:'pressure',text:'大气压力'})
      //   fieldList.push({type:'number',value:'illuminance',text:'光照度'})
      //   fieldList.push({type:'number',value:'tvoc',text:'UV线电压'})
      //   fieldList.push({type:'number',value:'co2',text:'二氧化碳'})
      //   fieldList.push({type:'number',value:'hcho',text:'甲醛'})
      //   fieldList.push({type:'number',value:'o3',text:'臭氧'})
      //   fieldList.push({type:'number',value:'o2',text:'氧气'})
      //   fieldList.push({type:'number',value:'h2s',text:'硫化氢'})
      //   fieldList.push({type:'number',value:'ch4',text:'甲烷'})
      //   fieldList.push({type:'number',value:'co',text:'一氧化碳'})
      //   fieldList.push({type:'number',value:'no2',text:'二氧化碳'})
      //   fieldList.push({type:'number',value:'so2',text:'二氧化硫'})
      //   fieldList.push({type:'number',value:'h2',text:'氢气'})
      //   fieldList.push({type:'number',value:'nh3',text:'氨气'})
      //   fieldList.push({type:'number',value:'noise',text:'噪声'})
      //   fieldList.push({type:'number',value:'odor',text:'异味'})
      //   fieldList.push({type:'number',value:'tsp',text:'TSP总悬浮微粒'})
      //   fieldList.push({type:'number',value:'smoke',text:'烟雾'})
      //   this.superFieldList = fieldList
      // }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>