rt-sim-training-client/src/views/display/demon/setTime.vue

118 lines
3.3 KiB
Vue
Raw Normal View History

2019-07-26 13:32:43 +08:00
<template>
<el-dialog v-dialogDrag :title="title" :visible.sync="show" width="550px" :before-close="doClose">
2019-08-30 15:46:08 +08:00
<el-form ref="form" label-width="120px" :model="formModel" :rules="rules">
2019-09-12 13:35:25 +08:00
<el-form-item :label="$t('display.setTime.systemTime')" prop="initTime">
2019-08-30 15:46:08 +08:00
<el-time-picker
v-model="formModel.initTime"
:picker-options="pickerOptions"
2019-09-12 13:35:25 +08:00
:placeholder="$t('display.setTime.anyTime')"
2019-08-30 15:46:08 +08:00
@change="handleChange"
/>
</el-form-item>
2019-09-12 13:35:25 +08:00
<el-form-item v-if="hasNumber" :label="$t('display.setTime.loadTrainNum')" prop="loadNum">
<el-input-number v-model="formModel.loadNum" :min="1" :max="maxNumber" :label="$t('display.setTime.selectLoadTrainNum')" />
<span> {{ ` (${$t('display.setTime.maxTrainNum')} ${maxNumber}) ` }} </span>
2019-08-30 15:46:08 +08:00
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
2019-09-12 13:35:25 +08:00
<el-button @click="show = false">{{$t('global.cancel')}}</el-button>
<el-button type="primary" :loading="status" @click="handleSure">{{$t('global.confirm')}}</el-button>
2019-08-30 15:46:08 +08:00
</span>
</el-dialog>
2019-07-26 13:32:43 +08:00
</template>
<script>
2019-08-30 15:46:08 +08:00
import { prefixIntrger } from '@/utils/date';
import { getDesignatedTimeTrainNum } from '@/api/simulation';
2019-07-26 13:32:43 +08:00
2019-08-30 15:46:08 +08:00
export default {
data() {
return {
show: false,
formModel: {
initTime: new Date(),
loadNum: 1
},
maxNumber: 1,
pickerOptions: { selectableRange: '00:00:00 - 23:59:59' },
status: false
2019-08-30 15:46:08 +08:00
};
},
computed: {
title() {
2019-09-12 13:35:25 +08:00
return this.$t('display.setTime.setSimulationSystemTime');
2019-08-30 15:46:08 +08:00
},
hasNumber() {
return this.$route.params.mode == 'demon' && this.$route.query.prdType == '04';
},
group() {
return this.$route.query.group;
},
rules() {
return {
initTime: [
2019-09-12 13:35:25 +08:00
{ required: true, message: this.$t('display.setTime.selectSystemTime'), trigger: 'change' },
2019-08-30 15:46:08 +08:00
{
validator(rule, value, callback) {
if (this.maxNumber == 0) {
2019-09-12 13:35:25 +08:00
callback(new Error(this.$t('display.setTime.selectValidStartTime')));
2019-08-30 15:46:08 +08:00
} else {
callback();
}
},
trigger: 'change',
maxNumber: this.maxNumber
}
],
loadNum: [
2019-09-12 13:35:25 +08:00
{ required: true, message: this.$t('display.setTime.selectTrainNum'), trigger: 'change' }
2019-07-26 13:32:43 +08:00
2019-08-30 15:46:08 +08:00
]
};
}
},
methods: {
doShow() {
this.formModel.initTime = new Date(this.$store.state.training.initTime || null);
this.handleChange(this.formModel.initTime);
this.show = true;
},
doClose() {
this.status = false;
2019-08-30 15:46:08 +08:00
this.show = false;
},
handleChange(initTime) {
this.formModel.loadNum = 0;
if (this.hasNumber) {
getDesignatedTimeTrainNum({ initTime: this.formatTime(initTime) }, this.group).then(resp => {
this.maxNumber = parseInt(resp.data);
});
}
},
formatTime(initTime) {
const hh = prefixIntrger(initTime.getHours(), 2);
const mm = prefixIntrger(initTime.getMinutes(), 2);
const ss = prefixIntrger(initTime.getSeconds(), 2);
return `${hh}:${mm}:${ss}`;
},
handleSure() {
this.$refs.form.validate((valid) => {
if (valid) {
this.status = true;
2019-08-30 15:46:08 +08:00
const model = {
initTime: this.formatTime(this.formModel.initTime)
};
2019-07-26 13:32:43 +08:00
2019-08-30 15:46:08 +08:00
if (this.hasNumber) {
model['loadNum'] = this.formModel.loadNum;
}
2019-07-26 13:32:43 +08:00
2019-08-30 15:46:08 +08:00
this.$emit('ConfirmSelectBeginTime', model);
this.doClose();
}
});
}
}
};
</script>