spring
8 天以前 ea6ad9ddc3d5b33897e93276282245f7023836ff
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
<template>
  <div class="app-container">
    <el-form :inline="true" :model="queryParams" class="search-form">
      <el-form-item label="退货单号">
        <el-input
          v-model="queryParams.returnNo"
          placeholder="请输入退货单号"
          clearable
          :style="{ width: '200px' }"
        />
      </el-form-item>
      <el-form-item label="供应商">
        <el-select
          v-model="queryParams.supplierId"
          placeholder="请选择供应商"
          clearable
          :style="{ width: '200px' }"
        >
          <el-option
            :label="item.label"
            v-for="item in supplierList"
            :key="item.value"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="状态">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择状态"
          clearable
          :style="{ width: '150px' }"
        >
          <el-option
            :label="item.label"
            v-for="item in statusList"
            :key="item.value"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="单据日期">
        <el-date-picker
          v-model="queryParams.dateRange"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          format="YYYY-MM-DD"
          value-format="YYYY-MM-DD"
          :style="{ width: '240px' }"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleQuery">查询</el-button>
        <el-button @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
 
    <el-card>
      <!-- 操作按钮区 -->
      <el-row :gutter="24" class="table-toolbar" justify="space-between">
        <el-button type="primary" :icon="Plus" @click="handleAdd">
          新增退货单
        </el-button>
        <el-button type="success" :icon="Refresh" @click="handleGenerateReturn">
          一键生成退货单
        </el-button>
        <el-button type="danger" :icon="Delete" @click="handleBatchDelete" :disabled="selectedIds.length === 0">
          批量删除
        </el-button>
      </el-row>
 
      <!-- 表格组件 -->
      <el-table
        v-loading="loading"
        :data="tableData"
        @selection-change="handleSelectionChange"
        border
        style="width: 100%"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column label="退货单号" prop="returnNo" width="180" />
        <el-table-column label="供应商" prop="supplierName" width="200" />
        <el-table-column label="单据日期" prop="returnDate" width="120" />
        <el-table-column label="操作员" prop="operatorName" width="120" />
        <el-table-column label="退货原因" prop="returnReason" width="200" show-overflow-tooltip />
        <el-table-column label="退货数量" prop="returnQuantity" width="120">
          <template #default="scope">
            {{ scope.row.returnQuantity }} 吨
          </template>
        </el-table-column>
        <el-table-column label="状态" prop="status" width="100">
          <template #default="scope">
            <el-tag :type="getStatusType(scope.row.status)">
              {{ getStatusText(scope.row.status) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" prop="createTime" width="160" />
        <el-table-column label="操作" width="200" fixed="right">
          <template #default="scope">
            <el-button
              size="small"
              type="primary"
              @click="handleView(scope.row)"
            >
              查看
            </el-button>
            <el-button
              size="small"
              type="warning"
              @click="handleEdit(scope.row)"
              v-if="scope.row.status === 'draft'"
            >
              编辑
            </el-button>
            <el-button
              size="small"
              type="danger"
              @click="handleDelete(scope.row)"
              v-if="scope.row.status === 'draft'"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
 
      <!-- 分页组件 -->
      <pagination
        v-if="total > 0"
        :page="current"
        :limit="pageSize"
        :total="total"
        @pagination="handlePagination"
        :layout="'total, prev, pager, next, jumper'"
      />
    </el-card>
 
    <!-- 新增/编辑对话框 -->
    <PurchaseReturnDialog
      v-model:dialogFormVisible="dialogFormVisible"
      v-model:form="form"
      :title="title"
      :is-edit="isEdit"
      @submit="handleSubmit"
      @success="handleSuccess"
      ref="purchaseReturnDialog"
    />
 
    <!-- 查看详情对话框 -->
    <PurchaseReturnViewDialog
      v-model:dialogViewVisible="dialogViewVisible"
      :form="viewForm"
      title="退货单详情"
    />
 
    <!-- 一键生成退货单对话框 -->
    <GenerateReturnDialog
      v-model:dialogGenerateVisible="dialogGenerateVisible"
      @success="handleGenerateSuccess"
    />
  </div>
</template>
 
<script setup>
import { ref, reactive, onMounted, getCurrentInstance } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { Plus, Edit, Delete, Refresh, View } from "@element-plus/icons-vue";
import Pagination from "@/components/Pagination";
import PurchaseReturnDialog from "./components/PurchaseReturnDialog.vue";
import PurchaseReturnViewDialog from "./components/PurchaseReturnViewDialog.vue";
import GenerateReturnDialog from "./components/GenerateReturnDialog.vue";
 
// 响应式数据
const loading = ref(false);
const tableData = ref([]);
const selectedIds = ref([]);
const current = ref(1);
const pageSize = ref(10);
const total = ref(0);
const dialogFormVisible = ref(false);
const dialogViewVisible = ref(false);
const dialogGenerateVisible = ref(false);
const isEdit = ref(false);
const title = ref("");
const form = ref({});
const viewForm = ref({});
 
// 查询参数
const queryParams = reactive({
  returnNo: "",
  supplierId: "",
  status: "",
  dateRange: []
});
 
// 供应商列表
const supplierList = ref([
  { value: "1", label: "供应商A" },
  { value: "2", label: "供应商B" },
  { value: "3", label: "供应商C" }
]);
 
// 状态列表
const statusList = ref([
  { value: "draft", label: "草稿" },
  { value: "pending", label: "待审核" },
  { value: "approved", label: "已审核" },
  { value: "rejected", label: "已拒绝" },
  { value: "completed", label: "已完成" }
]);
 
// 模拟数据
const mockData = [
  {
    id: "1",
    returnNo: "TH20241201001",
    supplierName: "供应商A",
    returnDate: "2024-12-01",
    operatorName: "陈志强",
    returnReason: "质量不合格,煤质不符合要求",
    returnQuantity: 50,
    status: "pending",
    createTime: "2024-12-01 10:00:00"
  },
  {
    id: "2",
    returnNo: "TH20241201002",
    supplierName: "供应商B",
    returnDate: "2024-12-01",
    operatorName: "刘美玲",
    returnReason: "交货滞后,影响生产计划",
    returnQuantity: 30,
    status: "approved",
    createTime: "2024-12-01 14:30:00"
  }
];
 
// 获取状态类型
const getStatusType = (status) => {
  const statusMap = {
    draft: "",
    pending: "warning",
    approved: "success",
    rejected: "danger",
    completed: "info"
  };
  return statusMap[status] || "";
};
 
// 获取状态文本
const getStatusText = (status) => {
  const statusMap = {
    draft: "草稿",
    pending: "待审核",
    approved: "已审核",
    rejected: "已拒绝",
    completed: "已完成"
  };
  return statusMap[status] || status;
};
 
// 查询
const handleQuery = () => {
  current.value = 1;
  loadData();
};
 
// 重置查询
const resetQuery = () => {
  Object.assign(queryParams, {
    returnNo: "",
    supplierId: "",
    status: "",
    dateRange: []
  });
  handleQuery();
};
 
// 加载数据
const loadData = () => {
  loading.value = true;
  // 模拟API调用
  setTimeout(() => {
    tableData.value = mockData;
    total.value = mockData.length;
    loading.value = false;
  }, 500);
};
 
// 分页处理
const handlePagination = (pagination) => {
  current.value = pagination.page;
  pageSize.value = pagination.limit;
  loadData();
};
 
// 选择变化
const handleSelectionChange = (selection) => {
  selectedIds.value = selection.map(item => item.id);
};
 
// 新增
const handleAdd = () => {
  isEdit.value = false;
  title.value = "新增退货单";
  form.value = {
    supplierId: "",
    returnDate: "",
    operatorId: "",
    returnReason: "",
    returnQuantity: "",
    returnAmount: "",
    returnItems: [],
    remark: ""
  };
  dialogFormVisible.value = true;
};
 
// 编辑
const handleEdit = (row) => {
  isEdit.value = true;
  title.value = "编辑退货单";
  form.value = { ...row };
  dialogFormVisible.value = true;
};
 
// 查看
const handleView = (row) => {
  viewForm.value = { ...row };
  dialogViewVisible.value = true;
};
 
// 删除
const handleDelete = (row) => {
  ElMessageBox.confirm(
    `确定要删除退货单 ${row.returnNo} 吗?`,
    "提示",
    {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning"
    }
  ).then(() => {
    // 模拟删除
    const index = tableData.value.findIndex(item => item.id === row.id);
    if (index > -1) {
      tableData.value.splice(index, 1);
      total.value--;
      ElMessage.success("删除成功");
    }
  });
};
 
// 批量删除
const handleBatchDelete = () => {
  if (selectedIds.value.length === 0) {
    ElMessage.warning("请选择要删除的记录");
    return;
  }
  
  ElMessageBox.confirm(
    `确定要删除选中的 ${selectedIds.value.length} 条记录吗?`,
    "提示",
    {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning"
    }
  ).then(() => {
    // 模拟批量删除
    tableData.value = tableData.value.filter(item => !selectedIds.value.includes(item.id));
    total.value = tableData.value.length;
    selectedIds.value = [];
    ElMessage.success("批量删除成功");
  });
};
 
// 一键生成退货单
const handleGenerateReturn = () => {
  dialogGenerateVisible.value = true;
};
 
// 提交表单
const handleSubmit = (formData) => {
  if (isEdit.value) {
    // 编辑
    const index = tableData.value.findIndex(item => item.id === formData.id);
    if (index > -1) {
      tableData.value[index] = { ...formData };
      ElMessage.success("编辑成功");
    }
  } else {
    // 新增
    const newItem = {
      id: Date.now().toString(),
      returnNo: `TH${Date.now()}`,
      supplierName: supplierList.value.find(item => item.value === formData.supplierId)?.label || "",
      returnDate: formData.returnDate,
      operatorName: "当前用户",
      returnReason: formData.returnReason,
      returnQuantity: formData.returnQuantity,
      status: "draft",
      createTime: new Date().toLocaleString()
    };
    tableData.value.unshift(newItem);
    total.value++;
    ElMessage.success("新增成功");
  }
  dialogFormVisible.value = false;
};
 
// 表单成功回调
const handleSuccess = () => {
  loadData();
};
 
// 生成退货单成功回调
const handleGenerateSuccess = (returnOrder) => {
  dialogGenerateVisible.value = false;
  // 将生成的退货单添加到列表中
  if (returnOrder) {
    const newItem = {
      id: Date.now().toString(),
      returnNo: returnOrder.returnNo,
      supplierName: returnOrder.supplierName,
      returnDate: returnOrder.returnDate,
      operatorName: returnOrder.operatorName,
      returnReason: returnOrder.returnReason,
      returnQuantity: returnOrder.returnQuantity,
      status: returnOrder.status,
      createTime: returnOrder.createTime,
      returnItems: returnOrder.returnItems
    };
    tableData.value.unshift(newItem);
    total.value++;
  }
  loadData();
  ElMessage.success("退货单生成成功");
};
 
// 页面加载
onMounted(() => {
  loadData();
});
</script>
 
<style scoped>
.search-form {
  margin-bottom: 20px;
}
 
.table-toolbar {
  margin-bottom: 20px;
}
 
.el-card {
  margin-bottom: 20px;
}
</style>