647556386
3 天以前 696edbff3c8812e4b820f624d66a02ae6ddb1a06
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
<template>
  <div class="print-input-container">
    <!-- 页面标题 -->
    <div class="page-title">物料标识卡打印参数输入</div>
 
    <!-- 表单区域 -->
    <el-card class="input-card">
      <el-form
        ref="printFormRef"
        :model="printForm"
        :rules="formRules"
        label-width="100px"
        size="default"
      >
        <!-- 双列布局 -->
        <el-row :gutter="20">
          <!-- 第一列 -->
          <el-col :span="12">
            <el-form-item label="料号" prop="materialCode">
              <el-input
                v-model="printForm.materialCode"
                placeholder="请输入物料编码"
                clearable
              />
            </el-form-item>
 
            <el-form-item label="品名" prop="materialName">
              <el-input
                v-model="printForm.materialName"
                placeholder="请输入物料名称"
                clearable
              />
            </el-form-item>
 
            <el-form-item label="规格" prop="materialSpec">
              <el-input
                v-model="printForm.materialSpec"
                placeholder="请输入物料规格"
                clearable
              />
            </el-form-item>
 
            <el-form-item label="批号" prop="barcode">
              <el-input
                v-model="printForm.barcode"
                placeholder="请输入批号(生成二维码用)"
                clearable
                @keyup.enter="fetchBarcodeData"  
                :loading="fetchingData"    
              />
            </el-form-item>
 
            <el-form-item label="厂区" prop="factoryArea">
              <el-input
                v-model="printForm.factoryArea"
                placeholder="请输入厂区名称"
                clearable
              />
            </el-form-item>
          </el-col>
 
          
          <el-col :span="12">
            <el-form-item label="供应商编码" prop="suplierCode">
              <el-input
                v-model="printForm.suplierCode"
                placeholder="请输入供应商编码"
                clearable
              />
            </el-form-item>
 
            <el-form-item label="采购单号" prop="pruchaseOrderNo">
              <el-input
                v-model="printForm.pruchaseOrderNo"
                placeholder="请输入采购单号"
                clearable
              />
            </el-form-item>
 
            <el-form-item label="数量/总数" prop="quantity">
              <el-input
                v-model="printForm.quantity"
                placeholder="例:100/5000"
                clearable
              />
            </el-form-item>
 
            <el-form-item label="批次" prop="batchNo">
              <el-input
                v-model="printForm.batchNo"
                placeholder="请输入批次号"
                clearable
              />
            </el-form-item>
 
            <el-form-item label="日期" prop="date">
              <el-date-picker
                v-model="printForm.date"
                type="date"
                placeholder="选择日期"
                format="YYYY-MM-DD"
                value-format="YYYY-MM-DD"
                clearable
              />
            </el-form-item>
          </el-col>
        </el-row>
 
        
        <el-form-item label="打印份数">
          <el-input-number
            v-model="printCopyCount"
            :min="1"
            :max="50"
            label="份数"
            placeholder="请输入打印份数"
          />
        </el-form-item>
 
        
        <el-form-item class="form-actions">
          <el-button type="primary" @click="submitForm">确认并打开打印弹窗</el-button>
          <el-button @click="resetForm">重置表单</el-button>
        </el-form-item>
      </el-form>
    </el-card>
 
    
    <print-view ref="printViewRef" />
  </div>
</template>
 
<script>
 
import printView from "@/extension/outbound/extend/printView.vue";
import { ElMessage } from "element-plus";
import http from '@/api/http.js'
 
export default {
  name: "PrintInputPage",
  components: { printView },
  data() {
    return {
      printForm: {
        materialCode: "", 
        suplierCode: "", 
        materialName: "", 
        pruchaseOrderNo: "", 
        materialSpec: "", 
        quantity: "", 
        barcode: "", 
        batchNo: "", 
        factoryArea: "", 
        date: "", 
      },
      
      printCopyCount: 1,
      
      formRules: {
        materialCode: [{ required: true, message: "请输入料号", trigger: "blur" }],
        materialName: [{ required: true, message: "请输入品名", trigger: "blur" }],
        barcode: [{ required: true, message: "请输入批号", trigger: "blur" }],
        date: [{ required: true, message: "请选择日期", trigger: "change" }],
      },
      
      fetchingData: false
    };
  },
  mounted() {
    const today = new Date();
    this.printForm.date = `${today.getFullYear()}-${(today.getMonth() + 1).toString().padStart(2, "0")}-${today.getDate().toString().padStart(2, "0")}`;
  },
  methods: {
    async fetchBarcodeData() {
      if (!this.printForm.barcode.trim()) {
        return;
      }
 
      try {
        
        this.fetchingData = true;
        
        const response = await http.post(
          `/api/Outbound/PrintFromData?barcode=` + this.printForm.barcode.trim()
        );
        const data = response.data;
        if (data) {
          this.printForm.materialCode = data.materialCode || "";
          this.printForm.suplierCode = data.suplierCode || "";
          this.printForm.materialName = data.materialName || "";
          this.printForm.pruchaseOrderNo = data.pruchaseOrderNo || "";
          this.printForm.materialSpec = data.materialSpec || "";
          this.printForm.quantity = data.quantity || "";
          this.printForm.batchNo = data.batchNo || "";
          this.printForm.factoryArea = data.factoryArea || "";
          
          
          ElMessage.success("已根据批号自动填充数据");
        } else {
          ElMessage.info("未查询到该批号对应的物料数据");
        }
      } catch (error) {
        console.error("获取批号数据失败:", error);
        ElMessage.error("获取数据失败,请检查网络或批号是否正确");
      } finally {
        this.fetchingData = false;
      }
    },
    submitForm() {
      this.$refs.printFormRef.validate((valid) => {
        if (!valid) {
          ElMessage.warning("请完善必填项后提交");
          return;
        }
 
        try {
          const printData = [];
          for (let i = 0; i < this.printCopyCount; i++) {
            printData.push({ ...this.printForm });
          }
          this.$refs.printViewRef.open(printData);
          ElMessage.success(`已生成 ${this.printCopyCount} 份打印数据,即将打开打印弹窗`);
        } catch (error) {
          console.error("打开打印弹窗失败:", error);
          ElMessage.error("打开打印弹窗失败,请重试");
        }
      });
    },
 
    
    resetForm() {
      this.$refs.printFormRef.resetFields();
      const today = new Date();
      this.printForm.date = `${today.getFullYear()}-${(today.getMonth() + 1).toString().padStart(2, "0")}-${today.getDate().toString().padStart(2, "0")}`;
      this.printCopyCount = 1;
    },
  },
};
</script>
 
<style scoped>
.print-input-container {
  padding: 20px;
  max-width: 1000px;
  margin: 0 auto;
}
 
.page-title {
  font-size: 20px;
  font-weight: bold;
  color: #303133;
  margin-bottom: 20px;
  text-align: center;
}
 
.input-card {
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
 
.form-actions {
  text-align: center;
  margin-top: 20px;
}
 
.form-actions .el-button {
  margin: 0 10px;
  padding: 10px 20px;
}
 
/* 适配小屏幕 */
@media (max-width: 768px) {
  .print-input-container {
    padding: 10px;
  }
 
  .el-form-item {
    margin-bottom: 15px;
  }
}
</style>