gaoluyang
昨天 c79771f7290d595d7b8e21cac1d1e1929b09f357
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
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
<template>
  <view class="material-inspection-page">
    <!-- 使用通用页面头部组件 -->
    <PageHeader title="过程检验"
                @back="goBack" />
    <!-- 搜索区域 -->
    <view class="search-section">
      <view class="search-bar">
        <view class="search-input">
          <up-input class="search-text"
                    placeholder="请输入工序搜索"
                    v-model="searchForm.process"
                    @change="getList"
                    clearable />
        </view>
        <!-- <view class="filter-button"
              @click="showDatePicker">
          <up-icon name="calendar"
                   size="24"
                   color="#999"></up-icon>
        </view> -->
        <view class="filter-button"
              @click="getList">
          <up-icon name="search"
                   size="24"
                   color="#999"></up-icon>
        </view>
      </view>
      <!-- 日期选择 -->
      <!-- <view class="date-range"
            v-if="searchForm.entryDate">
        <text class="date-text">{{ searchForm.entryDate[0] }} 至 {{ searchForm.entryDate[1] }}</text>
        <up-icon name="close"
                 size="16"
                 color="#999"
                 @click="clearDateRange"></up-icon>
      </view> -->
    </view>
    <!-- 统计信息卡片 -->
    <!-- <view class="stats-cards">
      <view class="stat-card">
        <text class="stat-number">{{ totalCount }}</text>
        <text class="stat-label">总检验</text>
      </view>
      <view class="stat-card">
        <text class="stat-number">{{ submittedCount }}</text>
        <text class="stat-label">已提交</text>
      </view>
      <view class="stat-card">
        <text class="stat-number">{{ pendingCount }}</text>
        <text class="stat-label">待提交</text>
      </view>
      <view class="stat-card">
        <text class="stat-number">{{ qualifiedCount }}</text>
        <text class="stat-label">已合格</text>
      </view>
    </view> -->
    <!-- 检验列表 -->
    <view class="inspection-list"
          v-if="inspectionList.length > 0">
      <view v-for="(item, index) in inspectionList"
            :key="index">
        <view class="inspection-item"
              @click="viewDetail(item)">
          <view class="item-header">
            <view class="item-left">
              <!-- <view class="material-icon"
                    :class="getStateClass(item.inspectState)">
                <up-icon :name="getStateIcon(item.inspectState)"
                         size="16"
                         color="#ffffff"></up-icon>
              </view> -->
              <view class="material-info">
                <text class="material-name">{{ item.productName }}</text>
                <text class="material-code">{{ item.model }}</text>
              </view>
            </view>
            <view class="status-tags">
              <u-tag :type="getTagType(item.checkResult)"
                     size="mini"
                     class="status-tag">
                {{ item.checkResult }}
              </u-tag>
              <u-tag :type="getStateTagType(item.inspectState)"
                     size="mini"
                     class="status-tag">
                {{ item.inspectState ? '已提交' : '未提交' }}
              </u-tag>
            </view>
          </view>
          <up-divider></up-divider>
          <view class="item-details">
            <view class="detail-row">
              <text class="detail-label">检测日期</text>
              <text class="detail-value">{{ formatDateTime(item.checkTime) || '-' }}</text>
            </view>
            <view class="detail-row">
              <text class="detail-label">生产工单号</text>
              <text class="detail-value">{{ item.workOrderNo || '-' }}</text>
            </view>
            <view class="detail-row">
              <text class="detail-label">工序</text>
              <text class="detail-value">{{ item.process || '-' }}</text>
            </view>
            <view class="detail-row">
              <text class="detail-label">检验员</text>
              <text class="detail-value">{{ item.checkName || '-' }}</text>
            </view>
            <view class="detail-row">
              <text class="detail-label">数量</text>
              <text class="detail-value">{{ item.quantity || 0 }} {{ item.unit || '' }}</text>
            </view>
            <view class="detail-row">
              <text class="detail-label">检测单位</text>
              <text class="detail-value">{{ item.checkCompany || '-' }}</text>
            </view>
          </view>
          <!-- 操作按钮 -->
          <view class="action-buttons">
            <!-- <u-button type="primary"
                      size="small"
                      class="action-btn"
                      :disabled="item.inspectState"
                      @click.stop="startInspection(item)">
              编辑
            </u-button> -->
            <u-button type="info"
                      size="small"
                      class="action-btn"
                      @click.stop="viewDetail(item)">
              详情
            </u-button>
            <!-- <u-button type="success"
                      size="small"
                      class="action-btn"
                      :disabled="item.inspectState"
                      @click.stop="submitInspection(item)">
              提交
            </u-button> -->
          </view>
          <view class="action-buttons">
            <!-- <u-button type="info"
                      size="small"
                      class="action-btn"
                      @click.stop="viewFileList(item)">
              附件
            </u-button>
            <u-button type="warning"
                      size="small"
                      class="action-btn"
                      :disabled="item.inspectState || item.checkName !== ''"
                      @click.stop="assignInspector(item)">
              分配检验员
            </u-button> -->
          </view>
        </view>
      </view>
    </view>
    <view v-else
          class="no-data">
      <up-empty mode="data"
                text="暂无检验任务"></up-empty>
    </view>
    <!-- 分页组件 -->
    <!-- 浮动新增按钮 -->
    <!-- <view class="fab-button"
          @click="addInspection">
      <up-icon name="plus"
               size="24"
               color="#ffffff"></up-icon>
    </view> -->
    <!-- 日期选择器 -->
    <up-popup v-model:show="showDate"
              mode="date"
              :start-year="2020"
              :end-year="2030"
              :range="true"
              @confirm="confirmDate" />
    <!-- 分配检验员弹窗 -->
    <up-popup v-model:show="showAssignDialog"
              mode="center"
              round
              style="width: 80%">
      <view class="assign-dialog">
        <view class="dialog-header">
          <text class="dialog-title">分配检验员</text>
          <up-icon name="close"
                   size="20"
                   color="#999"
                   @click="showAssignDialog = false"></up-icon>
        </view>
        <view class="dialog-content">
          <up-form-item label="检验员"
                        prop="checkName"
                        :label-width="60"
                        required>
            <up-input v-model="assignForm.checkName"
                      placeholder="请选择检验员"
                      readonly />
            <template #right>
              <up-icon @click="showInspectorSheet = true"
                       name="arrow-right" />
            </template>
          </up-form-item>
        </view>
        <view class="dialog-footer">
          <u-button type="default"
                    class="footer-btn"
                    @click="showAssignDialog = false">
            取消
          </u-button>
          <u-button type="primary"
                    class="footer-btn"
                    @click="submitAssign">
            确定
          </u-button>
        </view>
      </view>
    </up-popup>
    <!-- 检验员选择 -->
    <up-action-sheet :show="showInspectorSheet"
                     :actions="userSheetOptions"
                     @select="selectInspector"
                     title="选择检验员" />
  </view>
