Files
11-mes-new/src/views/material-manage/bom/components/add-panel.vue
2022-11-07 14:54:47 +08:00

379 lines
9.8 KiB
Vue

<!--
@Author:
@Date:
@LastEditors: lb
@LastEditTime: 2022-6-6 13:00:00
@Description: 物料管理 - BOM - BOM编辑新增详情页面
-->
<template>
<el-drawer :visible.sync="visible" :show-close="false" :wrapper-closable="false" class="drawer" size="60%">
<small-title slot="title" :no-padding="true">
BOM {{ isdetail ? 'btn.detail' : isedit ? 'btn.edit' : 'btn.add' | i18nFilter }}
</small-title>
<div class="content">
<div class="visual-part">
<!-- form -->
<el-form ref="dataForm" :model="dataForm" :rules="dataFormRules" label-position="top" label-width="100px">
<el-row :gutter="20">
<!-- 物料BOM编码 -->
<el-col :span="8">
<el-form-item :label="$t('module.materialManager.materialbom.bomcode_long')" prop="code">
<el-input
v-model="dataForm.code"
:disabled="isdetail"
:placeholder="$i18nForm(['placeholder.input', $t('module.materialManager.materialbom.bomcode_long')])"
/>
</el-form-item>
</el-col>
<!-- 物料BOM名称 -->
<el-col :span="8">
<el-form-item :label="$t('module.materialManager.materialbom.name_long')" prop="name">
<el-input
v-model="dataForm.name"
:disabled="isdetail"
:placeholder="$i18nForm(['placeholder.input', $t('module.materialManager.materialbom.name_long')])"
/>
</el-form-item>
</el-col>
<!-- 备注 -->
<el-col :span="8">
<el-form-item :label="$t('module.materialManager.materialbom.remark')" prop="remark">
<el-input
v-model="dataForm.remark"
:disabled="isdetail"
:placeholder="$i18nForm(['placeholder.input', $t('module.materialManager.materialbom.remark')])"
/>
</el-form-item>
</el-col>
</el-row>
</el-form>
<template v-if="isedit || isdetail">
<small-title style="padding-left: 8px;">
{{ $t('module.materialManager.materialbom.subtitle') }}
</small-title>
<div class="attr-list">
<base-table
:top-btn-config="!isdetail ? topBtnConfig : []"
:page="listQuery.current"
:limit="listQuery.size"
:table-config="tableProps"
:table-data="dataList"
:is-loading="listLoading"
@clickTopBtn="clickTopBtn"
>
<method-btn
v-if="!isdetail"
slot="handleBtn"
:width="trueWidth"
:method-list="tableBtn"
@clickBtn="handleClick"
/>
</base-table>
<pagination
v-show="total > 0"
:total="total"
:page.sync="listQuery.current"
:limit.sync="listQuery.size"
@pagination="getList()"
/>
</div>
</template>
</div>
<bom-detail-add v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getList" />
<div style="position: absolute; bottom: 24px; right: 24px;">
<el-button @click="close">{{ 'btn.cancel' | i18nFilter }}</el-button>
<el-button type="primary" @click="confirm">{{ 'btn.confirm' | i18nFilter }}</el-button>
</div>
</div>
</el-drawer>
</template>
<script>
import SmallTitle from '@/components/BaseDrawer/components/SmallTitle.vue'
import BaseTable from '@/components/BaseTable'
import { add, getInfo, update, getCode } from '@/api/material-manage/bom.js'
import { list as getBomDetailList, del } from '@/api/material-manage/bom-list.js'
import MethodBtn from '@/components/BaseTable/subcomponents/MethodBtn'
// import BomList from '@/views/material-manage/bom/bom-list'
import i18n from '@/lang'
import Pagination from '@/components/Pagination'
import { refineData } from '@/utils/helpers'
import { timeFormatter } from '@/filters'
import newBasicData from '@/filters/newBasicData'
import BomDetailAdd from './add-dialog.vue'
const topBtnConfig = [
{
type: 'add',
btnName: 'btn.add'
}
]
const tableBtn = [
{
type: 'edit',
btnName: 'btn.edit'
},
{
type: 'delete',
btnName: 'btn.delete'
}
]
const tableProps = [
{
prop: 'createTime',
label: i18n.t('module.materialManager.materialbom.createTime'),
width: 180,
filter: timeFormatter
},
{
prop: 'name',
label: i18n.t('module.materialManager.materialbom.detailname')
},
{
prop: 'code',
label: i18n.t('module.materialManager.materialbom.code'),
width: 200
},
{
prop: 'unit',
label: i18n.t('module.materialManager.materialbom.unit2'),
filter: newBasicData('1')
},
{
prop: 'quantity',
label: i18n.t('module.materialManager.materialbom.quantity')
},
{
prop: 'remark',
label: i18n.t('module.materialManager.materialbom.remark')
}
]
export default {
name: 'BomAddDrawer',
components: {
SmallTitle,
BaseTable,
Pagination,
MethodBtn,
BomDetailAdd
},
props: {},
data() {
return {
listLoading: false,
addOrUpdateVisible: false,
visible: false,
isdetail: false,
isedit: false,
tableProps,
tableBtn,
topBtnConfig,
trueWidth: 80,
dataForm: {
id: null, // 主键,更新时需要填写,示例值(1)
name: '',
code: '', // 编码
remark: '' // 备注
},
dataList: [],
dataFormRules: {
name: [
{
required: true,
message: i18n.t('module.materialManager.materialbom.placeholderbomName'),
trigger: 'change'
}
],
code: [
{
required: true,
message: i18n.t('module.materialManager.materialbom.placeholderbomcode'),
trigger: 'change'
}
]
},
listQuery: {
current: 1,
size: 10
},
total: 0
}
},
methods: {
initDataForm() {
this.dataForm = {
id: null,
name: '',
code: '',
remark: ''
}
},
init(data, isdetail) {
this.initDataForm()
this.dataList = []
this.listQuery = {
current: 1,
size: 10
}
this.isdetail = isdetail || false
this.isedit = false
this.$nextTick(() => {
this.$refs.dataForm.clearValidate()
if (data) {
this.isedit = true
this.dataForm.id = data.id
getInfo({ id: this.dataForm.id })
.then(res => {
this.dataForm = refineData(res.data, ['id', 'name', 'code', 'remark'])
})
.then(() => {
this.getList()
})
} else {
getCode().then(res => {
this.dataForm.code = res.data
})
}
})
this.visible = true
},
fetchList(type) {
switch (type) {
case 'bom-list':
return getBomDetailList({ ...this.listQuery, bomId: this.dataForm.id })
}
},
handleClick(raw) {
if (raw.type === 'delete') {
this.$confirm(
`${this.$t('module.basicData.visual.TipsBefore')}[${raw.data.name}]?`,
this.$t('module.basicData.visual.Tips'),
{
confirmButtonText: this.$t('module.basicData.visual.confirmButtonText'),
cancelButtonText: this.$t('module.basicData.visual.cancelButtonText'),
type: 'warning'
}
)
.then(() => {
del({ id: raw.data.id }).then(response => {
this.$message({
message: this.$t('module.basicData.visual.success'),
type: 'success',
duration: 1500,
onClose: () => {
this.listQuery.current = 1
this.getList()
}
})
})
})
.catch(() => {})
} else if (raw.type === 'edit') {
this.addNew(raw.data, false)
}
},
getList() {
this.fetchList('bom-list').then(res => {
if (res.data.records) {
this.dataList = res.data.records
} else {
this.dataList.splice(0)
}
this.total = res.data.total
})
},
close() {
this.visible = false
},
confirm() {
this.$refs.dataForm.validate(valid => {
if (valid) {
const ajaxAction = this.isedit ? update : add
ajaxAction(this.dataForm).then(res => {
this.$message({
type: 'success',
message: this.$t('module.materialManager.materialbom.successMessage'),
duration: 1500,
onClose: () => {
this.$emit('refreshDataList')
this.close()
}
})
})
}
})
},
addNew(data) {
this.addOrUpdateVisible = true
this.$nextTick(() => {
this.$refs.addOrUpdate.init({ ...data, bomId: this.dataForm.id })
})
},
clickTopBtn(val) {
if (val === 'add') {
this.addNew()
}
}
}
}
</script>
<style scoped>
.drawer >>> .el-drawer {
border-radius: 8px 0 0 8px;
}
.drawer >>> .el-form-item__label {
padding: 0;
}
.drawer >>> .el-drawer__header {
margin: 0;
padding: 32px 32px 24px;
border-bottom: 1px solid #dcdfe6;
margin-bottom: 30px;
}
.drawer >>> .content {
padding: 0 24px 30px;
display: flex;
flex-direction: column;
height: 100%;
}
.drawer >>> .visual-part {
flex: 1 auto;
max-height: 76vh;
overflow: hidden;
overflow-y: scroll;
padding-right: 10px; /* 调整滚动条样式 */
}
.drawer >>> .el-form,
.drawer >>> .attr-list {
padding: 0 16px;
}
</style>