pan
2025-11-11 c4e1a656954799267cbd61d3de3a040e8dc8e46a
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
<template>
  <div class="picking-confirm">
    <div class="page-header">
      <el-page-header @back="goBack">
        <template #content>
          <span class="title">出库拣选确认 - {{ orderInfo.orderNo }}</span>
        </template>
      </el-page-header>
    </div>
 
    <el-row :gutter="20" class="main-content">
      <el-col :span="8">
        <div class="scan-section">
          <el-card header="扫码区域">
            <el-form label-width="100px" size="small">
              <el-form-item label="托盘条码">
                <el-input 
                  v-model="scanForm.palletCode" 
                  placeholder="扫描或输入托盘条码"
                  @keyup.enter="handlePalletScan"
                  clearable
                >
                  <template #append>
                    <el-button @click="handlePalletScan">确认</el-button>
                  </template>
                </el-input>
              </el-form-item>
 
              <el-form-item label="物料条码">
                <el-input 
                  v-model="scanForm.barcode" 
                  placeholder="扫描或输入物料条码"
                  @keyup.enter="handleBarcodeScan"
                  :disabled="!currentPallet"
                  clearable
                >
                  <template #append>
                    <el-button @click="handleBarcodeScan" :disabled="!currentPallet">确认</el-button>
                  </template>
                </el-input>
              </el-form-item>
 
              <el-form-item label="拣选数量">
                <el-input-number 
                  v-model="scanForm.quantity" 
                  :min="1" 
                  :max="maxPickQuantity"
                  :disabled="!currentLockInfo"
                />
              </el-form-item>
            </el-form>
 
            <div class="current-info" v-if="currentPallet">
              <p>当前托盘: {{ currentPallet.palletCode }}</p>
              <p>货位: {{ currentPallet.locationCode }}</p>
              <p>状态: {{ currentPallet.statusText }}</p>
            </div>
          </el-card>
 
          <div class="action-buttons">
            <el-button 
              type="warning" 
              @click="handleBackToStock" 
              :disabled="!currentPallet"
              style="margin-bottom: 10px;"
            >
              回库
            </el-button>
            <el-button 
              type="success" 
              @click="handleDirectOutbound" 
              :disabled="!currentPallet"
              style="margin-bottom: 10px;"
            >
              直接出库
            </el-button>
            <el-button 
              type="primary" 
              @click="handleOpenSplit" 
              :disabled="!currentLockInfo"
            >
              拆包
            </el-button>
          </div>
        </div>
      </el-col>
 
      <el-col :span="16">
        <el-card header="拣选结果">
          <div class="summary-info">
            <el-alert
              :title="`未拣货: ${unpickedCount} 条, ${unpickedQuantity} 个`"
              type="warning"
              :closable="false"
            />
          </div>
 
          <vol-table
            :data="pickedList"
            :columns="pickedColumns"
            :pagination="false"
            :height="400"
          >
            <template #action="{ row }">
              <el-button type="text" @click="handleCancelPick(row)">撤销</el-button>
            </template>
          </vol-table>
        </el-card>
      </el-col>
    </el-row>
 
    <!-- 拆包弹窗 -->
    <vol-box
      v-model="splitVisible"
      title="拆包操作"
      :width="600"
      :height="500"
    >
      <SplitPackageModal
        v-if="splitVisible"
        :lockInfo="currentLockInfo"
        @success="handleSplitSuccess"
        @close="splitVisible = false"
      />
    </vol-box>
  </div>
</template>
 
<script>
import SplitPackageModal from './SplitPackageModal.vue'
 
