<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="导入时间" prop="drsjeQuery">
        <el-date-picker style="width:200px"
                        v-model="queryParams.drsjQuery"
                        type="monthrange"
                        align="right"
                        unlink-panels
                        range-separator="至"
                        start-placeholder="开始月份"
                        end-placeholder="结束月份"
                        value-format="yyyy-MM"
                        @change="handleQuery"
                        :picker-options="pickerOptions">
        </el-date-picker>
      </el-form-item>
<!--      <el-form-item>-->
<!--        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
<!--        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
<!--      </el-form-item>-->
    </el-form>

    <el-row :gutter="20">
      <!--部门数据-->
      <el-col :span="4" :xs="24">
        <el-tree
          :data="deptOptions"
          :props="defaultProps"
          :expand-on-click-node="false"
          :filter-node-method="filterNode"
          ref="tree"
          node-key="id"
          default-expand-all
          highlight-current
          @node-click="handleNodeClick"/>
      </el-col>
      <el-col :span="20" :xs="24">
        <el-card>
          <h3>整体情况</h3>
          <el-row :gutter="20">
            <el-col :span="4" style="margin-bottom: 10px">
              <div>
                <el-statistic
                  group-separator=","
                  :value="statisticsData.total"
                  title="图斑总数">
                </el-statistic>
              </div>
            </el-col>
            <el-col :span="4">
              <div>
                <el-statistic
                  :value="statisticsData.kc"
                  title="矿产图斑">
                </el-statistic>
              </div>
            </el-col>
            <el-col :span="4">
              <div>
                <el-statistic
                  group-separator=","
                  :value="statisticsData.td"
                  title="土地图斑">
                </el-statistic>
              </div>
            </el-col>
            <el-col :span="4">
              <div>
                <el-statistic
                  group-separator=","
                  :value="statisticsData.yxf"
                  title="已下发">
                </el-statistic>
              </div>
            </el-col>
            <el-col :span="4">
              <div>
                <el-statistic
                  group-separator=","
                  :value="statisticsData.wxf"
                  title="未下发">
                </el-statistic>
              </div>
            </el-col>
          </el-row>
          <el-row :gutter="20" style="margin-bottom: 10px">
            <el-col :span="4">
              <div>
                <el-statistic
                  group-separator=","
                  :value="statisticsData.yxc"
                  title="已巡查">
                </el-statistic>
              </div>
            </el-col>
            <el-col :span="4">
              <div>
                <el-statistic
                  group-separator=","
                  :value="statisticsData.zjxc"
                  title="州级巡查">
                </el-statistic>
              </div>
            </el-col>
            <el-col :span="4">
              <div>
                <el-statistic
                  group-separator=","
                  :value="statisticsData.xjxc"
                  title="县级巡查">
                </el-statistic>
              </div>
            </el-col>
            <el-col :span="4">
              <div>
                <el-statistic
                  group-separator=","
                  :value="statisticsData.wxc"
                  title="未巡查">
                </el-statistic>
              </div>
            </el-col>
          </el-row>
          <el-row :gutter="20" style="margin-bottom: 10px">
            <el-col :span="4">
              <div>
                <el-statistic
                  group-separator=","
                  :value="statisticsData.yzg"
                  title="已整改">
                </el-statistic>
              </div>
            </el-col>
            <el-col :span="4">
              <div>
                <el-statistic
                  group-separator=","
                  :value="statisticsData.wzg"
                  title="未整改">
                </el-statistic>
              </div>
            </el-col>
            <el-col :span="4">
              <div>
                <el-statistic
                  group-separator=","
                  :value="statisticsData.wzgdw"
                  title="未整改到位">
                </el-statistic>
              </div>
            </el-col>
            <el-col :span="4">
              <div>
                <el-statistic
                  group-separator=","
                  :value="statisticsData.shtg"
                  title="审核通过">
                </el-statistic>
              </div>
            </el-col>
            <el-col :span="4">
              <div>
                <el-statistic
                  group-separator=","
                  :value="statisticsData.shbtg"
                  title="审核不通过">
                </el-statistic>
              </div>
            </el-col>
          </el-row>
        </el-card>
        <el-card>
          <h3>巡查情况统计</h3>
          <ve-histogram :data="histogramData" :settings="chartSettings"></ve-histogram>
        </el-card>
        <el-card>
          <h3>每日巡查情况 <el-date-picker
            v-model="queryParams.lineDateQuery"
            type="month"
            align="right"
            value-format="yyyy-MM"
            @change="handleLineDataQuery"
            placeholder="选择月份">
          </el-date-picker></h3>
          <ve-line :data="lineData" :settings="chartSettings"></ve-line>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {getStatistics} from "@/api/cxxm/statistics";
import {deptTreeSelect, getUser} from "@/api/system/user";

export default {
  name: "Index",
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      // 部门树选项
      deptOptions: null,
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 查询参数
      queryParams: {
        deptId: null,
        drsjQuery: [],
        lineDateQuery: null
      },
      // 日期区间选择
      pickerOptions: {
        shortcuts: [{
          text: '本月',
          onClick(picker) {
            picker.$emit('pick', [new Date(), new Date()]);
          }
        }, {
          text: '今年至今',
          onClick(picker) {
            const end = new Date();
            const start = new Date(new Date().getFullYear(), 0);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近六个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setMonth(start.getMonth() - 6);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      statisticsData: null,
      chartSettings: {
        yAxisType: ['KMB'],
        yAxisName: ['数值'],
        labelMap: {
          'deptName': '部门名称',
          'yxf': '已下发',
          'wxf': '未下发',
          'yxc': '已巡查',
          'wxc': '未巡查',
          'zjxc': '州级巡查',
          'xjxc': '县级巡查',
          'yzg': '已整改',
          'wzg': '未整改',
          'wzgdw': '未整改到位',
          'shtg': '审核通过',
          'shbtg': '审核不通过',
        },
      },
      histogramData: {
        columns: ['deptName', 'yxf', 'wxf', 'yxc', 'wxc', 'zjxc', 'xjxc', 'yzg', 'wzg', 'wzgdw', 'shtg', 'shbtg'],
        rows: []
      },
      lineData: {
        columns: ['日期', "楚雄市", "禄丰市", "大姚县", "姚安县", "武定县", "双柏县", "牟定县", "南华县", "永仁县", "元谋县"],
        rows: []
      },
    };
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      if (this.queryParams.deptId == null) {
        // 部门数据
        deptTreeSelect().then(response => {
          this.queryParams.deptId = response.data[0].id;
          this.deptOptions = response.data;
          // 统计数据
          getStatistics(this.queryParams).then(response => {
            this.statisticsData = response.data
            this.histogramData.rows = response.data.histogramData
            this.lineData.rows = response.data.lineData
          })
        });
      }else{
        // 统计数据
        getStatistics(this.queryParams).then(response => {
          this.statisticsData = response.data
          this.histogramData.rows = response.data.histogramData
          this.lineData.rows = response.data.lineData
        })
      }
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.deptId = data.id;
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getData();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.drsjQuery = []
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleLineDataQuery(){
      this.getData();
    }
  }
};
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }

  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }

  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
</style>

