<template>
  <a-card :bordered="false">
    <a-tabs defaultActiveKey="1" @change="callback">
      <a-tab-pane tab="按年统计" key="1">
        <div class="table-page-search-wrapper">
            <a-form layout="inline">
              <a-row :gutter="24">
                <a-col :xl="6" :lg="7" :md="8" :sm="24">
                  <a-form-item label="年份">
                    <a-range-picker
                      :placeholder="['开始年份', '结束年份']"
                      format="YYYY"
                      :value="yearValue"
                      :mode="yearMode"
                      @panelChange="handleYear"/>
                  </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" icon="search" @click="queryYear">查询</a-button>
                    <a-button style="margin-left: 8px" type="primary" icon="reload" @click="yearReset">重置</a-button>
                  </span>
                </a-col>
              </a-row>
            </a-form>
        </div>
        <div>
          <div id="yearChart" style="margin-bottom:24px;height: 420px;"></div>
        </div>
        <div>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            class="j-table-force-nowrap"
            :scroll="{x:true}"
            :columns="yearColumns"
            :dataSource="yearDataSource"
            :pagination="ipagination"
            :loading="loading">

            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
              <img v-else :src="getImgView(text)" 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-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

          </a-table>
        </div>
      </a-tab-pane>
      <a-tab-pane tab="按月统计" key="2">
        <div class="table-page-search-wrapper">
          <a-form layout="inline">
            <a-row :gutter="24">
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="月份">
                  <a-range-picker
                    :placeholder="['开始月份', '结束月份']"
                    format="YYYY-MM"
                    :value="monthValue"
                    :mode="monthMode"
                    @panelChange="handleMonth"/>
                </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" icon="search" @click="queryMonth">查询</a-button>
                    <a-button style="margin-left: 8px" type="primary" icon="reload" @click="monthReset">重置</a-button>
                  </span>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <div>
          <div id="monthChart" style="margin-bottom:24px;height: 420px;"></div>
        </div>
        <div>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            class="j-table-force-nowrap"
            :scroll="{x:true}"
            :columns="monthColumns"
            :dataSource="monthDataSource"
            :pagination="ipagination"
            :loading="loading">

            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
              <img v-else :src="getImgView(text)" 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-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

          </a-table>
        </div>
      </a-tab-pane>
      <a-tab-pane tab="按设备统计" key="3">
        <div class="table-page-search-wrapper">
          <a-form layout="inline">
            <a-row :gutter="24">
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="日期">
                  <a-range-picker
                    :placeholder="['开始日期', '结束日期']"
                    format="YYYY-MM-DD"
                    :value="deviceValue"
                    :mode="deviceMode"
                    @panelChange="handleDevice"/>
                </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" icon="search" @click="queryDevice">查询</a-button>
                    <a-button style="margin-left: 8px" type="primary" icon="reload" @click="deviceReset">重置</a-button>
                  </span>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <div>
          <div id="deviceChart" style="margin-bottom:24px;height: 420px;"></div>
        </div>
        <div>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            class="j-table-force-nowrap"
            :scroll="{x:true}"
            :columns="deviceColumns"
            :dataSource="deviceDataSource"
            :pagination="ipagination"
            :loading="loading">

            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
              <img v-else :src="getImgView(text)" 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-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
          </a-table>
        </div>
      </a-tab-pane>
    </a-tabs>
  </a-card>
</template>

<script>
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction } from '@/api/manage'
  import moment from 'moment'

  export default {
    name: 'DeviceFaultStatistics',
    mixins: [JeecgListMixin],
    components: {

    },
  data() {
    return {
      url:{
        list:''
      },
      yearValue:[],
      yearMode:['year','year'],
      monthValue:[],
      monthMode:['month','month'],
      deviceValue:[],
      deviceMode:['date','date'],
      yearDataSource:[],
      monthDataSource:[],
      deviceDataSource:[],
      yearColumns:[],
      monthColumns:[],
      deviceColumns:[]
    }
  },
  created() {
      var nowDate=new Date();
      var lastDate=new Date();
      lastDate.setFullYear(lastDate.getFullYear()-1);
      console.log(moment(lastDate));
      this.yearValue=[moment(lastDate),moment(nowDate)];
  },
  methods: {
    callback(key) {

    },
    handleYear(value,mode){
      this.yearValue=value;
    },
    handleMonth(value,mode){
      this.monthValue=value;
    },
    handleDevice(value,mode){
      this.deviceValue=value;
    },
    queryYear(){

    },
    yearReset(){

    },
    queryMonth(){

    },
    monthReset(){

    },
    queryDevice(){

    },
    deviceReset(){

    }
  }
}
</script>

<style scoped>

</style>