<template>
  <template-page ref="pageRef" :get-list="getList" :table-attributes="tableAttributes" :table-events="tableEvents"
    :options-evens-group="optionsEvensGroup" :moreParameters="moreParameters" :column-parsing="columnParsing"
    :operation="operation()" :exportList="exportList">
    <div slot="moreSearch">
      <el-radio-group v-model="type" size="mini" @change="changeType">
        <el-radio-button label="">全部</el-radio-button>
        <el-radio-button :label="true">启用</el-radio-button>
        <el-radio-button :label="false">禁用</el-radio-button>
      </el-radio-group>
      <br><br>
    </div>
  </template-page>
</template>

<script>
import TemplatePage from '@/components/template/template-page-1.vue'
import import_mixin from '@/components/template/import_mixin.js'
import { closeActivityStatus, openActivityStatus, secKillGoodsActivityListPageV2, secKillGoodsActivityListPageV2Export } from '@/api/seckill'
import operation_mixin from '@/components/template/operation_mixin.js'
export default {
  components: { TemplatePage },
  mixins: [import_mixin,operation_mixin],
  data() {
    return {
      type: "",
      statistics: {},
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: false
      },
      // 表格事件
      tableEvents: {
        'selection-change': this.selectionChange
      },
      // 勾选选中行
      recordSelected: [],
    }
  },
  computed: {
	// 事件组合
	optionsEvensGroup() {
		return [
			[
				[
					this.optionsEvensAuth("add", {
						click: () => {
							this.$router.push({
							  name: "seckill_add",
							  query: {}
							})
						}
					})
				],
			]
		]
	},
    // 更多参数
    moreParameters() {
      return []
    },
  },
  methods: {
    // 切换状态
    changeType(val) {
      this.$refs.pageRef.refreshList()
    },
    // 列表请求函数
    getList(p) {
      try {
        var pam = JSON.parse(JSON.stringify(p))
        if (this.type !== '') {
          pam.status = this.type
          pam.params.push({ "param": "a.status", "compare": "=", "value": this.type })
        }
        return secKillGoodsActivityListPageV2(pam)
      } catch (error) {
        console.log(error)
      } finally {

      }
    },
    // 列表导出函数
    exportList: secKillGoodsActivityListPageV2Export,
    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      return defaultData
    },
    // 监听勾选变化
    selectionChange(data) {
      this.recordSelected = data
    },
	// 表格操作列
	operation() {
		return this.operationBtn({
		  edit: {
			btnType: 'text',
		    click: ({ row, index, column }) => {
		      this.$router.push({
		        name: "seckill_add",
		        query: {
		          id: row.secKillId
		        }
		      })
		    }
		  },
		  status: {
				btnType: 'text',
				name: ({ row, index, column }) => {
					return row.status ? "关闭" : "开启"
				},
					prompt:  ({ row, index, column }) => {
					return `是否确定${row.status ? "关闭" : "开启"}？`
				},
		    click: ({ row, index, column }) => {
		      (row.status ? closeActivityStatus : openActivityStatus)({ secKillId: row.secKillId }).then(res => {
		        this.$message({ type: 'success', message: `${row.status ? "关闭" : "开启"}成功!` })
		        this.$refs.pageRef.refreshList()
		      })
		    }
		  },
		})
	},
  }
}
</script>

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