<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 :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item label="海事机构">
              <j-tree-select
                v-model="queryParam.departId"
                placeholder="请选择机构"
                dict="view_depart,depart_nam,depart_no"
                pidField="updepart_no"
                pidValue="384"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="设备状况">
              <j-dict-select-tag v-model="queryParam.status" placeholder="请选择设备状况" dictCode="ad_device_status"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="设备类型">
              <j-dict-select-tag allowClear v-model="queryParam.type" placeholder="请选择设备类型" dictCode="ad_device_type"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <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>
<!--              <a-button type="primary" icon="download" @click="handleExportXls('企业月供电')" style="margin-left: 8px">导出</a-button>-->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i>总设备数&nbsp;<a style="font-weight: 600">{{ statistics['totalDevice'] }}</a>台&nbsp;&nbsp;
        <i class="anticon anticon-info-circle ant-alert-icon"></i>总供电艘次&nbsp;<a style="font-weight: 600">{{ statistics['totalShipNum'] }}</a>次&nbsp;&nbsp;
        <i class="anticon anticon-info-circle ant-alert-icon"></i>总供电量&nbsp;<a style="font-weight: 600">{{ statistics['totalConsumption'] }}</a>kW-h&nbsp;&nbsp;
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="false"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <span slot="areaName" slot-scope="text">
          <j-ellipsis :value="text" :length="15" />
        </span>
        <span slot="comName" slot-scope="text">
          <j-ellipsis :value="text" :length="15" />
        </span>

      </a-table>
    </div>

  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import JTreeSelect from '@/components/jeecg/JTreeSelect'
  import { getAction } from '@/api/manage'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import JEllipsis from "@/components/jeecg/JEllipsis"

  export default {
    name: "AdDeviceStatistics",
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JEllipsis,
      JDictSelectTag,
      JTreeSelect,
    },
    data () {
      return {
        description: '设备统计',
        // 表头
        columns: [
          {
            title:'设备名称',
            align:"center",
            dataIndex: 'serviceName'
          },
          {
            title:'作业地点',
            align:"center",
            dataIndex: 'areaName',
            scopedSlots: {customRender: 'areaName'},
          },
          {
            title:'作业单位',
            align:"center",
            dataIndex: 'comName',
            scopedSlots: {customRender: 'comName'},
          },
          {
            title:'管辖海事机构',
            align:"center",
            dataIndex: 'departNam'
          },
          {
            title:'设备类型',
            align:"center",
            dataIndex: 'type'
          },
          {
            title:'设备状况',
            align:"center",
            dataIndex: 'status'
          },
          {
            title:'电压（V）',
            align:"center",
            dataIndex: 'voltage'
          },
          {
            title:'总供电量（kW-h）',
            align:"center",
            dataIndex: 'consumption'
          },
          {
            title:'供电艘次',
            align:"center",
            dataIndex: 'shipNum'
          }
        ],
        url: {
          listStatis: "/ad/adChargingRecord/listDevice",
          exportXlsUrl: "/ad/adChargingRecord/exportDeviceXls",
        },
        dictOptions:{},
        queryParam: {
          departId: null,
          status: null,
          type: null
        },
        statistics: {}
      }
    },
    computed: {

    },
    created() {
      this.initTableData()
    },
    methods: {
      initDictConfig(){
      },
      initTableData () {
        getAction(this.url.listStatis, this.queryParam).then(res => {
          if (res.code === 200) {
            this.dataSource = []
            this.dataSource = res.result.list
            this.statistics = res.result
            console.log(res.result,this.dataSource)
          }
        })
      },
      handleTableChange() {

      },
      searchQuery() {
        this.initTableData()
      },
      searchReset() {
        this.queryParam = {
          departId: null,
          status: null,
          type: null
        }
      }
    }
  }
</script>
<style scoped>
  /*@import '~@assets/less/common.less';*/
</style>