Commit 5b0860eb by wangchunyang

整合inbound.vue的标签页面内容

parent 227c2bf1
...@@ -157,6 +157,156 @@ ...@@ -157,6 +157,156 @@
<Page class="page_style" :total="pagers.history.totalRecord" :current="pagers.history.pageNo" :page-size="pagers.history.pageSize" <Page class="page_style" :total="pagers.history.totalRecord" :current="pagers.history.pageNo" :page-size="pagers.history.pageSize"
show-total show-sizer @on-change="pageChange('history', $event)" @on-page-size-change="sizeChange('history', $event)" /> show-total show-sizer @on-change="pageChange('history', $event)" @on-page-size-change="sizeChange('history', $event)" />
</TabPane> </TabPane>
<TabPane label="办公用品入库" name="inbound">
<div class="search-div">
<Row type="flex" :gutter="16">
<Col span="18">
<span>入库单号:</span>
<Input
v-model="filters.inbound.inbound_no"
placeholder="请输入入库单号:"
class="mr10"
style="width: 200px"
/>
<span>批次号:</span>
<Input
v-model="filters.inbound.batch_no"
placeholder="请输入批次号:"
class="mr10"
style="width: 200px"
/>
<span>开始时间:</span>
<DatePicker
v-model="filters.inbound.startDate"
type="date"
format="yyyy-MM-dd"
value-format="yyyy-MM-dd"
placeholder="请选择开始时间"
class="mr10"
style="width: 150px"
/>
<span>结束时间:</span>
<DatePicker
v-model="filters.inbound.endDate"
type="date"
format="yyyy-MM-dd"
value-format="yyyy-MM-dd"
placeholder="请选择结束时间"
class="mr10"
style="width: 150px"
/>
<br>
<div class="mt8">
<span>入库类型:</span>
<Select
v-model="filters.inbound.inbound_type"
placeholder="请选择入库类型"
class="mr10"
style="width: 200px"
clearable
>
<Option :value='1'>手工入库</Option>
<Option :value='2'>归还入库</Option>
</Select>
<span>入库状态:</span>
<Select
v-model="filters.inbound.inbound_status"
placeholder="请选择入库状态"
class="mr10"
style="width: 200px"
clearable
>
<Option :value='0'>待入库</Option>
<Option :value='1'>已入库</Option>
</Select>
</div>
</Col>
<Col span="6" class="text-right">
<Button type="primary" class="mr10" @click="handleSearch('inbound')">搜索</Button>
<Button type="primary" class="mr10" @click="handleReset('inbound')">重置</Button>
<Button type="primary" class="mr10" @click="openInboundModal">新增入库</Button>
<Button type="primary" class="mr10" v-if="showImport()" @click="importShow = true">导入</Button>
</Col>
</Row>
</div>
<Table :data="tables.inbound" :loading="loading.inbound" :columns="inboundColumns" border>
<template slot="action" slot-scope="{ row }">
<Poptip confirm title="确认执行入库?" transfer @on-ok="doInbound(row)" v-if="canEditInbound(row)">
<Button size="small" type="success" class="mr5">入库</Button>
</Poptip>
<Button size="small" @click="openInboundDetail(row)" class="mr5">详细</Button>
<Button size="small" type="primary" @click="openEditInbound(row)" v-if="canEditInbound(row)" class="mr5">修改</Button>
<Poptip confirm title="确认删除?" transfer @on-ok="deleteInbound(row)" v-if="canEditInbound(row)">
<Button size="small" type="error">删除</Button>
</Poptip>
</template>
</Table>
<Page class="page_style" :total="pagers.inbound.totalRecord" :current="pagers.inbound.pageNo" :page-size="pagers.inbound.pageSize"
show-total show-sizer @on-change="pageChange('inbound', $event)" @on-page-size-change="sizeChange('inbound', $event)" />
</TabPane>
<TabPane label="办公用品归还" name="return">
<div class="search-div">
<Row type="flex" :gutter="16">
<Col span="18">
<span>部门:</span>
<Input
v-model="filters.return.department_name"
placeholder="请输入部门"
class="mr10"
style="width: 200px"
/>
<span>申领人:</span>
<Input
v-model="filters.return.applicant_name"
placeholder="请输入申请人"
class="mr10"
style="width: 200px"
/>
</Col>
<Col span="6" class="action-col">
<Button type="primary" class="mr10" @click="handleSearch('return')">搜索</Button>
<Button type="primary" class="mr10" @click="handleReset('return')" >重置</Button>
</Col>
</Row>
</div>
<Table :data="tables.return" :loading="loading.return" :columns="returnColumns" border>
<template slot="action" slot-scope="{ row }">
<Button size="small" type="primary" @click="openReturnModal(row)">归还</Button>
</template>
</Table>
<Page class="page_style" :total="pagers.return.totalRecord" :current="pagers.return.pageNo" :page-size="pagers.return.pageSize"
show-total show-sizer @on-change="pageChange('return', $event)" @on-page-size-change="sizeChange('return', $event)" />
</TabPane>
<TabPane label="库存查询" name="inventory">
<div class="search-div">
<Row type="flex" :gutter="16">
<Col span="18">
<span>物料编码:</span>
<Input
v-model="filters.inventory.material_code"
placeholder="请输入物料编码"
class="mr10"
style="width: 200px"
/>
<span>物料名称:</span>
<Input
v-model="filters.inventory.material_name"
placeholder="请输入物料名称"
class="mr10"
style="width: 200px"
/>
</Col>
<Col span="6" class="action-col">
<Button type="primary" class="mr10" @click="handleSearch('inventory')">搜索</Button>
<Button type="primary" class="mr10" @click="handleReset('inventory')">重置</Button>
</Col>
</Row>
</div>
<Table :data="tables.inventory" :loading="loading.inventory" :columns="inventoryColumns" border />
</TabPane>
</Tabs> </Tabs>
<!-- 申请弹窗 --> <!-- 申请弹窗 -->
...@@ -246,6 +396,99 @@ ...@@ -246,6 +396,99 @@
</div> </div>
<div slot="footer"><Button type="primary" @click="detailModal.visible=false">关闭</Button></div> <div slot="footer"><Button type="primary" @click="detailModal.visible=false">关闭</Button></div>
</Modal> </Modal>
<!-- 入库弹窗 -->
<Modal v-model="inboundModal.visible" :title="inboundModal.isEdit ? '修改入库' : '新增入库'" width="800">
<Form :model="inboundModal.form" :rules="inboundRules" :label-width="120" ref="inboundForm">
<FormItem label="入库单号" prop="inbound_no">
<Input v-model="inboundModal.form.inbound_no" />
</FormItem>
<FormItem label="批次号" prop="batch_no">
<Input v-model="inboundModal.form.batch_no" />
</FormItem>
<FormItem label="入库日期" prop="inbound_date">
<DatePicker
v-model="inboundModal.form.inbound_date"
type="date"
format="yyyy-MM-dd"
value-format="yyyy-MM-dd"
placeholder="请选择入库日期"
/>
</FormItem>
<FormItem label="存放位置">
<Input v-model="inboundModal.form.storage_location" />
</FormItem>
<FormItem label="备注">
<Input type="textarea" v-model="inboundModal.form.remark" :rows="2" />
</FormItem>
<h4>明细(从物料库选择)
<div style="float: right;">
<Button size="small" class="mr5" type="primary" @click="showMaterialSelector = true">添加</Button>
<Button size="small" type="error" @click="deleteSelectedInboundDetails">删除</Button>
</div>
</h4>
<Table :data="inboundModal.details" :columns="inboundDetailColumns" size="small" border @on-selection-change="onInboundDetailSelectionChange" style="width: 100%" />
<MaterialSelector v-model="showMaterialSelector" :selected="[]" @on-ok="handleInboundMaterialSelectorOk" @cancel="showMaterialSelector = false" />
</Form>
<div slot="footer">
<Button @click="inboundModal.visible=false">取消</Button>
<Button type="primary" :loading="inboundModal.saving" @click="saveInbound">保存</Button>
</div>
</Modal>
<!-- 归还弹窗 -->
<Modal v-model="returnModal.visible" title="归还物品" width="700">
<Form :model="returnModal.record" :label-width="120">
<FormItem label="申请单号"><span>{{ returnModal.record.application_no }}</span></FormItem>
<FormItem label="申请人"><span>{{ returnModal.record.applicant_name }}</span></FormItem>
<FormItem label="归还明细">
<Table :data="returnModal.details" :columns="returnDetailColumns" size="small" border />
</FormItem>
</Form>
<div slot="footer">
<Button @click="returnModal.visible=false">取消</Button>
<Button type="primary" :loading="returnModal.saving" @click="confirmReturn">归还</Button>
</div>
</Modal>
<!-- 入库详情弹窗 -->
<Modal v-model="inboundDetailModal.visible" title="入库/归还详情" width="720">
<Spin fix v-if="inboundDetailModal.loading"></Spin>
<div v-else>
<Row :gutter="16"><Col span="12"><p><strong>单号:</strong>{{ inboundDetailModal.data.inbound_no || inboundDetailModal.data.application_no }}</p></Col></Row>
<Row class="mt8"><Col span="24"><h4>明细</h4></Col></Row>
<Table :data="inboundDetailModal.details" :columns="inboundDetailDetailColumns" size="small" border />
</div>
<div slot="footer"><Button type="primary" @click="inboundDetailModal.visible=false">关闭</Button></div>
</Modal>
<!-- 导入物料弹窗 -->
<Modal v-model="importShow" title="入库导入" width="360">
<Row type="flex" justify="center" align="middle">
<Col span="10">
<div style="text-align: center;">
<Upload
action="#"
:show-upload-list="false"
:before-upload="handleBeforeUpload"
:format="['xls','xlsx']"
accept=".xls,.xlsx"
:max-size="4096">
<Button icon="ios-cloud-upload-outline" type="primary" :loading="impBtnDisabled">导入</Button>
</Upload>
</div>
</Col>
<Col span="12">
<div style="text-align: center;">
<Button type="primary" @click="tplDownload" style="margin-right: 10px;">下载模板</Button>
</div>
</Col>
</Row>
<div slot="footer">
<Button size="large" type="text" @click="importShow = false">关闭</Button>
</div>
</Modal>
<!-- <Modal v-model="approverModal.visible" title="选择审批人" width="500"> <!-- <Modal v-model="approverModal.visible" title="选择审批人" width="500">
<Form :model="approverModal.form" :label-width="80"> <Form :model="approverModal.form" :label-width="80">
<FormItem label="审批人:" required> <FormItem label="审批人:" required>
...@@ -291,10 +534,21 @@ import { ...@@ -291,10 +534,21 @@ import {
approveBorrow, approveBorrow,
rejectBorrow, rejectBorrow,
getBorrowById, getBorrowById,
getSupplyApproval getSupplyApproval,
getInboundList,
saveInbound,
deleteInbound,
doInbound,
getPendingReturnList,
processReturn,
getInventoryList,
getInboundById,
getPendingReturnById,
importInbound
} from '@/api/key-dm' } from '@/api/key-dm'
import MaterialSelector from '@/view/key-person/key_dm_conf/materialSelector.vue' import MaterialSelector from '@/view/key-person/key_dm_conf/materialSelector.vue'
import { normalizeVisitTimeValue } from '@/view/key-person/key_dm_conf/dates.js' import { normalizeVisitTimeValue } from '@/view/key-person/key_dm_conf/dates.js'
import axios from 'axios'
export default { export default {
name: 'key-dm-inventory-index', name: 'key-dm-inventory-index',
...@@ -310,6 +564,17 @@ export default { ...@@ -310,6 +564,17 @@ export default {
{ required: true, message: '请选择审批人', trigger: 'change' } { required: true, message: '请选择审批人', trigger: 'change' }
] ]
}, },
inboundRules: {
inbound_no: [
{ required: true, message: '请填写入库单号', trigger: 'blur' }
],
batch_no: [
{ required: true, message: '请选择批次号', trigger: 'blur' }
],
inbound_date: [
{ required: true, message: '请选择入库日期' }
]
},
approverModal: { approverModal: {
visible: false, visible: false,
submitting: false, submitting: false,
...@@ -326,11 +591,26 @@ export default { ...@@ -326,11 +591,26 @@ export default {
activeTab: 'apply', activeTab: 'apply',
filters: { filters: {
apply: { application_no: '', applicant_name: '', approval_status: null, startDate: null, endDate: null }, apply: { application_no: '', applicant_name: '', approval_status: null, startDate: null, endDate: null },
history: { application_no: '', applicant_name: '', approval_status: null, startDate: null, endDate: null } history: { application_no: '', applicant_name: '', approval_status: null, startDate: null, endDate: null },
inbound: {
inbound_no: null,
batch_no: null,
startDate: null,
endDate: null,
inbound_type: null,
inbound_status: null
},
return: {
application_no: '',
applicant_name: ''
},
inventory: {
material_name: ''
}
}, },
tables: { apply: [], pending: [], history: [] }, tables: { apply: [], pending: [], history: [], inbound: [], return: [], inventory: [] },
pagers: { apply: { pageNo: 1, pageSize: 10, totalRecord: 0 }, pending: { pageNo: 1, pageSize: 10, totalRecord: 0 }, history: { pageNo: 1, pageSize: 10, totalRecord: 0 } }, pagers: { apply: { pageNo: 1, pageSize: 10, totalRecord: 0 }, pending: { pageNo: 1, pageSize: 10, totalRecord: 0 }, history: { pageNo: 1, pageSize: 10, totalRecord: 0 }, inbound: { pageNo: 1, pageSize: 10, totalRecord: 0 }, return: { pageNo: 1, pageSize: 10, totalRecord: 0 }, inventory: { pageNo: 1, pageSize: 10, totalRecord: 0 } },
loading: { apply: false, pending: false, history: false }, loading: { apply: false, pending: false, history: false, inbound: false, return: false, inventory: false },
applyColumns: [ applyColumns: [
{ type: 'index', title: '序号', width: 60, align: 'center' }, { type: 'index', title: '序号', width: 60, align: 'center' },
// { title: '申请单号', key: 'application_no', align: 'center' }, // { title: '申请单号', key: 'application_no', align: 'center' },
...@@ -541,12 +821,173 @@ export default { ...@@ -541,12 +821,173 @@ export default {
}, },
{ title: '操作人', key: 'name' } { title: '操作人', key: 'name' }
], ],
// 入库相关表格列定义
inboundColumns: [
{ type: 'index', title: '序号', width: 60, align: 'center' },
{ title: '入库单号', key: 'inbound_no', align: 'center' },
{ title: '批次号', key: 'batch_no', align: 'center' },
{
title: '入库日期',
key: 'inbound_date',
align: 'center',
render: (h, { row }) => {
return h('span', this.formatDate(row.inbound_date) || row.inbound_date || '')
}
},
{
title: '类型',
key: 'inbound_type',
align: 'center',
render: (h, { row }) => {
return h('span', this.inboundTypeMap[row.inbound_type] || row.inbound_type || '-')
}
},
{
title: '状态',
key: 'inbound_status',
align: 'center',
render: (h, { row }) => {
return h('span', this.inboundStatusMap[row.inbound_status] || row.inbound_status || '-')
}
},
{ title: '操作', slot: 'action', width: 260, align: 'center' }
],
returnColumns: [
{ type: 'index', title: '序号', width: 60, align: 'center' },
{ title: '部门', key: 'department_name', align: 'center' },
{ title: '申领人', key: 'applicant_name', align: 'center' },
{ title: '申领用途', key: 'borrow_purpose', align: 'center' },
{
title: '提交审批时间',
key: 'submit_time',
align: 'center',
render: (h, { row }) => {
return h('span', this.formatDateTime(row.submit_time) || '-')
}
},
{
title: '审批通过时间',
key: 'approval_time',
align: 'center',
render: (h, { row }) => {
return h('span', this.formatDateTime(row.approval_time) || '-')
}
},
{
title: '发放状态',
key: 'issue_status',
align: 'center',
render: (h, { row }) => {
return h('span', this.issueStatusType[row.issue_status] || row.issue_status || '-')
}
},
{ title: '操作', slot: 'action', width: 140, align: 'center' }
],
inventoryColumns: [
{ type: 'index', title: '序号', width: 60, align: 'center' },
{ title: '物料编码', key: 'material_code', align: 'center' },
{ title: '物料名称', key: 'material_name', align: 'center' },
{ title: '总量', key: 'total_quantity', align: 'center' },
{ title: '借出', key: 'borrowed_quantity', align: 'center' },
{
title: '可用',
key: 'available_quantity',
align: 'center',
render: (h, { row }) => {
return h('span', (row.total_quantity - row.borrowed_quantity - row.damaged_quantity) || 0)
}
}
],
// 入库相关模态窗口内表格列定义
inboundDetailColumns: [
{ type: 'selection', width: 60 },
{ title: '物料编码', key: 'material_code', minWidth: 120 },
{ title: '物料名称', key: 'material_name', minWidth: 150 },
{ title: '入库数量',
key: 'inbound_quantity',
minWidth: 120,
render: (h, params) => {
return h('InputNumber', {
props: {
value: params.row.inbound_quantity || 0,
min: 0,
precision: 0
},
style: { width: '100px' },
on: {
'on-change': (val) => {
this.$set(this.inboundModal.details[params.index], 'inbound_quantity', Number(val) || 0)
const quantity = Number(val) || 0
const unitPrice = this.inboundModal.details[params.index].unit_price || 0
this.$set(this.inboundModal.details[params.index], 'total_amount', (quantity * unitPrice).toFixed(2))
}
}
})
}
},
{ title: '单价',
key: 'unit_price',
minWidth: 120,
render: (h, params) => {
return h('InputNumber', {
props: {
value: params.row.unit_price || 0,
min: 0,
precision: 2
},
style: { width: '100px' },
on: {
'on-change': (val) => {
this.$set(this.inboundModal.details[params.index], 'unit_price', Number(val) || 0)
const quantity = this.inboundModal.details[params.index].inbound_quantity || 0
const unitPrice = Number(val) || 0
this.$set(this.inboundModal.details[params.index], 'total_amount', (quantity * unitPrice).toFixed(2))
}
}
})
}
},
{
title: '总金额',
key: 'total_amount',
minWidth: 120,
render: (h, params) => {
const quantity = Number(params.row.inbound_quantity) || 0
const unitPrice = Number(params.row.unit_price) || 0
const total = (quantity * unitPrice).toFixed(2)
this.$set(params.row, 'total_amount', total)
return h('span', total)
}
}
],
returnDetailColumns: [
{ title: '物料名称', key: 'material_name' },
{ title: '申请数量', key: 'apply_quantity' },
{ title: '归还数量', key: 'returned_quantity' }
],
inboundDetailDetailColumns: [
{ title: '物料编码', key: 'material_code' },
{ title: '物料名称', key: 'material_name' },
{ title: '数量', key: 'inbound_quantity' },
{ title: '单价', key: 'unit_price' }
],
// 选择器控制与已选明细 // 选择器控制与已选明细
showMaterialSelector: false, showMaterialSelector: false,
applySelectedDetails: [], applySelectedDetails: [],
applyModal: { visible: false, isEdit: false, saving: false, form: {}, details: [], isEditing: false }, applyModal: { visible: false, isEdit: false, saving: false, form: {}, details: [], isEditing: false },
approveModal: { visible: false, record: {}, details: [], opinion: '', submitting: false }, approveModal: { visible: false, record: {}, details: [], opinion: '', submitting: false },
detailModal: { visible: false, loading: false, data: {}, details: [], logs: [] } detailModal: { visible: false, loading: false, data: {}, details: [], logs: [] },
// 入库相关数据
importShow: false,
impBtnDisabled: false,
inboundTypeMap: { '1': '手工', '2': '归还' },
inboundStatusMap: { '0': '待入库', '1': '已入库' },
opTypeMap: { '1': '入库', '2': '出库' },
issueStatusType: { '0': '待发放', '1': '已发放' },
inboundSelectedDetails: [],
inboundModal: { visible: false, isEdit: false, saving: false, form: {}, details: [] },
returnModal: { visible: false, record: {}, details: [], saving: false },
inboundDetailModal: { visible: false, loading: false, data: {}, details: [], logs: [] }
} }
}, },
created () { created () {
...@@ -649,9 +1090,12 @@ export default { ...@@ -649,9 +1090,12 @@ export default {
this.activeTab = name this.activeTab = name
if (name === 'pending') this.fetchList('pending') if (name === 'pending') this.fetchList('pending')
if (name === 'history') this.fetchList('history') if (name === 'history') this.fetchList('history')
if (name === 'inbound') this.fetchList('inbound')
if (name === 'return') this.fetchList('return')
if (name === 'inventory') this.fetchList('inventory')
}, },
fetchList (tab) { fetchList (tab) {
const apiMap = { apply: getBorrowList, pending: getPendingBorrowList, history: getHistoryBorrowList } const apiMap = { apply: getBorrowList, pending: getPendingBorrowList, history: getHistoryBorrowList, inbound: getInboundList, return: getPendingReturnList, inventory: getInventoryList }
const api = apiMap[tab]; if (!api) return const api = apiMap[tab]; if (!api) return
this.loading[tab] = true this.loading[tab] = true
// 清理空值,防止参数传递问题 // 清理空值,防止参数传递问题
...@@ -681,7 +1125,21 @@ export default { ...@@ -681,7 +1125,21 @@ export default {
(this.pagers[tab] || {}).pageNo = 1 (this.pagers[tab] || {}).pageNo = 1
this.fetchList(tab) this.fetchList(tab)
}, },
handleReset (tab) { this.filters[tab] = {}; (this.pagers[tab] || {}).pageNo = 1; this.fetchList(tab) }, handleReset (tab) {
if (tab === 'inbound') {
this.filters[tab] = {
inbound_no: null,
batch_no: null,
startDate: null,
endDate: null,
inbound_type: null,
inbound_status: null
}
} else {
this.filters[tab] = {}
}
; (this.pagers[tab] || {}).pageNo = 1; this.fetchList(tab)
},
pageChange (tab, pageNo) { (this.pagers[tab] || {}).pageNo = pageNo; this.fetchList(tab) }, pageChange (tab, pageNo) { (this.pagers[tab] || {}).pageNo = pageNo; this.fetchList(tab) },
sizeChange (tab, size) { (this.pagers[tab] || {}).pageSize = size; (this.pagers[tab] || {}).pageNo = 1; this.fetchList(tab) }, sizeChange (tab, size) { (this.pagers[tab] || {}).pageSize = size; (this.pagers[tab] || {}).pageNo = 1; this.fetchList(tab) },
...@@ -893,6 +1351,250 @@ export default { ...@@ -893,6 +1351,250 @@ export default {
this.detailModal.logs = ret.data.data.logs || [] this.detailModal.logs = ret.data.data.logs || []
} else this.$Notice.error({ title: '查询失败', desc: ret.data && ret.data.errmsg }) } else this.$Notice.error({ title: '查询失败', desc: ret.data && ret.data.errmsg })
}).finally(() => { this.detailModal.loading = false }) }).finally(() => { this.detailModal.loading = false })
},
// 入库相关方法
showImport () {
return true
},
async tplDownload () {
try {
const response = await axios.post(
'/api/ac/jilinsscgsdp/keyDmInbound/templateDownload',
{},
{
responseType: 'blob'
}
)
const url = window.URL.createObjectURL(new Blob([response.data]))
const link = document.createElement('a')
link.href = url
link.download = '入库导入模板.xlsx'
link.style.display = 'none'
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
window.URL.revokeObjectURL(url)
} catch (error) {
console.error('下载失败:', error)
}
},
handleBeforeUpload (file) {
const fileExt = file.name.split('.').pop().toLocaleLowerCase()
if (fileExt === 'xlsx' || fileExt === 'xls') {
this.readFile(file)
} else {
this.$Notice.warning({
title: '文件类型错误',
desc: '文件:' + file.name + '不是EXCEL文件,请选择后缀为.xlsx或者.xls的EXCEL文件。'
})
}
return false
},
async readFile (file) {
this.impBtnDisabled = true
const formdata = new FormData()
formdata.append('file', file)
formdata.append('fileName', file.name)
const ret = await importInbound(formdata)
if (ret && ret.data) {
this.importShow = false
this.impBtnDisabled = false
const mobj = ret.data.data || {}
let msg = '添加' + (mobj.insert || 0) + '条, 更新' + (mobj.update || 0) + '条'
if (mobj.error) {
msg += ', 缺少关键信息未能导入' + mobj.error + '条'
}
if (mobj.errInfo && mobj.errInfo !== '') {
msg += ', 以下记录导入失败:' + mobj.errInfo
}
if (mobj.errmsg && mobj.errmsg !== 'success') {
msg += mobj.errmsg
}
if ((mobj.insert || 0) + (mobj.update || 0) > 0) {
this.fetchList('inbound')
}
this.$Notice.success({
title: '导入完成!',
desc: msg
})
} else {
this.impBtnDisabled = false
this.$Notice.warning({
title: '未导入数据!',
desc: ret && ret.data && ret.data.errmsg
})
}
},
getTodayDate () {
const today = new Date()
const year = today.getFullYear()
const month = String(today.getMonth() + 1).padStart(2, '0')
const day = String(today.getDate()).padStart(2, '0')
return `${year}-${month}-${day}`
},
openInboundModal () {
this.inboundModal.isEdit = false
this.inboundModal.form = { inbound_no: '', batch_no: '', inbound_date: this.getTodayDate(), inbound_type: 1, storage_location: '', remark: '' }
this.inboundModal.details = []
this.inboundModal.visible = true
},
onInboundDetailSelectionChange (list) {
this.inboundSelectedDetails = list || []
},
handleInboundMaterialSelectorOk (selectedRows) {
console.log('选择的物料信息' + selectedRows)
if (!Array.isArray(selectedRows) || selectedRows.length === 0) {
this.$Message.warning('未选择物料')
return
}
selectedRows.forEach(sel => {
const code = sel.material_code
const exist = this.inboundModal.details.find(d => d.material_code === code)
if (exist) {
exist.inbound_quantity = Number(exist.inbound_quantity || 0) + 1
} else {
this.inboundModal.details.push({
material_id: sel.id,
material_code: sel.material_code,
material_name: sel.material_name,
inbound_quantity: 0,
unit_price: 0,
total_amount: 0
})
}
})
this.showMaterialSelector = false
},
deleteSelectedInboundDetails () {
if (!this.inboundSelectedDetails || this.inboundSelectedDetails.length === 0) {
this.$Message.warning('请先选择要删除的明细行')
return
}
const toRemoveCodes = this.inboundSelectedDetails.map(r => r.material_code)
this.inboundModal.details = this.inboundModal.details.filter(d => !toRemoveCodes.includes(d.material_code))
this.inboundSelectedDetails = []
},
openEditInbound (row) {
this.inboundModal.isEdit = true
getInboundById({ id: row.id }).then(ret => {
if (ret.data && ret.data.errcode === 0) {
this.inboundModal.form = ret.data.data || {}
if (this.inboundModal.form.inbound_date) {
this.inboundModal.form.inbound_date = this.formatDate(this.inboundModal.form.inbound_date) || ''
} else {
this.inboundModal.form.inbound_date = this.getTodayDate()
}
this.inboundModal.details = ret.data.data.details || []
}
})
this.inboundModal.visible = true
},
saveInbound () {
this.inboundModal.saving = true
const { inbound_no, batch_no, inbound_date } = this.inboundModal.form
if (!inbound_no || !batch_no || !inbound_date) {
this.$Message.warning('入库单号、批次号、入库日期为必填项')
this.inboundModal.saving = false
return
}
if (this.inboundModal.details === null || this.inboundModal.details.length < 1) {
this.$Message.warning('请至少入库一条用品')
this.inboundModal.saving = false
return
}
const invalidDetails = this.inboundModal.details.filter(detail => {
return !detail.inbound_quantity || detail.inbound_quantity <= 0
})
if (invalidDetails.length > 0) {
this.$Message.warning('请填写有效的入库数量(必须大于0)')
this.inboundModal.saving = false
return
}
const details = this.inboundModal.details.map(detail => {
return {
material_id: detail.material_id,
material_code: detail.material_code,
material_name: detail.material_name,
inbound_quantity: Number(detail.inbound_quantity) || 0,
unit_price: Number(detail.unit_price) || 0,
total_amount: Number(detail.total_amount) || 0
}
})
const payload = {
...this.inboundModal.form,
details: details
}
console.log('发送的数据:', payload)
saveInbound(payload).then(ret => {
if (ret.data && ret.data.errcode === 0) {
this.$Message.success('保存成功')
this.inboundModal.visible = false
this.fetchList('inbound')
} else {
this.$Notice.error({
title: '保存失败',
desc: ret.data && ret.data.errmsg || '未知错误'
})
}
}).catch(error => {
console.error('保存出错:', error)
this.$Notice.error({ title: '保存出错', desc: error.message })
}).finally(() => {
this.inboundModal.saving = false
})
},
canEditInbound (row) {
const userId = this.$store.state.user.userId
return row.inbound_status === 0 && row.create_by === userId
},
deleteInbound (row) {
deleteInbound({ id: row.id }).then(ret => {
if (ret.data && ret.data.errcode === 0) {
this.$Message.success('删除成功'); this.fetchList('inbound')
} else {
this.$Notice.error({
title: '删除失败', desc: ret.data && ret.data.errmsg
})
}
})
},
doInbound (row) {
doInbound({ id: row.id }).then(ret => {
if (ret.data && ret.data.errcode === 0) {
this.$Message.success('入库成功')
this.fetchList('inbound')
this.fetchList('inventory')
} else {
this.$Notice.error({ title: '入库失败', desc: ret.data && ret.data.errmsg })
}
})
},
openReturnModal (row) {
this.returnModal.record = Object.assign({}, row)
this.returnModal.details = []
getPendingReturnById({ id: row.id }).then(ret => {
if (ret.data && ret.data.errcode === 0) this.returnModal.details = ret.data.data.details || []
})
this.returnModal.visible = true
},
confirmReturn () {
this.returnModal.saving = true
processReturn({ id: this.returnModal.record.id }).then(ret => {
if (ret.data && ret.data.errcode === 0) { this.$Message.success('归还已入库并更新库存'); this.returnModal.visible = false; this.fetchList('return'); this.fetchList('inventory') } else this.$Notice.error({ title: '归还失败', desc: ret.data && ret.data.errmsg })
}).finally(() => { this.returnModal.saving = false })
},
openInboundDetail (row) {
this.inboundDetailModal.visible = true
this.inboundDetailModal.loading = true
getInboundById({ id: row.id }).then(ret => {
if (ret.data && ret.data.errcode === 0) {
console.log(ret.data)
this.inboundDetailModal.data = ret.data.data || {}
this.inboundDetailModal.details = ret.data.data.details || []
this.inboundDetailModal.logs = ret.data.data.logs || []
} else this.$Notice.error({ title: '查询失败', desc: ret.data && ret.data.errmsg })
}).finally(() => { this.inboundDetailModal.loading = false })
} }
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论