ZN
13 小时以前 077ab59c700b85efdd057265bf752ad5942395b2
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
<template>
  <view class="nonconforming-management-page">
    <PageHeader title="不合格品管理" @back="goBack" />
    
    <!-- 搜索与筛选 -->
    <view class="search-section">
      <up-search
        placeholder="请输入产品名称搜索"
        v-model="searchForm.productName"
        @search="handleQuery"
        @custom="handleQuery"
        @clear="handleQuery"
        :show-action="true"
        action-text="搜索"
        :animation="true"
        customStyle="margin-bottom: 20rpx"
      ></up-search>
      <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="showStatusSelect = true">
          <text>{{ statusLabel }}</text>
          <up-icon name="arrow-down" size="14" color="#999"></up-icon>
        </view>
      </view>
    </view>
 
    <!-- 列表区域 -->
    <view class="list-container" v-if="tableData.length > 0">
      <view v-for="(item, index) in tableData" :key="index" class="list-item">
        <view class="item-header">
          <text class="product-name">{{ item.productName }}</text>
          <up-tag :text="getStatusText(item.inspectState)" :type="getStatusType(item.inspectState)" size="mini"></up-tag>
        </view>
        <view class="item-content">
          <view class="item-row">
            <text class="item-label">类别:</text>
            <text class="item-value">{{ getInspectTypeText(item.inspectType) }}</text>
          </view>
          <view class="item-row">
            <text class="item-label">检测日期:</text>
            <text class="item-value">{{ item.checkTime || '-' }}</text>
          </view>
          <view class="item-row">
            <text class="item-label">规格型号:</text>
            <text class="item-value">{{ item.model || '-' }}</text>
          </view>
          <view class="item-row">
            <text class="item-label">不合格现象:</text>
            <text class="item-value text-error">{{ item.defectivePhenomena || '-' }}</text>
          </view>
          <view class="item-row" v-if="item.inspectState === 1">
            <text class="item-label">处理结果:</text>
            <text class="item-value text-success">{{ item.dealResult || '-' }}</text>
          </view>
        </view>
        <view class="item-actions">
          <up-button v-if="item.inspectState === 0" type="primary" size="mini" @click.stop="openDealDialog(item)">处理</up-button>
          <up-button type="error" size="mini" @click.stop="handleDelete(item)">删除</up-button>
        </view>
      </view>
      <view class="pagination-container">
        <up-loadmore :status="loadStatus" @loadmore="getList" />
      </view>
    </view>
    
    <view v-else class="no-data">
      <up-empty mode="data" text="暂无数据"></up-empty>
    </view>
 
    <!-- 类型选择器 -->
    <up-action-sheet
      :actions="typeActions"
      :show="showTypeSelect"
      @close="showTypeSelect = false"
      @select="selectType"
      title="请选择类别"
    ></up-action-sheet>
 
    <!-- 状态选择器 -->
    <up-action-sheet
      :actions="statusActions"
      :show="showStatusSelect"
      @close="showStatusSelect = false"
      @select="selectStatus"
      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?.defectivePhenomena }}</text>
          </view>
          <up-form-item label="处理结果" prop="dealResult" required borderBottom>
            <up-textarea v-model="dealForm.dealResult" placeholder="请输入处理结果" count 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-datetime-picker
      :show="showDatePicker"
      v-model="dateValue"
      mode="date"
      @confirm="confirmDate"
      @cancel="showDatePicker = false"
    ></up-datetime-picker>
  </view>
</template>
 
<script setup>
import { ref, reactive, onMounted, computed } from 'vue';
import {
  qualityUnqualifiedListPage,
  qualityUnqualifiedDeal,
  qualityUnqualifiedDel
} from '@/api/qualityManagement/nonconformingManagement.js';
import { toast, showConfirm } from '@/utils/common';
import dayjs from 'dayjs';
 
const searchForm = reactive({
  productName: '',
  inspectType: '',
  inspectState: ''
});
 
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 === searchForm.inspectType);
  return action ? action.name : '全部类别';
});
 
const showStatusSelect = ref(false);
const statusActions = [
  { name: '全部', value: '' },
  { name: '待处理', value: '0' },
  { name: '已处理', value: '1' }
];
const statusLabel = computed(() => {
  const action = statusActions.find(a => a.value === searchForm.inspectState);
  return action ? action.name : '全部状态';
});
 