export default {
  components: { SplitPackageModal },
  data() {
    return {
      orderInfo: {},
      scanForm: {
        palletCode: '',
        barcode: '',
        quantity: 1
      },
      currentPallet: null,
      currentLockInfo: null,
      pickedList: [],
      pickedColumns: [
        { field: 'barcode', title: '物料条码', width: 150 },
        { field: 'materielCode', title: '物料编码', width: 120 },
        { field: 'materielName', title: '物料名称', width: 150 },
        { field: 'pickQuantity', title: '拣选数量', width: 100 },
        { field: 'palletCode', title: '托盘编号', width: 120 },
        { field: 'pickTime', title: '拣选时间', width: 160 },
        { field: 'operator', title: '操作人', width: 100 },
        { field: 'action', title: '操作', width: 80, slot: true }
      ],
      splitVisible: false,
      maxPickQuantity: 0
    }
  },
  computed: {
    unpickedCount() {
      return this.orderInfo.unpickedCount || 0
    },
    unpickedQuantity() {
      return this.orderInfo.unpickedQuantity || 0
    }
  },
  methods: {
    goBack() {
      this.$router.back()
    },
 
    async loadOrderInfo() {
      const orderId = this.$route.query.orderId
      if (!orderId) return
 
      try {
        const result = await this.http.post(`api/OutboundOrder/GetById?id=${orderId}`)
        if (result.status) {
          this.orderInfo = result.data
        }
      } catch (error) {
        this.$message.error('加载出库单信息失败')
      }
    },
 
    async handlePalletScan() {
      if (!this.scanForm.palletCode) {
        this.$message.warning('请输入托盘条码')
        return
      }
 
      try {
        const result = await this.http.get(
          `api/OutboundPicking/GetPalletOutboundStatus?palletCode=${this.scanForm.palletCode}`
        )
        if (result.status) {
          this.currentPallet = result.data
          this.loadPalletLockInfo()
          this.$message.success(`托盘 ${this.scanForm.palletCode} 识别成功`)
        } else {
          this.$message.error(result.message)
        }
      } catch (error) {
        this.$message.error('托盘识别失败')
      }
    },
 
    async loadPalletLockInfo() {
      if (!this.currentPallet) return
 
      try {
        const result = await this.http.get(
          `api/OutboundPicking/GetPalletLockInfos?palletCode=${this.currentPallet.palletCode}`
        )
        if (result.status && result.data.length > 0) {
          this.currentLockInfo = result.data[0]
          this.maxPickQuantity = this.currentLockInfo.assignQuantity - this.currentLockInfo.pickedQty
        }
      } catch (error) {
        console.error('加载锁定信息失败:', error)
      }
    },
 
    async handleBarcodeScan() {
      // 实现扫码确认逻辑
      if (!this.scanForm.barcode) {
        this.$message.warning('请输入物料条码')
        return
      }
 
      try {
        const request = {
          barcode: this.scanForm.barcode,
          quantity: this.scanForm.quantity,
          palletCode: this.currentPallet.palletCode,
          orderId: this.orderInfo.id
        }
 
        const result = await this.http.post('api/OutboundPicking/ConfirmPicking', request)
        if (result.status) {
          this.$message.success('拣选确认成功')
          this.scanForm.barcode = ''
          this.scanForm.quantity = 1
          this.loadPickedHistory()
          this.loadOrderInfo()
        } else {
          this.$message.error(result.message)
        }
      } catch (error) {
        this.$message.error('拣选确认失败')
      }
    },
 
    async handleBackToStock() {
      if (!this.currentPallet) return
 
      try {
        await this.$confirm(`确定将托盘 ${this.currentPallet.palletCode} 回库吗?`, '提示', {
          type: 'warning'
        })
 
        const result = await this.http.post('api/BackToStock/GenerateBackToStockTask', {
          palletCode: this.currentPallet.palletCode,
          currentLocation: '拣选位'
        })
 
        if (result.status) {
          this.$message.success('回库任务已生成')
          this.resetCurrentPallet()
        }
      } catch (error) {
        // 用户取消
      }
    },
 
    async handleDirectOutbound() {
      if (!this.currentPallet) return
 
      try {
        await this.$confirm(`确定将托盘 ${this.currentPallet.palletCode} 直接出库吗?`, '提示', {
          type: 'warning'
        })
 
        const result = await this.http.post('api/OutboundPicking/DirectOutbound', {
          palletCode: this.currentPallet.palletCode
        })
 
        if (result.status) {
          this.$message.success('直接出库成功')
          this.resetCurrentPallet()
          this.loadOrderInfo()
        }
      } catch (error) {
        // 用户取消
      }
    },
 
    handleOpenSplit() {
      if (!this.currentLockInfo) {
        this.$message.warning('请先选择锁定信息')
        return
      }
      this.splitVisible = true
    },
 
    handleSplitSuccess() {
      this.$message.success('拆包成功')
      this.loadPalletLockInfo()
    },
 
    resetCurrentPallet() {
      this.currentPallet = null
      this.currentLockInfo = null
      this.scanForm.palletCode = ''
    },
 
    async loadPickedHistory() {
      const orderId = this.$route.query.orderId
      if (!orderId) return
 
      try {
        const result = await this.http.get(`api/OutboundPicking/GetPickingHistory?orderId=${orderId}`)
        if (result.status) {
          this.pickedList = result.data
        }
      } catch (error) {
        console.error('加载拣选历史失败:', error)
      }
    },
 
    async handleCancelPick(row) {
      try {
        await this.$confirm('确定撤销这条拣选记录吗?', '提示', { type: 'warning' })
        
        const result = await this.http.post('api/OutboundPicking/CancelPicking', {
          pickingHistoryId: row.id
        })
 
        if (result.status) {
          this.$message.success('撤销成功')
          this.loadPickedHistory()
          this.loadOrderInfo()
        }
      } catch (error) {
        // 用户取消
      }
    }
  },
  mounted() {
    this.loadOrderInfo()
    this.loadPickedHistory()
  }
}
</script>