quanwei
2 days ago 04102f7237efefa744090ed7c25f7b5d0807b679
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
<template>
  <div class="table-list">
    <!-- 搜索相关 -->
    <el-form ref="searchForm" :model="searchForm" class="search-form" inline>
      <el-form-item label="团购活动">
        <el-select v-model="searchForm.active_id" placeholder="请选择团购活动" clearable>
          <el-option
            v-for="item in activeList"
            :key="item.groupbuy_active_id"
            :label="item.active_name"
            :value="item.groupbuy_active_id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="商品名称">
        <el-input v-model="searchForm.product_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_product_id" label="ID" width="100" />
      <el-table-column prop="product.product_name" label="商品名称" min-width="200" />
      <el-table-column prop="active.active_name" label="团购活动" width="200" />
      <el-table-column prop="groupbuy_num" label="成团人数" width="100" />
      <el-table-column prop="groupbuySku.groupbuy_price" label="团购价格" width="100" />
      <el-table-column prop="stock" label="库存" width="100" />
      <el-table-column prop="total_sales" label="销量" width="100" />
      <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="200">
        <template slot-scope="scope">
          <el-button size="mini" @click="onEdit(scope.row)">编辑</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: 'SupplierGroupbuyProduct',
 
  data() {
    return {
      loading: false,
      list: [],
      activeList: [],
      searchForm: {
        active_id: '',
        product_name: '',
        status: ''
      },
      pageInfo: {
        page: 1,
        limit: 20,
        total: 0
      }
    }
  },
  created() {
    this.getList()
    this.getActiveList()
  },
  methods: {
    // 获取列表
    getList() {
      this.loading = true
      const params = {
        page: this.pageInfo.page,
        list_rows: this.pageInfo.limit,
        ...this.searchForm
      }
      PlusApi.productList(params).then(res => {
        this.list = res.data.list.data
        this.pageInfo.total = res.data.list.total
      }).finally(() => {
        this.loading = false
      })
    },
    // 获取活动列表
    getActiveList() {
      PlusApi.activeList({}).then(res => {
        this.activeList = res.data.list.data
      })
    },
    // 搜索
    onSearch() {
      this.pageInfo.page = 1
      this.getList()
    },
    // 重置
    onReset() {
      this.searchForm = {
        active_id: '',
        product_name: '',
        status: ''
      }
      this.pageInfo.page = 1
      this.getList()
    },
    // 新增
    onAdd() {
      this.$router.push('/plus/groupbuy/product/add')
    },
    // 编辑
    onEdit(row) {
      this.$router.push(`/plus/groupbuy/product/edit/${row.groupbuy_product_id}`)
    },
    // 删除
    onDelete(row) {
      this.$confirm('确认删除该团购商品?', '提示', {
        type: 'warning'
      }).then(() => {
        PlusApi.deleteProduct({ groupbuy_product_id: row.groupbuy_product_id }).then(res => {
          this.$message.success('删除成功')
          this.getList()
        })
      })
    }
  }
}
</script>