<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="planNum">
|
<el-input v-model="form.planNum" placeholder="请输入" v-trim/>
|
</el-form-item>
|
<el-form-item label="计划开工日期:" prop="planDate">
|
<el-date-picker
|
v-model="form.planDate"
|
value-format="yyyy-MM-dd"
|
type="date"
|
:picker-options="pickerOptions"
|
placeholder="选择日期">
|
</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 { getUserDevice } from '@/api/ext/userDeviceExt'
|
import { distributeById } from '@/api/ext/plansExt'
|
import { getDeviceByCondition } from '@/api/ext/deviceExt'
|
export default {
|
name: 'OrderDistrubution',
|
extends: BaseOpera,
|
components: { GlobalWindow },
|
data () {
|
return {
|
// 表单数据
|
form: {
|
planId: null,
|
planNum: 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' }
|
]
|
}
|
}
|
},
|
methods: {
|
open (title, target) {
|
this.title = title
|
this.visible = true
|
// 编辑
|
this.$nextTick(() => {
|
for (const key in this.form) {
|
this.form[key] = target[key]
|
}
|
this.form.planDate = new Date()
|
this.form.planId = target.id
|
this.form.planNum = target.num - target.distributNum
|
getDeviceByCondition({procedureId: target.procedureId})
|
.then(res => {
|
|
this.device = res
|
this.form.proGroupId = res[0] ? res[0].id : ''
|
this.getUser(this.form.proGroupId)
|
})
|
.catch(err => {
|
console.log(err)
|
})
|
})
|
},
|
selectDevice (v) {
|
this.getUser(v)
|
},
|
getUser (deviceId) {
|
findAll({
|
// dmodelProcedureId: target.procedureId
|
deviceId,
|
planId: this.form.planId
|
})
|
.then(res => {
|
this.form.proUserList = []
|
this.user = res
|
if (res.length > 0) {
|
this.user = [{userId:'all'} ,...res]
|
// if (res[0].userList.length > 0) {
|
// let tempUserId = res.userList[0].userId
|
// for (const item of res) {
|
// if (item.userId === tempUserId) {
|
// this.form.proUserList.push(item.userId)
|
// }
|
// }
|
// }
|
}
|
console.log(this.user)
|
})
|
.catch(err => {
|
console.log(err)
|
})
|
},
|
// changeModel (v) {
|
// // console.log('选择了', v)
|
// const item = this.user[v]
|
// this.form.userDeivceId = item.id
|
// },
|
selectUser (v) {
|
console.log(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')
|
}
|
},
|
__confirmCreate () {
|
this.$refs.form.validate((valid) => {
|
if (!valid) {
|
return
|
}
|
// 调用新建接口
|
this.isWorking = true
|
// let form = JSON.parse(JSON.stringify(this.form))
|
// form.proUserList = this.form.proUserList.join(',')
|
distributeById(this.form)
|
.then(() => {
|
this.visible = false
|
this.$tip.apiSuccess('分配成功')
|
this.$emit('success')
|
})
|
.catch(e => {
|
this.$tip.apiFailed(e)
|
})
|
.finally(() => {
|
this.isWorking = false
|
})
|
})
|
},
|
compairDate (data) {
|
let date1 = new Date(data);
|
let date2 = new Date();
|
console.log(date1, date2);
|
if (date1 > date2) {
|
return date1
|
} else {
|
return date2
|
}
|
},
|
// 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>
|