<template>
  <el-card shadow="never"
           class="aui-card--fill">
    <div class="mod-__metauserregisterrank}">
      <el-form :inline="true"
               :model="dataForm"
               @keyup.enter.native="getDataListSearch()">
        <el-form-item label="所属机构">
          <el-cascader v-model="deptIdList"
                       :options="options"
                       :props="{ checkStrictly: true }"
                       clearable></el-cascader>
        </el-form-item>
        <el-form-item label="截止日期">
          <el-date-picker v-model="dataForm.createdTime"
                          type="date"
                          placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="success" @click="getDataListSearch()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary"
                     @click="exportHandle()">{{ $t('export') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading"
                :data="dataList"
                border
                @selection-change="dataListSelectionChangeHandle"
                style="width: 100%;">
        <el-table-column prop="streetName"
                         label="街道名称"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="userCount"
                         label="用户总数"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="partyMemberCount"
                         label="党员数"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="residentCount"
                         label="已注册居民"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="unAuthorizedCount"
                         label="未注册居民"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="oldCount"
                         label="年龄超过50岁"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="oldPercent"
                         label="老龄化比例"
                         header-align="center"
                         align="center">
          <template slot-scope="scope">
            {{(scope.row.oldPercent*100).toFixed(2)}}%
          </template>
        </el-table-column>
        <el-table-column prop="youngCount"
                         label="50岁以下用户数量"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="youngPercent"
                         label="年轻化比例"
                         header-align="center"
                         align="center">
          <template slot-scope="scope">
            {{(scope.row.youngPercent*100).toFixed(2)}}%
          </template>
        </el-table-column>
        <el-table-column prop="maleCount"
                         label="男"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="femaleCount"
                         label="女"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="unknownSexCount"
                         label="未知性别"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="updatedTime"
                         label="更新时间"
                         header-align="center"
                         align="center"></el-table-column>
      </el-table>
      <el-pagination :current-page="page"
                     :page-sizes="[10, 20, 50, 100]"
                     :page-size="limit"
                     :total="total"
                     layout="total, sizes, prev, pager, next, jumper"
                     @size-change="pageSizeChangeHandle"
                     @current-change="pageCurrentChangeHandle">
      </el-pagination>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/analysis/metauserregisterrank/page',
        getDataListIsPage: true,
        deleteURL: '/analysis/metauserregisterrank',
        deleteIsBatch: true,
        exportURL: '/analysis/metauserregisterrank/export'
      },
      dataForm: {
        id: '',
        createdTime: ''
      },
      options: [],
      deptIdList: []
    }
  },
  created () {
    this.$http
      .get(`/sys/user/deptOptions/getByLoginUser`)
      .then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.options = res.data.options
      })
      .catch(() => { })
  },
  components: {
  },
  watch: {
    'deptIdList': function (val) {
      if (val.length !== 0) {
        this.dataForm.streetId = val[val.length - 1]
      } else {
        this.dataForm.streetId = ''
      }
    }
  }
}
</script>
