<template>
|
<a-spin :spinning='confirmLoading'>
|
<!-- 主表单区域 -->
|
<a-form-model ref='form' :model='model' :rules='validatorRules'>
|
<a-row>
|
<a-col :span='12'>
|
<a-form-model-item label='统一编码' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='num'>
|
<a-input v-model='model.num' placeholder='系统自动生成' :disabled = "true"></a-input>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span='12'>
|
<a-form-model-item label='设备名称' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='name'>
|
<a-input v-model='model.name' placeholder='系统自动生成' :disabled = "true"></a-input>
|
</a-form-model-item>
|
</a-col>
|
</a-row>
|
<a-row>
|
<a-col :span='12'>
|
<a-form-model-item label='规格' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='specification'>
|
<a-input v-model='model.specification' placeholder='系统自动生成' :disabled = "true"></a-input>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span='12'>
|
<a-form-model-item label='型号' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='model'>
|
<a-input v-model='model.model' placeholder='系统自动生成' :disabled = "true"></a-input>
|
</a-form-model-item>
|
</a-col>
|
</a-row>
|
</a-form-model>
|
|
<!-- 子表单区域 -->
|
<a-tabs v-model='activeKey' @change='handleChangeTabs'>
|
<a-tab-pane tab='备件' :key='refKeys[0]' :forceRender='true'>
|
<j-vxe-table
|
keep-source
|
:ref='refKeys[0]'
|
highlight-current-row
|
:loading='sparePartsVxeTable.loading'
|
:columns='sparePartsVxeTable.columns'
|
:dataSource='sparePartsVxeTable.dataSource'
|
:maxHeight='300'
|
:disabled='formDisabled'
|
:rowNumber='true'
|
:rowSelection='true'
|
@pageChange='handleTable1PageChange'
|
:pagination='sparePartsVxeTable.pagination'
|
:toolbar='true'
|
:toolbarConfig='toolbarConfig'
|
>
|
|
<template slot='toolbarPrefix'>
|
<a-button type='primary' @click='equipmentSparesSelect' :disabled="formDisabled">选择备件
|
</a-button>
|
</template>
|
</j-vxe-table>
|
</a-tab-pane>
|
</a-tabs>
|
<spare-parts-list @selectionRows='selectionRows' ref='SparePartsSelectModal' :categories="model.toolingCategoryFlag"></spare-parts-list>
|
</a-spin>
|
</template>
|
<script>
|
import { JVxeTableModelMixin } from '@/mixins/JVxeTableModelMixin.js'
|
import { JVXETypes } from '@/components/jeecg/JVxeTable'
|
import { getRefPromise, VALIDATE_FAILED } from '@/components/jeecg/JVxeTable/utils/vxeUtils.js'
|
import JFormContainer from '@/components/jeecg/JFormContainer'
|
import { getAction } from '@api/manage'
|
import { filterObj } from '@/utils/util'
|
import SparePartsList from '../serach/SparePartsList'
|
export default {
|
name: 'EquipmentSparePartsForm',
|
mixins: [JVxeTableModelMixin],
|
components: {
|
JFormContainer,
|
SparePartsList
|
},
|
data() {
|
return {
|
type: '',
|
disableSubmit: false,
|
documentTypeStr: '',
|
dataList: [],
|
detailList: [],
|
isShow: true,
|
company: '',
|
queryParam: {},
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 5 }
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 16 }
|
},
|
toolbarConfig: {
|
// prefix 前缀;suffix 后缀
|
slot: ['prefix', 'suffix'],
|
// add 新增按钮;remove 删除按钮;clearSelection 清空选择按钮
|
btn: ['remove', 'clearSelection']
|
},
|
model: {},
|
// 新增时子表默认添加几行空数据
|
addDefaultRowNum: 0,
|
validatorRules: {
|
},
|
refKeys: ['sparePartsCowsVagina'],
|
tableKeys: ['sparePartsCowsVagina'],
|
activeKey: 'sparePartsCowsVagina',
|
sparePartsVxeTable: {
|
loading: false,
|
pagination: { current: 1, pageSize: 1000, pageSizeOptions: ['1000', '2000'], total: 0 },
|
dataSource: [],
|
columns: [
|
{
|
title: '备件编码',
|
key: 'num',
|
type: JVXETypes.normal,
|
width: '200px',
|
align: 'center',
|
placeholder: '请输入${title}',
|
},
|
{
|
title: '备件名称',
|
key: 'name',
|
type: JVXETypes.normal,
|
width: '200px',
|
align: 'center',
|
placeholder: '请输入${title}',
|
},
|
{
|
title: '规格',
|
key: 'specification',
|
type: JVXETypes.normal,
|
width: '200px',
|
align: 'center',
|
},
|
{
|
title: '型号',
|
key: 'model',
|
align: 'center',
|
type: JVXETypes.normal,
|
width: '150px',
|
},
|
{
|
title: '单位',
|
key: 'unitName',
|
align: 'center',
|
type: JVXETypes.normal,
|
width: '150px',
|
},
|
]
|
},
|
result: Array,
|
url: {
|
list: '/tooling/toolingStockTaking/getToolingList',
|
add: '/tooling/toolingStockTaking/add',
|
edit: '/eam/equipmentSpares/editByEquipment',
|
queryById: '/tooling/toolingStockTaking/queryById',
|
sparePartsCowsVagina: {
|
list: '/eam/equipmentSpares/myList'
|
}
|
}
|
}
|
},
|
props: {
|
//表单禁用
|
disabled: {
|
type: Boolean,
|
default: false,
|
required: false
|
}
|
},
|
computed: {
|
formDisabled() {
|
return this.disabled
|
}
|
},
|
|
methods: {
|
selectionRows(data) {
|
// 增加选中的设备到列表中
|
|
this.addSelectedEquipments(data)
|
},
|
changeBtn() {
|
|
this.addSelectedEquipments(this.dataList)
|
},
|
|
|
getData() {
|
// 封装查询条件
|
let params = {
|
pageNo: this.sparePartsVxeTable.pagination.current,
|
pageSize: this.sparePartsVxeTable.pagination.pageSize,
|
id: this.model.id
|
}
|
// 调用查询数据接口
|
this.sparePartsVxeTable.loading = true
|
this.requestSubTableData(this.url.sparePartsCowsVagina.list, params, this.sparePartsVxeTable)
|
},
|
handleTable1PageChange(event) {
|
// 重新赋值
|
this.sparePartsVxeTable.pagination.current = event.current
|
this.sparePartsVxeTable.pagination.pageSize = event.pageSize
|
// 查询数据
|
this.getData()
|
},
|
|
//选择设备
|
equipmentSparesSelect() {
|
let ids = []
|
let tableData = this.$refs.sparePartsCowsVagina.getTableData()
|
let deleteData = this.$refs.sparePartsCowsVagina.getDeleteData()
|
for (let i = 0; i < tableData.length; i++) {
|
ids.push(tableData[i].sparePartId)
|
}
|
this.$refs.SparePartsSelectModal.showModals(ids)
|
this.$refs.SparePartsSelectModal.title = '选择备件'
|
this.$refs.SparePartsSelectModal.disableSubmit = false
|
},
|
addSelectedEquipments(data) {
|
let tableData = this.$refs.sparePartsCowsVagina.getTableData()
|
var tableStr = JSON.stringify(tableData)
|
const addRows = []
|
console.log(data)
|
console.log(tableStr)
|
|
for (let i = 0; i < data.length; i++) {
|
var sparePartsCowsVagina = {}
|
if (tableStr.indexOf(data[i].id) == -1) {
|
sparePartsCowsVagina = {
|
sparePartId:data[i].id,
|
num : data[i].num,
|
name: data[i].name,
|
model: data[i].model,
|
specification: data[i].specification,
|
unitId:data[i].mainUnitId,
|
unitName: data[i].mainUnitId_dictText,
|
delFlag: 0
|
}
|
}
|
addRows.push(sparePartsCowsVagina)
|
}
|
this.$refs.sparePartsCowsVagina.pushRows(addRows)
|
},
|
|
|
addBefore() {
|
this.sparePartsVxeTable.dataSource = []
|
},
|
getAllTable() {
|
let values = this.tableKeys.map(key => getRefPromise(this, key))
|
return Promise.all(values)
|
},
|
/** 调用完edit()方法之后会自动调用此方法 */
|
editAfter() {
|
this.$nextTick(() => {
|
})
|
// 加载子表数据
|
if (this.model.id) {
|
let params = {
|
pageNo: this.sparePartsVxeTable.pagination.current,
|
pageSize: this.sparePartsVxeTable.pagination.pageSize,
|
id: this.model.id
|
}
|
this.requestSubTableData(this.url.sparePartsCowsVagina.list, params, this.sparePartsVxeTable)
|
|
}
|
},
|
//校验所有一对一子表表单
|
validateSubForm(allValues) {
|
return new Promise((resolve, reject) => {
|
Promise.all([]).then(() => {
|
resolve(allValues)
|
}).catch(e => {
|
if (e.error === VALIDATE_FAILED) {
|
// 如果有未通过表单验证的子表,就自动跳转到它所在的tab
|
this.activeKey = e.index == null ? this.activeKey : this.refKeys[e.index]
|
} else {
|
console.error(e)
|
}
|
})
|
})
|
},
|
/** 整理成formData */
|
classifyIntoFormData(allValues) {
|
let main = Object.assign(this.model, allValues.formValue)
|
return {
|
...main, // 展开
|
equipmentSparesList: allValues.tablesValue[0].tableData
|
}
|
},
|
|
validateError(msg) {
|
this.$message.error(msg)
|
},
|
requestSubTableData(url, params, tab, success) {
|
tab.loading = true
|
getAction(url, params).then(res => {
|
let { result } = res
|
let dataSource = []
|
if (result) {
|
if (Array.isArray(result)) {
|
dataSource = result
|
} else if (Array.isArray(result.records)) {
|
dataSource = result.records
|
}
|
}
|
tab.dataSource = dataSource
|
if (res.result.total) {
|
this.sparePartsVxeTable.pagination.total = res.result.total
|
} else {
|
this.sparePartsVxeTable.pagination.total = 0
|
}
|
typeof success === 'function' ? success(res) : ''
|
}).finally(() => {
|
tab.loading = false
|
})
|
},
|
cleanData(){
|
this.$refs.sparePartsCowsVagina.remove();
|
}
|
|
}
|
}
|
</script>
|
|
<style scoped>
|
</style>
|