heshaofeng
7 天以前 375ace27ad6afbc3c83d92add0fb5a0347a6edbf
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
<template>
  <div class="split-package">
    <el-alert
      title="拆包操作将把选中的物料包分成两个包,系统会自动生成新条码"
      type="info"
      :closable="false"
      class="split-alert"
    />
 
    <!-- 原物料信息展示 -->
    <el-card header="原物料信息" class="original-info">
      <el-descriptions :column="2" border>
        <el-descriptions-item label="旧条码">
          <el-text type="primary">{{ lockInfo.MaterielCode }}</el-text>
        </el-descriptions-item>
        <el-descriptions-item label="物料名称">
          {{ lockInfo.MaterielName }}
        </el-descriptions-item>
        <el-descriptions-item label="批次号">
          {{ lockInfo.BatchNo }}
        </el-descriptions-item>
        <el-descriptions-item label="托盘编号">
          {{ lockInfo.PalletCode }}
        </el-descriptions-item>
        <el-descriptions-item label="库位编号">
          {{ lockInfo.LocationCode }}
        </el-descriptions-item>
        <el-descriptions-item label="任务号">
          {{ taskNo }}
        </el-descriptions-item>
        <el-descriptions-item label="分配数量">
          <el-text type="info">{{ lockInfo.AssignQuantity }}</el-text>
        </el-descriptions-item>
        <el-descriptions-item label="已拣数量">
          <el-text type="warning">{{ lockInfo.PickedQty }}</el-text>
        </el-descriptions-item>
        <el-descriptions-item label="可拆包数量">
          <el-text type="success">{{ availableQuantity }}</el-text>
        </el-descriptions-item>
      </el-descriptions>
    </el-card>
 
    <!-- 拆包信息输入 -->
    <el-card header="拆包信息" class="split-info">
      <el-form :model="splitForm" label-width="120px">
        <el-form-item label="拆包数量" required>
          <el-input-number
            v-model="splitForm.splitQuantity"
            :min="1"
            :max="availableQuantity"
            :precision="2"
            placeholder="请输入拆包数量"
            style="width: 200px"
          />
          <div class="form-tips">
            可拆包数量: {{ availableQuantity }} {{ lockInfo.Unit }}
          </div>
        </el-form-item>
        
        <el-form-item label="新条码" v-if="newBarcode">
          <el-text type="success">{{ newBarcode }}</el-text>
          <div class="form-tips">系统自动生成的新条码</div>
        </el-form-item>
      </el-form>
    </el-card>
 
    <div class="action-buttons">
      <el-button 
        type="primary" 
        @click="handleConfirm" 
        :loading="confirmLoading"
        :disabled="!splitForm.splitQuantity"
      >
        确认拆包
      </el-button>
      <el-button @click="$emit('close')">取消</el-button>
    </div>
  </div>
</template>
 
<script setup>
import { ref, reactive, computed } from 'vue'
import { ElMessage } from 'element-plus'
 
const props = defineProps({
  lockInfo: {
    type: Object,
    required: true
  }
})
 
const emit = defineEmits(['confirm', 'close'])
 
const splitForm = reactive({
  splitQuantity: 1
})
 
const confirmLoading = ref(false)
const newBarcode = ref('')
const taskNo = ref(`SPLIT_${Date.now()}`)
 
// 计算可拆包数量
const availableQuantity = computed(() => {
  return props.lockInfo.AssignQuantity - props.lockInfo.PickedQty
})
 
const handleConfirm = async () => {
  if (!splitForm.splitQuantity || splitForm.splitQuantity <= 0) {
    ElMessage.warning('请输入有效的拆包数量')
    return
  }
 
  if (splitForm.splitQuantity >= availableQuantity.value) {
    ElMessage.warning('拆包数量必须小于可拆包数量')
    return
  }
 
  confirmLoading.value = true
  
  try {
    const request = {
      lockInfoId: props.lockInfo.Id,
      taskNo: taskNo.value,
      splitQuantity: splitForm.splitQuantity
    }
 
    const result = await $http.post('/api/outbound/splitPackage', request)
    
    if (result.success) {
      newBarcode.value = result.data?.newBarcode || '生成成功'
      ElMessage.success(`拆包操作成功!新条码: ${newBarcode.value}`)
      
      // 延迟关闭,让用户看到新条码
      setTimeout(() => {
        emit('confirm')
      }, 2000)
    } else {
      ElMessage.error(result.message)
    }
  } catch (error) {
    ElMessage.error('拆包操作失败')
  } finally {
    confirmLoading.value = false
  }
}
</script>
 
<style scoped>
.split-package {
  max-height: 70vh;
  overflow-y: auto;
}
 
.split-alert {
  margin-bottom: 16px;
}
 
.original-info {
  margin-bottom: 16px;
}
 
.split-info {
  margin-bottom: 16px;
}
 
.form-tips {
  font-size: 12px;
  color: #909399;
  margin-top: 4px;
}
 
.action-buttons {
  text-align: center;
  margin-top: 20px;
}
</style>