quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<template>
  <div class="table-list">
    <!-- 搜索相关 -->
    <el-form ref="searchForm" :model="searchForm" class="search-form" inline>
      <el-form-item label="订单号">
        <el-input v-model="searchForm.order_no" placeholder="请输入订单号" />
      </el-form-item>
      <el-form-item label="团购商品">
        <el-input v-model="searchForm.product_name" placeholder="请输入团购商品名称" />
      </el-form-item>
      <el-form-item label="用户昵称">
        <el-input v-model="searchForm.nickName" placeholder="请输入用户昵称" />
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="searchForm.status" placeholder="请选择状态" clearable>
          <el-option label="待支付" :value="0"></el-option>
          <el-option label="团购中" :value="1"></el-option>
          <el-option label="已完成" :value="2"></el-option>
          <el-option label="已取消" :value="-1"></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-form-item>
    </el-form>
 
    <!-- 表格 -->
    <el-table
      :data="list"
      v-loading="loading"
      style="width: 100%">
      <el-table-column prop="groupbuy_bill_id" label="ID" width="100" />
      <el-table-column prop="order_no" label="订单号" width="200" />
      <el-table-column prop="product.product.product_name" label="团购商品" min-width="200" />
      <el-table-column prop="user.nickName" label="用户" width="120" />
      <el-table-column prop="actual_people" label="当前人数" width="100" />
      <el-table-column prop="groupbuy_num" label="成团人数" width="100" />
      <el-table-column prop="total_price" label="总价" width="100">
        <template slot-scope="scope">
          ¥{{ scope.row.total_price }}
        </template>
      </el-table-column>
      <el-table-column prop="actual_price" label="实付" width="100">
        <template slot-scope="scope">
          ¥{{ scope.row.actual_price }}
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态" width="100">
        <template slot-scope="scope">
          <el-tag :type="getStatusTagType(scope.row.status)">
            {{ getStatusText(scope.row.status) }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" width="160">
        <template slot-scope="scope">
          {{ formatDate(scope.row.create_time) }}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="150">
        <template slot-scope="scope">
          <el-button size="mini" @click="onView(scope.row)">查看</el-button>
          <el-button size="mini" type="success" @click="onUpdateStatus(scope.row)" v-if="canUpdateStatus(scope.row)">
            {{ getStatusButtonText(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>
 
    <!-- 订单详情弹窗 -->
    <el-dialog title="订单详情" :visible.sync="dialogVisible" width="60%">
      <div v-if="currentOrder">
        <el-descriptions :column="2" border>
          <el-descriptions-item label="订单号">{{ currentOrder.order_no }}</el-descriptions-item>
          <el-descriptions-item label="团购商品">{{ currentOrder.product.product.product_name }}</el-descriptions-item>
          <el-descriptions-item label="用户">{{ currentOrder.user.nickName }}</el-descriptions-item>
          <el-descriptions-item label="团购活动">{{ currentOrder.active.active_name }}</el-descriptions-item>
          <el-descriptions-item label="团购价格">¥{{ currentOrder.actual_price }}</el-descriptions-item>
          <el-descriptions-item label="团购人数">{{ currentOrder.actual_people }}/{{ currentOrder.groupbuy_num }}</el-descriptions-item>
          <el-descriptions-item label="订单状态">{{ getStatusText(currentOrder.status) }}</el-descriptions-item>
          <el-descriptions-item label="创建时间">{{ formatDate(currentOrder.create_time) }}</el-descriptions-item>
        </el-descriptions>
 
        <div class="mt20">
          <h4>参团用户列表</h4>
          <el-table :data="currentOrder.billUser" style="width: 100%" size="small">
            <el-table-column prop="user.nickName" label="用户名" />
            <el-table-column prop="is_creator" label="是否团长" width="100">
              <template slot-scope="scope">
                <el-tag :type="scope.row.is_creator ? 'success' : 'info'">
                  {{ scope.row.is_creator ? '是' : '否' }}
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column label="参团时间">
              <template slot-scope="scope">
                {{ formatDate(scope.row.create_time) }}
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import PlusApi from '@/api/plus/groupbuy'
 
export default {
  name: 'GroupbuyOrder',
  data() {
    return {
      loading: false,
      list: [],
      searchForm: {
        order_no: '',
        product_name: '',
        nickName: '',
        status: ''
      },
      pageInfo: {
        page: 1,
        limit: 20,
        total: 0
      },
      dialogVisible: false,
      currentOrder: null
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取列表
    getList() {
      this.loading = true
      const params = {
        page: this.pageInfo.page,
        list_rows: this.pageInfo.limit,
        ...this.searchForm
      }
      PlusApi.orderList(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 = {
        order_no: '',
        product_name: '',
        nickName: '',
        status: ''
      }
      this.pageInfo.page = 1
      this.getList()
    },
    // 查看订单
    onView(row) {
      this.currentOrder = row
      this.dialogVisible = true
    },
    // 更新订单状态
    onUpdateStatus(row) {
      let newStatus;
      if (row.status === 0) {
        newStatus = 1; // 从待支付改为团购中
      } else if (row.status === 1) {
        // 询问是成功还是失败
        this.$prompt('请输入操作备注(成功/失败)', '操作确认', {
          confirmButtonText: '成功',
          cancelButtonText: '失败',
          inputPlaceholder: '输入成功或失败'
        }).then(({ value }) => {
          if (value === '成功') {
            newStatus = 2; // 成功
          } else if (value === '失败') {
            newStatus = -1; // 失败
          } else {
            this.$message.error('请输入成功或失败');
            return;
          }
          this.updateOrderStatus(row.groupbuy_bill_id, newStatus);
        }).catch(() => {
          // 取消操作
        });
        return;
      }
 
      this.updateOrderStatus(row.groupbuy_bill_id, newStatus);
    },
    // 更新订单状态请求
    updateOrderStatus(orderId, status) {
      PlusApi.updateOrderStatus({ 
        groupbuy_bill_id: orderId, 
        status: status 
      }).then(res => {
        this.$message.success('状态更新成功');
        this.getList();
        this.dialogVisible = false;
      });
    },
    // 格式化日期
    formatDate(timestamp) {
      if (!timestamp) return '';
      const date = new Date(timestamp * 1000);
      return date.toLocaleString('zh-CN');
    },
    // 获取状态文本
    getStatusText(status) {
      const statusMap = {
        '-1': '已取消',
        '0': '待支付',
        '1': '团购中',
        '2': '已完成'
      };
      return statusMap[status] || '未知';
    },
    // 获取状态标签类型
    getStatusTagType(status) {
      const typeMap = {
        '-1': 'danger',
        '0': 'warning',
        '1': 'primary',
        '2': 'success'
      };
      return typeMap[status] || 'info';
    },
    // 是否可以更新状态
    canUpdateStatus(row) {
      return row.status === 0 || row.status === 1; // 只有待支付和团购中的订单可以更新状态
    },
    // 获取状态按钮文本
    getStatusButtonText(row) {
      if (row.status === 0) {
        return '标记为团购中';
      } else if (row.status === 1) {
        return '更新状态';
      }
      return '';
    },
    // 分页相关
    handleSizeChange(val) {
      this.pageInfo.limit = val
      this.pageInfo.page = 1
      this.getList()
    },
    handleCurrentChange(val) {
      this.pageInfo.page = val
      this.getList()
    }
  }
}
</script>