<template>
|
<el-dialog :title="titleMap[mode]" v-model="visible" :width="800" destroy-on-close @closed="$emit('closed')">
|
<el-form v-if="visible" :model="form" :rules="rules" :disabled="mode == 'show'" ref="dialogForm"
|
label-width="120px" label-position="center">
|
<el-row>
|
<el-col :span="24" style="padding:12px 0;">
|
基础信息
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="工位编号" prop="code">
|
<el-input style="width: 240px" :disabled="!!form.id" v-model="form.code" placeholder="工位编号"
|
clearable></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="工位名称" prop="name">
|
<el-input style="width: 240px" v-model="form.name" placeholder="工位名称" clearable></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="工位类型" prop="type">
|
<el-select v-model="form.type" style="width: 240px" :disabled="!!form.id">
|
<el-option v-for="item in options.types" :key="item.value" :label="item.label"
|
:value="item.value" />
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="所属工位组" prop="groupName">
|
<el-tree-select @node-click="nodeClick" v-model="form.groupName" :data="options.group"
|
:check-on-click-node="true" style="width: 240px" />
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="状态" prop="status">
|
<el-switch v-model="form.status" :active-value="1" :inactive-value="0" />
|
</el-form-item>
|
</el-col>
|
<el-col :span="24">
|
<el-form-item label="工位图片" prop="avatar">
|
<scUpload v-model="form.avatar" title="工位图片"></scUpload>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12" v-show="!form.id">
|
<el-form-item label="生产日历" prop="calendarCode">
|
<el-select v-model="form.calendarCode" style="width: 240px">
|
<el-option v-for="item in options.calendarList" :key="item.id" :label="item.name"
|
:value="item.code" />
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<!-- 修改的次日生效 -->
|
<el-col :span="11" v-show="form.id">
|
<el-form-item label="生产日历" prop="calendarCode">
|
<el-select v-model="form.calendarCodeWaiting" style="width: 240px">
|
<el-option v-for="item in options.calendarList" :key="item.id" :label="item.name"
|
:value="item.code" />
|
</el-select>
|
</el-form-item>
|
|
</el-col>
|
<el-col :span="1" v-show="form.id">
|
<div style="display: flex;align-items: center;height: 32px;margin-bottom: 18px;">
|
<el-tooltip class="box-item" effect="dark" content="修改后的日历次日生效" placement="top-start">
|
<el-icon>
|
<el-icon-warning-filled style="vertical-align: middle" />
|
</el-icon>
|
</el-tooltip>
|
</div>
|
|
</el-col>
|
<el-col :span="24" style="padding:12px 0;" v-if="form.type == 0">
|
机器信息
|
</el-col>
|
<el-col :span="12" v-if="form.type == 0 && !form.id">
|
<el-form-item label="选择机器" prop="linkWay">
|
<el-radio-group v-model="form.linkWay">
|
<el-radio v-for="item in options.linkWays" :key="item.value" :label="item.value">{{
|
item.label }}</el-radio>
|
</el-radio-group>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12" v-if="(form.type == 0 && form.linkWay == 0) || form.id">
|
<!-- machineCode -->
|
<el-form-item label="机器编号" prop="machineId">
|
<!-- <el-input style="width: 240px" v-model="form.machineId" placeholder="机器编号" clearable></el-input> -->
|
<el-select v-if="!form.id" v-model="form.machineId" style="width: 240px" @change="change" clear
|
filterable>
|
<el-option v-for="item in options.listnoband" :key="item.id" :label="item.machineName"
|
:value="item.id">
|
{{ `${item?.machineCode}-${item?.machineName}${item?.brand ? '-' + item.brand : ''}`
|
}}</el-option>
|
</el-select>
|
<el-input v-if="form.id" :disabled="form.id" v-model="form.machineName"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="24" style="padding:12px 0;">
|
扩展信息
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="工种" prop="deviceType">
|
<el-select v-model="form.deviceType" style="width: 240px">
|
<el-option v-for="item in options.work_type" :key="item.dictKey" :label="item.dictValue"
|
:value="item.dictKey - 0" />
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="加工属性" prop="properties">
|
<el-select v-model="form.properties" style="width: 240px">
|
<el-option v-for="item in options.machining_type" :key="item.dictKey"
|
:label="item.dictValue" :value="item.dictKey - 0" />
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<!-- <el-col :span="12">
|
<el-form-item label="程序传输方式" prop="transmissionMethod">
|
<el-select v-model="form.transmissionMethod" style="width: 240px">
|
<el-option label="FTP" :value="1" />
|
<el-option label="串口" :value="2" />
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="FTP目录" prop="ftpDirectoryType">
|
<el-select v-model="form.ftpDirectoryType" style="width: 240px">
|
<el-option v-for="item in options.ftpDirectoryType" :key="item.value" :label="item.label"
|
:value="item.value" />
|
</el-select>
|
</el-form-item>
|
</el-col> -->
|
<el-col :span="12" v-if="form.ftpDirectoryType == 1">
|
<el-form-item label="关联目录" prop="directoryId">
|
<el-select v-model="form.directoryId" style="width: 240px">
|
<el-option v-for="item in options.directorys" :key="item.id" :label="item.name"
|
:value="item.id" />
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<!-- <el-col :span="4">
|
<span>工作台</span>
|
|
</el-col>
|
<el-col style="margin-bottom: 14px;">
|
<ul class="workbranch">
|
<li v-for="item in form.workbenchVOList">
|
<span>{{ item.sort }}</span>
|
<el-input v-model="item.name" style="width: 200px"></el-input>
|
</li>
|
</ul>
|
<el-button style="margin-left: 50px;margin-top: 8px" @click="addWork">添加工作台</el-button>
|
</el-col> -->
|
<el-col :span="12">
|
<el-form-item label="所属部门" prop="createDept">
|
<el-tree-select :props="{
|
label: 'title',
|
id: 'id',
|
}" clearable @node-click="nodeClickTree" v-model="form.createDept" :data="tree"
|
:check-on-click-node="true" style="width: 240px">
|
<!-- <template #default="{ data: { title } }">
|
{{ title }}</template> -->
|
</el-tree-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-form>
|
<template #footer>
|
<el-button @click="visible = false">取 消</el-button>
|
<el-button v-if="mode != 'show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
|
</template>
|
</el-dialog>
|
</template>
|
|
<script>
|
import deepmerge from 'deepmerge'
|
import http from "@/utils/request"
|
export default {
|
emits: ['success', 'closed'],
|
props: {
|
option: {
|
type: Object
|
}
|
},
|
computed: {
|
options() {
|
let group = deepmerge([], this.option.group)
|
group[0].disabled = true
|
return {
|
...this.option,
|
group,
|
calendarList: this.calendarList,
|
linkWays: this.linkWays,
|
work_type: this.work_type,
|
machining_type: this.machining_type,
|
listnoband: this.listnoband,
|
directorys: this.directorys,
|
ftpDirectoryType: this.ftpDirectoryType
|
}
|
}
|
},
|
data() {
|
return {
|
mode: "add",
|
titleMap: {
|
add: '新建工位',
|
edit: '编辑工位',
|
// show: '查看'
|
},
|
params: {},
|
visible: false,
|
isSaveing: false,
|
//表单数据
|
form: {
|
id: '',
|
code: '',
|
name: '',
|
type: '',
|
groupName: '',
|
status: '',
|
avatar: '',
|
calendarCode: '',
|
calendarCodeWaiting: '',
|
linkWay: '',
|
machineId: '',
|
machineCode: '',
|
machineName: '',
|
deviceType: '',
|
properties: '',
|
transmissionMethod: '',
|
ftpDirectoryType: '',
|
workbenchVOList: [],
|
createDept: '',
|
},
|
//验证规则
|
rules: {
|
code: [
|
{ required: true, message: '必填' }
|
],
|
name: [
|
{ required: true, message: '必填' }
|
],
|
type: [
|
{ required: true, message: '必填' }
|
],
|
groupName: [
|
{ required: true, message: '必填' }
|
],
|
status: [
|
{ required: true, message: '必填' }
|
],
|
linkWay: [
|
{ required: true, message: '必填' }
|
],
|
machineId: [
|
{ required: true, message: '必填' }
|
],
|
directoryId: [
|
{ required: true, message: '必填' }
|
],
|
},
|
//所需数据选项
|
calendarList: [],
|
work_type: [],
|
machining_type: [],
|
listnoband: [],
|
directorys: [],
|
ftpDirectoryType: [
|
{
|
label: '不关联目录',
|
value: 0
|
},
|
{
|
label: '关联目录',
|
value: 1
|
},
|
{
|
label: '创建同名目录',
|
value: 2
|
},
|
],
|
linkWays: [
|
{
|
label: '关联机器',
|
value: 0
|
}, {
|
label: '创建同名机器',
|
value: 1
|
}
|
],
|
tree: []
|
}
|
},
|
created() {
|
this.$API.workstation.calendarList.get().then(res => {
|
this.calendarList = res.data
|
})
|
this.$API.system.dic.getDic.get({ code: 'work_type' }).then(res => {
|
this.work_type = res.data
|
})
|
this.$API.system.dic.getDic.get({ code: 'machining_type' }).then(res => {
|
this.machining_type = res.data
|
})
|
this.$API.workstation.getlistnoband.get().then(res => {
|
this.listnoband = res.data
|
})
|
this.$HTTP.get(`/api/blade-system/data-scope-manager/tree`).then(res => {
|
this.tree = res.data.map(item => {
|
return {
|
...item,
|
label: item.title
|
}
|
})
|
})
|
},
|
methods: {
|
//显示
|
open(mode = 'add', params) {
|
this.isSaveing = false;
|
this.mode = mode;
|
this.visible = true;
|
console.log('---------', params)
|
if (params) {
|
Object.keys(this.form).forEach(key => {
|
this.form[key] = params[key]
|
})
|
|
this.$HTTP.get(`/api/smis/workstation/get?workstationId=${params.id}`).then(res => {
|
this.form = res?.data
|
if (this.form.calendarCode && !this.form.calendarCodeWaiting) this.form.calendarCodeWaiting = this.form.calendarCode
|
this.$HTTP.get(`/api/smis/workstation-workbench/listWorkbench?workstationId=${params.id}`).then(res => {
|
this.form.workbenchVOList = res?.data?.workstationList || []
|
})
|
})
|
} else {
|
this.form.id = ''
|
this.form.workbenchVOList = []
|
Object.keys(this.form).forEach(key => {
|
this.form[key] = ''
|
})
|
}
|
return this
|
},
|
//表单提交方法
|
submit() {
|
if (!this.form.workbenchVOList) {
|
this.form.workbenchVOList = []
|
}
|
if (this.mode === 'add' && this.form.linkWay === 1) {
|
this.form.machineId
|
this.form.machineCode = this.form.code
|
this.form.machineName = this.form.name
|
}
|
this.$refs.dialogForm.validate(async (valid) => {
|
if (valid) {
|
this.isSaveing = true;
|
try {
|
var res = await this.$API.workstation.add.post(this.form);
|
} catch (error) {
|
this.isSaveing = false;
|
}
|
this.isSaveing = false;
|
if (res.code == 200) {
|
this.$emit('success', this.form, this.mode)
|
this.visible = false;
|
this.$message.success("操作成功")
|
} else {
|
this.$alert(res.message, "提示", { type: 'error' })
|
}
|
} else {
|
return false;
|
}
|
})
|
},
|
//表单注入数据
|
setData(data) {
|
this.form.id = data.id
|
this.form.userName = data.userName
|
this.form.avatar = data.avatar
|
this.form.name = data.name
|
this.form.dept = data.dept
|
|
//可以和上面一样单个注入,也可以像下面一样直接合并进去
|
//Object.assign(this.form, data)
|
},
|
change(id) {
|
let row = this.options.listnoband.find(v => v.id == id)
|
if (!row) {
|
this.form.machineCode = ''
|
this.form.machineId = ''
|
this.form.machineName = ''
|
|
} else {
|
this.form.machineCode = row.machineCode
|
this.form.machineId = row.id
|
this.form.machineName = row.machineName
|
}
|
this.$HTTP.get(`/api/blade-dnc/ftp-director/get-machine-of-workstation-ftp?id=${this.form.machineId}`).then(res => {
|
this.directorys = res.data
|
})
|
console.log(row)
|
},
|
nodeClick(node) {
|
console.log(node)
|
if (node.parentId == 0) return
|
this.$nextTick(() => {
|
this.form.groupId = node.id
|
this.form.groupName = node.name
|
})
|
},
|
nodeClickTree(node) {
|
this.$nextTick(() => {
|
this.form.createDept = node.id
|
})
|
},
|
addWork() {
|
if (!this.form.workbenchVOList) {
|
this.form.workbenchVOList = []
|
}
|
this.form.workbenchVOList.push({
|
sort: this.form.workbenchVOList.length + 1,
|
name: ''
|
})
|
}
|
}
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
.workbranch {
|
list-style: none;
|
padding-left: 50px;
|
|
li {
|
margin-top: 8px;
|
|
span {
|
display: inline-block;
|
width: 25px;
|
height: 25px;
|
line-height: 25px;
|
text-align: center;
|
border-radius: 50%;
|
background: #ccc;
|
margin-right: 8px;
|
}
|
|
|
}
|
}
|
</style>
|