<template>
  <div class="">
    <div class="m-10 bg-w p-20 br-10">
      <div class="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>
    </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="$AliOssMultiModal()"
        >批量上传照片</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, delItem } from '@/api/photoWarehouse';

export default {
  name: 'PhotoVerify',

  components: { toolbar },

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

  data() {
    return {
      statistics: {},
      columns: [
        {
          key: 'id',
          name: '标识',
          width: this.$col.b
        },
        {
          key: 'activityName',
          name: '活动',
          minWidth: this.$col.b
        },
        {
          key: 'nickname',
          name: '账号昵称',
          minWidth: this.$col.b
        },
        {
          key: 'nickname',
          name: '账号昵称',
          minWidth: this.$col.b
        },
        {
          key: 'phonenumber',
          name: '账号手机号码',
          width: this.$col.m
        },
        {
          key: 'listPreview',
          name: '列表预览图',
          width: this.$col.b,
          render: (h, { row }) => {
            if (!row.listPreview) {
              return h('span', '图片正在处理中请稍等...');
            }
            return h('img', {
              style: {
                width: '160px',
                height: '90px'
              },
              class: 'pre-img',
              attrs: {
                src: row.listPreview
              },
              on: {
                click: () =>
                  this.$AdvanceViewImageModal({
                    items: [{ src: row.listPreview }]
                  })
              }
            });
          }
        },
        {
          key: 'createAt',
          name: '上传时间',
          width: this.$col.b
        },
        {
          key: 'auditStatus',
          name: '状态',
          width: this.$col.s,
          type: 'tag',
          fetchTagType: val => {
            switch (val) {
              case 1:
                return 'success';
              case 0:
                return 'info';
              case -1:
                return 'danger';
              default:
                return 'info';
            }
          },
          tagName: row => {
            switch (row.auditStatus) {
              case 1:
                return '通过';
              case 0:
                return '待审核';
              case -1:
                return '拒绝';
              default:
                return '-';
            }
          }
        },
        {
          key: 'action',
          name: '操作',
          width: '120',
          render: (h, { row }) => {
            const action = [];
            action.push(
              h(
                'BaseBtn',
                {
                  props: {
                    popip: true,
                    txt: '删除',
                    type: 'text'
                  },
                  class: 'ml-10',
                  on: {
                    ok: () => this.handleDelItem(row)
                  }
                },
                '删除'
              )
            );
            return h('div', action);
          }
        }
      ]
    };
  },

  created() {
    this.$g_on('photo_reload', this.reload);
  },

  beforeDestroy() {
    this.$g_off('photo_reload', this.reload);
  },

  methods: {
    async handleDelItem(item) {
      const { success, msg } = await delItem({
        id: item.id
      });
      if (success) {
        this.$success('删除成功！');
        this.$g_emit('photo_reload');
      }
    },
    async pageChange(page) {
      this.pagination.page = page;
      const inParams = {
        ...this.filter,
        ...this.internalFilterObj,
        start: this.pagination.page,
        limit: this.pagination.pageSize
      };

      const { data, msg } = await this.apiList(inParams);

      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>
