<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" />

    <div class="m-10 bg-w p-20 br-10">
      <!--  <el-button type="primary" icon="el-icon-plus" @click="handleSubmit"
        >新增</el-button
      > -->
      <base-table
        :columns="columns"
        :items="items"
        :pagination="pagination"
        :page-change="pageChange"
      />
    </div>
  </div>
</template>

<script>
import toolbar from './toolbar';
import mxFilterList from '@/mixins/filterList';
import { getPage, getCount } from '@/api/system/account';

export default {
  name: 'AccountManagement',

  components: { toolbar },

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

  data() {
    return {
      statistics: {},
      columns: [
        {
          key: 'id',
          name: '#',
          minWidth: this.$col.b
        },
        {
          key: 'mobileNumber',
          name: '手机号码',
          minWidth: this.$col.b
        },
        {
          key: 'nickname',
          name: '昵称'
        },
        {
          key: 'avatarUrl',
          name: '头像',
          width: '120',
          render: (h, { row }) => {
            if (!row.avatarUrl) {
              return h('span', '-');
            }
            return h('img', {
              style: {
                width: '160px',
                height: '90px'
              },
              class: 'pre-img',
              attrs: {
                src: row.avatarUrl
              },
              on: {
                click: () =>
                  this.$AdvanceViewImageModal({
                    items: [{ src: row.avatarUrl }]
                  })
              }
            });
          }
        },
        {
          key: 'gender',
          name: '性别',
          width: '120',
          type: 'tag',
          fetchTagType: val => 'info',
          tagName: row =>
            row.gender === 0 ? '未知' : row.gender === 1 ? '男' : '女'
        },
        {
          key: 'isLocked',
          name: '封锁状态',
          width: '80',
          type: 'tag',
          fetchTagType: val => (val ? 'danger' : 'info'),
          tagName: row => (row.isLocked ? '是' : '否')
        },
        {
          key: 'createAt',
          name: '注册时间',
          width: this.$col.b
        }
        // {
        //   key: 'action',
        //   name: '操作',
        //   width: '120'
        // }
      ]
    };
  },
  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 getCount(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>
