huminmin
昨天 7529786b5f409ffa7ea0b1d5c3f550c4d0a83d3b
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
<template>
  <view class="nonconforming-management-page">
    <PageHeader title="不合格品管理" @back="goBack" />
    
    <!-- 搜索与筛选(样式参照仓储物流模块) -->
    <view class="search-section">
      <view class="search-row">
        <view class="search-input-wrap">
          <up-input v-model="searchForm.productName" placeholder="产品名称" clearable />
        </view>
        <view class="btn-search" @click="handleQuery">
          <view class="btn-search-inner">
            <up-icon name="search" size="22" color="#fff"></up-icon>
            <text>搜索</text>
          </view>
        </view>
      </view>
      <view class="filter-row">
        <view class="filter-item" @click="showTypeSelect = true">
          <text>{{ typeLabel }}</text>
          <up-icon name="arrow-down" size="14" color="#999"></up-icon>
        </view>
        <view class="filter-item" @click="openDateRange">
          <text>{{ dateRangeLabel }}</text>
          <up-icon name="calendar" size="14" color="#999"></up-icon>
        </view>
      </view>
    </view>
 
    <!-- 列表区域 -->
    <view class="list-section">
      <view v-if="tableData.length > 0">
        <view v-for="(item, index) in tableData" :key="item.id || index" class="card-item">
          <view class="card-click" @click="openForm('edit', item)">
            <view class="card-header">
              <view class="header-main">
                <text class="product-name">{{ item.productName }}</text>
              </view>
              <view class="header-sub">
                <text class="sub-title">{{ item.model || '-' }}</text>
                <up-tag :text="getInspectTypeText(item.checkType ?? item.inspectType)" type="primary" size="mini" />
              </view>
            </view>
            <up-divider />
            <view class="card-body">
              <view class="row"><text class="l">检测日期</text><text class="r">{{ item.checkTime || '-' }}</text></view>
              <view class="row"><text class="l">批号</text><text class="r">{{ item.batchNo || '-' }}</text></view>
              <view class="row"><text class="l">检验员</text><text class="r">{{ item.checkName || '-' }}</text></view>
              <view class="row"><text class="l">不合格现象</text><text class="r text-error">{{ item.defectivePhenomena || '-' }}</text></view>
              <view class="row" v-if="item.inspectState == 1"><text class="l">处理结果</text><text class="r text-success">{{ getDealResultLabel(item.dealResult) || item.dealResult || '-' }}</text></view>
              <view class="row" v-if="item.inspectState == 1"><text class="l">处理人</text><text class="r">{{ item.dealName || '-' }}</text></view>
              <view class="row" v-if="item.inspectState == 1"><text class="l">处理日期</text><text class="r">{{ item.dealTime || '-' }}</text></view>
            </view>
          </view>
          <view class="card-actions">
            <view class="btn-link btn-link-primary" v-if="item.inspectState == 0" @click.stop="openDealDialog(item)">处理</view>
            <view class="btn-link btn-link-plain" v-if="item.inspectState == 0" @click.stop="openForm('edit', item)">编辑</view>
            <view class="btn-link btn-link-warn" v-if="item.inspectState == 0" @click.stop="handleDelete(item)">删除</view>
          </view>
        </view>
        <view class="load-more-wrap">
          <u-loadmore :status="loadStatus" @loadmore="loadMore" />
        </view>
      </view>
      <view v-else class="no-data">暂无数据</view>
    </view>
    
    <!-- 类型选择器 -->
    <up-action-sheet
      :actions="typeActions"
      :show="showTypeSelect"
      @close="showTypeSelect = false"
      @select="selectType"
      title="请选择类别"
    ></up-action-sheet>
 
    <!-- 处理弹窗 -->
    <up-popup v-model:show="dealDialogVisible" mode="center" round closeable @close="dealDialogVisible = false">
      <view class="dialog-content">
        <view class="dialog-header">
          <text class="dialog-title">不合格品处理</text>
        </view>
        <up-form :model="dealForm" ref="dealFormRef" label-width="100" label-position="top">
          <view class="info-summary">
            <text class="summary-text">产品:{{ currentItem?.productName }}</text>
            <text class="summary-text">检测日期:{{ currentItem?.checkTime || '-' }}</text>
          </view>
          <up-form-item label="不合格现象" prop="defectivePhenomena" required borderBottom>
            <up-textarea v-model="dealForm.defectivePhenomena" placeholder="请输入不合格现象" count border="surround" />
          </up-form-item>
          <up-form-item label="处理结果" prop="dealResult" required borderBottom>
            <view class="selector-trigger" @click="showDealResultSelect = true">
              <text class="selector-text" :class="{ placeholder: !dealResultLabel }">{{ dealResultLabel || '请选择处理结果' }}</text>
              <up-icon name="arrow-down" size="14" color="#999"></up-icon>
            </view>
          </up-form-item>
          <up-form-item label="处理人" prop="dealName" required borderBottom>
            <up-input v-model="dealForm.dealName" placeholder="请输入处理人" border="surround" />
          </up-form-item>
          <up-form-item label="处理日期" prop="dealTime" required borderBottom>
            <up-input
              v-model="dealForm.dealTime"
              placeholder="请选择处理日期"
              border="surround"
              readonly
              @click="showDatePicker = true"
            />
          </up-form-item>
        </up-form>
        <view class="dialog-footer">
          <up-button type="primary" text="提交处理" @click="submitDeal" :loading="submitLoading"></up-button>
          <up-button text="取消" @click="dealDialogVisible = false" customStyle="margin-top: 20rpx"></up-button>
        </view>
      </view>
    </up-popup>
 
    <!-- 处理结果选择器 -->
    <up-action-sheet
      :actions="dealResultActions"
      :show="showDealResultSelect"
      @close="showDealResultSelect = false"
      @select="selectDealResult"
      title="请选择处理结果"
    />
 
    <!-- 日期选择器 -->
    <up-datetime-picker
      :show="showDatePicker"
      v-model="dateValue"
      mode="date"
      @confirm="confirmDate"
      @cancel="showDatePicker = false"
    ></up-datetime-picker>
 
    <!-- 录入日期范围选择:开始 -->
    <up-datetime-picker
      :show="showEntryStartPicker"
      v-model="entryStartValue"
      mode="date"
      @confirm="confirmEntryStart"
      @cancel="showEntryStartPicker = false"
    />
    <!-- 录入日期范围选择:结束 -->
    <up-datetime-picker
      :show="showEntryEndPicker"
      v-model="entryEndValue"
      mode="date"
      @confirm="confirmEntryEnd"
      @cancel="showEntryEndPicker = false"
    />
 
    <!-- 右下角新增按钮 -->
    <view class="fab-button" @click="openForm('add')">
      <up-icon name="plus" size="24" color="#ffffff"></up-icon>
    </view>
  </view>
