<template>
  <!-- 数据分析 -->
  <template-page
    ref="pageRef"
    :get-list="getList"
    :export-list="exportList"
    :options-evens-group="optionsEvensGroup"
    :column-parsing="columnParsing"
  />
</template>

<script>
import TemplatePage from '@/components/template/template-page-1.vue'
import import_mixin from '@/components/template/import_mixin.js'
import add_callback_mixin from '@/components/template/add_callback_mixin.js'

import {
  getDataList,
  exportDataList
} from '@/api/dataAnalysis'

export default {
  components: { TemplatePage },
  mixins: [import_mixin, add_callback_mixin],
  data() {
    return {
      visible: false,
      // 事件组合
      optionsEvensGroup: [
        [
          [
            {
              name: '是否更新',
              click: () => {
                this.$alert(!this.valve ? '是否开启更新?' : '是否关闭更新?', '提示', {
                  confirmButtonText: '确定',
                  callback: (e) => {
                    if (e === 'confirm') {
                      this.valve = !this.valve
                      if (this.valve) {
                        this.timer = setInterval(() => {
                          this.$refs.pageRef.refreshList()
                        }, 5000)
                      } else {
                        clearInterval(this.timer)
                        this.timer = null
                      }
                    }
                  }
                })
              }
            }
          ]
        ]
      ],
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: true
      }, // 关闭新增弹窗

      // 表格事件
      tableEvents: {
        'selection-change': this.selectionChange
      },
      recordSelected: [],

      detailsId: '',
      valve: false,
      timer: null
    }
  },
  deactivated() {
    clearInterval(this.timer)
    this.timer = null
  },
  methods: {
    // 列表请求函数
    getList(...p) {
      this.recordSelected = []
      return getDataList(...p)
    },
    // 列表导出函数
    exportList: exportDataList,
    // 表格列解析渲染数据更改
    columnParsing(_item, defaultData) {
      return defaultData
    },
    // 监听勾选变化
    selectionChange(data) {
      this.recordSelected = data
    },
    operation() {
      return (_h, { row, index, column }) => {
        return (
          <div class='operation-btns'>
            <el-button
              size='mini'
              type='text'
              onClick={ () => {
                this.visible = true
                this.orderCode = row.id
              }}
            >
              编辑
            </el-button>
          </div>
        )
      }
    },
    handleClose() {
      this.addOff(() => {
        this.visible = false
      })()
    }
  }
}
</script>

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