Commit 5fb48cf8 by zhangtw

入库、申领

parent d3c15121
...@@ -215,6 +215,9 @@ export default { ...@@ -215,6 +215,9 @@ export default {
components: { MaterialSelector }, components: { MaterialSelector },
data () { data () {
return { return {
// 申请弹窗中的可编辑行状态
editingRowIndex: -1,
editingCellField: '',
// 审批状态映射字典 // 审批状态映射字典
approvalStatusMap: { '0': '待提交', '1': '审核中', '9': '审核通过', '-1': '驳回' }, approvalStatusMap: { '0': '待提交', '1': '审核中', '9': '审核通过', '-1': '驳回' },
activeTab: 'apply', activeTab: 'apply',
...@@ -248,7 +251,14 @@ export default { ...@@ -248,7 +251,14 @@ export default {
{ title: '申请单号', key: 'application_no', align: 'center' }, { title: '申请单号', key: 'application_no', align: 'center' },
{ title: '申请人', key: 'applicant_name', align: 'center' }, { title: '申请人', key: 'applicant_name', align: 'center' },
{ title: '部门', key: 'department_name', align: 'center' }, { title: '部门', key: 'department_name', align: 'center' },
{ title: '提交时间', key: 'submit_time', align: 'center' }, {
title: '提交时间',
key: 'submit_time',
align: 'center',
render: (h, { row }) => {
return h('span', this.formatDate(row.submit_time) || row.submit_time || '-')
}
},
{ title: '操作', slot: 'action', width: 120, align: 'center' } { title: '操作', slot: 'action', width: 120, align: 'center' }
], ],
historyColumns: [ historyColumns: [
...@@ -271,7 +281,77 @@ export default { ...@@ -271,7 +281,77 @@ export default {
{ type: 'selection', width: 60 }, { type: 'selection', width: 60 },
{ title: '物料编码', key: 'material_code' }, { title: '物料编码', key: 'material_code' },
{ title: '物料名称', key: 'material_name' }, { title: '物料名称', key: 'material_name' },
{ title: '申请数量', key: 'apply_quantity' }, {
title: '申请数量',
key: 'apply_quantity',
render: (h, { row, column, index }) => {
// 如果当前行是编辑状态,显示输入框
if (this.editingRowIndex === index && this.editingCellField === 'apply_quantity') {
return h('InputNumber', {
props: {
value: row.apply_quantity,
min: 1,
max: row.available_quantity || 9999,
precision: 0
},
style: { width: '100%' },
on: {
input: (value) => {
// 更新数据
this.applyModal.details[index].apply_quantity = value
},
'on-blur': () => {
// 失去焦点时退出编辑模式
this.editingRowIndex = -1
this.editingCellField = ''
},
'on-keyup': (event) => {
// 按回车键保存并退出编辑
if (event.keyCode === 13) {
this.editingRowIndex = -1
this.editingCellField = ''
}
}
}
})
} else {
// 非编辑状态,显示文本和编辑图标
return h('div', {
style: {
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
cursor: 'pointer',
padding: '0 8px'
},
on: {
click: () => {
// 点击进入编辑模式
this.editingRowIndex = index
this.editingCellField = 'apply_quantity'
// 下一个tick聚焦到输入框
this.$nextTick(() => {
const input = document.querySelector(`.ivu-table-cell-with-input input`)
if (input) input.focus()
})
}
}
}, [
h('span', row.apply_quantity || 0),
h('Icon', {
props: {
type: 'md-create',
size: 14
},
style: {
color: '#2d8cf0',
marginLeft: '8px'
}
})
])
}
}
},
{ title: '单位', key: 'unit' }, { title: '单位', key: 'unit' },
{ title: '备注', key: 'issue_remark' } { title: '备注', key: 'issue_remark' }
], ],
...@@ -297,16 +377,41 @@ export default { ...@@ -297,16 +377,41 @@ export default {
// 选择器控制与已选明细 // 选择器控制与已选明细
showMaterialSelector: false, showMaterialSelector: false,
applySelectedDetails: [], applySelectedDetails: [],
applyModal: { visible: false, isEdit: false, saving: false, form: {}, details: [] }, 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: [] }
} }
}, },
created () { this.fetchList('apply') }, created () { this.fetchList('apply') },
methods: { methods: {
// 获取当天日期,格式为 yyyy-MM-dd
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}`
},
// 处理单元格点击编辑
handleCellEdit (row, column, index, field) {
if (field === 'apply_quantity') {
this.editingRowIndex = index
this.editingCellField = field
// 下一个tick聚焦到输入框
this.$nextTick(() => {
const input = document.querySelector(`.ivu-table-cell-with-input input`)
if (input) input.focus()
})
}
},
// 添加方法:退出编辑模式
exitEditMode () {
this.editingRowIndex = -1
this.editingCellField = ''
},
// 转换时间戳为yyyy-MM-dd // 转换时间戳为yyyy-MM-dd
formatDate (timestamp) { formatDate (timestamp) {
if (!timestamp || isNaN(Number(timestamp))) return '未设置' if (!timestamp || isNaN(Number(timestamp))) return ''
const d = new Date(Number(timestamp)) const d = new Date(Number(timestamp))
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}` return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
}, },
...@@ -350,9 +455,10 @@ export default { ...@@ -350,9 +455,10 @@ export default {
openApplyModal () { openApplyModal () {
this.applyModal.isEdit = false this.applyModal.isEdit = false
this.applyModal.form = { applicant_id: '', applicant_name: '', department_id: '', department_name: '', borrow_purpose: '', expected_return_date: '', approval_status: 0 } this.applyModal.form = { applicant_id: '', applicant_name: '', department_id: '', department_name: '', borrow_purpose: '', expected_return_date: this.getTodayDate(), approval_status: 0 }
this.applyModal.details = [] this.applyModal.details = []
this.applyModal.visible = true this.applyModal.visible = true
this.exitEditMode()
}, },
openEdit (row) { openEdit (row) {
console.log(row) console.log(row)
...@@ -363,7 +469,7 @@ export default { ...@@ -363,7 +469,7 @@ export default {
this.applyModal.form.expected_return_date = this.formatDate(this.applyModal.form.expected_return_date) this.applyModal.form.expected_return_date = this.formatDate(this.applyModal.form.expected_return_date)
} else { } else {
// 空值兜底 // 空值兜底
this.applyModal.form.expected_return_date = '' this.applyModal.form.expected_return_date = this.getTodayDate()
} }
// load details from backend when open (simplified) // load details from backend when open (simplified)
getBorrowById({ id: row.id }).then(ret => { getBorrowById({ id: row.id }).then(ret => {
...@@ -372,6 +478,7 @@ export default { ...@@ -372,6 +478,7 @@ export default {
} }
}) })
this.applyModal.visible = true this.applyModal.visible = true
this.exitEditMode()
}, },
onApplyDetailSelectionChange (list) { onApplyDetailSelectionChange (list) {
this.applySelectedDetails = list || [] this.applySelectedDetails = list || []
...@@ -409,6 +516,7 @@ export default { ...@@ -409,6 +516,7 @@ export default {
this.applySelectedDetails = [] this.applySelectedDetails = []
}, },
saveApplication () { saveApplication () {
this.exitEditMode()
this.applyModal.saving = true this.applyModal.saving = true
const payload = Object.assign({}, this.applyModal.form, { details: this.applyModal.details }) const payload = Object.assign({}, this.applyModal.form, { details: this.applyModal.details })
saveBorrowApplication(payload).then(ret => { saveBorrowApplication(payload).then(ret => {
...@@ -536,4 +644,17 @@ export default { ...@@ -536,4 +644,17 @@ export default {
padding: 16px 0 0 0; padding: 16px 0 0 0;
} }
} }
/* 添加一些样式来美化编辑状态 */
.ivu-table-cell {
position: relative;
}
.edit-icon {
opacity: 0;
transition: opacity 0.2s;
}
.ivu-table-row:hover .edit-icon {
opacity: 1;
}
</style> </style>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论