zhangwencui
6 天以前 bbb54adc8d9fd6ae6b87ac036c8b21f3ad7daef4
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
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MesProFeedbackApi } from '#/api/mes/pro/feedback';
 
import { nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
 
import {
  DICT_TYPE,
  MesProFeedbackStatusEnum,
} from '@vben/constants';
import { useVbenModal } from '@vben/common-ui';
 
import { Button, message, Popconfirm, Space } from 'ant-design-vue';
 
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
  approveFeedback,
  deleteFeedback,
  getFeedbackPage,
  rejectFeedback,
  submitFeedback,
} from '#/api/mes/pro/feedback';
import { $t } from '#/locales';
 
import FeedbackForm from '../../../pro/feedback/modules/form.vue';
 
defineOptions({ name: 'WorkbenchFeedbackHistoryTab' });
 
const props = defineProps<{
  taskId?: number;
  /** 外部触发刷新 */
  refreshKey?: number;
}>();
 
const emit = defineEmits<{ reported: [] }>();
 
const [FormModal, formModalApi] = useVbenModal({
  connectedComponent: FeedbackForm,
  destroyOnClose: true,
});
 
/** 查看详情 */
function handleDetail(row: MesProFeedbackApi.Feedback) {
  formModalApi.setData({ formType: 'detail', id: row.id }).open();
}
 
/** 编辑(仅草稿) */
function handleEdit(row: MesProFeedbackApi.Feedback) {
  formModalApi.setData({ formType: 'update', id: row.id }).open();
}
 
/** 删除(仅草稿) */
async function handleDelete(row: MesProFeedbackApi.Feedback) {
  await deleteFeedback(row.id!);
  message.success('删除成功');
  refreshGrid();
  emit('reported');
}
 
/** 提交(仅草稿) */
async function handleSubmit(row: MesProFeedbackApi.Feedback) {
  await submitFeedback(row.id!);
  message.success('报工单已提交');
  refreshGrid();
  emit('reported');
}
 
/** 审批通过(仅审批中) */
async function handleApprove(row: MesProFeedbackApi.Feedback) {
  const finished = await approveFeedback(row.id!);
  message.success(
    finished ? '报工单已审批完成' : '报工成功,请等待质量检验完成!',
  );
  refreshGrid();
  emit('reported');
}
 
/** 驳回(仅审批中) */
async function handleReject(row: MesProFeedbackApi.Feedback) {
  await rejectFeedback(row.id!);
  message.success('报工单已驳回');
  refreshGrid();
  emit('reported');
}
 
/** 状态常量供模板使用 */
const STATUS_PREPARE = MesProFeedbackStatusEnum.PREPARE;
const STATUS_APPROVING = MesProFeedbackStatusEnum.APPROVING;
 
const gridHeight = ref(300);
const gridContainerRef = ref<HTMLElement>();
let resizeObserver: ResizeObserver | null = null;
 
const [Grid, gridApi] = useVbenVxeGrid({
  gridOptions: {
    columns: [
      {
        field: 'code',
        title: '报订单号',
        width: 160,
        slots: { default: 'code' },
      },
      { field: 'workOrderCode', title: '工单编码', width: 140 },
      { field: 'processName', title: '工序', width: 100 },
      { field: 'itemName', title: '产品', minWidth: 120 },
      { field: 'feedbackQuantity', title: '报工数量', width: 100 },
      { field: 'qualifiedQuantity', title: '合格品', width: 90 },
      { field: 'unqualifiedQuantity', title: '不良品', width: 90 },
      { field: 'feedbackUserNickname', title: '报工人', width: 100 },
      { field: 'approveUserNickname', title: '审核人', width: 100 },
      {
        field: 'status',
        title: '状态',
        width: 100,
        cellRender: {
          name: 'CellDict',
          props: { type: DICT_TYPE.MES_PRO_FEEDBACK_STATUS },
        },
      },
      {
        field: 'feedbackTime',
        title: '报工时间',
        width: 170,
        formatter: 'formatDateTime',
      },
      {
        title: '操作',
        width: 260,
        fixed: 'right',
        slots: { default: 'actions' },
      },
    ],
    height: gridHeight.value,
    keepSource: true,
    proxyConfig: {
      ajax: {
        query: async ({ page }) => {
          if (!props.taskId) {
            return { list: [], total: 0 };
          }
          return await getFeedbackPage({
            taskId: props.taskId,
            pageNo: page.currentPage,
            pageSize: page.pageSize,
          });
        },
      },
    },
    rowConfig: { isHover: true, keyField: 'id' },
    toolbarConfig: { refresh: true },
  } as VxeTableGridOptions<MesProFeedbackApi.Feedback>,
});
 
