<template>
  <div class="">
    <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 { getList, delItem } from '@/api/photoWarehouse';

export default {
  name: 'ImageGoodsManagement',

  components: { toolbar },

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

  data() {
    return {
      columns: [
        {
          key: 'listPreview',
          name: '图片',
          width: '160',
          render: (h, { row }) =>
            h('img', {
              style: {
                width: '160px',
                height: '90px'
              },
              attrs: {
                src: row.listPreview
              },
              on: {
                click: () =>
                  this.$AdvanceViewImageModal({
                    items: [{ src: row.listPreview }]
                  })
              }
            })
        },
        {
          key: 'location',
          name: '上传位置',
          minWidth: '180',
          render: (h, { row }) =>
            h('span', `${row.kindergartenName}/${row.activityName}`)
        },
        {
          key: 'createAt',
          name: '上传时间',
          width: '140'
        },
        {
          key: 'likes',
          name: '点赞数',
          width: '140'
        },
        {
          key: 'collections',
          name: '收藏数',
          width: '140'
        },
        {
          key: 'hdLogoPhotoPrice',
          name: '高清价',
          width: '140',
          render: (h, { row }) => h('span', `${row.hdLogoPhotoPrice}`)
        },
        {
          key: 'originPhotoPrice',
          name: '原图价',
          width: '140',
          render: (h, { row }) => h('span', `${row.originPhotoPrice}`)
        },
        {
          key: 'isShow',
          name: '状态',
          width: '80',
          type: 'tag',
          fetchTagType: val => (val ? 'success' : 'info'),
          tagName: row => (row.isShow ? '上架' : '下架')
        },
        {
          key: 'action',
          name: '操作',
          width: '120',
          render: (h, { row }) => {
            const action = [];
            action.push(
              h(
                'el-button',
                {
                  props: {
                    type: 'text'
                  },
                  on: {
                    click: () =>
                      this.$ImageGoodsItemModal({
                        id: row.id
                      })
                  }
                },
                '编辑'
              )
            );
            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('photot_reload', this.reload);
  },

  beforeDestroy() {
    this.$g_off('photot_reload', this.reload);
  }
};
</script>

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