</template>
 
<script setup>
import { ref, reactive, computed } from 'vue';
import {
  qualityUnqualifiedListPage,
  qualityUnqualifiedDeal,
  qualityUnqualifiedDel
} from '@/api/qualityManagement/nonconformingManagement.js';
import { toast, showConfirm } from '@/utils/common';
import { useDict } from '@/utils/dict'
import dayjs from 'dayjs';
import PageHeader from '@/components/PageHeader.vue'
import { onReachBottom, onShow } from '@dcloudio/uni-app'
 
const searchForm = reactive({
  productName: '',
  checkType: '',
  entryDateStart: undefined,
  entryDateEnd: undefined
});
 
const tableData = ref([]);
const page = reactive({
  current: 1,
  size: 20,
  total: 0
});
const loadStatus = ref('loadmore');
 
const showTypeSelect = ref(false);
const typeActions = [
  { name: '全部', value: '' },
  { name: '入厂检', value: '0' },
  { name: '车间检', value: '1' },
  { name: '出厂检', value: '2' }
];
const typeLabel = computed(() => {
  const action = typeActions.find(a => a.value === String(searchForm.checkType ?? ''));
  return action ? action.name : '全部类别';
});
 
const dateRangeLabel = computed(() => {
  if (searchForm.entryDateStart && searchForm.entryDateEnd) return `${searchForm.entryDateStart}~${searchForm.entryDateEnd}`
  if (searchForm.entryDateStart) return `${searchForm.entryDateStart}~`
  if (searchForm.entryDateEnd) return `~${searchForm.entryDateEnd}`
  return '检测日期'
})
 
const dealDialogVisible = ref(false);
const submitLoading = ref(false);
const currentItem = ref(null);
const dealForm = reactive({
  id: null,
  defectivePhenomena: '',
  dealResult: '',
  dealName: '',
  dealTime: dayjs().format('YYYY-MM-DD')
});
 
const { rejection_handling } = useDict('rejection_handling')
const showDealResultSelect = ref(false)
const dealResultActions = computed(() => {
  const list = rejection_handling?.value || []
  return (list || []).map(it => ({ name: it.label, value: it.value }))
})
const dealResultLabel = computed(() => {
  const list = rejection_handling?.value || []
  const v = dealForm.dealResult
  return (list || []).find(it => String(it.value) === String(v))?.label || ''
})
function getDealResultLabel(value) {
  const list = rejection_handling?.value || []
  return (list || []).find(it => String(it.value) === String(value))?.label || ''
}
 
