update 工段设备关联

This commit is contained in:
g7hoo 2022-08-30 10:29:56 +08:00
parent e690c90d74
commit 1e78bbf6ee
4 changed files with 318 additions and 74 deletions

View File

@ -2,8 +2,9 @@
"singleQuote": true,
"tabWidth": 2,
"bracketSameLine": true,
"jsxBracketSameLine": true,
"embeddedLanguageFormatting": "auto",
"printWidth": 180,
"printWidth": 80,
"quoteProps": "consistent",
"trailingComma": "none",
"semi": false,

View File

@ -92,8 +92,6 @@ export default {
getProductLine() {
this.$http.get(this.$http.adornUrl('/monitoring/productionLine/list')).then(({ data: res }) => {
if (res && res.code === 0) {
// this.plList = res.data
console.log('res', res)
this.addOrUpdateConfigs.fields.forEach(item => {
if (item.name === 'productionLineId') item.options = res.data.map(item => ({ label: item.name, value: item.id }))
})

View File

@ -1,55 +1,108 @@
<template>
<el-dialog class="super-flexible-dialog" :title="isDetail ? '详情' : !dataForm.id ? '新增' : '编辑'" :visible.sync="visible" @close="handleClose">
<el-dialog
class="super-flexible-dialog"
:title="isDetail ? '详情' : !dataForm.id ? '新增' : '编辑'"
:visible.sync="visible"
>
<div style="max-height: 60vh; overflow-y: scroll; overflow-x: hidden;">
<el-form ref="dataForm" :model="dataForm" :rules="dataFormRules">
<el-row :gutter="20">
<el-col :span="12"
><el-form-item label="工段名称" prop="name"> <el-input v-model="dataForm.name" placeholder="请输入工段名称" /> </el-form-item
><el-form-item label="工段名称" prop="name">
<el-input
v-model="dataForm.name"
placeholder="请输入工段名称"
/> </el-form-item
></el-col>
<el-col :span="12"
><el-form-item label="工段编码" prop="code"> <el-input v-model="dataForm.code" placeholder="请输入工段编码" /> </el-form-item
><el-form-item label="工段编码" prop="code">
<el-input
v-model="dataForm.code"
placeholder="请输入工段编码"
/> </el-form-item
></el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12"
><el-form-item label="所属产线" prop="productionLineId">
<el-select v-model="dataForm.productionLineId" placeholder="请输入所属产线">
<el-option v-for="line in lineList" :key="line.id" :value="line.id" :label="line.name" />
<el-select
v-model="dataForm.productionLineId"
placeholder="请输入所属产线"
>
<el-option
v-for="line in lineList"
:key="line.id"
:value="line.id"
:label="line.name"
/>
</el-select> </el-form-item
></el-col>
<el-col :span="12"
><el-form-item label="描述" prop="description"> <el-input v-model="dataForm.description" placeholder="请输入描述" /> </el-form-item
><el-form-item label="描述" prop="description">
<el-input
v-model="dataForm.description"
placeholder="请输入描述"
/> </el-form-item
></el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12"
><el-form-item label="备注" prop="remark"> <el-input v-model="dataForm.remark" placeholder="请输入备注" /> </el-form-item
><el-form-item label="备注" prop="remark">
<el-input
v-model="dataForm.remark"
placeholder="请输入备注"
/> </el-form-item
></el-col>
</el-row>
</el-form>
<div class="table" v-if="dataForm.id && !showAttrForm">
<h3>设备绑定 <el-button type="text" @click="addEq">新增</el-button></h3>
<base-table :data="eqList" :table-head-configs="tableProps" :max-height="500" @operate-event="handleOperations" @refreshDataList="getDataList" />
<el-pagination
@size-change="sizeChangeHandle"
@current-change="currentChangeHandle"
:current-page="page"
:page-sizes="[5, 10, 15, 20]"
:page-size="limit"
:total="eqTotal"
layout="total, sizes, prev, pager, next, jumper"
<section class="attr-form-section" v-if="dataForm.id">
<h3>
设备绑定
<el-button type="text" v-if="!showAttrForm" @click="addEq"
>新增</el-button
>
</h3>
<div class="table" v-if="!showAttrForm">
<base-table
:data="eqList"
:table-head-configs="tableProps"
:max-height="500"
@operate-event="handleOperations"
@refreshDataList="getDataList"
/>
<el-pagination
@size-change="sizeChangeHandle"
@current-change="currentChangeHandle"
:current-page="page"
:page-sizes="[5, 10, 15, 20]"
:page-size="limit"
:total="eqTotal"
layout="total, sizes, prev, pager, next, jumper"
/>
</div>
<attr-form
v-else
ref="AttrFrom"
:workshop-section-id="dataForm.id"
@close-attr-form="showAttrForm = false"
@refresh-list="handleRefreshList"
/>
</div>
<attr-form v-if="showAttrForm" />
</section>
</div>
<span slot="footer" class="dialog-footer">
<el-button @click="handleClick({ name: 'cancel' })">返回</el-button>
<el-button v-if="dataForm.id" @click="handleClick({ name: 'update' })">更新</el-button>
<el-button v-else @click="handleClick({ name: 'save' })">保存</el-button>
<el-button
type="primary"
v-if="dataForm.id"
@click="handleClick({ name: 'update' })"
>更新</el-button
>
<el-button type="success" v-else @click="handleClick({ name: 'save' })"
>保存</el-button
>
</span>
</el-dialog>
</template>
@ -59,53 +112,19 @@ import BaseTable from '@/components/base-table'
import SmallTitle from '@/components/small-title'
import { pick } from 'lodash/object'
import TableOperateComponent from '@/components/base-table/components/operationComponent'
const AttrForm = {
name: 'AttrForm',
props: ['workshopSectionId'],
data() {
return {
dataForm: {
id: '',
equipmentId: null
}
}
},
methods: {
getEqList() {},
handleCancel() {},
handleSave() {}
},
template: `
<div class="" style="background: #eee; border-radius: 8px; padding: 8px;">
<el-row>
<el-form ref="dataForm">
<el-form-item :prop>
</el-form>
</el-row>
<el-row style="text-align: right">
<el-button size="small" @click="handleCancel">取消</el-button>
<el-button size="small" type="success" @click="handleSave">保存</el-button>
</el-row>
</div>
`,
render: function(h) {
var self = this
return h('div', { style: { background: '#eee', borderRadius: '8px', padding: '8px' } }, [
h('el-row', null,
h('el-form', { ref: 'dataForm' },
h('el-form-item', { props: { label: '设备名', prop: 'equipmentId' } },
h('el-input', { domProps: { value: self.dataForm.equipmentId } })
),
h('el-row', null, [])
])
}
}
import AttrForm from './workshopSectionDialogAttrForm.vue'
const tableProps = [
{ name: '设备名', prop: 'equipmentName' },
{ name: '排序', prop: 'sort' },
{ name: '操作', prop: 'operations', fixed: 'right', width: 180, subcomponent: TableOperateComponent, options: ['edit', 'delete'] }
{
name: '操作',
prop: 'operations',
fixed: 'right',
width: 180,
subcomponent: TableOperateComponent,
options: ['edit', 'delete']
}
]
export default {
@ -159,11 +178,19 @@ export default {
if (id) {
//
this.$http({
url: this.$http.adornUrl('/monitoring/workshopSection/' + this.dataForm.id),
url: this.$http.adornUrl(
'/monitoring/workshopSection/' + this.dataForm.id
),
method: 'get'
}).then(({ data: res }) => {
if (res.data) {
const { name, code, productionLineId, description, remark } = res.data
const {
name,
code,
productionLineId,
description,
remark
} = res.data
this.dataForm.name = name
this.dataForm.code = code
this.dataForm.productionLineId = productionLineId
@ -234,10 +261,85 @@ export default {
this.getDataList()
},
addEq() {
this.showAttrForm = true
this.handleAddOrUpdate()
},
handleOperations() {},
handleClose() {}
handleOperations({ type, data: id }) {
switch (type) {
case 'edit':
this.handleAddOrUpdate(id)
break
case 'delete':
this.handleDeleteEq(id)
break
}
},
handleDeleteEq(id) {
this.$confirm(`确定删除这条记录吗?`, '提示', {
// this.$confirm(` ${id} ?`, '', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.$http({
url: '/yd-monitor/monitoring/workshopSectionEquipment',
method: 'delete',
data: [id]
}).then(({ data }) => {
if (data && data.code === 0) {
this.$message({
message: '操作成功',
type: 'success',
duration: 1500,
onClose: () => {
this.getDataList()
}
})
} else {
this.$message.error(data.msg)
}
})
})
},
handleRefreshList() {
this.getDataList()
this.showAttrForm = false
},
handleAddOrUpdate(id) {
this.showAttrForm = true
if (id) {
this.$nextTick(() => {
this.$refs.AttrFrom.setInitialId(id)
})
}
},
handleClick({ name }) {
switch (name) {
case 'cancel':
this.visible = false
break
case 'update':
case 'save':
this.handleCreateOrUpdate()
break
}
},
handleCreateOrUpdate() {
this.$http({
url: '/yd-monitor/monitoring/workshopSection',
method: this.dataForm.id ? 'put' : 'post',
data: {
...this.dataForm
}
}).then(({ data: res }) => {
this.$message.success({
message: '操作成功',
onClose: () => {
this.$emit('refreshDataList')
this.visible = false
}
})
})
}
}
}
</script>

View File

@ -0,0 +1,143 @@
<template>
<div class="" style="background: #eee; border-radius: 8px; padding: 24px;">
<el-row>
<el-form ref="dataForm" :model="dataForm" :rules="dataFormRules">
<el-row :gutter="20">
<el-col :span="12">
<el-form-item
:label="edit ? '已绑定的设备' : '选择一个设备进行绑定'"
prop="equipmentId"
>
<el-select v-if="!edit" clearable v-model="dataForm.equipmentId">
<el-option
v-for="eq in eqList"
:key="eq.id"
:label="eq.name"
:value="eq.id"
/>
</el-select>
<el-input
v-else
disabled
v-model="bindedEquipmentName"
/> </el-form-item
></el-col>
<el-col :span="12">
<el-form-item label="排序" prop="sort">
<el-input
v-model="dataForm.sort"
placeholder="请输入工段中设备的顺序"
clearable
/> </el-form-item
></el-col>
</el-row>
</el-form>
</el-row>
<el-row style="text-align: right">
<el-button size="small" @click="handleCancel">取消</el-button>
<el-button size="small" type="success" @click="handleSave">{{
edit ? '修改' : '绑定'
}}</el-button>
</el-row>
</div>
</template>
<script>
export default {
name: 'AttrForm',
props: {
workshopSectionId: {
type: String,
required: true
}
},
data() {
return {
edit: false,
bindedEquipmentName: '',
dataForm: {
id: null,
sort: null,
equipmentId: null
},
dataFormRules: {
sort: [
{
type: 'integer',
message: '请输入整数',
transform: val => Number(val),
trigger: 'blur'
}
]
},
eqList: []
}
},
mounted() {
this.edit = false
this.bindedEquipmentName = ''
this.getEqList()
},
methods: {
setInitialId(id) {
this.edit = true
//
this.$http({
url: '/yd-monitor/monitoring/workshopSectionEquipment/' + id,
method: 'get'
}).then(({ data: res }) => {
if (res.data) {
const { id, equipmentId, equipmentName, sort } = res.data
this.dataForm = { id, equipmentId, sort }
this.bindedEquipmentName = equipmentName
} else {
this.dataForm = { id: null, equipmentId: null, sort: null }
this.bindedEquipmentName = ''
}
})
},
getEqList() {
this.$http({
url: this.$http.adornUrl('/monitoring/equipment/noBindEqu'),
method: 'get'
}).then(({ data: res }) => {
if (res.data) {
this.eqList = res.data.map(item => ({ id: item.id, name: item.name }))
} else {
this.eqList.splice(0)
}
})
},
handleCancel() {
this.eqList.splice(0)
this.dataForm = {
id: null,
sort: null,
equipmentId: null
}
this.$emit('close-attr-form')
},
handleSave() {
this.$http({
url: '/yd-monitor/monitoring/workshopSectionEquipment',
method: this.edit ? 'put' : 'post',
data: {
...this.dataForm,
workshopSectionId: this.workshopSectionId
}
}).then(({ data: res }) => {
if (res.data) {
this.$message.success({
message: '操作成功',
duration: 1500,
onClose: () => {
this.$emit('refresh-list')
this.handleCancel()
}
})
}
})
}
}
}
</script>