Files
wuHanXinRui/mes/qd/src/views/wms/sb/outbill/AddDialog.vue
2022-07-20 19:37:49 +08:00

459 lines
15 KiB
Vue

<template>
<el-dialog
:title="crud.status.title"
fullscreen
append-to-body
:before-close="crud.cancelCU"
:visible.sync="crud.status.cu > 0 || crud.status.view > 0"
width="1200px"
@open="open"
@close="close"
>
<el-row v-show="crud.status.cu > 0" :gutter="20">
<el-col :span="20" style="border: 1px solid white">
<span/>
</el-col>
<el-col :span="4">
<span>
<el-button icon="el-icon-check" size="mini" :loading="crud.cu === 2" type="primary"
@click="crud.submitCU">保存</el-button>
<el-button icon="el-icon-close" size="mini" type="info" @click="crud.cancelCU">关闭</el-button>
</span>
</el-col>
</el-row>
<el-form ref="form" style="border: 1px solid #cfe0df;margin-top: 10px;padding-top: 10px;" :inline="true"
:model="form" :rules="rules" size="mini" label-width="85px" label-suffix=":">
<el-form-item label="单据号" prop="bill_code">
<label slot="label">单&nbsp;&nbsp;据&nbsp;号:</label>
<el-input v-model="form.bill_code" disabled placeholder="系统生成" clearable style="width: 210px"/>
</el-form-item>
<el-form-item label="业务类型" prop="bill_type">
<el-select
v-model="form.bill_type"
clearable
placeholder="业务类型"
style="width: 210px"
class="filter-item"
:disabled="crud.status.view > 0"
@change="billTypeChange"
>
<el-option
v-for="item in billtypelist"
:key="item.code"
:label="item.name"
:value="item.code"
/>
</el-select>
</el-form-item>
<el-form-item label="关联设备" prop="device_name">
<label slot="label">关联设备:</label>
<el-input v-model="form.device_name" size="mini" style="width: 210px">
<el-button slot="append" icon="el-icon-plus" @click="putDevice"/>
</el-input>
</el-form-item>
<el-form-item label="仓库" prop="stor_id">
<label slot="label">仓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;库:</label>
<el-select
v-model="form.stor_id"
clearable
placeholder="仓库"
class="filter-item"
style="width: 210px"
:disabled="crud.status.view > 0"
>
<el-option
v-for="item in storlist"
:key="item.stor_id"
:label="item.stor_name"
:value="item.stor_id"
/>
</el-select>
</el-form-item>
<el-form-item label="业务部门" prop="bizdeptid">
<treeselect
v-model="form.bizdeptid"
:options="depts"
:load-options="loadDepts"
style="width: 200px"
placeholder="选择部门"
/>
</el-form-item>
<el-form-item label="业务人员" prop="bizperson">
<label slot="label">业务人员:</label>
<el-input v-model="form.bizperson" size="mini" style="width: 210px"/>
</el-form-item>
<el-form-item label="明细数" prop="detail_count">
<label slot="label">明&nbsp;&nbsp;细&nbsp;数:</label>
<el-input v-model="form.detail_count" size="mini" disabled style="width: 210px"/>
</el-form-item>
<el-form-item label="总数量" prop="total_qty">
<label slot="label">总&nbsp;&nbsp;数&nbsp;量:</label>
<el-input-number
v-model="form.total_qty"
:controls="false"
:precision="3"
:min="0"
disabled
style="width: 210px"
/>
</el-form-item>
<el-form-item label="摘要" prop="remark">
<label slot="label">摘&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;要:</label>
<el-input v-model="form.remark" style="width: 380px;" rows="2" type="textarea"
:disabled="crud.status.view > 0"/>
</el-form-item>
</el-form>
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
<div class="crud-opts2" style="margin-bottom: 5px;">
<span class="crud-opts-right2">
<!--左侧插槽-->
<slot name="left"/>
<el-button
slot="left"
class="filter-item"
type="warning"
icon="el-icon-check"
size="mini"
:disabled="mater_btn"
@click="insertdtl()"
>
新增一行
</el-button>
</span>
</div>
<!--表格渲染-->
<el-table
ref="table"
:data="form.tableData"
style="width: 100%;"
border
:header-cell-style="{background:'#f5f7fa',color:'#606266'}"
>
<el-table-column type="index" label="序号" width="55" align="center"/>
<el-table-column show-overflow-tooltip prop="material_code" label="物料编码" width="190" align="center">
<template scope="scope">
<el-input v-show="!scope.row.edit" v-model="scope.row.material_code" disabled class="input-with-select">
<el-button slot="append" icon="el-icon-plus" @click="queryMater(scope.$index, scope.row)"/>
</el-input>
<span v-show="!scope.row.edit && mater_btn">{{ scope.row.material_code }}</span>
<span v-show="scope.row.edit">{{ scope.row.material_code }}</span>
</template>
</el-table-column>
<el-table-column prop="material_name" label="物料名称" align="center" min-width="150px" show-overflow-tooltip/>
<el-table-column prop="material_spec" label="规格" align="center" min-width="150px" show-overflow-tooltip/>
<el-table-column prop="material_model" label="型号" align="center" min-width="150px" show-overflow-tooltip/>
<el-table-column prop="sum_qty" label="库存" align="center" min-width="150px" show-overflow-tooltip/>
<el-table-column prop="plan_qty" width="220" label="出库数量" align="center">
<template scope="scope">
<el-input-number v-model="scope.row.plan_qty" :disabled="scope.row.edit" :precision="3" :controls="false"
:min="0" style="width: 120px"/>
</template>
</el-table-column>
<el-table-column prop="qty_unit_name" label="单位" align="center"/>
<el-table-column v-if="crud.status.cu > 0" align="center" label="操作" width="190" fixed="right">
<template scope="scope">
<el-button
type="danger"
class="filter-item"
size="mini"
icon="el-icon-delete"
@click.native.prevent="deleteRow(scope.$index, form.tableData)"
/>
<el-button
v-show="!scope.row.edit"
type="primary"
class="filter-item"
size="mini"
icon="el-icon-edit"
@click="handleEdit(scope.$index, scope.row)"
>编辑
</el-button>
<el-button
v-show="scope.row.edit"
type="success"
class="filter-item"
size="mini"
icon="el-icon-check"
@click="handleEdit(scope.$index, scope.row)"
>完成
</el-button>
</template>
</el-table-column>
</el-table>
<MaterDtl :dialog-show.sync="materShow" :is-single="true" :mater-opt-code="materType"
@tableChanged2="tableChanged2"/>
<DeviceDialog :dialog-show.sync="deviceDialog" :is-single="true" @tableChanged2="tableChanged"/>
</el-dialog>
</template>
<script>
import crudOperation from '@crud/CRUD.operation'
import CRUD, { crud, form } from '@crud/crud'
import crudStorattr from '@/api/wms/basedata/st/storattr'
import sparePart from '@/api/wms/sb/sparepartout'
import crudRawAssist from '@/api/wms/st/core/inbill/rawassist'
import MaterDtl from '@/views/wms/sb/outbill/IvtDialog'
import DeviceDialog from '@/views/wms/sb/upkeep/devicemaintenanceplan/DeviceDialog'
import { getDepts, getDeptSuperior } from '@/api/system/dept'
import Treeselect, { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
const defaultForm = {
bill_code: '',
stor_id: '',
bill_status: '10',
total_qty: '0',
detail_count: '0',
bill_type: '',
remark: '',
device_code: '',
device_id: '',
bizdeptid: null,
device_name: '',
bizperson: '',
source_id: '',
biz_date: new Date().format('yyyy-MM-dd'),
create_mode: '',
tableData: []
}
export default {
name: 'AddDialog',
components: { crudOperation, MaterDtl, DeviceDialog, Treeselect },
mixins: [crud(), form(defaultForm)],
props: {
dialogShow: {
type: Boolean,
default: false
},
bussConfig: {
type: Object
},
openParam: {
type: Object
}
},
data() {
return {
dialogVisible: false,
materShow: false,
dtlShow: false,
opendtlParam: null,
mater_btn: false,
materType: '',
deviceDialog: false,
storlist: [],
depts: [],
billtypelist: [],
rules: {
stor_id: [
{ required: true, message: '仓库不能为空', trigger: 'blur' }
],
bill_type: [
{ required: true, message: '业务类型不能为空', trigger: 'blur' }
],
device_code: [
{ required: true, message: '关联设备不能为空', trigger: 'blur' }
]
}
}
},
watch: {
dialogShow: {
handler(newValue, oldValue) {
this.dialogVisible = newValue
}
}
},
methods: {
open() {
if (this.crud.status.cu > 0) {
this.mater_btn = false
}
if (this.crud.status.view > 0) {
this.mater_btn = true
}
// 查询原材料库的仓库
crudStorattr.getStor({ 'is_attachment': '1' }).then(res => {
this.storlist = res.content
this.form.stor_id = this.storlist[0].stor_id
})
// 获取单据类型
crudRawAssist.getType({ 'io_code': '0109', 'io_flag': '01' }).then(res => {
this.billtypelist = res
this.form.bill_type = this.billtypelist[0].code
})
},
[CRUD.HOOK.afterToCU](crud, form) {
if (!form.bill_code) {
this.getDepts()
} else {
debugger
this.getSupDepts(form.bizdeptid)
}
},
getDepts() {
getDepts({ enabled: true }).then(res => {
this.depts = res.content.map(function(obj) {
if (obj.hasChildren) {
obj.children = null
}
return obj
})
})
},
getSupDepts(deptId) {
var number = parseFloat(deptId)
getDeptSuperior(number).then(res => {
const date = res.content
this.buildDepts(date)
this.depts = date
})
},
buildDepts(depts) {
debugger
depts.forEach(data => {
if (data.children) {
this.buildDepts(data.children)
}
if (data.hasChildren && !data.children) {
data.children = null
}
})
},
// 获取弹窗内部门数据
loadDepts({ action, parentNode, callback }) {
if (action === LOAD_CHILDREN_OPTIONS) {
getDepts({ enabled: true, pid: parentNode.id }).then(res => {
parentNode.children = res.content.map(function(obj) {
if (obj.hasChildren) {
obj.children = null
}
return obj
})
setTimeout(() => {
callback()
}, 200)
})
}
},
[CRUD.HOOK.afterToEdit]() {
// 获取入库单明细
sparePart.getIODtl({ 'bill_code': this.form.bill_code }).then(res => {
this.form.tableData = res
// 将明细变成不可编辑
for (let i = 0; i < this.form.tableData.length; i++) {
const row = this.form.tableData[i]
row.edit = true
this.form.tableData.splice(i, 1, row)
}
})
},
[CRUD.HOOK.beforeSubmit]() {
// 提交前校验
if (this.form.tableData.length === 0) {
this.crud.notify('请至少选择一条明细', CRUD.NOTIFICATION_TYPE.INFO)
return false
}
for (let i = 0; i < this.form.tableData.length; i++) {
if (!this.form.tableData[i].edit) {
this.crud.notify('尚有未完成编辑的物料明细序号' + (i + 1) + ',请检查!')
return false
}
}
},
putDevice() {
this.deviceDialog = true
},
billTypeChange(val) {
this.form.tableData = []
this.form.total_qty = 0
this.form.detail_count = 0
},
tableChanged2(row) {
debugger
// 新增一行物料时,给行进行赋值
this.nowrow.material_code = row.material_code
this.nowrow.material_id = row.material_id
this.nowrow.material_name = row.material_name
this.nowrow.material_spec = row.material_spec
this.nowrow.material_model = row.material_model
this.nowrow.qty_unit_id = row.qty_unit_id
this.nowrow.qty_unit_name = row.qty_unit_name
this.nowrow.sum_qty = row.sum_qty
this.form.tableData.splice(this.nowindex, 1, this.nowrow) // 通过splice 替换数据 触发视图更新
},
tableChanged(row) {
this.form.device_id = row.devicerecord_id
this.form.device_code = row.device_code
this.form.device_name = row.device_name
},
async queryMater(index, row) {
this.materShow = true
this.nowindex = index
this.nowrow = row
},
async insertdtl() {
if (this.form.bill_type == '') {
this.crud.notify('请选择业务类型!', CRUD.NOTIFICATION_TYPE.INFO)
return
}
this.form.tableData.push({ edit: false, plan_qty: '0' })
this.form.detail_count = this.form.tableData.length
},
handleEdit(index, row) {
if (!row.edit) {
if (parseFloat(row.plan_qty) <= 0) {
this.crud.notify('数量不可为空!', CRUD.NOTIFICATION_TYPE.INFO)
return false
}
if (!row.material_id) {
this.crud.notify('物料不可为空!', CRUD.NOTIFICATION_TYPE.INFO)
return false
}
if (parseFloat(row.plan_qty) > parseFloat(row.sum_qty)) {
this.crud.notify('出库数量不能大于库存!', CRUD.NOTIFICATION_TYPE.INFO)
return false
}
}
// 修改行的编辑状态
row.edit = !row.edit
this.form.tableData.splice(index, 1, row) // 通过splice 替换数据 触发视图更新
if (row.edit) {
this.form.total_qty = 0
this.form.tableData.forEach((item) => {
this.form.total_qty = this.form.total_qty + item.plan_qty
})
}
},
deleteRow(index, rows) {
this.form.total_qty = parseFloat(this.form.total_qty) - parseFloat(rows[index].plan_qty)
rows.splice(index, 1)
this.form.detail_count = this.form.tableData.length
},
close() {
this.$emit('AddChanged')
}
}
}
</script>
<style>
.crud-opts2 {
padding: 4px 0;
display: -webkit-flex;
display: flex;
align-items: center;
}
.crud-opts2 .crud-opts-right2 {
margin-left: auto;
}
</style>