<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 :md="6" :sm="8">
            <a-form-item label="设备名称">
              <j-select-device placeholder="请选择设备名称" :multiple="false" v-model="queryParam.deviceId" @change="deviceChange"/>
<!--              <j-search-select-tag placeholder="请选择设备名称" v-model="queryParam.deviceId" dict="bu_device,device_name,id" @change="deviceChange"/>-->
            </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 :md="6" :sm="8">
            <a-form-item label="传感器">
              <a-select placeholder="请选择传感器" :multiple="true" v-model="queryParam.ip"
                        @change="numberChange" :filter-option="filterOption">
                <a-select-option v-for="d in sensorDicDatas" :key="d.ip" :value="d.ip" >
                  {{d.dataValue}}
                </a-select-option>
              </a-select>
            </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="loadData" 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_sensor_device_dfj_copy1')">导出</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>
<!--      <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>-->
    </div>

<!--    <bu-sensor-device-dfj-copy1-modal ref="modalForm" @ok="modalFormOk"></bu-sensor-device-dfj-copy1-modal>-->
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import {getAction} from "@api/manage";
  import JSelectSensor from '@comp/jeecgbiz/JSelectSensor'
  import {initDictOptions} from "@comp/dict/JDictSelectUtil";
  import JSelectDevice from '@comp/jeecgbiz/JSelectDevice'
  export default {
    name: 'BuSensorDeviceDfjCopy1List',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JSelectSensor,
      JSelectDevice
    },
    data () {
      return {
        description: '数据管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'采集时刻',
            align:"center",
            dataIndex: 'time',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          // {
          //   title:'设备名称',
          //   align:"center",
          //   dataIndex: 'device_name'
          // },
          {
            title:'U相电流',
            align:"center",
            dataIndex: 'udl'
          },
          {
            title:'V相电流',
            align:"center",
            dataIndex: 'vdl'
          },
          {
            title:'W相电流',
            align:"center",
            dataIndex: 'wdl'
          },
          {
            title:'U相电压',
            align:"center",
            dataIndex: 'udy'
          },
          {
            title:'V相电压',
            align:"center",
            dataIndex: 'vdy'
          },
          {
            title:'W相电压',
            align:"center",
            dataIndex: 'wdy'
          },
          {
            title:'总功率',
            align:"center",
            dataIndex: 'gl'
          },
          {
            title:'震动x',
            align:"center",
            dataIndex: 'zdx'
          },
          {
            title:'震动y',
            align:"center",
            dataIndex: 'zdy'
          },
          {
            title:'震动z',
            align:"center",
            dataIndex: 'zdz'
          },
          {
            title:'氧气',
            align:"center",
            dataIndex: 'yq'
          },
          {
            title:'一氧化碳',
            align:"center",
            dataIndex: 'co'
          },
          {
            title:'可燃性气体',
            align:"center",
            dataIndex: 'ch'
          },
          {
            title:'温湿度',
            align:"center",
            dataIndex: 'wsd'
          },
          {
            title:'湿度',
            align:"center",
            dataIndex: 'sd'
          },
          {
            title:'烟雾',
            align:"center",
            dataIndex: 'smoke'
          },
          // {
          //   title:'噪声',
          //   align:"center",
          //   dataIndex: 'zs'
          // },
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align:"center",
          //   fixed:"right",
          //   width:147,
          //   scopedSlots: { customRender: 'action' }
          // }
        ],
        url: {
          list: "/sensor/buSensorDeviceDfjCopy1/list",
          delete: "/sensor/buSensorDeviceDfjCopy1/delete",
          deleteBatch: "/sensor/buSensorDeviceDfjCopy1/deleteBatch",
          exportXlsUrl: "/sensor/buSensorDeviceDfjCopy1/exportXls",
          importExcelUrl: "sensor/buSensorDeviceDfjCopy1/importExcel",
          getDeviceList: "/sensor/buSensor/getDeviceList",
          sensor: "/sensor/buSensorDeviceData/getSensorDatas",
        },
        dictOptions:{},
        superFieldList:[],
        sensorDicDatas:[],
      }
    },
    // mounted() {
    //   this.initDictConfig()
    // },
    created() {
      this.loadData(0)
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      // 加载数据字典
      // initDictConfig() {
      //   // 初始化字典
      //   initDictOptions('bu_device,device_name,id').then((res) => {
      //     if (res.success) {
      //       console.log("123456",res.result)
      //       this.queryParam.deviceId = res.result[0].value;
      //     }
      //   });
      // },
      deviceChange: function (value){
        this.getSensorDatas(value);
      },
      getSensorDatas(deviceId){
        this.$http.get(this.url.sensor,{params:{deviceId:deviceId}})
          .then(res => {
            this.sensorDicDatas = res.result
          })
      },
      onChange(data){
        this.queryParam.beginTime = data + " 00:00:00";
        this.queryParam.endTime = data + " 23:59:59";
      },
      numberChange: function (value) {
        this.checkItem = value;
      },
      filterOption(input, option) {
        return (
          option.data.attrs.tag.toLowerCase().indexOf(input.toLowerCase()) >= 0
        );
      },
      loadData(arg) {
        if(!this.url.getDeviceList){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        if(arg === 0){
          this.queryParam.deviceId = '1384437889241600001'
        }
        var params = this.getQueryParams();//查询条件
        console.log("123456",params)
        this.loading = true;
        getAction(this.url.getDeviceList, params).then((res) => {
          if (res.success) {
            this.dataSource = 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:'date',value:'time',text:'采集时刻'})
      //   fieldList.push({type:'string',value:'deviceId',text:'设备名称'})
      //   fieldList.push({type:'string',value:'udl',text:'U相电流'})
      //   fieldList.push({type:'string',value:'vdl',text:'V相电流'})
      //   fieldList.push({type:'string',value:'wdl',text:'W相电流'})
      //   fieldList.push({type:'string',value:'udy',text:'U相电压'})
      //   fieldList.push({type:'string',value:'vdy',text:'V相电压'})
      //   fieldList.push({type:'string',value:'wdy',text:'W相电压'})
      //   fieldList.push({type:'string',value:'zs',text:'总功率'})
      //   fieldList.push({type:'string',value:'zdx',text:'震动x'})
      //   fieldList.push({type:'string',value:'zdy',text:'震动y'})
      //   fieldList.push({type:'string',value:'zdz',text:'震动z'})
      //   fieldList.push({type:'string',value:'yq',text:'氧气'})
      //   fieldList.push({type:'string',value:'co',text:'一氧化碳'})
      //   fieldList.push({type:'string',value:'ch',text:'可燃性气体'})
      //   fieldList.push({type:'string',value:'wd',text:'温度'})
      //   fieldList.push({type:'string',value:'sd',text:'湿度'})
      //   fieldList.push({type:'string',value:'smoke',text:'烟雾'})
      //   this.superFieldList = fieldList
      // }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>