const showDatePicker = ref(false);
const dateValue = ref(Number(new Date()));
 
const showEntryStartPicker = ref(false)
const showEntryEndPicker = ref(false)
const entryStartValue = ref(Date.now())
const entryEndValue = ref(Date.now())
 
const getInspectTypeText = (type) => {
  const types = { '0': '入厂检', '1': '车间检', '2': '出厂检' };
  return types[String(type ?? '')] || '-';
};
 
const getList = (force = false) => {
  const isFirstPage = page.current === 1
  if (
    !force &&
    (loadStatus.value === 'loading' ||
      (!isFirstPage && page.total > 0 && tableData.value.length >= page.total))
  )
    return
 
  loadStatus.value = 'loading'
  const params = {
    productName: searchForm.productName || null,
    checkType: searchForm.checkType === '' ? null : searchForm.checkType,
    entryDateStart: searchForm.entryDateStart,
    entryDateEnd: searchForm.entryDateEnd,
    current: page.current,
    size: page.size
  };
  
  qualityUnqualifiedListPage(params).then(res => {
    const records = res?.data?.records || [];
    if (page.current === 1) {
      tableData.value = records;
    } else {
      tableData.value = [...tableData.value, ...records];
    }
    page.total = res?.data?.total || 0;
    
    if (tableData.value.length >= page.total) {
      loadStatus.value = 'nomore';
    } else {
      loadStatus.value = 'loadmore';
    }
  }).catch(() => {
    loadStatus.value = 'error';
  });
};
 
const loadMore = () => {
  if (loadStatus.value === 'nomore' || loadStatus.value === 'loading') return
  loadStatus.value = 'loading'
  page.current++
  getList()
}
 
const handleQuery = () => {
  page.current = 1;
  page.total = 0;
  tableData.value = [];
  loadStatus.value = 'loadmore';
  getList(true);
};
 
const selectType = (e) => {
  searchForm.checkType = e.value;
  handleQuery();
};
 
const openDateRange = () => {
  entryStartValue.value = searchForm.entryDateStart ? dayjs(searchForm.entryDateStart, 'YYYY-MM-DD').valueOf() : Date.now()
  showEntryStartPicker.value = true
}
const confirmEntryStart = (e) => {
  const ts = e?.value ?? entryStartValue.value
  searchForm.entryDateStart = dayjs(ts).format('YYYY-MM-DD')
  showEntryStartPicker.value = false
  entryEndValue.value = searchForm.entryDateEnd ? dayjs(searchForm.entryDateEnd, 'YYYY-MM-DD').valueOf() : Date.now()
  showEntryEndPicker.value = true
}
const confirmEntryEnd = (e) => {
  const ts = e?.value ?? entryEndValue.value
  searchForm.entryDateEnd = dayjs(ts).format('YYYY-MM-DD')
  showEntryEndPicker.value = false
  handleQuery()
}
 
const openDealDialog = (item) => {
  currentItem.value = item;
  dealForm.id = item.id;
  dealForm.defectivePhenomena = item.defectivePhenomena || ''
  dealForm.dealResult = item.dealResult || '';
  dealForm.dealName = item.dealName || ''
  dealForm.dealTime = dayjs().format('YYYY-MM-DD');
  dealDialogVisible.value = true;
};
 
const selectDealResult = (e) => {
  dealForm.dealResult = e.value
  showDealResultSelect.value = false
}
 
const submitDeal = () => {
  if (!dealForm.defectivePhenomena) {
    toast('请输入不合格现象')
    return;
  }
  if (!dealForm.dealResult) {
    toast('请选择处理结果')
    return
  }
  if (!dealForm.dealName) {
    toast('请输入处理人')
    return
  }
  submitLoading.value = true;
  qualityUnqualifiedDeal(dealForm).then(() => {
    toast('处理成功');
    dealDialogVisible.value = false;
    handleQuery();
  }).finally(() => {
    submitLoading.value = false;
  });
};
 
const handleDelete = (row) => {
  showConfirm('确认删除该不合格记录吗?').then(async res => {
    if (!res.confirm) return
    await qualityUnqualifiedDel([row.id])
    toast('删除成功')
    handleQuery()
  })
};
 
const confirmDate = (e) => {
  dealForm.dealTime = dayjs(e.value).format('YYYY-MM-DD');
  showDatePicker.value = false;
};
 
const openForm = (type, row) => {
  if (type !== 'add' && row?.inspectState == 1) {
    toast('已处理的数据不能再编辑')
    return
  }
  const id = row?.id
  uni.navigateTo({
    url: `/pages/qualityManagement/nonconformingManagement/form?type=${type}${id ? `&id=${id}` : ''}`
  })
}
 
