<template>
|
<a-modal :title="title" :width="800" :visible="visible" :confirmLoading="confirmLoading"
|
@ok="handleOk" @cancel="handleCancel" cancelText="关闭">
|
<a-spin :spinning="confirmLoading">
|
<a-form :form="form">
|
<a-row :gutter="24">
|
<a-col :span="12">
|
<a-form-item label="班次编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
<a-input allow-clear placeholder="请输入班次编码"
|
v-decorator="['shiftCode',validatorRules.shiftCode]"/>
|
</a-form-item>
|
</a-col>
|
<a-col :span="12">
|
<a-form-item label="班次名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
<a-input allow-clear placeholder="请输入班次名称" v-decorator="['shiftName',validatorRules.shiftName]"/>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
<a-row :gutter="24">
|
<a-col :span="12">
|
<a-form-item label="开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
<a-time-picker v-decorator="['startTime',validatorRules.startTime]"/>
|
</a-form-item>
|
</a-col>
|
<a-col :span="12">
|
<a-form-item label="结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
<a-time-picker v-decorator="['endTime',validatorRules.endTime]"/>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
|
<a-row :gutter="24">
|
<a-col :span="12">
|
<a-form-item label="工作时长" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
<a-input-number v-decorator="['workHours',validatorRules.workHours]" placeholder="请输入工作时长(小时)" style="width: 100%" />
|
</a-form-item>
|
</a-col>
|
<a-col :span="12">
|
<a-form-item label="是否跨天" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
<a-switch v-model="crossDayFlag" checked-children="是" un-checked-children="否"/>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
|
</a-form>
|
</a-spin>
|
</a-modal>
|
</template>
|
|
<script>
|
import moment from 'moment'
|
import pick from 'lodash.pick'
|
import {
|
getAction,
|
postAction,
|
requestPut
|
} from '@/api/manage'
|
import {
|
duplicateCheck
|
} from '@/api/api'
|
|
|
export default {
|
name: 'ShiftModel',
|
components: {},
|
props: {},
|
data() {
|
return {
|
title: '',
|
crossDayFlag: false,
|
visible: false,
|
model: {},
|
labelCol: {
|
xs: {
|
span: 24
|
},
|
sm: {
|
span: 6
|
}
|
},
|
wrapperCol: {
|
xs: {
|
span: 24
|
},
|
sm: {
|
span: 18
|
}
|
},
|
confirmLoading: false,
|
form: this.$form.createForm(this),
|
validatorRules: {
|
shiftCode: {
|
rules: [
|
{
|
required: true,
|
message: '请输入班次编号'
|
},
|
{ validator: this.validateNum }
|
]
|
},
|
shiftName: {
|
rules: [
|
{
|
required: true,
|
message: '请输入班次名称'
|
},
|
{ validator: this.validateName }
|
]
|
},
|
startDate: {
|
rules: [
|
{
|
required: true,
|
message: '请选择开始时间'
|
}
|
]
|
},
|
endDate: {
|
rules: [
|
{
|
required: true,
|
message: '请选择结束时间'
|
}
|
]
|
}
|
},
|
url: {
|
add: '/base/shift/add',
|
edit: '/base/shift/edit',
|
list: '/base/shift/list'
|
},
|
disableSubmit: true
|
}
|
},
|
created() {
|
|
},
|
|
methods: {
|
|
add() {
|
let _this = this
|
this.visible = true
|
this.form.resetFields()
|
this.model = {}
|
this.$nextTick(() => {
|
this.crossDayFlag = false
|
})
|
},
|
edit(record) {
|
this.form.resetFields()
|
this.model = Object.assign({}, record)
|
this.visible = true
|
this.$nextTick(() => {
|
this.form.setFieldsValue(pick(this.model, 'shiftCode', 'shiftName', 'startTime', 'endTime','workHours'))
|
this.form.setFieldsValue({
|
startTime: moment(this.model.startTime, 'HH:mm:ss'),
|
endTime: moment(this.model.endTime, 'HH:mm:ss')
|
})
|
if (record.crossDayFlag == '1') {
|
this.crossDayFlag = true
|
} else {
|
this.crossDayFlag = false
|
}
|
})
|
},
|
close() {
|
this.$emit('close')
|
this.visible = false
|
},
|
handleOk() {
|
const that = this
|
// 触发表单验证
|
this.form.validateFields((err, values) => {
|
if (!err) {
|
// debugger
|
that.confirmLoading = true
|
let formData = Object.assign(this.model, values)
|
if(that.crossDayFlag == true){
|
formData.crossDayFlag = '1'
|
}else if(that.crossDayFlag == false){
|
formData.crossDayFlag = '0'
|
}
|
formData.startTime = moment(formData.startTime).format('HH:mm:ss')
|
formData.endTime = moment(formData.endTime).format('HH:mm:ss')
|
if (formData.crossDayFlag == '0') {
|
let startTimeOne = formData.startTime.replace(/:/g, '')
|
let endTimeOne = formData.endTime.replace(/:/g, '')
|
if (startTimeOne > endTimeOne) {
|
// that.$message.warning("非跨天班次结束时间不能小于等于开始时间!")
|
that.$notification.warning({
|
message: '消息',
|
description: '非跨天班次结束时间不能小于等于开始时间!'
|
})
|
that.confirmLoading = false
|
that.close()
|
} else {
|
formData.shiftStatus = 1
|
let obj
|
if (!this.model.id) {
|
obj = postAction(this.url.add, formData)
|
} else {
|
obj = requestPut(this.url.edit, formData, {
|
id: this.model.id
|
})
|
}
|
obj.then((res) => {
|
if (res.success) {
|
// that.$message.success("保存成功")
|
that.$notification.success({
|
message: '消息',
|
description: '保存成功'
|
})
|
that.$emit('ok', res.result)
|
} else {
|
// that.$message.warning(res.message)
|
that.$notification.warning({
|
message: '消息',
|
description: res.message
|
})
|
}
|
}).finally(() => {
|
that.confirmLoading = false
|
that.close()
|
})
|
}
|
} else {
|
formData.shiftStatus = 1
|
let obj
|
if (!this.model.id) {
|
obj = postAction(this.url.add, formData)
|
} else {
|
obj = requestPut(this.url.edit, formData, {
|
id: this.model.id
|
})
|
}
|
obj.then((res) => {
|
if (res.success) {
|
// that.$message.success
|
that.$notification.success({
|
message: '消息',
|
description: '保存成功'
|
})
|
that.$emit('ok', res.result)
|
} else {
|
// that.$message.warning(res.message)
|
that.$notification.warning({
|
message: '消息',
|
description: res.message
|
})
|
}
|
}).finally(() => {
|
that.confirmLoading = false
|
that.close()
|
})
|
}
|
|
}
|
})
|
},
|
handleCancel() {
|
this.close()
|
},
|
//验证 编码
|
validateNum(rule, value, callback) {
|
var params = {
|
tableName: 'base_shift',
|
fieldName: 'shift_code',
|
fieldVal: value,
|
dataId: this.model.id,
|
//数据库中存在字段del_flag并使用该字段作为未删除策略,真删除:false 假删除:true
|
delFlag: 'true'
|
}
|
duplicateCheck(params).then((res) => {
|
if (res.success) {
|
callback()
|
} else {
|
callback('班次编号已存在!')
|
}
|
})
|
},
|
//验证 名称
|
validateName(rule, value, callback) {
|
var params = {
|
tableName: 'base_shift',
|
fieldName: 'shift_name',
|
fieldVal: value,
|
dataId: this.model.id,
|
//数据库中存在字段del_flag并使用该字段作为未删除策略,真删除:false 假删除:true
|
delFlag: 'true',
|
};
|
duplicateCheck(params).then((res) => {
|
if (res.success) {
|
callback();
|
} else {
|
callback("班次名称已存在!");
|
}
|
})
|
},
|
|
}
|
}
|
</script>
|
|
<style scoped>
|
.ant-btn {
|
padding: 0 10px;
|
margin-left: 3px;
|
}
|
|
.ant-form-item-control {
|
line-height: 0px;
|
}
|
|
/** 主表单行间距 */
|
.ant-form .ant-form-item {
|
margin-bottom: 10px;
|
}
|
|
/** Tab页面行间距 */
|
.ant-tabs-content .ant-form-item {
|
margin-bottom: 0px;
|
}
|
</style>
|