<script setup>
|
import { ref, reactive } from 'vue';
|
import { useRouter } from "vue-router";
|
import { get, post, postForm } from '@/utils/request.js'
|
import { message, Modal } from 'ant-design-vue';
|
import { logout } from '@/config.js';
|
import { formatMessage } from '@/utils/localeUtils.js';
|
import useTableSearch from '@/utils/tableUtils.jsx';
|
import MatQueryView from '@/components/mat/matQuery/index.vue'
|
|
const router = useRouter();
|
|
const TABLE_KEY = 'table-locDetl';
|
const matQueryChild = ref(null)
|
const searchInput = ref(null)
|
|
let tableData = ref([]);
|
getColumns();
|
|
const {
|
getColumnSearchProps,
|
handleResizeColumn,
|
} = useTableSearch();
|
|
const state = reactive({
|
selectedRowKeys: [],
|
loading: false,
|
columns: [],
|
});
|
const onSelectChange = selectedRowKeys => {
|
// console.log('selectedRowKeys changed: ', selectedRowKeys);
|
state.selectedRowKeys = selectedRowKeys;
|
};
|
|
state.columns = [
|
{
|
title: formatMessage('db.man_loc_detl.qty', '实际数量'),
|
dataIndex: 'qty',
|
width: 140,
|
ellipsis: true,
|
},
|
{
|
title: formatMessage('db.man_loc_detl.anfme', '库存数量'),
|
dataIndex: 'anfme',
|
width: 140,
|
ellipsis: true,
|
},
|
{
|
title: formatMessage('db.man_loc_detl.matnr', '商品编号'),
|
dataIndex: 'matnr',
|
width: 140,
|
ellipsis: true,
|
...getColumnSearchProps('matnr'),
|
},
|
{
|
title: formatMessage('db.man_loc_detl.batch', '批号'),
|
dataIndex: 'batch',
|
width: 140,
|
ellipsis: true,
|
...getColumnSearchProps('batch'),
|
},
|
];
|
|
let columnsOther = [
|
{
|
title: formatMessage('db.man_loc_detl.loc_id', '库位'),
|
dataIndex: 'locId$',
|
width: 140,
|
ellipsis: true,
|
...getColumnSearchProps('locId$'),
|
},
|
{
|
title: formatMessage('db.man_loc_detl.loc_no', '库位号'),
|
dataIndex: 'locNo',
|
width: 140,
|
ellipsis: true,
|
...getColumnSearchProps('locNo'),
|
},
|
// {
|
// title: formatMessage('db.man_loc_detl.mat_id', '商品'),
|
// dataIndex: 'matId$',
|
// width: 140,
|
// ellipsis: true,
|
// ...getColumnSearchProps('matId$'),
|
// },
|
{
|
title: formatMessage('db.man_loc_detl.order_no', '订单号'),
|
dataIndex: 'orderNo',
|
width: 140,
|
ellipsis: true,
|
...getColumnSearchProps('orderNo'),
|
},
|
{
|
title: formatMessage('db.man_loc_detl.anfme', '数量'),
|
dataIndex: 'anfme',
|
width: 140,
|
ellipsis: true,
|
...getColumnSearchProps('anfme'),
|
},
|
{
|
title: formatMessage('db.man_loc_detl.freeze', '是否冻结'),
|
dataIndex: 'freeze$',
|
width: 140,
|
ellipsis: true,
|
...getColumnSearchProps('freeze$'),
|
},
|
{
|
title: formatMessage('db.man_loc_detl.status', '状态'),
|
dataIndex: 'status$',
|
width: 140,
|
ellipsis: true,
|
...getColumnSearchProps('status$'),
|
},
|
// {
|
// title: formatMessage('db.man_loc_detl.create_time', '添加时间'),
|
// dataIndex: 'createTime$',
|
// width: 140,
|
// ellipsis: true,
|
// ...getColumnSearchProps('createTime$'),
|
// },
|
// {
|
// title: formatMessage('db.man_loc_detl.create_by', '添加人员'),
|
// dataIndex: 'createBy$',
|
// width: 140,
|
// ellipsis: true,
|
// ...getColumnSearchProps('createBy$'),
|
// },
|
{
|
title: formatMessage('db.man_loc_detl.update_time', '修改时间'),
|
dataIndex: 'updateTime$',
|
width: 140,
|
ellipsis: true,
|
...getColumnSearchProps('updateTime$'),
|
},
|
{
|
title: formatMessage('db.man_loc_detl.update_by', '修改人员'),
|
dataIndex: 'updateBy$',
|
width: 140,
|
ellipsis: true,
|
...getColumnSearchProps('updateBy$'),
|
},
|
{
|
title: formatMessage('db.man_loc_detl.memo', '备注'),
|
dataIndex: 'memo',
|
width: 140,
|
ellipsis: true,
|
...getColumnSearchProps('memo'),
|
},
|
]
|
|
let fieldList = [];
|
//加载扩展字段
|
async function getColumns() {
|
let fieldResp = await post('/api/matField/list', {
|
unique: 1
|
})
|
let fieldResult = fieldResp.data;
|
let tmp = state.columns;
|
if (fieldResult.code == 200) {
|
let data = fieldResult.data;
|
data.forEach((item) => {
|
let filed = {
|
title: formatMessage(item.language, item.describe),
|
name: item.name,
|
dataIndex: item.name,
|
key: item.name,
|
width: 140,
|
editable: true,
|
...getColumnSearchProps(item.name),
|
}
|
tmp.push(filed)
|
fieldList.push(filed)
|
})
|
|
tmp = tmp.concat(columnsOther)
|
|
tmp.push({
|
title: formatMessage('common.operation', '操作'),
|
name: 'oper',
|
dataIndex: 'oper',
|
key: 'oper',
|
width: 140,
|
fixed: 'right',
|
})
|
|
state.columns = tmp;
|
} else if (result.code === 401) {
|
message.error(result.msg);
|
logout()
|
} else {
|
message.error(result.msg);
|
}
|
}
|
|
const openSelect = () => {
|
if (loc.value == null) {
|
message.error(formatMessage('page.stockAdjust.locDetlListNull', '请检索库位'));
|
return;
|
}
|
|
if (loc.value.locSts$ != 'F') {
|
message.error(formatMessage('page.stockAdjust.locDetlListNull', '当前库位状态不可调整'));
|
return;
|
}
|
|
matQueryChild.value.open = true;
|
}
|
|
const handleMatQueryOk = (result) => {
|
let tmp = [];
|
|
if (tableData.value != undefined) {
|
tmp = [...tableData.value]
|
}
|
|
for (let i = 0; i < result.length; i++) {
|
let item = result[i]
|
item.anfme = 0;
|
item.qty = 0;
|
item.matId = item.id;
|
item.id = null;
|
|
fieldList.forEach((filed) => {
|
item[filed.key] = ''
|
})
|
|
tmp.push(item)
|
}
|
|
tableData.value = tmp;
|
}
|
|
const handleDel = (record) => {
|
let data = tableData.value;
|
let tmp = []
|
|
for (let i = 0; i < data.length; i++) {
|
let item = data[i]
|
if (item.id == record.id) {
|
continue
|
}
|
tmp.push(item)
|
}
|
tableData.value = tmp
|
}
|
|
const loc = ref(null)
|
const onSearch = () => {
|
if (searchInput.value == '' || searchInput.value == null) {
|
message.error(formatMessage('page.stockAdjust.input.loc', '请先输入库位号'));
|
return;
|
}
|
|
postForm('/api/loc/search/locNo', {
|
locNo: searchInput.value,
|
}).then(resp => {
|
let result = resp.data;
|
if (result.code == 200) {
|
loc.value = result.data.loc;
|
|
let detls = [];
|
result.data.locDetls.forEach((item) => {
|
item.qty = item.anfme;
|
detls.push(item)
|
})
|
tableData.value = detls;
|
} else {
|
message.error(result.msg);
|
loc.value = null;
|
tableData.value = null;
|
}
|
})
|
}
|
|
const submitAdj = () => {
|
Modal.confirm({
|
title: formatMessage('page.stockAdjust.adjust', '调整库存'),
|
content: formatMessage('page.stockAdjust.confirm', '确定调整库存吗?'),
|
maskClosable: true,
|
onOk: async () => {
|
confirmAdj()
|
},
|
});
|
|
}
|
|
const confirmAdj = () => {
|
if (loc.value == null) {
|
message.error(formatMessage('page.stockAdjust.locDetlListNull', '请检索库位'));
|
return;
|
}
|
|
if (loc.value.locSts$ != 'F') {
|
message.error(formatMessage('page.stockAdjust.locDetlListNull', '当前库位状态不可调整'));
|
return;
|
}
|
|
let tmpData = tableData.value;
|
if (tmpData.length == 0) {
|
message.error(formatMessage('page.stockAdjust.locDetlListNull', '库存信息不能为空'));
|
return;
|
}
|
|
post('/api/loc/adjust', {
|
locNo: loc.value.locNo,
|
detls: tmpData
|
}).then(resp => {
|
let result = resp.data;
|
if (result.code == 200) {
|
message.success(formatMessage('page.stockAdjust.success', '库存调整成功'));
|
|
loc.value = null;
|
tableData.value = null;
|
searchInput.value = null;
|
} else {
|
message.error(result.msg);
|
}
|
})
|
}
|
|
</script>
|
|
<script>
|
export default {
|
name: '库存调整'
|
}
|
</script>
|
|
<template>
|
<div>
|
<div style="margin-bottom: 20px;display: flex;align-items: center;">
|
<a-input-search v-model:value="searchInput" :placeholder="formatMessage('page.input', '请输入')"
|
style="width: 200px;" @search="onSearch" />
|
<div v-if="loc" style="margin-left: 20px;font-size: 18px;">
|
当前检索库位: {{ loc.locNo }} ,库位状态: {{ loc.locSts$ }}.{{ loc.locStsId$ }}
|
</div>
|
</div>
|
<div class="table-header">
|
<div>
|
<a-button @click="openSelect">新增库存</a-button>
|
<a-button style="margin-left: 5px;" type="primary" @click="submitAdj">调整库存</a-button>
|
</div>
|
</div>
|
<a-table :row-selection="{ selectedRowKeys: state.selectedRowKeys, onChange: onSelectChange }"
|
:data-source="tableData" :defaultExpandAllRows="false" :key="TABLE_KEY" rowKey="id"
|
:scroll="{ y: 768, scrollToFirstRowOnChange: true }" :columns="state.columns"
|
@resizeColumn="handleResizeColumn">
|
<template #bodyCell="{ column, text, record }">
|
<template v-if="column.dataIndex === 'oper'">
|
<div style="display: flex;justify-content: space-evenly;">
|
<a-button type="link" danger @click="handleDel(record)">{{ formatMessage('page.delete', '删除')
|
}}</a-button>
|
</div>
|
</template>
|
|
<template v-if="column.dataIndex === 'qty'">
|
<div>
|
<a-input-number v-model:value="record[column.dataIndex]" :min="1" />
|
</div>
|
</template>
|
|
<template v-if="column.dataIndex === 'batch'">
|
<div>
|
<a-input v-model:value="record[column.dataIndex]" />
|
</div>
|
</template>
|
|
<template v-if="column.editable">
|
<div>
|
<a-input v-model:value="record[column.dataIndex]" />
|
</div>
|
</template>
|
</template>
|
</a-table>
|
|
<MatQueryView ref="matQueryChild" @handle-ok="handleMatQueryOk" />
|
</div>
|
</template>
|
|
<style></style>
|