const goBack = () => {
  uni.navigateBack();
};
 
onShow(() => {
  handleQuery()
})
 
onReachBottom(() => {
  loadMore()
})
</script>
 
<style lang="scss" scoped>
.nonconforming-management-page {
  min-height: 100vh;
  background: #f5f5f5;
  padding-bottom: 120rpx;
}
 
.search-section {
  background: #fff;
  margin: 24rpx;
  padding: 24rpx;
  border-radius: 16rpx;
}
 
.search-row { display: flex; align-items: center; margin-bottom: 20rpx; }
.search-input-wrap { flex: 1; margin-right: 20rpx; min-width: 0; }
.btn-search {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 180rpx;
  min-height: 72rpx;
  flex-shrink: 0;
  padding: 20rpx 24rpx;
  background: #2979ff;
  color: #fff;
  border-radius: 12rpx;
  font-size: 28rpx;
  box-sizing: border-box;
  text-align: center;
}
.btn-search-inner { display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 8rpx; }
 
.filter-row {
  display: flex;
  gap: 20rpx;
}
 
.filter-item {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18rpx 20rpx;
  background: #f5f5f5;
  border-radius: 12rpx;
  font-size: 26rpx;
  color: #666;
}
 
.list-section { padding: 0 24rpx; }
.card-item {
  background: #fff;
  border-radius: 16rpx;
  padding: 16rpx 20rpx;
  margin-bottom: 20rpx;
  box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
}
.card-header { padding: 2rpx 0 6rpx; }
.header-main { display: flex; justify-content: space-between; align-items: center; gap: 16rpx; }
.product-name { font-size: 30rpx; font-weight: 500; color: #333; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-sub { display: flex; justify-content: space-between; gap: 16rpx; margin-top: 6rpx; }
.sub-title { font-size: 24rpx; color: #999; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub-right { font-size: 24rpx; color: #999; flex-shrink: 0; }
.card-body .row { display: flex; justify-content: space-between; padding: 6rpx 0; font-size: 26rpx; }
.card-body .l { color: #666; width: 180rpx; flex-shrink: 0; }
.card-body .r { color: #333; flex: 1; text-align: right; word-break: break-all; }
.card-actions {
  display: flex;
  gap: 16rpx;
  justify-content: flex-end;
  align-items: center;
  margin-top: 12rpx;
  padding-top: 14rpx;
  border-top: 1rpx solid #eee;
}
.btn-link {
  font-size: 28rpx;
  padding: 10rpx 22rpx;
  border-radius: 999rpx;
  border: 1rpx solid transparent;
}
.btn-link-primary { color: #2979ff; border-color: rgba(41, 121, 255, 0.4); background: rgba(41, 121, 255, 0.08); }
.btn-link-plain { color: #606266; border-color: rgba(96, 98, 102, 0.35); background: rgba(96, 98, 102, 0.06); }
.btn-link-warn { color: #f56c6c; border-color: rgba(245, 108, 108, 0.55); background: rgba(245, 108, 108, 0.08); }
 
.text-error {
  color: #f56c6c;
}
 
.text-success {
  color: #67c23a;
}
 
.no-data { text-align: center; padding: 60rpx 0; color: #999; font-size: 28rpx; }
.load-more-wrap { padding: 24rpx 24rpx 8rpx; }
 
.dialog-content {
  width: 650rpx;
  padding: 40rpx;
  background-color: #ffffff;
  border-radius: 24rpx;
  overflow: hidden;
  box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08);
}
 
.dialog-header {
  margin-bottom: 30rpx;
  text-align: center;
}
 
.dialog-title {
  font-size: 32rpx;
  font-weight: bold;
}
 
.info-summary {
  background-color: #f5f7fa;
  padding: 20rpx;
  border-radius: 8rpx;
  margin-bottom: 30rpx;
}
 
.summary-text {
  display: block;
  font-size: 26rpx;
  color: #606266;
  margin-bottom: 10rpx;
}
 
.dialog-footer {
  margin-top: 40rpx;
}
 
.selector-trigger { display: flex; align-items: center; justify-content: space-between; padding: 20rpx 24rpx; background: #f5f5f5; border-radius: 12rpx; }
.selector-text { font-size: 28rpx; color: #333; }
.selector-text.placeholder { color: #999; }
 
.fab-button {
  position: fixed;
  right: 36rpx;
  bottom: 72rpx;
  width: 104rpx;
  height: 104rpx;
  border-radius: 52rpx;
  background: #2979ff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10rpx 26rpx rgba(41, 121, 255, 0.35);
  z-index: 20;
}
</style>