pan
2025-11-13 80dbe95a364ec753195ab9087c1eca1f5a6fa27c
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<template>
  <div class="picking-container">
    <!-- 出库单列表 -->
    <div class="card mb-4" v-for="order in pickingOrders" :key="order.outStockOrderId">
      <div class="card-header bg-light d-flex justify-content-between align-items-center">
        <div>
          <h5 class="mb-0">出库单: {{ order.orderNumber }}</h5>
          <small class="text-muted">
            需求: {{ order.totalRequiredQuantity }} | 
            已锁定: {{ order.totalLockedQuantity }}
          </small>
        </div>
        <button @click="confirmOrder(order)" class="btn btn-primary btn-sm"
                :disabled="!canConfirmOrder(order)">
          <i class="fas fa-check"></i> 确认整单出库
        </button>
      </div>
      
      <div class="card-body p-0">
        <div class="table-responsive">
          <table class="table table-hover mb-0">
            <thead>
              <tr>
                <th width="5%">#</th>
                <th>产品名称</th>
                <th>批号/条码</th>
                <th>出库数量</th>
                <th>库存数量</th>
                <th>库位</th>
                <th width="20%">操作</th>
              </tr>
            </thead>
            <tbody>
              <tr v-for="(item, index) in order.pickingItems" :key="item.outStockLockId"
                  :class="{
                    'table-success': item.status === 'Confirmed',
                    'table-warning': needsSplit(item)
                  }">
                <td>{{ index + 1 }}</td>
                <td>{{ item.productName }}</td>
                <td>
                  <div>
                    <strong>{{ item.batchNumber }}</strong>
                    <br>
                    <small class="text-muted">{{ item.barCode }}</small>
                  </div>
                </td>
                <td>
                  <span class="font-weight-bold text-primary">
                    {{ item.outStockQuantity }}
                  </span>
                  <small class="text-muted ml-1">{{ item.packageUnit }}</small>
                </td>
                <td>
                  <span :class="{
                    'text-success': item.isWholePackage,
                    'text-warning': needsSplit(item)
                  }">
                    {{ item.stockQuantity }} {{ item.packageUnit }}
                  </span>
                </td>
                <td>{{ item.location }}</td>
                <td>
                  <!-- 整包直接确认 -->
                  <button v-if="item.isWholePackage && item.status === 'Pending'"
                          @click="confirmWholePicking(item)"
                          class="btn btn-success btn-sm"
                          :disabled="loading">
                    <i class="fas fa-check"></i> 确认
                  </button>
                  
                  <!-- 需要拆包的情况 -->
                  <div v-else-if="needsSplit(item) && item.status === 'Pending'">
                    <button @click="showSplitModal(item)"
                            class="btn btn-warning btn-sm mb-1"
                            :disabled="loading">
                      <i class="fas fa-cube"></i> 拆包
                    </button>
                    <div class="small text-muted">
                      需拆包: {{ item.outStockQuantity }}/{{ item.stockQuantity }}
                    </div>
                  </div>
                  
                  <!-- 已确认状态 -->
                  <span v-else-if="item.status === 'Confirmed'" class="text-success">
                    <i class="fas fa-check-circle"></i> 已确认
                  </span>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
 
    <!-- 拆包模态框 -->
    <div class="modal fade" id="splitModal" tabindex="-1">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title">拆包操作</h5>
            <button type="button" class="close" data-dismiss="modal">
              <span>&times;</span>
            </button>
          </div>
          <div class="modal-body">
            <div v-if="currentSplitItem">
              <div class="form-group">
                <label>产品名称</label>
                <input type="text" class="form-control" :value="currentSplitItem.productName" readonly>
              </div>
              <div class="form-group">
                <label>原条码</label>
                <input type="text" class="form-control" :value="currentSplitItem.barCode" readonly>
              </div>
              <div class="row">
                <div class="col-6">
                  <div class="form-group">
                    <label>原库存数量</label>
                    <input type="text" class="form-control" :value="currentSplitItem.stockQuantity" readonly>
                  </div>
                </div>
                <div class="col-6">
                  <div class="form-group">
                    <label>出库数量</label>
                    <input type="text" class="form-control" :value="currentSplitItem.outStockQuantity" readonly>
                  </div>
                </div>
              </div>
              <div class="form-group">
                <label>拆包数量</label>
                <input type="number" class="form-control" v-model="splitQuantity"
                       :max="currentSplitItem.stockQuantity - 0.01" step="0.01" min="0.01">
                <small class="form-text text-muted">
                  拆出数量: {{ splitQuantity }} | 
                  剩余数量: {{ (currentSplitItem.stockQuantity - splitQuantity).toFixed(2) }}
                </small>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
            <button type="button" class="btn btn-warning" @click="confirmSplit" 
                    :disabled="!splitQuantity || splitQuantity <= 0">
              <i class="fas fa-cube"></i> 确认拆包
            </button>
          </div>
        </div>
      </div>
    </div>
 
    <!-- 操作提示 -->
    <div v-if="message" :class="['alert', messageType === 'success' ? 'alert-success' : 'alert-danger', 'mt-3']">
      {{ message }}
    </div>
  </div>
