1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<template>
  <div class="table-list">
    <!-- 搜索相关 -->
    <el-form ref="searchForm" :model="searchForm" class="search-form" inline>
      <el-form-item label="活动名称">
        <el-input v-model="searchForm.active_name" placeholder="请输入活动名称" />
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="searchForm.status" placeholder="请选择状态" clearable>
          <el-option label="启用" :value="1"></el-option>
          <el-option label="禁用" :value="0"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSearch">查询</el-button>
        <el-button @click="onReset">重置</el-button>
        <el-button type="primary" @click="onAdd">新增团购活动</el-button>
      </el-form-item>
    </el-form>
 
    <!-- 表格 -->
    <el-table
      :data="list"
      v-loading="loading"
      style="width: 100%">
      <el-table-column prop="groupbuy_active_id" label="ID" width="100" />
      <el-table-column prop="active_name" label="活动名称" min-width="200" />
      <el-table-column label="活动封面" width="120">
        <template slot-scope="scope">
          <el-image
            v-if="scope.row.file && scope.row.file.file_path"
            :src="scope.row.file.file_path"
            class="table-image"
            fit="cover" />
        </template>
      </el-table-column>
      <el-table-column prop="start_time" label="开始时间" width="160" />
      <el-table-column prop="end_time" label="结束时间" width="160" />
      <el-table-column prop="together_time" label="成团时限(小时)" width="130" />
      <el-table-column prop="status" label="状态" width="100">
        <template slot-scope="scope">
          <el-tag :type="scope.row.status === 1 ? 'success' : 'danger'">
            {{ scope.row.status === 1 ? '启用' : '禁用' }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="250">
        <template slot-scope="scope">
          <el-button size="mini" @click="onEdit(scope.row)">编辑</el-button>
          <el-button size="mini" type="success" @click="onToggleStatus(scope.row)">
            {{ scope.row.status === 1 ? '禁用' : '启用' }}
          </el-button>
          <el-button size="mini" type="danger" @click="onDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
 
    <!-- 分页 -->
    <div class="pagination">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageInfo.page"
        :page-size="pageInfo.limit"
        layout="total, prev, pager, next, jumper"
        :total="pageInfo.total">
      </el-pagination>
    </div>
  </div>
</template>
 
<script>
import PlusApi from '@/api/plus/groupbuy'
 
export default {
  name: 'SupplierGroupbuyActivity',
  data() {
    return {
      loading: false,
      list: [],
      searchForm: {
        active_name: '',
        status: ''
      },
      pageInfo: {
        page: 1,
        limit: 20,
        total: 0
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取列表
    getList() {
      this.loading = true
      const params = {
        page: this.pageInfo.page,
        list_rows: this.pageInfo.limit,
        ...this.searchForm
      }
      PlusApi.activeList(params).then(res => {
        this.list = res.data.list.data
        this.pageInfo.total = res.data.list.total
      }).finally(() => {
        this.loading = false
      })
    },
    // 搜索
    onSearch() {
      this.pageInfo.page = 1
      this.getList()
    },
    // 重置
    onReset() {
      this.searchForm = {
        active_name: '',
        status: ''
      }
      this.pageInfo.page = 1
      this.getList()
    },
    // 新增
    onAdd() {
      this.$router.push('/plus/groupbuy/activity/add')
    },
    // 编辑
    onEdit(row) {
      this.$router.push(`/plus/groupbuy/activity/edit?groupbuy_active_id=${row.groupbuy_active_id}`);
    },
    // 切换状态
    onToggleStatus(row) {
      const newStatus = row.status === 1 ? 0 : 1
      this.$confirm(`确认${newStatus === 1 ? '启用' : '禁用'}该团购活动?`, '提示', {
        type: 'warning'
      }).then(() => {
        PlusApi.updateActiveStatus({
          groupbuy_active_id: row.groupbuy_active_id,
          status: newStatus
        }).then(res => {
          this.$message.success(`${newStatus === 1 ? '启用' : '禁用'}成功`)
          this.getList()
        })
      })
    },
    // 删除
    onDelete(row) {
      this.$confirm('确认删除该团购活动?', '提示', {
        type: 'warning'
      }).then(() => {
        PlusApi.deleteActive({ groupbuy_active_id: row.groupbuy_active_id }).then(res => {
          this.$message.success('删除成功')
          this.getList()
        })
      })
    },
    // 分页相关
    handleSizeChange(val) {
      this.pageInfo.limit = val
      this.pageInfo.page = 1
      this.getList()
    },
    handleCurrentChange(val) {
      this.pageInfo.page = val
      this.getList()
    }
  }
}
</script>