<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 { secKillGoodsSpecListPageV2, secKillGoodsSpecListPageV2Export, closeGoodsStatus, openGoodsStatus, deleteGoods } from '@/api/seckill'

export default {
  components: { TemplatePage },
  mixins: [import_mixin],
  data() {
    return {
      type: "",
      statistics: {},
      // 事件组合
      optionsEvensGroup: [],
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: false
      },
      // 表格事件
      tableEvents: {
        'selection-change': this.selectionChange
      },
      // 勾选选中行
      recordSelected: [],
    }
  },
  computed: {
    // 更多参数
    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 secKillGoodsSpecListPageV2(pam)
      } catch (error) {
        console.log(error)
      } finally {

      }
    },
    // 列表导出函数
    exportList: secKillGoodsSpecListPageV2Export,
    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      if (item.jname === 'imgUrl') {
        defaultData.render = (h, { row, column, index }) => {
          return <div style="width: 100px; height: 100px; overflow: hidden">
            <el-image style="width: 100px; height: 100px" src={row.imgUrl} fit="fit"></el-image>
          </div>
        }
      }
      return defaultData
    },
    // 监听勾选变化
    selectionChange(data) {
      this.recordSelected = data
    },
    // 表格操作列
    operation(h, { row, index, column }) {
      return (
        <div class='operation-btns'>
          <el-popconfirm
            title={`是否确定${row.status ? "关闭" : "开启"}？`}
            onConfirm={() => {
              (row.status ? closeGoodsStatus : openGoodsStatus)({ secKillSpecId: row.secKillSpecId }).then(res => {
                this.$message({ type: 'success', message: `${row.status ? "关闭" : "开启"}成功!` })
                this.$refs.pageRef.refreshList()
              })
            }}
          >
            <el-button type="text" slot="reference">{row.status ? "关闭" : "开启"}</el-button>
          </el-popconfirm>
          <el-popconfirm
            title={`是否确定删除？`}
            onConfirm={() => {
              deleteGoods({ secKillSpecId: row.secKillSpecId }).then(res => {
                this.$message({ type: 'success', message: `删除成功!` })
                this.$refs.pageRef.refreshList()
              })
            }}
          >
            <el-button type="text" slot="reference">删除</el-button>
          </el-popconfirm>
        </div>
      )
    },
  }
}
</script>

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