<template>
  <div class="app-container">
    <!-- 顶部操作区域 -->
    <div class="filter-container">
      <div class="filter-control">
        <span>活动名称:</span>
        <el-input
          v-model="listQuery.name"
          placeholder="活动名称"
          clearable
          @keyup.enter.native="getList"
          @clear="getList"
        />
      </div>
      <div class="filter-control">
        <span>小程序状态:</span>
        <el-select v-model="listQuery.status" style="width: 120px" clearable @change="getList">
          <el-option value="" label="请选择" />
          <el-option :value="1" label="未开始" />
          <el-option :value="2" label="进行中" />
          <el-option :value="3" label="已结束" />
        </el-select>
      </div>
      <div class="filter-control">
        <span>状态:</span>
        <el-select v-model="listQuery.activityStatus" style="width: 120px" clearable @change="getList">
          <el-option value="" label="请选择" />
          <el-option :value="1" label="已启用" />
          <el-option :value="2" label="已停用" />
        </el-select>
      </div>
      <div class="filter-control">
        <el-button type="primary" @click="getList"> 查询 </el-button>
        <el-button type="primary" @click="getList"> 添加活动 </el-button>
      </div>
    </div>
    <!-- 列表 -->
    <el-table v-loading="isLoading" :data="list" border style="width: 100%" height="660">
      <el-table-column prop="name" label="活动名称" align="center" width="200">
        <template slot-scope="{ row }">
          {{ row.name ? row.name : '---' }}
        </template>
      </el-table-column>
      <el-table-column prop="status" label="小程序状态" align="center" width="200">
        <template slot-scope="{ row }">
          <el-tag v-if="row.status === 1" type="success" size="small">已启用</el-tag>
          <el-tag v-else type="info" size="small">已停用</el-tag>
          <el-button
            v-if="row.status === 2"
            type="success"
            size="mini"
            style="margin: 4px"
            @click="handleShangeStatus(row.id, row.status)"
          >
            启用
          </el-button>
          <el-button
            v-else
            type="warning"
            size="mini"
            style="margin: 4px"
            @click="handleShangeStatus(row.id, row.status)"
          >
            停用
          </el-button>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="小程序状态" align="center" width="200">
        <template slot-scope="{ row }">
          <el-tag v-if="row.status === 1" type="warning" size="small">未开始</el-tag>
          <el-tag v-if="row.status === 2" type="success" size="small">进行中</el-tag>
          <el-tag v-if="row.status === 3" type="info" size="small">已结束</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="beginTime" label="开始时间" align="center">
        <template slot-scope="{ row }">
          {{ row.beginTime ? row.beginTime : '---' }}
        </template>
      </el-table-column>
      <el-table-column prop="endTime" label="结束时间" align="center">
        <template slot-scope="{ row }">
          {{ row.endTime ? row.endTime : '---' }}
        </template>
      </el-table-column>
      <el-table-column prop="addTime" label="创建时间" align="center">
        <template slot-scope="{ row }">
          {{ row.addTime ? row.addTime : '---' }}
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center">
        <template slot-scope="{ row }">
          <el-button type="primary" size="mini" style="margin: 2px" @click="handleRecordDetail(3, row)">
            商品列表
          </el-button>
          <el-button type="primary" size="mini" style="margin: 2px" @click="handleRecordDetail(3, row)">
            编辑
          </el-button>
          <el-button type="danger" size="mini" style="margin: 2px" @click="handleRecordDetail(3, row)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 页码 -->
    <pagination
      :total="total"
      :page-sizes="[10, 20, 30, 100]"
      :page-size="20"
      :page.sync="listQuery.pageNum"
      :limit.sync="listQuery.pageSize"
      @pagination="getHeHeProductActive"
    />
  </div>
</template>

<script>
import { getHeHeProductActive } from '@/api/stricts/active/active'
export default {
  name: 'ActivitysList',
  filters: {
    activityStatusFilters(value) {
      const map = {
        1: '未开始',
        2: '进行中',
        3: '已结束'
      }
      return map[value]
    }
  },
  data() {
    return {
      isLoading: true,
      listQuery: {
        status: '',
        name: '',
        activityStatus: '',
        pageNum: 1,
        pageSize: 20
      },
      list: [],
      total: 0
    }
  },
  computed: {},
  created() {
    this.getList()
  },
  mounted() {},
  methods: {
    // 获取行为记录列表
    getList() {
      this.list = []
      this.listQuery.pageNum = 1
      this.getHeHeProductActive()
    },
    // 获取首页导航列表
    async getHeHeProductActive() {
      try {
        this.isLoading = true
        const res = await getHeHeProductActive(this.listQuery)
        this.list = res.data.results
        this.total = res.data.totalRecord
        this.isLoading = false
      } catch (error) {
        console.log(error)
      }
    },
    // 菜单排序
    async consultSort(row) {
      try {
        // await consultSort({ id: row.id, sortNumber: row.sortNumber })
        this.getList()
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  float: left;
}
.uploader-tips {
  position: absolute;
  bottom: 0;
  left: 160px;
  line-height: 28px;
  color: red;
  margin: 0;
}
</style>