</template>
 
<script setup>
  import { ref, computed, onMounted } from "vue";
  import { onShow } from "@dcloudio/uni-app";
  import PageHeader from "@/components/PageHeader.vue";
  import dayjs from "dayjs";
  import {
    submitQualityInspect,
    qualityInspectUpdate,
    qualityInspectListPage,
  } from "@/api/qualityManagement/materialInspection.js";
  import { userListNoPage } from "@/api/system/user.js";
 
  // 显示提示信息
  const showToast = message => {
    uni.showToast({
      title: message,
      icon: "none",
    });
  };
 
  // 搜索表单
  const searchForm = ref({
    process: "",
    entryDate: undefined,
    entryDateStart: undefined,
    entryDateEnd: undefined,
  });
 
  // 日期选择器
  const showDate = ref(false);
 
  // 分配检验员弹窗
  const showAssignDialog = ref(false);
  const showInspectorSheet = ref(false);
  const assignForm = ref({
    checkName: "",
  });
  const currentAssignRow = ref(null);
 
  // 检验列表数据
  const inspectionList = ref([]);
 
  // 分页数据
  const page = ref({
    current: -1,
    size: -1,
    total: 0,
  });
 
  // 加载状态
  const tableLoading = ref(false);
 
  // 统计数据
  const totalCount = ref(0);
  const submittedCount = ref(0);
  const pendingCount = ref(0);
  const qualifiedCount = ref(0);
 
  // 检验员列表
  const userList = ref([]);
 
  // ActionSheet选项
  const userSheetOptions = computed(() => {
    return userList.value.map(item => ({
      name: item.nickName,
      value: item.nickName,
    }));
  });
 
  // 返回上一页
  const goBack = () => {
    uni.navigateBack();
  };
 
  // 格式化日期时间
  const formatDateTime = dateStr => {
    if (!dateStr) return "";
    return dayjs(dateStr).format("YYYY-MM-DD");
  };
 
  // 获取状态样式
  const getStateClass = inspectState => {
    return inspectState ? "state-submitted" : "state-pending";
  };
 
  // 获取状态图标
  const getStateIcon = inspectState => {
    return inspectState ? "checkmark-circle" : "time";
  };
 
  // 获取标签类型
  const getTagType = checkResult => {
    if (checkResult === "合格") return "success";
    if (checkResult === "不合格") return "error";
    return "default";
  };
 
  // 获取状态标签类型
  const getStateTagType = inspectState => {
    return inspectState ? "success" : "warning";
  };
 
  // 显示日期选择器
  const showDatePicker = () => {
    showDate.value = true;
  };
 
  // 确认日期选择
  const confirmDate = e => {
    searchForm.value.entryDate = e.value;
    searchForm.value.entryDateStart = dayjs(e.value[0]).format("YYYY-MM-DD");
    searchForm.value.entryDateEnd = dayjs(e.value[1]).format("YYYY-MM-DD");
    getList();
  };
  const viewFileList = item => {
    uni.setStorageSync("qualityInspectFileId", item.id);
    uni.navigateTo({
      url: "/pages/qualityManagement/processInspection/fileList",
    });
  };
 
  // 清除日期范围
  const clearDateRange = () => {
    searchForm.value.entryDate = undefined;
    searchForm.value.entryDateStart = undefined;
    searchForm.value.entryDateEnd = undefined;
    getList();
  };
 
  // 获取用户列表
  const getUserList = async () => {
    try {
      const userRes = await userListNoPage();
      userList.value = userRes.data || [];
    } catch (e) {
      console.error("加载检验员列表失败", e);
      userList.value = [];
    }
  };
 
  // 查询列表
  const getList = () => {
    tableLoading.value = true;
    const params = { ...searchForm.value, ...page.value };
    params.entryDate = undefined;
    qualityInspectListPage({ ...params, inspectType: 1 })
      .then(res => {
        tableLoading.value = false;
        inspectionList.value = res.data.records || [];
        page.value.total = res.data.total || 0;
        totalCount.value = res.data.total || 0;
        submittedCount.value = inspectionList.value.filter(
          item => item.inspectState
        ).length;
        pendingCount.value = inspectionList.value.filter(
          item => !item.inspectState
        ).length;
        qualifiedCount.value = inspectionList.value.filter(
          item => item.checkResult === "合格"
        ).length;
      })
      .catch(err => {
        tableLoading.value = false;
        console.error("获取列表失败:", err);
        showToast("获取列表失败,请重试");
      });
  };
 
  // 编辑检验
  const startInspection = item => {
    if (!item) {
      showToast("参数错误");
      return;
    }
    // 存储完整的检验数据
    uni.setStorageSync("processInspectionEditData", item);
    // 跳转到编辑页面
    uni.navigateTo({
      url: `/pages/qualityManagement/processInspection/add?id=${item.id}&isEdit=true`,
    });
  };
 
  // 查看详情
  const viewDetail = item => {
    if (!item) {
      showToast("参数错误");
      return;
    }
    uni.setStorageSync("processInspectionEditData", item);
    // 跳转到详情页面
    uni.navigateTo({
      url: `/pages/qualityManagement/processInspection/detail?id=${item.id}`,
    });
  };
 
  // 新增检验
  const addInspection = () => {
    uni.navigateTo({
      url: "/pages/qualityManagement/processInspection/add",
    });
  };
 
  // 提交检验
  const submitInspection = async item => {
    if (!item) {
      showToast("参数错误");
      return;
    }
    try {
      const res = await submitQualityInspect({ id: item.id });
      if (res.code === 200) {
        showToast("提交成功");
        setTimeout(() => {
          getList();
        }, 1000);
      } else {
        showToast("提交失败:" + (res.msg || "未知错误"));
      }
    } catch (error) {
      console.error("提交失败:", error);
      showToast("提交失败,请重试");
    }
  };
 
  // 分配检验员
  const assignInspector = item => {
    if (!item) {
      showToast("参数错误");
      return;
    }
    currentAssignRow.value = item;
    getUserList();
    showAssignDialog.value = true;
  };
 
  // 选择检验员
  const selectInspector = e => {
    assignForm.value.checkName = e.value;
    showInspectorSheet.value = false;
  };
 
  // 提交分配
  const submitAssign = async () => {
    if (!currentAssignRow.value || !assignForm.value.checkName) {
      showToast("请选择检验员");
      return;
    }
    try {
      const data = {
        ...assignForm.value,
        id: currentAssignRow.value.id,
      };
      const res = await qualityInspectUpdate(data);
      if (res.code === 200) {
        showToast("分配成功");
        showAssignDialog.value = false;
        setTimeout(() => {
          getList();
        }, 1000);
      } else {
        showToast("分配失败:" + (res.msg || "未知错误"));
      }
    } catch (error) {
      console.error("分配失败:", error);
      showToast("分配失败,请重试");
    }
  };
 
  // 处理分页
  const handlePagination = obj => {
    page.value.current = obj.current;
    page.value.size = obj.size;
    getList();
  };
 
  onMounted(() => {
    getList();
    getUserList();
  });
 
  onShow(() => {
    getList();
  });