const dealDialogVisible = ref(false);
const submitLoading = ref(false);
const currentItem = ref(null);
const dealForm = reactive({
  id: null,
  dealResult: '',
  dealTime: dayjs().format('YYYY-MM-DD')
});
 
const showDatePicker = ref(false);
const dateValue = ref(Number(new Date()));
 
const getInspectTypeText = (type) => {
  const types = { '0': '入厂检', '1': '车间检', '2': '出厂检' };
  return types[type] || '-';
};
 
const getStatusText = (state) => {
  return state === 1 ? '已处理' : '待处理';
};
 
const getStatusType = (state) => {
  return state === 1 ? 'success' : 'warning';
};
 
const getList = () => {
  if (loadStatus.value === 'loading' || (page.total > 0 && tableData.value.length >= page.total)) return;
  
  loadStatus.value = 'loading';
  const params = {
    productName: searchForm.productName || null,
    inspectType: searchForm.inspectType || null,
    inspectState: searchForm.inspectState || null,
    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';
      page.current++;
    }
  }).catch(() => {
    loadStatus.value = 'loadmore';
  });
};
 
const handleQuery = () => {
  page.current = 1;
  page.total = 0;
  tableData.value = [];
  loadStatus.value = 'loadmore';
  getList();
};
 
const selectType = (e) => {
  searchForm.inspectType = e.value;
  handleQuery();
};
 
const selectStatus = (e) => {
  searchForm.inspectState = e.value;
  handleQuery();
};
 
const openDealDialog = (item) => {
  currentItem.value = item;
  dealForm.id = item.id;
  dealForm.dealResult = '';
  dealForm.dealTime = dayjs().format('YYYY-MM-DD');
  dealDialogVisible.value = true;
};
 
const submitDeal = () => {
  if (!dealForm.dealResult) {
    toast('请输入处理结果');
    return;
  }
  submitLoading.value = true;
  qualityUnqualifiedDeal(dealForm).then(() => {
    toast('处理成功');
    dealDialogVisible.value = false;
    handleQuery();
  }).finally(() => {
    submitLoading.value = false;
  });
};
 
const handleDelete = (row) => {
  showConfirm('确认删除该不合格记录吗?').then(res => {
    if (res.confirm) {
      qualityUnqualifiedDel([row.id]).then(() => {
        toast('删除成功');
        handleQuery();
      });
    }
  });
};
 
const confirmDate = (e) => {
  dealForm.dealTime = dayjs(e.value).format('YYYY-MM-DD');
  showDatePicker.value = false;
};
 
const goBack = () => {
  uni.navigateBack();
};
 
onMounted(() => {
  handleQuery();
});
</script>
 
<style lang="scss" scoped>
.nonconforming-management-page {
  padding-bottom: 20rpx;
  background-color: #f5f7fa;
  min-height: 100vh;
}
 
.search-section {
  padding: 20rpx 30rpx;
  background-color: #ffffff;
  position: sticky;
  top: 0;
  z-index: 10;
}
 
.filter-row {
  display: flex;
  justify-content: space-around;
  padding: 10rpx 0;
}
 
.filter-item {
  display: flex;
  align-items: center;
  gap: 10rpx;
  font-size: 28rpx;
  color: #606266;
}
 
.list-container {
  padding: 20rpx;
}
 
.list-item {
  background-color: #ffffff;
  border-radius: 16rpx;
  padding: 30rpx;
  margin-bottom: 20rpx;
  box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
}
 
.item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20rpx;
}
 
.product-name {
  font-size: 30rpx;
  font-weight: bold;
  color: #303133;
}
 
.item-content {
  margin-bottom: 20rpx;
}
 
.item-row {
  display: flex;
  margin-bottom: 10rpx;
}
 
.item-label {
  color: #909399;
  width: 180rpx;
  font-size: 28rpx;
}
 
.item-value {
  flex: 1;
  color: #303133;
  font-size: 28rpx;
}
 
.text-error {
  color: #f56c6c;
}
 
.text-success {
  color: #67c23a;
}
 
.item-actions {
  display: flex;
  justify-content: flex-end;
  gap: 20rpx;
  border-top: 1rpx solid #ebeef5;
  padding-top: 20rpx;
}
 
.no-data {
  padding-top: 200rpx;
}
 
.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;
}
</style>