bug: 提交物料申请

This commit is contained in:
my_ong 2024-12-05 21:28:24 +08:00
parent 94d825fa2d
commit b2efb54608
3 changed files with 234 additions and 191 deletions

View File

@ -1,79 +1,109 @@
<template>
<div>
<vxe-table border show-overflow ref="tableRef" max-height="500" size="medium"
:edit-config="{ trigger: 'manual', mode: 'cell' }" v-model:data="tableData">
<vxe-column type="seq" width="70" />
<vxe-column field="name" title="物料名称" />
<vxe-column field="scan" title="是否扫码" />
<vxe-column field="applyNum" title="申请数量" :edit-render="{ name: 'VxeInput', props: { type: 'integer' } }" />
<vxe-column field="scanNum" title="扫码数量" :edit-render="{ name: 'VxeInput', props: { type: 'integer' } }" />
<vxe-column field="remark" title="备注" :edit-render="{ name: 'VxeInput' }" />
<div>
<vxe-table
ref="tableRef"
border
show-overflow
max-height="500"
size="medium"
:edit-config="{ trigger: 'manual', mode: 'cell' }"
:data="tableData"
>
<vxe-column type="seq" width="70" />
<vxe-column field="id" title="物料id" :visible="false" />
<vxe-column field="name" title="物料名称" />
<vxe-column field="scan" title="是否扫码" />
<vxe-column field="applyNum" title="申请数量" :edit-render="{ name: 'VxeInput', props: { type: 'integer' } }" />
<vxe-column field="scanNum" title="扫码数量" :edit-render="{ name: 'VxeInput', props: { type: 'integer' } }" />
<vxe-column field="remark" title="备注" :edit-render="{ name: 'VxeInput' }" />
<vxe-column title="操作">
<template #default="{ row }">
<template v-if="hasEditStatus(row)">
<vxe-button @click="saveRowEvent(row)">保存</vxe-button>
<vxe-button @click="cancelRowEvent()">取消</vxe-button>
</template>
<template v-else>
<vxe-button @click="editRowEvent(row)">编辑</vxe-button>
</template>
</template>
</vxe-column>
</vxe-table>
</div>
<vxe-column title="操作">
<template #default="{ row }">
<template v-if="hasEditStatus(row)">
<vxe-button @click="saveRowEvent(row)">保存</vxe-button>
<vxe-button @click="cancelRowEvent()">取消</vxe-button>
</template>
<template v-else>
<vxe-button @click="editRowEvent(row)">编辑</vxe-button>
</template>
</template>
</vxe-column>
</vxe-table>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import { VxeUI, VxeTableInstance } from 'vxe-table'
import { ref } from 'vue'
import { VxeUI, VxeTableInstance } from 'vxe-table'
//
defineProps({
tableData: {
type: Array as PropType<Array<object>>,
default: () => [],
},
})
const getTableData = () => {
const $table = tableRef.value
if ($table) {
return $table.getTableData().fullData.map((row) => {
return {
materialId: row.id,
quantity: row.applyNum,
confirmQuantity: row.scanNum,
exceptionRemark: row.remark,
}
})
}
return []
}
interface RowVO {
id: number
name: string
scan: string
applyNum: number
scanNum: number
remark: string
}
defineExpose({ getTableData })
const tableRef = ref<VxeTableInstance<RowVO>>()
interface RowVO {
id: number
name: string
scan: string
applyNum: number
scanNum: number
remark: string
}
const loading = ref(false)
const tableData = ref<RowVO[]>()
const tableRef = ref<VxeTableInstance<RowVO>>()
const hasEditStatus = (row: RowVO) => {
const $table = tableRef.value
if ($table) {
return $table.isEditByRow(row)
}
}
const loading = ref(false)
const editRowEvent = (row: RowVO) => {
const $table = tableRef.value
if ($table) {
$table.setEditRow(row)
}
}
const hasEditStatus = (row: RowVO) => {
const $table = tableRef.value
if ($table) {
return $table.isEditByRow(row)
}
}
const saveRowEvent = (row: RowVO) => {
const $table = tableRef.value
if ($table) {
$table.clearEdit().then(() => {
loading.value = true
setTimeout(() => {
loading.value = false
VxeUI.modal.message({ content: `保存成功name=${row.name}`, status: 'success' })
}, 300)
})
}
}
const editRowEvent = (row: RowVO) => {
const $table = tableRef.value
if ($table) {
$table.setEditRow(row)
}
}
const cancelRowEvent = () => {
const $table = tableRef.value
if ($table) {
$table.clearEdit()
}
}
const saveRowEvent = (row: RowVO) => {
const $table = tableRef.value
if ($table) {
$table.clearEdit().then(() => {
loading.value = true
setTimeout(() => {
loading.value = false
VxeUI.modal.message({ content: `保存成功name=${row.name}`, status: 'success' })
}, 300)
})
}
}
const cancelRowEvent = () => {
const $table = tableRef.value
if ($table) {
$table.clearEdit()
}
}
</script>

