Files
wuHanXinRui/mes/qd/src/views/wms/basedata/em/devicebom/AddDialog.vue
2022-11-17 09:40:23 +08:00

466 lines
12 KiB
Vue

<template>
<el-dialog
:title="crud.status.title"
append-to-body
fullscreen
:before-close="crud.cancelCU"
:visible.sync="crud.status.cu > 0 || crud.status.view > 0"
>
<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="100px" label-suffix=":">
<el-row>
<el-col :span="8">
<el-form-item label="设备类别" prop="material_type_id">
<treeselect
v-model="form.material_type_id"
:options="classes"
:load-options="loadClass"
style="width: 200px;"
placeholder="请选择"
:disabled="crud.status.view > 0"
/>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="BOM编码">
<el-input v-model="form.device_bom_code" style="width: 250px;" disabled placeholder="系统生成" />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="BOM名称" prop="material_name">
<el-input v-model="form.material_name" style="width: 250px;" :disabled="crud.status.view > 0" />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" style="width: 580px;" rows="2" type="textarea" :disabled="crud.status.view > 0" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<div class="crud-opts2">
<span class="role-span">对应明细</span>
<span class="crud-opts-right2">
<!--左侧插槽-->
<slot name="left" />
<el-button
slot="left"
class="filter-item"
type="primary"
icon="el-icon-check"
size="mini"
:disabled="crud.status.view > 0"
@click="putMaterial"
>
添加物料
</el-button>
</span>
</div>
<el-card class="box-card" shadow="never" :body-style="{padding:'0'}">
<!--表格渲染-->
<el-table
ref="table2"
:data="form.tableData"
style="width: 100%;"
max-height="500"
border
:highlight-current-row="true"
:header-cell-style="{background:'#f5f7fa',color:'#606266'}"
>
<el-table-column type="index" label="序号" width="55" align="center" />
<el-table-column v-if="false" prop="material_id" label="物料id" align="center" />
<el-table-column v-if="false" prop="base_unit_id" label="单位id" align="center" />
<el-table-column prop="material_code" label="备件物料编码" align="center" />
<el-table-column prop="material_name" label="备件物料名称" align="center" />
<el-table-column prop="qty" label="标准数量" align="center">
<template slot-scope="scope">
<el-input-number
v-model="scope.row.qty"
size="mini"
:controls="false"
:precision="0"
:min="0"
:disabled="crud.status.view > 0"
/>
</template>
</el-table-column>
<el-table-column prop="base_unit_id_name" label="单位" align="center" />
<el-table-column prop="dtl_remark" label="备注" align="center">
<template slot-scope="scope">
<el-input v-show="!scope.row.edit" v-model="scope.row.dtl_remark" class="input-with-select" :disabled="crud.status.view > 0" />
</template>
</el-table-column>
<el-table-column v-permission="[]" label="操作" width="120px" align="center" fixed="right">
<template slot-scope="scope">
<el-button type="danger" class="filter-item" size="mini" icon="el-icon-delete" @click.native.prevent="delRow(scope.$index, form.tableData)" :disabled="crud.status.view > 0" />
</template>
</el-table-column>
</el-table>
</el-card>
<DeviceMaterDialog :dialog-show.sync="materDialog" :mater-opt-code="materOpt_code" :is-single="false" @tableChanged2="tableChanged2"/>
</el-dialog>
</template>
<script>
const defaultForm = {
material_type_id: null,
device_bom_code: null,
material_name: null,
remark: null,
tableData: []
}
import crudClassstandard from '@/api/wms/basedata/master/classstandard'
import crudDevicebom from '@/api/wms/basedata/em/devicebom'
import DeviceMaterDialog from '@/views/wms/pub/DeviceMaterDialog'
import crudMaterialbase from '@/api/wms/basedata/master/materialbase'
import CRUD, { form, crud } from '@crud/crud'
import Treeselect, { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
export default {
name: 'AddDialog',
components: { Treeselect, DeviceMaterDialog },
mixins: [form(defaultForm), crud()],
props: {
dialogShow: {
type: Boolean,
default: false
},
openParam: {
type: Object
}
},
watch: {
dialogShow: {
handler(newValue, oldValue) {
this.dialogVisible = newValue
}
}
},
data() {
return {
classes: [],
class_idStr: null,
materOpt_code: '23',
materOpt_code_2: '26',
classBj_id: null,
dialogVisible: false,
materDialog: false,
rules: {
material_type_id: [
{ required: true, message: '设备类别不能为空', trigger: 'blur' }
],
material_name: [
{ required: true, message: '设备BOM名称不能为空', trigger: 'blur' }
]
}
}
},
created() {
const param = {
'materOpt_code': this.materOpt_code
}
crudMaterialbase.getMaterOptType(param).then(res => {
this.class_idStr = res.class_idStr
this.queryClassId()
})
const data = {
'materOpt_code': this.materOpt_code_2
}
crudDevicebom.getBjId(data).then(res => {
this.classBj_id = res.class_idStr
})
},
methods: {
[CRUD.HOOK.beforeSubmit]() {
const arr = this.form.tableData
if (arr.length === 0) {
this.crud.notify('明细不能为空', CRUD.NOTIFICATION_TYPE.INFO)
return false
}
for (let i = 0; i < arr.length; i++) {
if (arr[i].qty === undefined) {
this.crud.notify('请填写数量', CRUD.NOTIFICATION_TYPE.INFO)
return false
}
}
},
[CRUD.HOOK.afterToEdit]() {
const data = {
'device_bom_id': this.form.device_bom_id
}
crudDevicebom.getDtl(data).then(res => {
this.form.tableData = res
})
},
[CRUD.HOOK.afterToView](crud, form) {
const data = {
'device_bom_id': this.form.device_bom_id
}
crudDevicebom.getDtl(data).then(res => {
this.form.tableData = res
})
if (!form.device_bom_code) {
this.queryClassId()
} else {
const data = {}
data.id = form.material_type_id
data.goal_id = this.classBj_id
this.getSubTypes(data)
}
},
[CRUD.HOOK.afterToCU](crud, form) {
if (!form.device_bom_code) {
this.queryClassId()
} else {
const data = {}
data.id = form.material_type_id
data.goal_id = this.classBj_id
this.getSubTypes(data)
}
},
getSubTypes(id) {
crudClassstandard.getClassSuperior2(id).then(res => {
const date = res.content
this.buildClass(date)
this.classes = date
})
},
buildClass(classes) {
classes.forEach(data => {
if (data.children) {
this.buildClass(data.children)
}
if (data.hasChildren && !data.children) {
data.children = null
}
})
},
handleClose(done) {
this.$confirm('确认关闭?')
.then(_ => {
done()
})
.catch(_ => {
})
},
close() {
this.$emit('update:dialogShow', false)
},
loadClass({ action, parentNode, callback }) {
if (action === LOAD_CHILDREN_OPTIONS) {
crudClassstandard.getClass({ pid: parentNode.id }).then(res => {
parentNode.children = res.content.map(function(obj) {
if (obj.hasChildren) {
obj.children = null
}
return obj
})
setTimeout(() => {
callback()
}, 100)
})
}
},
queryClassId() {
const param = {
'class_idStr': this.class_idStr
}
crudClassstandard.queryClassById(param).then(res => {
this.classes = res.content.map(obj => {
if (obj.hasChildren) {
obj.children = null
}
return obj
})
})
},
putMaterial() {
this.materDialog = true
},
tableChanged2(row) {
const arr = row
const data = this.form.tableData
arr.forEach((item) => {
if (this.form.tableData.length !== 0) {
this.fla = false
for (let i = 0; i < data.length; i++) {
if (data[i].material_id === item.material_id) {
this.fla = true
}
}
if (this.fla === false) {
this.form.tableData.push(item)
}
} else {
this.form.tableData.push(item)
}
})
},
delRow(index, rows) {
rows.splice(index, 1)
}
}
}
</script>
<style>
.crud-opts2 {
padding: 0;
display: -webkit-flex;
display: flex;
align-items: center;
}
.crud-opts2 .el-dialog__title2 {
line-height: 24px;
font-size:20px;
color:#303133;
}
.crud-opts2 .role-span {
padding: 10px 0px 10px 0px;
}
.crud-opts2 .crud-opts-form {
padding: 10px 0px 0px 20px;
}
.input-with-select {
background-color: #fff;
}
</style>
<style rel="stylesheet/scss" lang="scss" scoped>
::v-deep {
.vue-treeselect__menu {
overflow-x: auto !important;
width: 300px;
max-height: 300px !important;
}
.vue-treeselect__label {
overflow: unset;
text-overflow: unset;
}
.vue-treeselect__control {
height: 20px !important;
}
.vue-treeselect__multi-value-item-container,
.vue-treeselect--has-value .vue-treeselect__multi-value {
height: 30px;
line-height: 24px;
padding: 0;
}
.vue-treeselect__limit-tip,
.vue-treeselect--searchable.vue-treeselect--multi.vue-treeselect--has-value
.vue-treeselect__input-container {
padding-top: 0;
}
.vue-treeselect--has-value .vue-treeselect__multi-value {
// margin-bottom: 15px;
}
.vue-treeselect__placeholder,
.vue-treeselect__single-value {
height: 28px;
line-height: 32px;
font-size: small;
color: "#CCCFD6";
}
.vue-treeselect--has-value .vue-treeselect__input {
height: 18px !important;
line-height: 18px !important;
}
.vue-treeselect div,
.vue-treeselect span {
box-sizing: content-box;
}
// 选中后的溢出隐藏
.vue-treeselect__multi-value-label {
display: block;
width: 140px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.vue-treeselect__value-container {
display: block;
height: 32px;
}
}
</style>