<template>
|
<GlobalWindow
|
:title="title"
|
:visible.sync="visible"
|
:confirm-working="isWorking"
|
@confirm="confirm"
|
>
|
<el-form :model="form" ref="form" :rules="rules">
|
<el-form-item label="设备:" prop="deviceId">
|
<el-select v-model="form.deviceId" clearable filterable placeholder="请选择">
|
<el-option
|
v-for="(item, index) in device()"
|
:key="index"
|
:label="'【' + item.code+' 】'+ item.name"
|
:value="item.id">
|
<span class="long-title-style" :title="'【' + item.code + '】'+ item.name">【{{ item.code }}】{{item.name}}</span>
|
</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="所属员工:" prop="userIds">
|
<el-select v-model="form.userIds" reserve-keyword multiple clearable filterable placeholder="请选择" @change="selectUser">
|
<el-option
|
v-for="(item, index) in select()"
|
:key="item.id"
|
:label="index==0?'全部':(item.name + '-' + item.dmodel.name + '-' + item.phone)"
|
:value="item.id">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</el-form>
|
</GlobalWindow>
|
</template>
|
|
<script>
|
import BaseOpera from '@/components/base/BaseOpera'
|
import GlobalWindow from '@/components/common/GlobalWindow'
|
|
export default {
|
name: 'OperaUserDeviceExtWindow',
|
extends: BaseOpera,
|
components: { GlobalWindow },
|
data () {
|
return {
|
// 表单数据
|
form: {
|
id: null,
|
userIds: [],
|
deviceId: null
|
},
|
// device: [],
|
// user: [],
|
// 验证规则
|
rules: {
|
userIds: [
|
{ required: true, message: '请选择员工', trigger: 'change' }
|
],
|
deviceId: [
|
{ required: true, message: '请选择设备', trigger: 'change' }
|
]
|
}
|
}
|
},
|
inject: ['device', 'user'],
|
created () {
|
this.config({
|
api: '/ext/userDeviceExt',
|
'field.id': 'id'
|
})
|
},
|
methods: {
|
/**
|
* 确认新建
|
*
|
* @private
|
*/
|
__confirmCreate () {
|
this.$refs.form.validate((valid) => {
|
if (!valid) {
|
return
|
}
|
const form = JSON.parse(JSON.stringify(this.form))
|
form.userIds = form.userIds.join(',')
|
// 调用新建接口
|
this.isWorking = true
|
this.api.create(form)
|
.then(() => {
|
this.visible = false
|
this.$tip.apiSuccess('新建成功')
|
this.$emit('success')
|
})
|
.catch(e => {
|
this.$tip.apiFailed(e)
|
})
|
.finally(() => {
|
this.isWorking = false
|
})
|
})
|
},
|
select() {
|
if (this.user().length > 0) {
|
return [{id:'all'} ,...this.user()]
|
}
|
return []
|
},
|
selectUser (v) {
|
console.log(v);
|
if (v.indexOf('all') != -1) {
|
console.log('all');
|
let all = this.user().map(item=> item.id)
|
this.form.userIds = all.filter(item => item!='all')
|
}
|
}
|
// selectDevice (v) {
|
// console.log(v)
|
// this.userIds = []
|
// getUserDevice({ devmodelId: v })
|
// .then(res => {
|
// this.user = res
|
// })
|
// .catch(err => {
|
// console.log(err)
|
// })
|
// }
|
}
|
}
|
</script>
|