</script>
 
<style scoped lang="scss">
  @import "../../../styles/sales-common.scss";
 
  .material-inspection-page {
    min-height: 100vh;
    background: #f8f9fa;
    padding-bottom: 80px;
  }
 
  // 搜索区域
  .search-section {
    padding: 10px 15px;
    background: #fff;
    border-bottom: 1px solid #f0f0f0;
  }
 
  .search-bar {
    display: flex;
    align-items: center;
    background: #f8f9fa;
    border-radius: 20px;
    padding: 0 15px;
    height: 40px;
  }
 
  .search-input {
    flex: 1;
  }
 
  .search-text {
    background: transparent;
    border: none;
  }
 
  .filter-button {
    margin-left: 10px;
    padding: 5px;
  }
 
  // 统计卡片
  .stats-cards {
    display: flex;
    padding: 15px;
    gap: 10px;
    background: #fff;
    margin-bottom: 10px;
  }
 
  .stat-card {
    flex: 1;
    background: #2979ff;
    border-radius: 12px;
    padding: 15px;
    text-align: center;
    color: #fff;
    box-shadow: 0 2px 8px rgba(41, 121, 255, 0.2);
  }
 
  .stat-number {
    display: block;
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 5px;
  }
 
  .stat-label {
    font-size: 12px;
    opacity: 0.9;
  }
 
  // 检验列表
  .inspection-list {
    padding: 20px;
  }
 
  .inspection-item {
    background: #ffffff;
    border-radius: 12px;
    margin-bottom: 16px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    padding: 0 16px;
 
    &:active {
      transform: scale(0.98);
      box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    }
  }
 
  .item-header {
    padding: 16px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
 
  .item-left {
    display: flex;
    align-items: center;
    gap: 8px;
  }
 
  .material-icon {
    width: 24px;
    height: 24px;
    background: #2979ff;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
 
  .state-pending {
    background: #ff9900;
  }
 
  .state-submitted {
    background: #52c41a;
  }
 
  .material-info {
    flex: 1;
  }
 
  .material-name {
    font-size: 14px;
    color: #333;
    font-weight: 500;
  }
 
  .material-code {
    font-size: 12px;
    color: #999;
    margin-left: 8px;
  }
 
  .status-tags {
    display: flex;
    gap: 8px;
  }
 
  .status-tag {
    margin: 0;
  }
 
  .date-range {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: 8px;
  }
 
  .date-text {
    font-size: 12px;
    color: #666;
  }
 
  // 详情行
  .item-details {
    padding: 16px 0;
  }
 
  .detail-row {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 8px;
 
    &:last-child {
      margin-bottom: 0;
    }
  }
 
  .detail-label {
    font-size: 12px;
    color: #777777;
    min-width: 60px;
  }
 
  .detail-value {
    font-size: 12px;
    color: #000000;
    text-align: right;
    flex: 1;
    margin-left: 16px;
  }
 
  // 操作按钮
  .action-buttons {
    display: flex;
    gap: 12px;
    padding: 0 0 16px 0;
    justify-content: space-between;
  }
 
  .action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
  }
 
  // 空状态
  .no-data {
    padding: 60px 20px;
    text-align: center;
  }
 
  // 浮动按钮
  .fab-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    background: #2979ff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(41, 121, 255, 0.3);
    z-index: 1000;
  }
 
  // 分配检验员弹窗
  .assign-dialog {
    padding: 24px;
    background: #ffffff;
    border-radius: 12px;
  }
 
  .dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid #f0f0f0;
  }
 
  .dialog-title {
    font-size: 18px;
    font-weight: 600;
    color: #303133;
  }
 
  .dialog-content {
    margin-bottom: 24px;
  }
 
  .dialog-footer {
    display: flex;
    gap: 16px;
    padding-top: 16px;
    border-top: 1px solid #f0f0f0;
  }
 
  .footer-btn {
    flex: 1;
    height: 44px;
    font-size: 16px;
  }
 
  // 输入框样式
  :deep(.up-input__inner) {
    border-radius: 8px;
    height: 44px;
    font-size: 14px;
  }
 
  // 表单项样式
  :deep(.up-form-item) {
    margin-bottom: 0;
  }
 
  :deep(.up-form-item__label) {
    font-size: 14px;
    color: #606266;
    margin-bottom: 8px;
  }
 
  // 按钮样式
  :deep(.up-button--primary) {
    border-radius: 8px;
  }
 
  :deep(.up-button--default) {
    border-radius: 8px;
  }
 
  // 分页组件
  .pagination {
    padding: 20px;
    background: #fff;
    margin-top: 10px;
    display: flex;
    justify-content: center;
  }
</style>