function updateGridHeight() {
  if (gridContainerRef.value) {
    const h = gridContainerRef.value.clientHeight;
    if (h > 100 && h !== gridHeight.value) {
      gridHeight.value = h;
      gridApi.setGridOptions({ height: h });
    }
  }
}
 
onMounted(() => {
  nextTick(() => {
    updateGridHeight();
    if (gridContainerRef.value) {
      resizeObserver = new ResizeObserver(() => updateGridHeight());
      resizeObserver.observe(gridContainerRef.value);
    }
  });
});
 
onBeforeUnmount(() => {
  resizeObserver?.disconnect();
  resizeObserver = null;
});
 
function refreshGrid() {
  gridApi.query();
}
 
// 监听 taskId 变化刷新
watch(
  () => props.taskId,
  () => {
    if (props.taskId) {
      gridApi.query();
    }
  },
);
 
// 监听外部 refreshKey 变化刷新
watch(
  () => props.refreshKey,
  () => {
    gridApi.query();
  },
);
</script>
 
<template>
  <div class="feedback-history-tab">
    <FormModal @success="refreshGrid" />
 
    <div v-if="!taskId" class="feedback-history-tab__empty">
      请从左侧工单列表选择一条任务查看报工记录
    </div>
 
    <div v-else ref="gridContainerRef" class="feedback-history-tab__grid">
      <Grid table-title="报工记录">
        <template #code="{ row }">
          <Button type="link" @click="handleDetail(row)">
            {{ row.code }}
          </Button>
        </template>
        <template #actions="{ row }">
          <Space :size="4" wrap>
            <Button type="link" size="small" @click="handleDetail(row)">
              查看
            </Button>
            <!-- 草稿:编辑、删除、提交 -->
            <Button
              v-if="row.status === STATUS_PREPARE"
              type="link"
              size="small"
              @click="handleEdit(row)"
            >
              编辑
            </Button>
            <Popconfirm
              v-if="row.status === STATUS_PREPARE"
              title="确认提交该报工单?提交后将不能修改。"
              @confirm="handleSubmit(row)"
            >
              <Button type="link" size="small">
                提交
              </Button>
            </Popconfirm>
            <Popconfirm
              v-if="row.status === STATUS_PREPARE"
              title="确认删除该报工单?"
              @confirm="handleDelete(row)"
            >
              <Button type="link" size="small" danger>
                删除
              </Button>
            </Popconfirm>
            <!-- 审批中:审批通过、驳回 -->
            <Popconfirm
              v-if="row.status === STATUS_APPROVING"
              title="确认审批通过该报工单?"
              @confirm="handleApprove(row)"
            >
              <Button type="link" size="small">
                审批通过
              </Button>
            </Popconfirm>
            <Popconfirm
              v-if="row.status === STATUS_APPROVING"
              title="确认驳回该报工单?"
              @confirm="handleReject(row)"
            >
              <Button type="link" size="small" danger>
                驳回
              </Button>
            </Popconfirm>
          </Space>
        </template>
      </Grid>
    </div>
  </div>
</template>
 
<style lang="scss" scoped>
.feedback-history-tab {
  padding: 16px 20px;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
 
.feedback-history-tab__grid {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
 
.feedback-history-tab__empty {
  padding: 64px 0;
  text-align: center;
  color: #8c8c8c;
  font-size: 16px;
}
</style>