</template>
 
<script>
export default {
  data() {
    return {
      pickingOrders: [],
      loading: false,
      message: '',
      messageType: 'success',
      currentSplitItem: null,
      splitQuantity: 0
    }
  },
  mounted() {
    this.loadPickingList();
    // 初始化模态框
    $('#splitModal').on('hidden.bs.modal', () => {
      this.currentSplitItem = null;
      this.splitQuantity = 0;
    });
  },
  methods: {
    async loadPickingList() {
      try {
        this.loading = true;
        const response = await this.$http.get('/Picking/PickingList');
        this.pickingOrders = response.data;
      } catch (error) {
        this.showMessage('加载拣选列表失败', 'error');
      } finally {
        this.loading = false;
      }
    },
 
    // 判断是否需要拆包
    needsSplit(item) {
      return !item.isWholePackage && item.outStockQuantity <= item.stockQuantity;
    },
 
    // 整包确认
    async confirmWholePicking(item) {
      try {
        this.loading = true;
        const response = await this.$http.post('/Picking/ConfirmWholePicking', {
          outStockLockId: item.outStockLockId
        });
        
        if (response.data.success) {
          this.showMessage(response.data.message, 'success');
          this.loadPickingList();
        } else {
          this.showMessage(response.data.message, 'error');
        }
      } catch (error) {
        this.showMessage('操作失败', 'error');
      } finally {
        this.loading = false;
      }
    },
 
    // 显示拆包模态框
    showSplitModal(item) {
      this.currentSplitItem = item;
      this.splitQuantity = item.outStockQuantity; // 默认拆出数量为出库数量
      $('#splitModal').modal('show');
    },
 
    // 确认拆包
    async confirmSplit() {
      if (!this.splitQuantity || this.splitQuantity <= 0) {
        this.showMessage('请输入有效的拆包数量', 'error');
        return;
      }
 
      try {
        this.loading = true;
        const response = await this.$http.post('/Picking/SplitPackage', {
          outStockLockId: this.currentSplitItem.outStockLockId,
          splitQuantity: this.splitQuantity
        });
        
        if (response.data.success) {
          this.showMessage(`拆包成功!新条码: ${response.data.data.newBarCode}`, 'success');
          $('#splitModal').modal('hide');
          this.loadPickingList();
        } else {
          this.showMessage(response.data.message, 'error');
        }
      } catch (error) {
        this.showMessage('拆包失败', 'error');
      } finally {
        this.loading = false;
      }
    },
 
    // 确认整单出库
    async confirmOrder(order) {
      if (!confirm(`确定要确认整个出库单 ${order.orderNumber} 吗?`)) return;
      
      try {
        this.loading = true;
        const response = await this.$http.post('/Picking/ConfirmOutStockOrder', {
          outStockOrderId: order.outStockOrderId
        });
        
        if (response.data.success) {
          this.showMessage(response.data.message, 'success');
          this.loadPickingList();
        } else {
          this.showMessage(response.data.message, 'error');
        }
      } catch (error) {
        this.showMessage('操作失败', 'error');
      } finally {
        this.loading = false;
      }
    },
 
    // 检查是否可以确认整单
    canConfirmOrder(order) {
      return order.pickingItems.every(item => 
        item.status === 'Pending' && 
        (item.isWholePackage || this.needsSplit(item))
      );
    },
 
    showMessage(msg, type) {
      this.message = msg;
      this.messageType = type;
      setTimeout(() => {
        this.message = '';
      }, 3000);
    }
  }
}
</script>
 
<style scoped>
.picking-container {
  max-width: 1400px;
  margin: 0 auto;
}
 
.table td {
  vertical-align: middle;
}
 
.btn-sm {
  min-width: 80px;
}
 
.badge {
  font-family: monospace;
}
</style>