| | |
| | | <el-button type="primary" |
| | | @click="openForm('add')">新增</el-button> |
| | | <el-button @click="handleOut">导出</el-button> |
| | | <el-button type="primary" |
| | | plain |
| | | :loading="batchSubmitting" |
| | | @click="handleBatchSubmit">批量提交</el-button> |
| | | <el-button type="danger" |
| | | plain |
| | | @click="handleDelete">删除</el-button> |
| | |
| | | const tableData = ref([]); |
| | | const selectedRows = ref([]); |
| | | const tableLoading = ref(false); |
| | | const batchSubmitting = ref(false); |
| | | const dialogFormVisible = ref(false); |
| | | const form = ref({ |
| | | checkName: "", |
| | |
| | | selectedRows.value = selection; |
| | | }; |
| | | |
| | | const canSubmit = row => { |
| | | // 已提交则禁用 |
| | | if (row.inspectState == 1) return false; |
| | | // 如果检验员有值,只有当前登录用户能提交 |
| | | if (row.checkName) { |
| | | return row.checkName === userStore.nickName; |
| | | } |
| | | return true; |
| | | }; |
| | | |
| | | // 打开弹框 |
| | | const openForm = (type, row) => { |
| | | nextTick(() => { |
| | |
| | | getList(); |
| | | } |
| | | }; |
| | | |
| | | const handleBatchSubmit = () => { |
| | | if (selectedRows.value.length === 0) { |
| | | proxy.$modal.msgWarning("请选择数据"); |
| | | return; |
| | | } |
| | | |
| | | const submitRows = selectedRows.value.filter(item => canSubmit(item)); |
| | | const skipCount = selectedRows.value.length - submitRows.length; |
| | | if (submitRows.length === 0) { |
| | | proxy.$modal.msgWarning("所选数据均不可提交"); |
| | | return; |
| | | } |
| | | |
| | | const message = |
| | | skipCount > 0 |
| | | ? `已选择${selectedRows.value.length}条,其中${submitRows.length}条可提交,${skipCount}条已提交或无权限,将自动跳过。是否确认提交?` |
| | | : `选中的${submitRows.length}条内容将被提交,是否确认提交?`; |
| | | |
| | | ElMessageBox.confirm(message, "批量提交", { |
| | | confirmButtonText: "确认", |
| | | cancelButtonText: "取消", |
| | | type: "warning", |
| | | }) |
| | | .then(async () => { |
| | | batchSubmitting.value = true; |
| | | const results = await Promise.allSettled( |
| | | submitRows.map(item => submitQualityInspect({ id: item.id })) |
| | | ); |
| | | const successCount = results.filter( |
| | | item => item.status === "fulfilled" && item.value?.code === 200 |
| | | ).length; |
| | | const failCount = submitRows.length - successCount; |
| | | |
| | | if (failCount === 0 && skipCount === 0) { |
| | | proxy.$modal.msgSuccess("批量提交成功"); |
| | | } else if (failCount === 0) { |
| | | proxy.$modal.msgSuccess( |
| | | `成功提交${successCount}条,跳过${skipCount}条` |
| | | ); |
| | | } else if (successCount > 0) { |
| | | proxy.$modal.msgWarning( |
| | | `成功提交${successCount}条,失败${failCount}条,跳过${skipCount}条` |
| | | ); |
| | | } else { |
| | | proxy.$modal.msgError( |
| | | `批量提交失败,失败${failCount}条,跳过${skipCount}条` |
| | | ); |
| | | } |
| | | getList(); |
| | | }) |
| | | .catch(() => { |
| | | proxy.$modal.msg("已取消"); |
| | | }) |
| | | .finally(() => { |
| | | batchSubmitting.value = false; |
| | | }); |
| | | }; |
| | | const open = async row => { |
| | | let userLists = await userListNoPage(); |
| | | userList.value = userLists.data; |