<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="时间">
              <a-month-picker
                v-model="queryParam.month"
                :allowClear="false"
                format="YYYY-MM"
                valueFormat="YYYY-MM"
                placeholder="请选择年月"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="作业单位">
              <a-input placeholder="请输入作业单位" v-model="queryParam.comNo"></a-input>
            </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['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;
        <i class="anticon anticon-info-circle ant-alert-icon"></i>总供电时长&nbsp;<a style="font-weight: 600">{{ statistics['totalChargeLength'] }}</a>小时&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">

      </a-table>
    </div>

  </a-card>
</template>

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

  export default {
    name: "AdChargingMonth",
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JTreeSelect,
      JDate
    },
    data () {
      return {
        description: '企业月供电页面',
        // 表头
        columns: [
          {
            title:'作业单位',
            align:"center",
            dataIndex: 'comName'
          },
          {
            title:'月供电艘次',
            align:"center",
            dataIndex: 'shipNum'
          },
          {
            title:'月受电量(kW-h)',
            align:"center",
            dataIndex: 'consumption'
          },
          {
            title:'月受电时长',
            align:"center",
            dataIndex: 'chargeLength'
          }
        ],
        url: {
          listMonth: "/ad/adChargingRecord/listMonth",
          exportXlsUrl: "/ad/adChargingRecord/exportMonthXls",
        },
        dictOptions:{},
        queryParam: {
          departId: null,
          month: this.getYearAndMonth(),
          comNo: null
        },
        statistics: {}
      }
    },
    computed: {

    },
    created() {
      this.initTableData()
    },
    methods: {
      moment,
      initDictConfig(){
      },
      initTableData () {
        getAction(this.url.listMonth, this.queryParam).then(res => {
          if (res.code === 200) {
            this.dataSource = res.result.list
            this.statistics = res.result
          }
        })
      },
      handleTableChange() {

      },
      searchQuery() {
        this.initTableData()
      },
      searchReset() {
        this.queryParam = {
          departId: null,
          month: this.getYearAndMonth(),
          comNo: null
        }
      },
      getYearAndMonth() {
        const date = new Date()
        const year = date.getFullYear()
        let month = date.getMonth() + 1
        month = month > 9 ? month : '0' + month
        return `${year}-${month}`
      }
    }
  }
</script>
<style scoped>
  /*@import '~@assets/less/common.less';*/
</style>