gaoluyang
2025-09-29 530297eda34d030e9b3c8bd168ad818fde1a6ded
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="产品名称" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="批次号" prop="batchNumber">
        <el-input
          v-model="queryParams.batchNumber"
          placeholder="请输入批次号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="退回日期" prop="returnDate">
        <el-date-picker
          clearable
          v-model="queryParams.returnDate"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择退回日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
 
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
 
    <el-table v-loading="loading" :data="nearExpiryReturnList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" width="50" align="center" />
      <el-table-column label="产品名称" prop="productName" />
      <el-table-column label="产品规格" prop="productSpec" />
      <el-table-column label="批次号" prop="batchNumber" />
      <el-table-column label="生产日期" prop="productionDate" align="center">
        <template #default="scope">
          <span>{{ parseTime(scope.row.productionDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="到期日期" prop="expiryDate" align="center">
        <template #default="scope">
          <span>{{ parseTime(scope.row.expiryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="退回数量" prop="returnQuantity" />
      <el-table-column label="退回原因" prop="returnReason" />
      <el-table-column label="退回日期" prop="returnDate" align="center">
        <template #default="scope">
          <span>{{ parseTime(scope.row.returnDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理状态" prop="status" align="center">
        <template #default="scope">
          <dict-tag :options="statusOptions" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button size="mini" type="text" icon="Edit" @click="handleUpdate(scope.row)">修改</el-button>
          <el-button size="mini" type="text" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
 
    <!-- 添加或修改临期退回台账对话框 -->
    <el-dialog :title="title" v-model="open" width="800px" append-to-body>
      <el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="产品名称" prop="productName">
              <el-input v-model="form.productName" placeholder="请输入产品名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="产品规格" prop="productSpec">
              <el-input v-model="form.productSpec" placeholder="请输入产品规格" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="批次号" prop="batchNumber">
              <el-input v-model="form.batchNumber" placeholder="请输入批次号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="退回数量" prop="returnQuantity">
              <el-input-number v-model="form.returnQuantity" controls-position="right" :min="1" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="生产日期" prop="productionDate">
              <el-date-picker
                clearable
                v-model="form.productionDate"
                type="date"
                value-format="YYYY-MM-DD"
                placeholder="请选择生产日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="到期日期" prop="expiryDate">
              <el-date-picker
                clearable
                v-model="form.expiryDate"
                type="date"
                value-format="YYYY-MM-DD"
                placeholder="请选择到期日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="退回日期" prop="returnDate">
              <el-date-picker
                clearable
                v-model="form.returnDate"
                type="date"
                value-format="YYYY-MM-DD"
                placeholder="请选择退回日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="处理状态" prop="status">
              <el-select v-model="form.status" placeholder="请选择处理状态">
                <el-option
                  v-for="dict in statusOptions"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="退回原因" prop="returnReason">
              <el-input v-model="form.returnReason" type="textarea" placeholder="请输入退回原因" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
 
<script setup name="NearExpiryReturn">
import { ref, reactive, onMounted } from "vue";
import { ElMessageBox } from "element-plus";
import {
  nearExpiryReturnListPage,
  nearExpiryReturnAdd,
  nearExpiryReturnUpdate,
  nearExpiryReturnDel,
  nearExpiryReturnDetail
} from "@/api/qualityManagement/nearExpiryReturn";
 
const { proxy } = getCurrentInstance();
const { parseTime } = proxy;
 
const nearExpiryReturnList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
 
// 状态字典
const statusOptions = ref([
  { label: "待处理", value: "0" },
  { label: "处理中", value: "1" },
  { label: "已完成", value: "2" }
]);
 
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    productName: null,
    batchNumber: null,
    returnDate: null
  },
  rules: {
    productName: [
      { required: true, message: "产品名称不能为空", trigger: "blur" }
    ],
    productSpec: [
      { required: true, message: "产品规格不能为空", trigger: "blur" }
    ],
    batchNumber: [
      { required: true, message: "批次号不能为空", trigger: "blur" }
    ],
    returnQuantity: [
      { required: true, message: "退回数量不能为空", trigger: "blur" }
    ],
    productionDate: [
      { required: true, message: "生产日期不能为空", trigger: "blur" }
    ],
    expiryDate: [
      { required: true, message: "到期日期不能为空", trigger: "blur" }
    ],
    returnDate: [
      { required: true, message: "退回日期不能为空", trigger: "blur" }
    ],
    returnReason: [
      { required: true, message: "退回原因不能为空", trigger: "blur" }
    ],
    status: [
      { required: true, message: "处理状态不能为空", trigger: "change" }
    ]
  }
});
 
const { queryParams, form, rules } = toRefs(data);
 
/** 查询临期退回台账列表 */
function getList() {
  loading.value = true;
  // 使用假数据
  const mockData = {
    records: [
      {
        id: 1,
        productName: "维生素C片",
        productSpec: "100mg×30片",
        batchNumber: "VC20240315001",
        productionDate: "2024-03-15",
        expiryDate: "2024-09-15",
        returnQuantity: 50,
        returnReason: "临近保质期",
        returnDate: "2024-09-10",
        status: "1",
        remark: "退回仓库处理"
      },
      {
        id: 2,
        productName: "阿莫西林胶囊",
        productSpec: "250mg×24粒",
        batchNumber: "AMX20240220002",
        productionDate: "2024-02-20",
        expiryDate: "2024-08-20",
        returnQuantity: 30,
        returnReason: "包装破损且临期",
        returnDate: "2024-08-18",
        status: "2",
        remark: "已销毁处理"
      },
      {
        id: 3,
        productName: "感冒灵颗粒",
        productSpec: "10g×12袋",
        batchNumber: "GML20240110003",
        productionDate: "2024-01-10",
        expiryDate: "2024-07-10",
        returnQuantity: 25,
        returnReason: "临近保质期",
        returnDate: "2024-07-08",
        status: "0",
        remark: "待重新包装"
      },
      {
        id: 4,
        productName: "复合维生素片",
        productSpec: "60片/瓶",
        batchNumber: "VB20240405004",
        productionDate: "2024-04-05",
        expiryDate: "2025-04-05",
        returnQuantity: 80,
        returnReason: "临近保质期",
        returnDate: "2024-09-25",
        status: "1",
        remark: "正在联系销售渠道"
      },
      {
        id: 5,
        productName: "钙片",
        productSpec: "600mg×100片",
        batchNumber: "CA20240301005",
        productionDate: "2024-03-01",
        expiryDate: "2024-09-01",
        returnQuantity: 120,
        returnReason: "包装问题且临期",
        returnDate: "2024-08-30",
        status: "2",
        remark: "已完成退货处理"
      }
    ],
    total: 5
  };
 
  // 模拟过滤逻辑
  let filteredRecords = mockData.records;
  
  if (queryParams.value.productName) {
    filteredRecords = filteredRecords.filter(item => 
      item.productName.includes(queryParams.value.productName)
    );
  }
  
  if (queryParams.value.batchNumber) {
    filteredRecords = filteredRecords.filter(item => 
      item.batchNumber.includes(queryParams.value.batchNumber)
    );
  }
  
  if (queryParams.value.returnDate) {
    filteredRecords = filteredRecords.filter(item => 
      item.returnDate === queryParams.value.returnDate
    );
  }
 
  nearExpiryReturnList.value = filteredRecords;
  total.value = filteredRecords.length;
  loading.value = false;
}
 
// 取消按钮
function cancel() {
  open.value = false;
  reset();
}
 
// 表单重置
function reset() {
  form.value = {
    id: null,
    productName: null,
    productSpec: null,
    batchNumber: null,
    productionDate: null,
    expiryDate: null,
    returnQuantity: null,
    returnReason: null,
    returnDate: null,
    status: null,
    remark: null
  };
  proxy.resetForm("formRef");
}
 
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
 
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryForm");
  handleQuery();
}
 
// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length !== 1;
  multiple.value = !selection.length;
}
 
/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加临期退回台账";
}
 
/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const id = row.id || ids.value;
  
  // 使用假数据获取详情
  const mockDetail = nearExpiryReturnList.value.find(item => item.id === (Array.isArray(id) ? id[0] : id));
  if (mockDetail) {
    form.value = { ...mockDetail };
    open.value = true;
    title.value = "修改临期退回台账";
  }
}
 
/** 提交按钮 */
function submitForm() {
  proxy.$refs["formRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        // 模拟更新
        const index = nearExpiryReturnList.value.findIndex(item => item.id === form.value.id);
        if (index !== -1) {
          nearExpiryReturnList.value[index] = { ...form.value };
        }
        proxy.$modal.msgSuccess("修改成功");
        open.value = false;
        getList();
      } else {
        // 模拟新增
        const newId = Math.max(...nearExpiryReturnList.value.map(item => item.id)) + 1;
        nearExpiryReturnList.value.push({ ...form.value, id: newId });
        total.value = nearExpiryReturnList.value.length;
        proxy.$modal.msgSuccess("新增成功");
        open.value = false;
        getList();
      }
    }
  });
}
 
/** 删除按钮操作 */
function handleDelete(row) {
  const deleteIds = row.id || ids.value;
  ElMessageBox.confirm('是否确认删除临期退回台账编号为"' + deleteIds + '"的数据项?', "警告", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning"
  }).then(function() {
    // 模拟删除
    if (Array.isArray(deleteIds)) {
      deleteIds.forEach(id => {
        const index = nearExpiryReturnList.value.findIndex(item => item.id === id);
        if (index !== -1) {
          nearExpiryReturnList.value.splice(index, 1);
        }
      });
    } else {
      const index = nearExpiryReturnList.value.findIndex(item => item.id === deleteIds);
      if (index !== -1) {
        nearExpiryReturnList.value.splice(index, 1);
      }
    }
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}
 
/** 导出按钮操作 */
function handleExport() {
  proxy.download('quality/nearExpiryReturn/export', {
    ...queryParams.value
  }, `临期退回台账_${new Date().getTime()}.xlsx`);
}
 
onMounted(() => {
  getList();
});
</script>