<template>
  <div class="">
    <div
      class="m-10 bg-w p-20 br-10 f-sa-s">
      <div class="f-fs-c f-col">
        <div style="font-size: 16px;">总量</div>
        <div class="mt-4" style="font-weight: bold; font-size: 18px;">{{statistics.all}}</div>
      </div>
      <div class="f-fs-c f-col">
        <div style="font-size: 16px;">月新增</div>
        <div class="mt-4" style="font-weight: bold; font-size: 18px;">{{statistics.month}}</div>
      </div>
      <div class="f-fs-c f-col">
        <div style="font-size: 16px;">周新增</div>
        <div class="mt-4" style="font-weight: bold; font-size: 18px;">{{statistics.week}}</div>
      </div>
    </div>

    <toolbar @on-filter="filterData" @on-reset="filterData" />

    <base-table
      class="m-10 bg-w p-20 br-10"
      :columns="columns"
      :items="items"
      :pagination="pagination"
      :page-change="pageChange"
    />
  </div>
</template>

<script>
import toolbar from './toolbar';
import mxFilterList from '@/mixins/filterList';
import { getUploadPage, getUploadCount } from '@/api/statistics';


export default {
  name: 'UploadImage',

  components: { toolbar },

  mixins: [
    mxFilterList({
      fetchList: getUploadPage // 在下方data再声明一个 fetchList: iGetList 同等效果
    })
  ],

  data() {
    return {
      statistics: {},
      columns: [
        {
          key: 'kindergartenName',
          name: '场景',
          minWidth: this.$col.b
        },
        {
          key: 'activityName',
          name: '活动',
          minWidth: this.$col.b
        },
        {
          key: 'nickname',
          name: '账号昵称',
          minWidth: this.$col.b
        },
        {
          key: 'phonenumber',
          name: '账号手机号码',
          width: this.$col.m
        },
        {
          key: 'isTakeTrue',
          name: '手机上传数',
          minWidth: '120'
        },
        {
          key: 'isTakeFalse',
          name: '电脑上传数',
          minWidth: '120'
        },
        {
          key: 'isTake',
          name: '总上传数',
          width: '140',
          render:(h, {row}) => h('span', `${row.isTakeTrue+row.isTakeFalse}`)
        },
        {
          key: 'createAt',
          name: '上传时间',
          minWidth: this.$col.b
        },
      ]
    };
  },
  methods:{
    async pageChange(page) {
      this.pagination.page = page;
      const inParams = {
        ...this.filter,
        ...this.internalFilterObj,
        page: this.pagination.page,
        size: this.pagination.pageSize
      };

      const { data, msg } = await this.apiList(inParams, {
        limit: this.pagination.pageSize,
        start: this.pagination.page
      });

      const res2 = await getUploadCount(inParams)
      this.statistics = res2.data
      if ('data' in data) {
        const items = data.data;
        if (items.length === 0 && this.pagination.page > 1) {
          this.pageChange(1);
        } else {
          this.items = items;
          this.pagination.total = data.total;
        }
        this.loadCallBack(data);
      }
    }
  }
};
</script>

<style type="scss" scoped></style>
