|
|
|
|
@ -0,0 +1,431 @@
|
|
|
|
|
<template>
|
|
|
|
|
<div>
|
|
|
|
|
<xy-dialog
|
|
|
|
|
ref="dialog"
|
|
|
|
|
:width="80"
|
|
|
|
|
:is-show.sync="isShow"
|
|
|
|
|
type="form"
|
|
|
|
|
:title="titleName"
|
|
|
|
|
:form="form"
|
|
|
|
|
:rules="rules"
|
|
|
|
|
@submit="submit"
|
|
|
|
|
>
|
|
|
|
|
<template v-slot:chukuriqi>
|
|
|
|
|
<div class="xy-table-item">
|
|
|
|
|
<div class="xy-table-item-label">
|
|
|
|
|
<span style="color: red;font-weight: 600;padding-right: 4px;">*</span>出库日期:
|
|
|
|
|
</div>
|
|
|
|
|
<div class="xy-table-item-content">
|
|
|
|
|
<el-date-picker
|
|
|
|
|
v-model="form.chukuriqi"
|
|
|
|
|
style="width: 300px;"
|
|
|
|
|
type="date"
|
|
|
|
|
placeholder="选择出库日期"
|
|
|
|
|
value-format="yyyy-MM-dd"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-slot:jingbanren>
|
|
|
|
|
<div class="xy-table-item">
|
|
|
|
|
<div class="xy-table-item-label">
|
|
|
|
|
<span style="color: red;font-weight: 600;padding-right: 4px;">*</span>经办人:
|
|
|
|
|
</div>
|
|
|
|
|
<div class="xy-table-item-content">
|
|
|
|
|
<el-input v-model="form.jingbanren" placeholder="请填写经办人" clearable style="width: 300px;" />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-slot:fujian>
|
|
|
|
|
<div class="xy-table-item">
|
|
|
|
|
<div class="xy-table-item-label">
|
|
|
|
|
<span style="color: red;font-weight: 600;padding-right: 4px;" />附件:
|
|
|
|
|
</div>
|
|
|
|
|
<div class="xy-table-item-content">
|
|
|
|
|
<el-upload
|
|
|
|
|
ref="fileUpload"
|
|
|
|
|
:action="action"
|
|
|
|
|
multiple
|
|
|
|
|
class="upload-demo"
|
|
|
|
|
:file-list="fileList"
|
|
|
|
|
style="width:400px"
|
|
|
|
|
:auto-upload="true"
|
|
|
|
|
:headers="headers"
|
|
|
|
|
:on-success="handleSuccess"
|
|
|
|
|
:on-remove="handleRemove"
|
|
|
|
|
>
|
|
|
|
|
<el-button size="small" type="primary">点击上传</el-button>
|
|
|
|
|
</el-upload>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-slot:beizhu>
|
|
|
|
|
<div class="xy-table-item">
|
|
|
|
|
<div class="xy-table-item-label">
|
|
|
|
|
<span style="color: red;font-weight: 600;padding-right: 4px;" />备注:
|
|
|
|
|
</div>
|
|
|
|
|
<div class="xy-table-item-content">
|
|
|
|
|
<el-input
|
|
|
|
|
v-model="form.beizhu"
|
|
|
|
|
type="textarea"
|
|
|
|
|
:rows="3"
|
|
|
|
|
placeholder="请输入备注"
|
|
|
|
|
clearable
|
|
|
|
|
style="width: 300px;"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-slot:chukuwuzi>
|
|
|
|
|
<div class="xy-table-item">
|
|
|
|
|
<div class="xy-table-item-label">
|
|
|
|
|
<span style="color: red;font-weight: 600;padding-right: 4px;" />出库物资:
|
|
|
|
|
</div>
|
|
|
|
|
<div class="xy-table-item-content" style="width: 100%;">
|
|
|
|
|
<div style="margin-bottom: 10px;">
|
|
|
|
|
<el-button type="primary" size="small" @click="selectMaterial">新增物资</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
<el-table
|
|
|
|
|
:data="materialList"
|
|
|
|
|
border
|
|
|
|
|
style="width: 90%;"
|
|
|
|
|
max-height="400"
|
|
|
|
|
>
|
|
|
|
|
<el-table-column type="index" label="序号" width="60" align="center" />
|
|
|
|
|
<el-table-column prop="cangkumingcheng" label="仓库名称" width="150" align="center" />
|
|
|
|
|
<el-table-column prop="xianwuzimingcheng" label="现物资名称" width="150" align="center" />
|
|
|
|
|
<el-table-column prop="yuanwuzimingcheng" label="原物资名称" width="150" align="center" />
|
|
|
|
|
<el-table-column prop="wuzidaima" label="物资代码" width="120" align="center" />
|
|
|
|
|
<el-table-column prop="guigexinghao" label="规格型号" width="120" align="center" />
|
|
|
|
|
<el-table-column prop="kucunshuliang" label="库存数量" width="100" align="center" />
|
|
|
|
|
<el-table-column label="出库数量" width="120" align="center">
|
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
<el-input-number
|
|
|
|
|
v-model="scope.row.chukushuliang"
|
|
|
|
|
:min="0"
|
|
|
|
|
:max="scope.row.kucunshuliang || 999999"
|
|
|
|
|
:precision="0"
|
|
|
|
|
size="small"
|
|
|
|
|
style="width: 100px;"
|
|
|
|
|
@change="handleQuantityChange(scope.row)"
|
|
|
|
|
/>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column prop="danwei" label="单位" width="80" align="center" />
|
|
|
|
|
<el-table-column prop="jiazhiyuan" label="价值(元)" width="100" align="center" />
|
|
|
|
|
<el-table-column prop="quyu" label="区域" width="100" align="center" />
|
|
|
|
|
<el-table-column fixed="right" label="操作" width="100" align="center">
|
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
<el-button
|
|
|
|
|
type="danger"
|
|
|
|
|
size="mini"
|
|
|
|
|
@click="removeMaterial(scope.$index)"
|
|
|
|
|
>删除</el-button>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</xy-dialog>
|
|
|
|
|
|
|
|
|
|
<!-- 选择物资弹窗 -->
|
|
|
|
|
<selectMaterial
|
|
|
|
|
ref="selectMaterial"
|
|
|
|
|
@materials-selected="handleMaterialsSelected"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import {
|
|
|
|
|
save,
|
|
|
|
|
show
|
|
|
|
|
} from '@/api/system/baseForm.js'
|
|
|
|
|
import {
|
|
|
|
|
Message
|
|
|
|
|
} from 'element-ui'
|
|
|
|
|
import selectMaterial from './selectMaterial.vue'
|
|
|
|
|
import { getToken } from '@/utils/auth'
|
|
|
|
|
import { getInfo } from '@/api/user.js'
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
components: {
|
|
|
|
|
selectMaterial
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
isShow: false,
|
|
|
|
|
type: 'add',
|
|
|
|
|
id: '',
|
|
|
|
|
titleName: '',
|
|
|
|
|
tableName: 'flood_outbound',
|
|
|
|
|
action: `${process.env.VUE_APP_UPLOAD_API}`,
|
|
|
|
|
fileList: [],
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: `Bearer ${getToken()}`
|
|
|
|
|
},
|
|
|
|
|
materialList: [], // 出库物资列表
|
|
|
|
|
form: {
|
|
|
|
|
chukuriqi: '',
|
|
|
|
|
jingbanren: '',
|
|
|
|
|
fujian: [],
|
|
|
|
|
beizhu: '',
|
|
|
|
|
chukuwuzi:[] // 出库物资列表
|
|
|
|
|
},
|
|
|
|
|
rules: {
|
|
|
|
|
chukuriqi: [{
|
|
|
|
|
required: true,
|
|
|
|
|
message: '请选择出库日期'
|
|
|
|
|
}],
|
|
|
|
|
jingbanren: [{
|
|
|
|
|
required: true,
|
|
|
|
|
message: '请填写经办人'
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
isShow(newVal) {
|
|
|
|
|
if (newVal) {
|
|
|
|
|
this.titleName = this.type === 'add' ? `新增出库记录` : `编辑出库记录`
|
|
|
|
|
if (this.type === 'editor') {
|
|
|
|
|
this.getDetail()
|
|
|
|
|
} else {
|
|
|
|
|
this.resetForm()
|
|
|
|
|
// 新增时自动填充经办人
|
|
|
|
|
this.getUserName()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.id = ''
|
|
|
|
|
this.type = ''
|
|
|
|
|
this.resetForm()
|
|
|
|
|
if (this.$refs['dialog']) {
|
|
|
|
|
this.$refs['dialog'].reset()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
async getUserName() {
|
|
|
|
|
try {
|
|
|
|
|
const res = await getInfo()
|
|
|
|
|
if (res && res.name) {
|
|
|
|
|
this.form.jingbanren = res.name
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('获取用户信息失败', error)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
resetForm() {
|
|
|
|
|
this.form = {
|
|
|
|
|
chukuriqi: '',
|
|
|
|
|
jingbanren: '',
|
|
|
|
|
fujian: [],
|
|
|
|
|
beizhu: '',
|
|
|
|
|
chukuwuzi:[]
|
|
|
|
|
}
|
|
|
|
|
this.fileList = []
|
|
|
|
|
this.materialList = []
|
|
|
|
|
},
|
|
|
|
|
handleSuccess(response, file, fileList) {
|
|
|
|
|
this.fileList = fileList
|
|
|
|
|
const arr = []
|
|
|
|
|
for (const item of this.fileList) {
|
|
|
|
|
if (item.response && item.response.id) {
|
|
|
|
|
arr.push(item.response.id)
|
|
|
|
|
} else if (item.id) {
|
|
|
|
|
arr.push(item.id)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.form.fujian = arr
|
|
|
|
|
},
|
|
|
|
|
handleRemove(file, fileList) {
|
|
|
|
|
this.fileList = fileList
|
|
|
|
|
const arr = []
|
|
|
|
|
for (const item of this.fileList) {
|
|
|
|
|
if (item.response && item.response.id) {
|
|
|
|
|
arr.push(item.response.id)
|
|
|
|
|
} else if (item.id) {
|
|
|
|
|
arr.push(item.id)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.form.fujian = arr
|
|
|
|
|
},
|
|
|
|
|
selectMaterial() {
|
|
|
|
|
// 打开物资选择弹窗
|
|
|
|
|
this.$refs['selectMaterial'].show()
|
|
|
|
|
},
|
|
|
|
|
handleMaterialsSelected(selectedMaterials) {
|
|
|
|
|
// 接收选中的物资,添加到出库物资列表
|
|
|
|
|
if (selectedMaterials && selectedMaterials.length > 0) {
|
|
|
|
|
selectedMaterials.forEach(material => {
|
|
|
|
|
// 检查是否已经存在(根据物资ID)
|
|
|
|
|
const exists = this.materialList.find(item => item.id === material.id)
|
|
|
|
|
if (!exists) {
|
|
|
|
|
// 添加出库数量字段,默认为0
|
|
|
|
|
const newMaterial = {
|
|
|
|
|
...material,
|
|
|
|
|
kucunshuliang: material.shuliang || 0, // 库存数量
|
|
|
|
|
chukushuliang: 0, // 出库数量,需要用户填写
|
|
|
|
|
tempId: Date.now() + Math.random() // 临时ID用于删除
|
|
|
|
|
}
|
|
|
|
|
this.materialList.push(newMaterial)
|
|
|
|
|
} else {
|
|
|
|
|
Message({
|
|
|
|
|
type: 'warning',
|
|
|
|
|
message: `物资"${material.xianwuzimingcheng}"已存在,请勿重复添加`
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
Message({
|
|
|
|
|
type: 'success',
|
|
|
|
|
message: `已添加${selectedMaterials.length}条物资,请填写出库数量`
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
handleQuantityChange(row) {
|
|
|
|
|
// 验证出库数量不能超过库存数量
|
|
|
|
|
if (row.chukushuliang > row.kucunshuliang) {
|
|
|
|
|
Message({
|
|
|
|
|
type: 'warning',
|
|
|
|
|
message: '出库数量不能超过库存数量'
|
|
|
|
|
})
|
|
|
|
|
row.chukushuliang = row.kucunshuliang
|
|
|
|
|
}
|
|
|
|
|
if (row.chukushuliang < 0) {
|
|
|
|
|
row.chukushuliang = 0
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
removeMaterial(index) {
|
|
|
|
|
this.materialList.splice(index, 1)
|
|
|
|
|
Message({
|
|
|
|
|
type: 'success',
|
|
|
|
|
message: '删除成功'
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
async getDetail() {
|
|
|
|
|
const res = await show({
|
|
|
|
|
id: this.id,
|
|
|
|
|
table_name: this.tableName
|
|
|
|
|
})
|
|
|
|
|
this.form = {
|
|
|
|
|
chukuriqi: res?.chukuriqi || '',
|
|
|
|
|
jingbanren: res?.jingbanren || '',
|
|
|
|
|
fujian: res?.fujian ? (Array.isArray(res.fujian) ? res.fujian : JSON.parse(res.fujian)) : [],
|
|
|
|
|
beizhu: res?.beizhu || '',
|
|
|
|
|
chukuwuzi: res?.chukuwuzi ? (Array.isArray(res.chukuwuzi) ? res.chukuwuzi : JSON.parse(res.chukuwuzi)) : []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理附件列表
|
|
|
|
|
if (this.form.fujian && this.form.fujian.length > 0) {
|
|
|
|
|
this.fileList = this.form.fujian.map((id, index) => ({
|
|
|
|
|
id: id,
|
|
|
|
|
name: `附件${index + 1}`,
|
|
|
|
|
url: ''
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理出库物资列表
|
|
|
|
|
if (res.chukuwuzi) {
|
|
|
|
|
try {
|
|
|
|
|
this.materialList = Array.isArray(res.chukuwuzi) ? res.chukuwuzi : JSON.parse(res.chukuwuzi)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
this.materialList = []
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.materialList = []
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
submit() {
|
|
|
|
|
// 验证出库物资
|
|
|
|
|
if (!this.materialList || this.materialList.length === 0) {
|
|
|
|
|
Message({
|
|
|
|
|
type: 'warning',
|
|
|
|
|
message: '请至少添加一条出库物资'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 验证出库数量
|
|
|
|
|
const invalidMaterials = this.materialList.filter(item => !item.chukushuliang || item.chukushuliang <= 0)
|
|
|
|
|
if (invalidMaterials.length > 0) {
|
|
|
|
|
Message({
|
|
|
|
|
type: 'warning',
|
|
|
|
|
message: '请填写所有物资的出库数量'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 验证出库数量不能超过库存数量
|
|
|
|
|
const exceedMaterials = this.materialList.filter(item => item.chukushuliang > item.kucunshuliang)
|
|
|
|
|
if (exceedMaterials.length > 0) {
|
|
|
|
|
Message({
|
|
|
|
|
type: 'warning',
|
|
|
|
|
message: '出库数量不能超过库存数量'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const submitData = {
|
|
|
|
|
table_name: this.tableName,
|
|
|
|
|
chukuriqi: this.form.chukuriqi,
|
|
|
|
|
jingbanren: this.form.jingbanren,
|
|
|
|
|
fujian: JSON.stringify(this.form.fujian),
|
|
|
|
|
beizhu: this.form.beizhu,
|
|
|
|
|
chukuwuzi: JSON.stringify(this.materialList)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.type === 'add') {
|
|
|
|
|
save(submitData).then(res => {
|
|
|
|
|
Message({
|
|
|
|
|
type: 'success',
|
|
|
|
|
message: '新增成功'
|
|
|
|
|
})
|
|
|
|
|
this.isShow = false
|
|
|
|
|
this.$emit('refresh')
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
Message({
|
|
|
|
|
type: 'error',
|
|
|
|
|
message: '新增失败:' + (err.message || '未知错误')
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
} else if (this.type === 'editor') {
|
|
|
|
|
submitData.id = this.id
|
|
|
|
|
save(submitData).then(res => {
|
|
|
|
|
Message({
|
|
|
|
|
type: 'success',
|
|
|
|
|
message: '编辑成功'
|
|
|
|
|
})
|
|
|
|
|
this.isShow = false
|
|
|
|
|
this.$emit('refresh')
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
Message({
|
|
|
|
|
type: 'error',
|
|
|
|
|
message: '编辑失败:' + (err.message || '未知错误')
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
.xy-table-item-label {
|
|
|
|
|
width: 160px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
::v-deep .el-upload--picture-card {
|
|
|
|
|
font-size: 28px;
|
|
|
|
|
color: #8c939d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
::v-deep .xy-table-item-label {
|
|
|
|
|
width: 160px !important;
|
|
|
|
|
}
|
|
|
|
|
::v-deep .beizhu,
|
|
|
|
|
::v-deep .chukuwuzi {
|
|
|
|
|
flex-basis: 100% !important;
|
|
|
|
|
}
|
|
|
|
|
</style>
|