<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="planDate">
|
<el-date-picker
|
v-model="form.planDate"
|
type="date"
|
placeholder="选择日期"
|
value-format="yyyy-MM-dd"
|
:picker-options="pickerOptions"
|
></el-date-picker>
|
</el-form-item>
|
<el-form-item label="生产设备:" prop="proGroupId">
|
<el-select v-model="form.proGroupId" clearable filterable placeholder="请选择生产设备" @change="selectDevice">
|
<el-option
|
v-for="(item, index) in device"
|
:key="index"
|
:label="'【' + item.code + '】' +item.name "
|
:value="item.id">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="生产人员:" prop="proUserList">
|
<el-select v-model="form.proUserList" :disabled="!form.proGroupId" multiple clearable filterable placeholder="请选择生产人员" @change="selectUser">
|
<el-option
|
v-for="(item, index) in user"
|
:key="index"
|
:label="index==0?'全部':(item.umodel.name + ' - ' + (item.tmodel && item.tmodel.name))"
|
:value="item.userId">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</el-form>
|
</GlobalWindow>
|
</template>
|
|
<script>
|
import BaseOpera from '@/components/base/BaseOpera'
|
import GlobalWindow from '@/components/common/GlobalWindow'
|
import { findAll } from '@/api/ext/userDeviceExt'
|
import { distributeById } from '@/api/ext/workorderExt'
|
import { getDeviceByCondition } from '@/api/ext/deviceExt'
|
export default {
|
name: 'OrderRedistrubution',
|
extends: BaseOpera,
|
components: { GlobalWindow },
|
data () {
|
return {
|
// 表单数据
|
form: {
|
id: null,
|
planDate: null,
|
proGroupId: '',
|
proUserList: [],
|
},
|
parent: [],
|
isShow: false,
|
device: [],
|
user: [],
|
index: null,
|
|
pickerOptions: {},
|
// 验证规则
|
rules: {
|
planNum: [
|
{ required: true, message: '请输入计划生产数量', trigger: 'blur' }
|
],
|
planDate: [
|
{ required: true, message: '请选择计划生产日期', trigger: 'change' }
|
],
|
proUserId: [
|
{ required: true, message: '请选择生产人员/设备', trigger: 'change' }
|
]
|
},
|
draerData: {
|
show: false
|
}
|
}
|
},
|
methods: {
|
open (title, target) {
|
this.title = title
|
this.visible = true
|
getDeviceByCondition({})
|
.then(res => {
|
this.device = res
|
})
|
.catch(err => {
|
console.log(err)
|
})
|
|
// 编辑
|
this.$nextTick(() => {
|
for (const key in this.form) {
|
this.form[key] = target[key]
|
}
|
console.log(this.form)
|
this.selectDevice(target.proGroupId)
|
this.form.proUserList = target.proUserList.map((item) => { return item.proUserId })
|
this.form.planDate = new Date()
|
})
|
},
|
compairDate (data) {
|
let date1 = new Date(data);
|
let date2 = new Date();
|
console.log(date1, date2);
|
if (date1 > date2) {
|
return date1
|
} else {
|
return date2
|
}
|
},
|
selectDevice (v) {
|
this.getUser(v)
|
},
|
getUser (deviceId) {
|
findAll({
|
// dmodelProcedureId: target.procedureId
|
deviceId,
|
// planId: this.form.id
|
})
|
.then(res => {
|
this.form.proUserList = []
|
// console.log(this.form);
|
this.user = res
|
if (res.length > 0) {
|
this.user = [{userId:'all'} ,...res]
|
}
|
})
|
.catch(err => {
|
console.log(err)
|
})
|
},
|
changeModel (v) {
|
// console.log('选择了', v)
|
const item = this.user[v]
|
this.form.userDeivceId = item.id
|
},
|
selectUser (v) {
|
if (v.indexOf('all') != -1) {
|
console.log('all');
|
let all = this.user.map(item=> item.userId)
|
this.form.proUserList = all.filter(item => item!='all')
|
}
|
},
|
__confirmEdit () {
|
this.$refs.form.validate((valid) => {
|
if (!valid) {
|
return
|
}
|
// 调用新建接口
|
this.isWorking = true
|
distributeById(this.form)
|
.then(() => {
|
this.visible = false
|
this.$tip.apiSuccess('分配成功')
|
this.$emit('success')
|
})
|
.catch(e => {
|
this.$tip.apiFailed(e)
|
})
|
.finally(() => {
|
this.isWorking = false
|
})
|
})
|
},
|
pickerOptions(data) {
|
let time = new Date(data);
|
let tempTime = 3600 * 1000 * 24
|
return {
|
disabledDate: time.getTime() < new Date(data)-tempTime
|
}
|
}
|
},
|
created () {
|
this.config({
|
api: '/ext/categoryExt',
|
'field.id': 'id'
|
})
|
this.pickerOptions.disabledDate = (time) => {
|
// 一天
|
let tempTime = 3600 * 1000 * 24
|
return time.getTime() < new Date()-tempTime
|
}
|
}
|
}
|
</script>
|