<template>
  <div>
    <YMTableSearch :loading="loading" :search-form="searchForm" @onValueChange="onValueChange" @submit="onSubmit" />
    <YMTable
      ref="table"
      :table-key="1"
      :index="true"
      :selection="false"
      :table-options="tableOptions"
      :edit-form="editForm"
      :edit-config="editConfig"
      :columns="columns"
      :rows-actions="rowsActions"
      :show-summary="false"
      :apis="apis"
      :custom-style="{ height: 'calc(100vh - 310px)' }"
      @onResponse="onResponse"
    />

  </div>
</template>
<script>

export default {
  data() {
    return {
      loading: false,
      visibleBasicDrawer: false,
      renderContent: '',
      searchForm: [
        {
          label: '汇总类型',
          type: 'select',
          prop: 'xxxx',
          clearable: false,
          options: [
            {
              value: 0,
              label: '否'
            },
            {
              value: 1,
              label: '是'
            }
          ]
        },
        {
          label: '时间',
          type: 'datetimerange',
          prop: 'xxxx',
          clearable: false
        }
      ],
      columns: [
        {
          label: '时间',
          prop: 'xxxx'
        },
        {
          label: 'H5注册',
          prop: 'xxxx'
        },
        {
          label: 'app注册',
          prop: 'xxxx'
        },
        {
          label: 'H5首存次数',
          prop: 'xxxx'
        },
        {
          label: 'app首存次数',
          prop: 'xxxx'
        },
        {
          label: '活跃会员',
          prop: 'xxxx'
        },
        {
          label: '存款总额',
          prop: 'xxxx'
        },
        {
          label: '下单总数',
          prop: 'xxxx'
        },
        {
          label: '公司盈利',
          prop: 'xxxx'
        },
        {
          label: '商城',
          prop: 'xxxx'
        },
        {
          label: 'SYOAI',
          prop: 'xxxx'
        },
        {
          label: '订阅',
          prop: 'xxxx'
        },
        {
          label: 'KTV',
          prop: 'xxxx'
        },
        {
          label: '总计',
          prop: 'xxxx'
        }
      ],
      rowsActions: [],
      apis: {
        list: {
          url: 'chart/user/converge',
          dataParam: 'data.list',
          resultParam: 'data',
          init: false
        },
        add: {
          url: '',
          cover: true,
          coverMethod: (row, node) => {
            return row.year + '、' + node[0].label
          }
        },
        edit: {
          url: '',
          cover: true,
          coverMethod: (row, node) => {
            return row.year + '、' + node[0].label
          }
        },
        preview: {
          url: '',
          dataParam: 'datas',
          keyParam: 'cache_key'
        },
        import: {
          url: '',
          params: 'cache_key'
        },
        batchDelete: {
          url: '',
          params: 'ids'
        },
        delete: {
          url: '',
          params: 'ids'
        }
      },
      tableOptions: {
        add: {
          show: false,
          initData: () => {
            return { test: 'test' }
          }
        },
        import: {
          show: false,
          tip: '注：备注',
          columns: [
            {
              label: '严控',
              prop: 0,
              required: true
            }
          ]
        },
        export: {
          show: false,
          dataName: 'xxx.xlsx',
          baseApi: process.env.VUE_APP_BASE_IMG + '/',
          theadMap: [
            {
              xxxx: {}
            }
          ],
          theadProps: {
            xxxx: {}
          }
        },
        download: {
          show: false,
          url: '/static/template.xlsx'
        },
        batchDelete: {
          show: false
        }
      },
      editForm: [
        {
          body: [
            {
              label: '年度',
              type: 'year',
              prop: 'year',
              clearable: false,
              rules: [
                {
                  required: true,
                  message: '请选择年度',
                  trigger: 'change'
                }
              ]
            }
          ]
        }
      ],
      editConfig: {
        addTip: '注：备注',
        editTip: '注：备注'
      },
      countData: {}
    }
  },
  created() {
  },
  mounted() {
    this.onSubmit()
  },
  methods: {
    onResponse(data) {
      var arr = []
      for (const key in data) {
        arr.push({ year: key, ...data[key] })
      }
      return arr
    },
    onValueChange(val) {

    },
    onSubmit(params) {
      this.$refs.table.getList(params)
    }
  }
}
</script>
