<template>
|
<el-dialog
|
append-to-body
|
:title="!dataForm.id ? '新增' : '修改'"
|
:close-on-click-modal="false"
|
:visible.sync="visible"
|
>
|
<el-form
|
:model="dataForm"
|
:rules="dataRule"
|
ref="dataForm"
|
label-width="80px"
|
class="l-mes"
|
:disabled="!editable"
|
>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="班次编号" prop="dutyNo">
|
<el-input
|
v-model="dataForm.dutyNo"
|
placeholder=""
|
disabled
|
></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="工作站" prop="workstationId">
|
<el-select
|
v-model="dataForm.workstationId"
|
placeholder=""
|
filterable
|
style="width: 100%"
|
disabled
|
>
|
<el-option
|
v-for="item in workstations"
|
:key="item.id"
|
:label="item.name + '[' + item.workstationNo + ']'"
|
:value="item.id"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="班次" prop="shiftId">
|
<el-select
|
v-model="dataForm.shiftId"
|
placeholder=""
|
filterable
|
style="width: 100%"
|
@change="selectShiftChanged"
|
>
|
<el-option
|
v-for="item in shifts"
|
:key="item.id"
|
:label="item.name"
|
:value="item.id"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="班组" prop="crewId">
|
<el-select
|
v-model="dataForm.crewId"
|
placeholder=""
|
filterable
|
style="width: 100%"
|
>
|
<el-option
|
v-for="item in crews"
|
:key="item.id"
|
:label="item.crewName"
|
:value="item.id"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="班次日期" prop="dutyDate">
|
<el-date-picker
|
style="width: 100%"
|
v-model="dataForm.dutyDate"
|
type="date"
|
placeholder=""
|
value-format="yyyy-MM-dd HH:mm:ss"
|
@change="selectDutyDate"
|
>
|
</el-date-picker>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="班次时间" prop="dutyTime">
|
<el-input v-model="dataForm.dutyTime" placeholder=""></el-input>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="开始" prop="startTime">
|
<el-date-picker
|
style="width: 100%"
|
v-model="dataForm.startTime"
|
type="datetime"
|
placeholder=""
|
value-format="yyyy-MM-dd HH:mm:ss"
|
>
|
</el-date-picker>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="结束" prop="endTime">
|
<el-date-picker
|
style="width: 100%"
|
v-model="dataForm.endTime"
|
type="datetime"
|
placeholder=""
|
value-format="yyyy-MM-dd HH:mm:ss"
|
>
|
</el-date-picker>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="接班记录" prop="receiveRemark">
|
<el-input
|
v-model="dataForm.receiveRemark"
|
placeholder=""
|
type="textarea"
|
:rows="3"
|
></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="交班记录" prop="deliveryRemark">
|
<el-input
|
v-model="dataForm.deliveryRemark"
|
placeholder=""
|
type="textarea"
|
:rows="3"
|
></el-input>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<div style="background-color: #F0F2F5;height: 10px" />
|
</el-form>
|
<span slot="footer" class="dialog-footer">
|
<el-button @click="visible = false">取消</el-button>
|
<el-button
|
type="primary"
|
:disabled="isSubmit"
|
v-thinclick="`dataFormSubmit`"
|
>确定</el-button
|
>
|
</span>
|
</el-dialog>
|
</template>
|
|
<script>
|
import {
|
getDutyRecord,
|
addDutyRecord,
|
putDutyRecord
|
} from '@/api/product/dutyrecord'
|
import { getAllCrewList } from '@/api/basic/crew'
|
import { getAllShiftList } from '@/api/basic/shift'
|
import { getAllWorkstationList } from '@/api/basic/workstation'
|
import { dateFormat } from '@/util/date'
|
|
export default {
|
props: {
|
workstationId: {
|
type: Number,
|
default: null
|
}
|
},
|
data() {
|
return {
|
visible: false,
|
dataForm: {
|
id: 0,
|
dutyNo: '',
|
dutyDate: '',
|
startTime: '',
|
endTime: '',
|
dutyTime: '',
|
shiftId: '',
|
workstationId: '',
|
receiveRemark: '',
|
deliveryRemark: '',
|
crewId: '',
|
isSubmit: false
|
},
|
dataRule: {
|
dutyDate: [
|
{ required: true, message: '班次日期不能为空', trigger: 'change' }
|
],
|
startTime: [
|
{ required: true, message: '开始时间不能为空', trigger: 'change' }
|
],
|
endTime: [
|
{ required: true, message: '结束时间不能为空', trigger: 'change' }
|
],
|
dutyTime: [
|
{ required: true, message: '班次时间不能为空', trigger: 'blur' }
|
],
|
shiftId: [
|
{ required: true, message: '班次不能为空', trigger: 'change' }
|
],
|
workstationId: [
|
{ required: true, message: '工作站不能为空', trigger: 'change' }
|
]
|
},
|
crews: [],
|
shifts: [],
|
workstations: [],
|
isSubmit: false
|
}
|
},
|
created() {
|
this.initOptions()
|
},
|
computed: {
|
editable: function() {
|
if (!this.dataForm.id) {
|
return true
|
}
|
if (this.dataForm.id && this.dataForm.isConfirm == false) {
|
return true
|
}
|
return false
|
}
|
},
|
watch: {
|
workstationId: {
|
handler: function(newVal, oldVal) {
|
if (this.workstationId) {
|
this.dataForm.workstationId = this.workstationId
|
}
|
},
|
immediate: true
|
}
|
},
|
methods: {
|
init(id) {
|
this.dataForm.id = id || 0
|
this.visible = true
|
this.$nextTick(() => {
|
this.$refs.dataForm.resetFields()
|
if (this.dataForm.id) {
|
getDutyRecord(this.dataForm.id).then((response) => {
|
this.dataForm = response.data.data
|
})
|
}
|
})
|
},
|
// 表单提交
|
dataFormSubmit() {
|
this.isSubmit = true
|
this.$refs.dataForm.validate((valid) => {
|
if (valid) {
|
if (this.dataForm.id) {
|
if (this.dataForm.isConfirm) {
|
this.isSubmit = false
|
this.$message.warning('已确认,无法修改')
|
} else {
|
putDutyRecord(
|
Object.assign(new Object(), this.dataForm, {
|
operationType: '编辑',
|
isLimitUpd: true
|
})
|
).then((data) => {
|
this.$message.success('修改成功')
|
this.visible = false
|
this.isSubmit = false
|
this.$emit('refreshDataList')
|
})
|
}
|
} else {
|
addDutyRecord(this.dataForm).then((data) => {
|
this.$message.success('添加成功')
|
this.visible = false
|
this.isSubmit = false
|
this.$emit('refreshDataList')
|
})
|
}
|
} else {
|
this.isSubmit = false
|
}
|
})
|
},
|
// 初始化选择项
|
initOptions() {
|
getAllCrewList().then((response) => {
|
this.crews = response.data.data
|
})
|
getAllShiftList().then((response) => {
|
this.shifts = response.data.data
|
})
|
getAllWorkstationList().then((response) => {
|
this.workstations = response.data.data
|
})
|
},
|
// 班次选择,自动带出班次日期/班次时间/开始/结束
|
selectShiftChanged(shiftId) {
|
const shift = this.shifts.find((item) => item.id === shiftId)
|
let date = new Date()
|
if (this.dataForm.dutyDate) {
|
date = this.dataForm.dutyDate
|
} else {
|
this.dataForm.dutyDate = dateFormat(date)
|
}
|
this.autoValue(shift, date)
|
},
|
autoValue(shift, date) {
|
const a = new Array(
|
'sunday',
|
'monday',
|
'tuesday',
|
'wensday',
|
'thursday',
|
'friday',
|
'saturday'
|
)
|
const day = a[new Date().getDay()]
|
const hours = day + 'Hours'
|
const workHours = day + 'WorkHours'
|
const start = shift[`${hours}`].split('-')[0]
|
const end = shift[`${hours}`].split('-')[1]
|
this.dataForm.startTime =
|
this.dataForm.dutyDate.split(' ')[0] + ' ' + start + ':00'
|
// 夜班这种情况结束时间要计算到下一天
|
if (start < end) {
|
this.dataForm.endTime =
|
this.dataForm.dutyDate.split(' ')[0] + ' ' + end + ':00'
|
} else {
|
const nextDay = dateFormat(
|
new Date(new Date().setDate(new Date(date).getDate() + 1))
|
)
|
this.dataForm.endTime = nextDay.split(' ')[0] + ' ' + end + ':00'
|
}
|
this.dataForm.dutyTime = shift[`${workHours}`]
|
},
|
selectDutyDate(dutyDate) {
|
const shift = this.shifts.find(
|
(item) => item.id === this.dataForm.shiftId
|
)
|
if (shift) {
|
this.autoValue(shift, dutyDate)
|
}
|
}
|
}
|
}
|
</script>
|