<template>
    <div style="margin-top: 10px; margin-left: 10px;">
        <a-row>
            <a-col :md="8" :sm="1">
                <div class="table-page-search-wrapper">
                <a-form layout="inline">
                    <a-row :gutter="30">
                        <a-col :md="18" :sm="10" >
                            <a-form-item label="关键词">
                                <a-input placeholder="请输入搜索关键词" v-model="queryParam.name"></a-input>
                            </a-form-item>
                        </a-col>
                        <a-col :md="6" :sm="10" >
                            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                                <a-button @click="loadData" type="primary" v-has="'cont:btn'" icon="search">查询</a-button>
                            </span>
                        </a-col>
                    </a-row>
                </a-form>
                </div>
                <a-table
                    ref="table"
                    size="middle"
                    bordered
                    rowKey="id"
                    :columns="columns"
                    :dataSource="dataSource"
                    @change="handleTableChange">
            <!--        :locale="myLocale"-->

                    <!-- 字符串超长截取省略号显示-->
                    <span slot="action" slot-scope="text, record">
                        <a @click="handleEdit(record)" v-has="'cont:btn'">选中</a>
                    </span>
                </a-table>
            </a-col>
            <a-col :md="16" :sm="2">
                <a-row>
                    <div class="quarter">
                        <div class="quarter-div">
                            <a-row>
                                <a-col :span="12" style="text-align: center;">
                                    <img style="margin-top: 10px;" :src="guaz" />
                                </a-col>
                                <a-col :span="12">
                                    <div style="margin-top: 14px">{{fileNum.totalNumRow}}</div>
                                    <div>结构化数据条数</div>
                                </a-col>
                            </a-row>
                        </div>
                        <div class="quarter-div">
                            <a-row>
                                <a-col :span="12" style="text-align: center;">
                                    <img style="margin-top: 10px;" :src="guaz" />
                                </a-col>
                                <a-col :span="12">
                                    <div style="margin-top: 14px">{{fileNum.totalFileSize}}GB</div>
                                    <div>非结构化文件(大小)</div>
                                </a-col>
                            </a-row>
                        </div>
                        <div class="quarter-div">
                            <a-row>
                                <a-col :span="12" style="text-align: center;">
                                    <img style="margin-top: 10px;" :src="guaz" />
                                </a-col>
                                <a-col :span="12">
                                    <div style="margin-top: 14px">{{fileNum.tableCount}}</div>
                                    <div>表数量</div>
                                </a-col>
                            </a-row>
                        </div>
                        <div class="quarter-div">
                            <a-row>
                                <a-col :span="12" style="text-align: center;">
                                    <img style="margin-top: 10px;" :src="guaz" />
                                </a-col>
                                <a-col :span="12">
                                    <div style="margin-top: 14px">{{ fileNum.fileLinkCount }}</div>
                                    <div>文件接引数量</div>
                                </a-col>
                            </a-row>
                        </div>
                        <div class="quarter-div">
                            <a-row>
                                <a-col :span="12" style="text-align: center;">
                                    <img style="margin-top: 10px;" :src="guaz" />
                                </a-col>
                                <a-col :span="12">
                                    <div style="margin-top: 14px">{{ fileNum.docFileCount }}</div>
                                    <div>文档数量</div>
                                </a-col>
                            </a-row>
                        </div>
                    </div>
                </a-row>
                <a-row>
                    <a-col :md="12" :sm="2">
                        <div id="cleaningVariance" class="cleaningVariance" ref="cleaningVariance"></div>
                    </a-col>
                    <a-col :md="12" :sm="2">
                        <div id="totalNumberCatalogues" class="totalNumberCatalogues" ref="totalNumberCatalogues"></div>
                    </a-col>
                </a-row>
            </a-col>
        </a-row>
    </div>
  </template>
  
  <script>
    import { shipModelPageList,
        shipModeldeleteById } from '@/api/ship'
    import { getDataAnalysis,
        taskPageList, } from '@/api/task'
   import { getAction } from '@/api/manage'
   import JEllipsis from "@/components/jeecg/JEllipsis";
   import guaz from '@assets/guaz.png'
   export default {
      name: "statistics",
      components: {
        JEllipsis
      },
      data () {
        return {
          description: '任务统计',
          dataSource: [],
          guaz,
          queryParam: {
            pageNum :1,
            pageSize:20,
            name:""
          },
          columns: [
            {
                title: '#',
                dataIndex: '',
                key:'id',
                width:60,
                align:"id",
                customRender:function (t,r,index) {
                return parseInt(index)+1;
                }
            },
            {
                title: '任务名称',
                align:"name",
                dataIndex: 'name',
            },
            {
                title: '结束时间',
                align:"endTime",
                dataIndex: 'endTime',
            },
            {
                title: '操作',
                dataIndex: 'action',
                align:"center",
                width:180,
                scopedSlots: { customRender: 'action' },
            }
          ],
          fileNum:{
            totalNumRow:0,
            tableCount:0,
            docFileCount:0,
            totalFileSize:0,
            fileLinkCount:0
          },
          cleaningVariancesource:[]
        }
      },
      mounted() { 
         this.getTables()
         this.loadData();
      },
      computed: {

      },
      destroyed: function () { 
      },
      created () {
  
      },
      methods: {
        //筛选需要重写handleTableChange
        handleTableChange(pagination, filters, sorter) {
            //分页、排序、筛选变化时触发
            //TODO 筛选
            if (Object.keys(sorter).length > 0) {
            this.isorter.column = sorter.field;
            this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
            }
            this.ipagination = pagination;
            this.loadData();
        },
        handleEdit(value){
            this.cleaningVariancesource =[];
            getDataAnalysis({taskId:value.id,startDate:value.startTime,endDate:value.endTime}).then((res) => {
                if (res.success) {
                   res.result.schemaNames.forEach(row => {
                    this.cleaningVariancesource.push([row, parseInt(res.result.numRowMap[row]) ])
                   })
                   this.fileNum.totalNumRow = res.result.totalNumRow
                   this.fileNum.tableCount = res.result.tableCount
                   this.fileNum.docFileCount = res.result.docFileCount
                   this.fileNum.totalFileSize = res.result.totalFileSize
                   this.fileNum.fileLinkCount = res.result.fileLinkCount
                   this.getcleaningVariance();
                } else {
                    this.$message.warning(res.message);
                }
            });
        },
        loadData() {
            taskPageList(this.queryParam).then((res) => {
                if (res.success) {
                    this.dataSource = res.result.rows||res.result;
                } else {
                    this.$message.warning(res.message);
                }
            });
        },
        getTables(){
           
            this.gettotalNumberCatalogues();
        },
        getcleaningVariance(){
          var myChart = this.$echarts.init(this.$refs.cleaningVariance);
          var option = {
                title: {
                    text: '数据清洗差异统计'
                },
                legend: {},
                tooltip: {},
                dataset: {
                    source: this.cleaningVariancesource
                },
                xAxis: { type: 'category',
                nameTextStyle: {
                    align: "center"
                } },
                yAxis: {},
                // Declare several bar series, each will be mapped
                // to a column of dataset.source by default.
                series: [{ type: 'bar' }],
                color:['#5470c6', '#91cc75', '#fac858', '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc']
            };
           myChart.setOption(option);
        },
        gettotalNumberCatalogues(){
          var myChart = this.$echarts.init(this.$refs.totalNumberCatalogues);
          var option = {
            title: {
                text: '数据类型存储占比统计',
                left: 'left'
            },
            tooltip: {
                trigger: 'item'
            },
            legend: {
                bottom: 10,
                left: 'center',
            },
            series: [
                {
                name: '占比',
                type: 'pie',
                radius: '50%',
                data: [
                    { value: 1048, name: '文档' },
                    { value: 735, name: '视频' },
                    { value: 580, name: '音频' },
                    { value: 484, name: '结构化数据' },
                ],
                emphasis: {
                    itemStyle: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
                }
            ],
            color:['#5470c6', '#91cc75', '#fac858', '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc']
            };
            myChart.setOption(option);
        },
      }
    }
  </script>
  <style scoped>
    @import '~@assets/less/common.less';

    .quarter-div {
        width: 18%;
        height: 100px;
        float: left;
        margin-right: 6px;
        background: #edf2ff;
        border: 1px solid #d3e5fd;
        border-radius: 10px;
    }
    /deep/ .ant-layout-sider {
        background: #f6f8ff !important;
        border: 1px solid #dfe4f3;
        border-radius: 10px;
        height: calc(100vh - 180px);
        min-width: 200px !important;
        margin-left: 0px;
        margin-right: 50px;
    }
    .cleaningVariance {
        width: 620px; height: 450px; float: left; padding: 30px 10px 10px 20px;
    }
    .totalNumberCatalogues {
        width: 620px; height: 450px; float: right; padding: 30px 10px 10px 20px;
    }
    .quarter {
        margin-left: 10px; margin-bottom: 20px;padding: 30px 10px 10px 20px;
    }
  </style>