View File

@ -1,136 +1,136 @@
<template>
<!-- steps -->
<div v-show="current != 3">
<a-steps v-model:current="current" :items="items"></a-steps>
<a-divider style="height: 2px; background-color: #7cb305" />
</div>
<!-- steps -->
<div v-show="current != 3">
<a-steps v-model:current="current" :items="items"></a-steps>
<a-divider style="height: 2px; background-color: #7cb305" />
</div>
<!-- step1 -->
<!-- step1 -->
<div class="step-1" v-show="current === 0">
<apply-form :apply-type="applyType" ref="applyFormRef"></apply-form>
</div>
<div v-show="current === 0" class="step-1">
<apply-form ref="applyFormRef" :apply-type="applyType"></apply-form>
</div>
<div class="step-2" v-show="current === 1">
<scan-form :total-value="totalValue" ref="scanFormRef"></scan-form>
</div>
<div class="step-3" v-show="current === 2">
<apply-confirm :table-data="conformData" ref="applyConfirmRef"></apply-confirm>
</div>
<div class="step-4" v-show="current === 3">
<successResul></successResul>
</div>
<div v-show="current === 1" class="step-2">
<scan-form ref="scanFormRef" :total-value="totalValue"></scan-form>
</div>
<div v-show="current === 2" class="step-3">
<apply-confirm ref="applyConfirmRef" :table-data="conformData"></apply-confirm>
</div>
<div v-show="current === 3" class="step-4">
<successResul></successResul>
</div>
<!-- 按钮 -->
<a-space wrap class="fixed-button-container">
<a-button type="dashed" v-if="current != 0" @click="current--">上一步</a-button>
<a-button type="primary" v-if="current != 2" @click="nextStep">下一步</a-button>
<a-button type="primary" :loading="loading" v-if="current === 2" @click="submit">提交申请</a-button>
</a-space>
<!-- 按钮 -->
<a-space v-show="current != 3" wrap class="fixed-button-container">
<a-button v-if="current != 0" type="dashed" @click="current--">上一步</a-button>
<a-button v-if="current != 2" type="primary" @click="nextStep">下一步</a-button>
<a-button v-if="current === 2" type="primary" :loading="loading" @click="submit">提交申请</a-button>
</a-space>
</template>
<script setup lang="ts">
import applyForm from '../component/applyForm.vue'
import scanForm from '../component/scanForm.vue';
import applyConfirm from '../component/applyConfirm.vue';
import successResul from '../component/successResul.vue';
import api from '@/api'
import applyForm from '../component/applyForm.vue'
import scanForm from '../component/scanForm.vue'
import applyConfirm from '../component/applyConfirm.vue'
import successResul from '../component/successResul.vue'
import api from '@/api'
//
defineProps(
{
applyType: {
type: String,
default: '',
}
} // applyType使121: 2:
)
// steps
const current = ref<number>(0) //
const applyFormRef = ref(); // step1
const scanFormRef = ref(); // step2
const applyConfirmRef = ref(); // step3
//
defineProps(
{
applyType: {
type: String,
default: '',
},
}, // applyType使121: 2:
)
// steps
const current = ref<number>(0) //
const applyFormRef = ref() // step1
const scanFormRef = ref() // step2
const applyConfirmRef = ref() // step3
const selectData = ref(); // step1,
const scanData = ref(); // step2
const totalValue = ref(0); //
const conformData = ref<Array<object>>([]); // step3
const loading = ref(false); // loading
const selectData = ref() // step1,
const scanData = ref() // step2
const totalValue = ref(0) //
const conformData = ref<Array<object>>([]) // step3
const loading = ref(false) // loading
const items = [{ title: '录入申请' }, { title: '扫码点货' }, { title: '人工确认' }]
/**
* 点击下一步
*/
const nextStep = () => {
if (applyFormRef.value && current.value === 0) { // step1step1
selectData.value = applyFormRef.value.getTableData();
selectData.value.forEach((item) => {
if (item.assignRule === 1) {
totalValue.value += item.quantity
}
})
}
if (scanFormRef.value && current.value === 1) { // step2step2
const items = scanFormRef.value.getTableData();
const groupedSums = items.reduce((acc, item) => {
if (!acc[item.code]) {
acc[item.code] = 0;
}
acc[item.code]++;
return acc;
}, {});
scanData.value = items
//
conformData.value = selectData.value.map(item => {
return {
id: item.id,
name: item.name,
code: item.code,
applyNum: item.quantity,
scan: item.assignRule,
scanNum: groupedSums[item.code] || 0,
remark: item.quantity != groupedSums[item.code] ? `实际扫码数量与申请数量不一致` : '',
}
});
}
//
current.value++
}
/**
* 提交申请
*/
const submit = () => {
loading.value = true;
//
console.log('提交申请')
//
const applyDetails = applyConfirmRef.value.getTableData(); //
const applyForm = applyFormRef.value.getApplyForm(); //
api.materialApi.apply.saveOrUpdateApply({ applyForm: applyForm, applyDetails: applyDetails }, () => {
console.log('申请成功')
//
loading.value = false;
current.value = 3;
});
}
const items = [{ title: '录入申请' }, { title: '扫码点货' }, { title: '人工确认' }]
/**
* 点击下一步
*/
const nextStep = () => {
if (applyFormRef.value && current.value === 0) {
// step1step1
selectData.value = applyFormRef.value.getTableData()
selectData.value.forEach((item) => {
if (item.assignRule === 1) {
totalValue.value += item.quantity
}
})
}
if (scanFormRef.value && current.value === 1) {
// step2step2
const items = scanFormRef.value.getTableData()
const groupedSums = items.reduce((acc, item) => {
if (!acc[item.code]) {
acc[item.code] = 0
}
acc[item.code]++
return acc
}, {})
scanData.value = items
//
conformData.value = selectData.value.map((item) => {
return {
id: item.id,
name: item.name,
code: item.code,
applyNum: item.quantity,
scan: item.assignRule,
scanNum: groupedSums[item.code] || 0,
remark: item.quantity != groupedSums[item.code] ? `实际扫码数量与申请数量不一致` : '',
}
})
}
//
current.value++
}
/**
* 提交申请
*/
const submit = () => {
loading.value = true
//
console.log('提交申请')
//
const applyDetails = applyConfirmRef.value.getTableData() //
const applyForm = applyFormRef.value.getApplyForm() //
api.materialApi.apply.saveOrUpdateApply({ applyForm: applyForm, applyDetails: applyDetails }, () => {
console.log('申请成功')
//
loading.value = false
current.value = 3
})
}
</script>
<style scoped>
/* 固定按钮容器样式 */
.fixed-button-container {
position: fixed;
bottom: 80px;
/* 距离底部的距离 */
right: 30px;
/* 距离右侧的距离 */
z-index: 1000;
/* 确保按钮在其他内容之上 */
}
/* 固定按钮容器样式 */
.fixed-button-container {
position: fixed;
/* 距离底部的距离 */
right: 30px;
bottom: 80px;
/* 距离右侧的距离 */
z-index: 1000;
/* 确保按钮在其他内容之上 */
}
</style>

View File

@ -1,11 +1,24 @@
<template>
<a-result status="success" title="Successfully Purchased Cloud Server ECS!"
sub-title="Order number: 2017182818828182881 Cloud server configuration takes 1-5 minutes, please wait.">
<template #extra>
<a-button key="console" type="primary">查询申请</a-button>
<a-button key="buy">继续提交申请</a-button>
</template>
</a-result>
<a-result
status="success"
title="Successfully Purchased Cloud Server ECS!"
sub-title="Order number: 2017182818828182881 Cloud server configuration takes 1-5 minutes, please wait."
>
<template #extra>
<a-button type="primary" @click="select">查询申请</a-button>
<a-button @click="again">继续提交申请</a-button>
</template>
</a-result>
</template>
<script lang="ts" setup>
import router from '@/router'
const select = () => {
router.push({ path: '/statistic/inbound' }) //
}
const again = () => {
router.push({ path: '/stock/inbound' })
}
</script>