Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
psa-web
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
高滢
psa-web
Commits
47522ed5
Commit
47522ed5
authored
Mar 03, 2025
by
方建宇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
领用申请库存更新
parent
647c9287
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
36 deletions
+74
-36
materialApply.vue
src/views/material/materialApply.vue
+60
-14
materialEntry.vue
src/views/material/materialEntry.vue
+14
-22
No files found.
src/views/material/materialApply.vue
View file @
47522ed5
...
@@ -83,7 +83,7 @@
...
@@ -83,7 +83,7 @@
<el-radio-group
v-model=
"form.usageType"
>
<el-radio-group
v-model=
"form.usageType"
>
<div
class=
"radio-item"
>
<div
class=
"radio-item"
>
<el-radio
label=
"借用(需归还)"
class=
"borrow"
><span
class=
"radio-label"
>
借用(需归还)
</span></el-radio>
<el-radio
label=
"借用(需归还)"
class=
"borrow"
><span
class=
"radio-label"
>
借用(需归还)
</span></el-radio>
<br>
<br>
<el-radio
label=
"领用(无需归还)"
class=
"receive"
><span
class=
"radio-label"
>
领用(无需归还)
</span></el-radio>
<el-radio
label=
"领用(无需归还)"
class=
"receive"
><span
class=
"radio-label"
>
领用(无需归还)
</span></el-radio>
</div>
</div>
</el-radio-group>
</el-radio-group>
...
@@ -138,7 +138,7 @@
...
@@ -138,7 +138,7 @@
<
script
>
<
script
>
import
{
addApply
,
updateApply
}
from
'@/api/material/apply.js'
;
import
{
addApply
,
updateApply
}
from
'@/api/material/apply.js'
;
import
{
listMaterial
}
from
'@/api/material/material.js'
;
import
{
listMaterial
,
getMaterial
,
updateMaterial
}
from
'@/api/material/material.js'
;
import
{
ElMessageBox
}
from
'element-plus'
;
import
{
ElMessageBox
}
from
'element-plus'
;
export
default
{
export
default
{
...
@@ -149,7 +149,7 @@ export default {
...
@@ -149,7 +149,7 @@ export default {
applicant
:
''
,
applicant
:
''
,
department
:
''
,
department
:
''
,
items
:
[
items
:
[
{
itemType
:
''
,
itemName
:
''
,
unit
:
''
,
stock
:
0
,
applyQuantity
:
0
,
applyRemaining
:
0
}
{
itemType
:
''
,
itemName
:
''
,
unit
:
''
,
stock
:
0
,
applyQuantity
:
0
,
applyRemaining
:
0
,
materialId
:
''
}
],
],
usageType
:
'借用(需归还)'
,
usageType
:
'借用(需归还)'
,
remark
:
''
,
remark
:
''
,
...
@@ -172,7 +172,7 @@ export default {
...
@@ -172,7 +172,7 @@ export default {
},
},
methods
:
{
methods
:
{
addItem
()
{
addItem
()
{
this
.
form
.
items
.
push
({
itemType
:
''
,
itemName
:
''
,
unit
:
''
,
stock
:
0
,
applyQuantity
:
0
,
applyRemaining
:
0
});
this
.
form
.
items
.
push
({
itemType
:
''
,
itemName
:
''
,
unit
:
''
,
stock
:
0
,
applyQuantity
:
0
,
applyRemaining
:
0
,
materialId
:
''
});
},
},
pasteItem
()
{
pasteItem
()
{
this
.
showPasteDialog
=
true
;
this
.
showPasteDialog
=
true
;
...
@@ -185,15 +185,55 @@ export default {
...
@@ -185,15 +185,55 @@ export default {
items
:
JSON
.
stringify
(
this
.
form
.
items
)
items
:
JSON
.
stringify
(
this
.
form
.
items
)
};
};
addApply
(
data
).
then
(
response
=>
{
addApply
(
data
).
then
(
response
=>
{
ElMessageBox
.
alert
(
'申请提交成功'
,
'提示'
,
{
if
(
response
&&
response
.
code
===
200
)
{
confirmButtonText
:
'确定'
,
ElMessageBox
.
alert
(
'申请提交成功'
,
'提示'
,
{
callback
:
action
=>
{
confirmButtonText
:
'确定'
,
this
.
$message
.
success
(
'申请提交成功'
);
callback
:
action
=>
{
this
.
resetForm
();
this
.
$message
.
success
(
'申请提交成功'
);
// 提交成功后清空草稿
// 更新每个物品的 stock
localStorage
.
removeItem
(
'materialApplyDraft'
);
this
.
form
.
items
.
forEach
(
item
=>
{
}
if
(
item
.
materialId
)
{
});
getMaterial
(
item
.
materialId
).
then
(
materialResponse
=>
{
if
(
materialResponse
&&
materialResponse
.
code
===
200
)
{
console
.
log
(
'Material Response:'
,
materialResponse
);
// 添加调试信息
// 获取原 stock 数量
let
originalStock
=
materialResponse
.
data
.
stock
||
0
;
// 计算新的 stock 数量
let
newStock
=
originalStock
-
item
.
applyQuantity
;
// 调用 updateMaterial 接口更新 material 表中相应物品的 stock 字段
updateMaterial
({
materialId
:
item
.
materialId
,
stock
:
newStock
}).
then
(
updateResponse
=>
{
if
(
updateResponse
&&
updateResponse
.
code
===
200
)
{
console
.
log
(
'Stock updated successfully for materialId:'
,
item
.
materialId
);
}
else
{
this
.
$message
.
error
(
'更新库存失败: '
+
updateResponse
.
msg
);
}
}).
catch
(
updateError
=>
{
this
.
$message
.
error
(
'更新库存失败: '
+
updateError
.
message
);
});
}
else
{
this
.
$message
.
error
(
'获取物品信息失败: '
+
materialResponse
.
msg
);
}
}).
catch
(
materialError
=>
{
this
.
$message
.
error
(
'获取物品信息失败: '
+
materialError
.
message
);
});
}
});
this
.
resetForm
();
// 提交成功后清空草稿
localStorage
.
removeItem
(
'materialApplyDraft'
);
}
});
}
else
{
ElMessageBox
.
alert
(
'申请提交失败'
,
'提示'
,
{
confirmButtonText
:
'确定'
,
callback
:
action
=>
{
this
.
$message
.
error
(
'申请提交失败: '
+
response
.
msg
);
}
});
}
}).
catch
(
error
=>
{
}).
catch
(
error
=>
{
ElMessageBox
.
alert
(
'申请提交失败'
,
'提示'
,
{
ElMessageBox
.
alert
(
'申请提交失败'
,
'提示'
,
{
confirmButtonText
:
'确定'
,
confirmButtonText
:
'确定'
,
...
@@ -221,7 +261,7 @@ export default {
...
@@ -221,7 +261,7 @@ export default {
applicant
:
''
,
applicant
:
''
,
department
:
''
,
department
:
''
,
items
:
[
items
:
[
{
itemType
:
''
,
itemName
:
''
,
unit
:
''
,
stock
:
0
,
applyQuantity
:
0
,
applyRemaining
:
0
}
{
itemType
:
''
,
itemName
:
''
,
unit
:
''
,
stock
:
0
,
applyQuantity
:
0
,
applyRemaining
:
0
,
materialId
:
''
}
],
],
usageType
:
'借用(需归还)'
,
usageType
:
'借用(需归还)'
,
remark
:
''
,
remark
:
''
,
...
@@ -264,6 +304,7 @@ export default {
...
@@ -264,6 +304,7 @@ export default {
this
.
form
.
items
[
index
].
itemType
=
newItemType
;
this
.
form
.
items
[
index
].
itemType
=
newItemType
;
this
.
form
.
items
[
index
].
itemName
=
''
;
// 清空物品名称
this
.
form
.
items
[
index
].
itemName
=
''
;
// 清空物品名称
this
.
form
.
items
[
index
].
unit
=
''
;
// 清空单位
this
.
form
.
items
[
index
].
unit
=
''
;
// 清空单位
this
.
form
.
items
[
index
].
materialId
=
''
;
// 清空 materialId
this
.
updateItemNames
(
index
);
// 更新物品名称选项
this
.
updateItemNames
(
index
);
// 更新物品名称选项
},
},
updateUnitBasedOnItemName
(
index
)
{
updateUnitBasedOnItemName
(
index
)
{
...
@@ -275,9 +316,14 @@ export default {
...
@@ -275,9 +316,14 @@ export default {
);
);
if
(
selectedItem
)
{
if
(
selectedItem
)
{
item
.
unit
=
selectedItem
.
unit
;
item
.
unit
=
selectedItem
.
unit
;
item
.
stock
=
selectedItem
.
stock
!==
null
?
selectedItem
.
stock
:
0
;
// 处理 stock 为 null 的情况
item
.
materialId
=
selectedItem
.
materialId
;
// 设置 materialId
}
else
{
}
else
{
item
.
unit
=
''
;
item
.
unit
=
''
;
item
.
stock
=
0
;
// 默认库存为0
item
.
materialId
=
''
;
// 清空 materialId
}
}
this
.
updateRemaining
(
index
);
// 更新剩余库存
}
}
}
}
},
},
...
...
src/views/material/materialEntry.vue
View file @
47522ed5
...
@@ -94,7 +94,7 @@
...
@@ -94,7 +94,7 @@
<
script
>
<
script
>
import
{
ElMessageBox
}
from
'element-plus'
;
import
{
ElMessageBox
}
from
'element-plus'
;
import
{
addEntry
,
listEntry
}
from
'@/api/material/entry.js'
;
import
{
addEntry
,
listEntry
}
from
'@/api/material/entry.js'
;
import
{
listMaterial
,
updateMaterial
}
from
'@/api/material/material.js'
;
import
{
getMaterial
,
listMaterial
,
updateMaterial
}
from
'@/api/material/material.js'
;
export
default
{
export
default
{
data
()
{
data
()
{
...
@@ -127,26 +127,19 @@ export default {
...
@@ -127,26 +127,19 @@ export default {
ElMessageBox
.
alert
(
'提交成功'
,
'提示'
,
{
ElMessageBox
.
alert
(
'提交成功'
,
'提示'
,
{
confirmButtonText
:
'确定'
,
confirmButtonText
:
'确定'
,
callback
:
action
=>
{
callback
:
action
=>
{
// 调用
listEntry 接口查询所有与刚刚提交的物品一样的入库记录
// 调用
getMaterial 接口查询物品的 stock 信息
listEntry
({
materialId
:
this
.
form
.
materialId
}).
then
(
entry
Response
=>
{
getMaterial
(
this
.
form
.
materialId
).
then
(
material
Response
=>
{
if
(
entryResponse
&&
entry
Response
.
code
===
200
)
{
if
(
materialResponse
&&
material
Response
.
code
===
200
)
{
console
.
log
(
'
Entry Response:'
,
entry
Response
);
// 添加调试信息
console
.
log
(
'
Material Response:'
,
material
Response
);
// 添加调试信息
//
初始化 totalStock 为 0
//
获取原 stock 数量
let
totalStock
=
0
;
let
originalStock
=
materialResponse
.
data
.
stock
||
0
;
// 统计入库数量(entry_quantity 字段的总和)
// 计算新的 stock 数量
if
(
entryResponse
.
rows
&&
Array
.
isArray
(
entryResponse
.
rows
))
{
let
newStock
=
originalStock
+
this
.
form
.
entryQuantity
;
totalStock
=
entryResponse
.
rows
.
reduce
((
sum
,
entry
)
=>
{
// 确保 entry.entry_quantity 不为 null
return
sum
+
(
entry
.
entryQuantity
!==
null
?
entry
.
entryQuantity
:
0
);
},
0
);
}
console
.
log
(
'Total Stock:'
,
totalStock
);
// 添加调试信息
// 调用 updateMaterial 接口更新 material 表中相应物品的 stock 字段
// 调用 updateMaterial 接口更新 material 表中相应物品的 stock 字段
updateMaterial
({
materialId
:
this
.
form
.
materialId
,
stock
:
total
Stock
}).
then
(
updateResponse
=>
{
updateMaterial
({
materialId
:
this
.
form
.
materialId
,
stock
:
new
Stock
}).
then
(
updateResponse
=>
{
if
(
updateResponse
&&
updateResponse
.
code
===
200
)
{
if
(
updateResponse
&&
updateResponse
.
code
===
200
)
{
// 提交成功后清空草稿
// 提交成功后清空草稿
localStorage
.
removeItem
(
'materialApplyDraft'
);
localStorage
.
removeItem
(
'materialApplyDraft'
);
...
@@ -160,10 +153,10 @@ export default {
...
@@ -160,10 +153,10 @@ export default {
this
.
$message
.
error
(
'更新库存失败: '
+
updateError
.
message
);
this
.
$message
.
error
(
'更新库存失败: '
+
updateError
.
message
);
});
});
}
else
{
}
else
{
this
.
$message
.
error
(
'获取
入库记录失败: '
+
entry
Response
.
msg
);
this
.
$message
.
error
(
'获取
物品信息失败: '
+
material
Response
.
msg
);
}
}
}).
catch
(
entry
Error
=>
{
}).
catch
(
material
Error
=>
{
this
.
$message
.
error
(
'获取
入库记录失败: '
+
entry
Error
.
message
);
this
.
$message
.
error
(
'获取
物品信息失败: '
+
material
Error
.
message
);
});
});
}
}
});
});
...
@@ -179,8 +172,7 @@ export default {
...
@@ -179,8 +172,7 @@ export default {
callback
:
action
=>
{}
callback
:
action
=>
{}
});
});
}
}
},
},
resetForm
()
{
resetForm
()
{
this
.
form
=
{
this
.
form
=
{
entryDate
:
''
,
entryDate
:
''
,
entryPerson
:
''
,
entryPerson
:
''
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment