时间表

ds1.0
fanluyan 2 years ago
parent 4dd13f11bf
commit 50f3822bc7

@ -0,0 +1,260 @@
<template>
<el-dialog
class="adddeviceDialog"
:title="title"
:visible.sync="isShow"
:close-on-click-modal="false"
width="670px"
@close="handleclose"
>
<el-form
label-position="left"
ref="formInfo"
label-width="auto"
:rules="rules"
:model="ruleForm"
>
<el-form-item label="名称" prop="name">
<el-input v-model="ruleForm.name" autocomplete="off"></el-input>
</el-form-item>
<div class="addtimeBox" ref="timescrollref">
<div
class="timeBoxArr"
v-for="(item, index) in ruleForm.list"
:key="index"
>
<el-form-item
label="时间"
:prop="'list.' + index + '.time'"
:rules="{ required: true, message: '请选择时间', trigger: 'blur' }"
>
<el-time-picker
is-range
v-model="item.time"
range-separator="至"
start-placeholder="开始时间"
end-placeholder="结束时间"
format="HH:mm"
value-format="HH:mm"
>
</el-time-picker>
</el-form-item>
<el-form-item label="间隔(分)" :prop="'list.' + index + '.span'">
<!-- <el-input v-model="ruleForm.span" autocomplete="off" type="number"></el-input> -->
<el-input-number v-model="item.span" :min="1"></el-input-number>
</el-form-item>
<div class="btngrop">
<el-button
v-if="index !== 0"
type="danger"
icon="el-icon-minus"
@click="deleteModule(item, index)"
></el-button>
<el-button
icon="el-icon-plus"
type="primary"
@click="addModule()"
v-if="index + 1 == ruleForm.list.length"
></el-button>
</div>
</div>
</div>
<el-form-item label="备注" prop="remark">
<el-input v-model="ruleForm.remark" autocomplete="off"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="isShow = false"> </el-button>
<el-button type="primary" @click="submitForm()"> </el-button>
</div>
</el-dialog>
</template>
<script>
import { addScheduleRulel, updateScheduleRulel } from "@/utils/api/index";
import moment from "moment";
export default {
props: {
title: String,
},
data() {
return {
isShow: false,
rules: {
name: [{ required: true, message: "请输入名称", trigger: "blur" }],
},
ruleForm: {},
};
},
methods: {
//
getdataform(val) {
console.log(val);
if (val == null) {
return (this.ruleForm = {
name: "",
list: [
{
time: "",
span: "",
},
],
remark: "",
});
}
//this.ruleForm = val;
this.ruleForm = JSON.parse(JSON.stringify(val));
this.ruleForm.list.forEach((val) => {
this.$set(val, "time", [val.startTime, val.endTime]);
console.log(val.startTime);
console.log(val.endTime);
});
},
addModule() {
//
this.ruleForm.list.push({
time: "",
span: "",
});
console.log(this.$refs.timescrollref);
this.$nextTick(() => {
console.log(this.$refs.timescrollref);
if (this.$refs.timescrollref) {
console.log(this.$refs.timescrollref.scrollHeight);
this.$refs.timescrollref.scrollTop =
this.$refs.timescrollref.scrollHeight;
}
});
},
//
deleteModule(item, index) {
console.log(item, index);
const itemList = this.ruleForm.list.indexOf(item);
if (itemList !== -1) {
this.ruleForm.list.splice(index, 1);
}
},
//
submitForm() {
this.$refs.formInfo.validate((valid) => {
if (valid) {
// delete this.ruleForm.time;
this.ruleForm.list.forEach((val) => {
this.$set(val, "startTime", val.time[0]);
this.$set(val, "endTime", val.time[1]);
});
// console.log(this.ruleForm.list[0].startTime);
let arr = [];
for (var i = 0; i < this.ruleForm.list.length; i++) {
console.log(this.ruleForm.list[i].startTime.split(":")[0]);
console.log(this.ruleForm.list[i].startTime.split(":")[1]);
console.log(this.ruleForm.list[i].endTime.split(":")[0]);
console.log(this.ruleForm.list[i].endTime.split(":")[1]);
// let str = moment(new Date()).format("hh:mm");
// console.log(typeof str);
// console.log(this.ruleForm.list[i].startTime);
// console.log(typeof this.ruleForm.list[i].startTime);
// var Stime = this.ruleForm.list[i].startTime;
// var Etime = this.ruleForm.list[i].endTime;
// console.log(Stime, Etime);
// var date = new Date(Stime);
// console.log(date);
// moment(date).format("YYYY-MM-DD HH:mm:ss")
arr.push(
{
hour: Math.floor(this.ruleForm.list[i].span / 60),
minute: this.ruleForm.list[i].span % 60,
preset: 255,
},
{
hour: this.ruleForm.list[i].startTime.split(":")[0],
minute: this.ruleForm.list[i].startTime.split(":")[1],
preset: 255,
},
{
hour: this.ruleForm.list[i].endTime.split(":")[0],
minute: this.ruleForm.list[i].endTime.split(":")[1],
preset: 255,
}
);
}
this.ruleForm.list = arr;
if (this.title == "新增") {
addScheduleRulel(this.ruleForm)
.then((res) => {
this.isShow = false;
this.$message({
duration: 1500,
showClose: true,
message: "添加成功",
type: "success",
});
this.$parent.deviceList();
})
.catch((err) => {
this.$message({
duration: 1500,
showClose: true,
message: "添加失败",
type: "error",
});
});
} else {
updateScheduleRulel(this.ruleForm)
.then((res) => {
this.isShow = false;
this.$message.success("修改成功");
this.$parent.deviceList();
})
.catch((err) => {
this.$message.error("修改失败");
});
}
} else {
return false;
}
});
},
display() {
this.isShow = true;
},
hide() {
this.isShow = false;
},
handleclose() {
this.$parent.deviceList();
},
},
mounted() {},
};
</script>
<style lang="less">
.adddeviceDialog {
.el-form {
.addtimeBox {
max-height: 205px;
overflow: auto;
}
.timeBoxArr {
display: flex;
.el-date-editor.el-input,
.el-date-editor.el-input__inner {
width: 226px;
margin-right: 16px;
}
.btngrop {
margin-bottom: 16px;
margin-left: 16px;
height: 32px;
.el-button--small {
padding: 9px 8px;
width: 30px;
}
}
}
}
}
</style>

@ -20,12 +20,12 @@
<div class="addtimeBox" ref="timescrollref">
<div
class="timeBoxArr"
v-for="(item, index) in ruleForm.list"
v-for="(item, index) in ruleForm.listTime"
:key="index"
>
<el-form-item
label="时间"
:prop="'list.' + index + '.time'"
:prop="'listTime.' + index + '.time'"
:rules="{ required: true, message: '请选择时间', trigger: 'blur' }"
>
<el-time-picker
@ -35,11 +35,13 @@
start-placeholder="开始时间"
end-placeholder="结束时间"
format="HH:mm"
value-format="HH:mm"
>
</el-time-picker>
</el-form-item>
<el-form-item label="间隔(分)" :prop="'list.' + index + '.span'">
<el-form-item
label="间隔(分)"
:prop="'listTime.' + index + '.span'"
>
<!-- <el-input v-model="ruleForm.span" autocomplete="off" type="number"></el-input> -->
<el-input-number v-model="item.span" :min="1"></el-input-number>
</el-form-item>
@ -54,7 +56,7 @@
icon="el-icon-plus"
type="primary"
@click="addModule()"
v-if="index + 1 == ruleForm.list.length"
v-if="index + 1 == ruleForm.listTime.length"
></el-button>
</div>
</div>
@ -91,25 +93,25 @@ export default {
if (val == null) {
return (this.ruleForm = {
name: "",
list: [
listTime: [
{
hour: "",
minute: "",
preset: "",
time: "",
span: "",
},
],
list: [],
remark: "",
});
}
//this.ruleForm = val;
this.ruleForm = JSON.parse(JSON.stringify(val));
this.ruleForm.list.forEach((val) => {
this.ruleForm.listTime.forEach((val) => {
this.$set(val, "time", [val.startTime, val.endTime]);
});
},
addModule() {
//
this.ruleForm.list.push({
this.ruleForm.listTime.push({
time: "",
span: "",
});
@ -136,11 +138,39 @@ export default {
this.$refs.formInfo.validate((valid) => {
if (valid) {
// delete this.ruleForm.time;
this.ruleForm.list.forEach((val) => {
console.log(val);
this.ruleForm.listTime.forEach((val) => {
this.$set(val, "startTime", val.time[0]);
this.$set(val, "endTime", val.time[1]);
// console.log(val.time[0]);
// console.log(typeof val.time[0]);
// console.log(new Date(val.time[0]));
// console.log(new Date(val.time[1]));
// console.log(new Date(val.time[0]).getHours());
// console.log(new Date(val.time[0]).getMinutes());
});
let arr = [];
for (var i = 0; i < this.ruleForm.listTime.length; i++) {
console.log(this.ruleForm.listTime);
arr.push(
{
hour: Math.floor(this.ruleForm.listTime[i].span / 60),
minute: this.ruleForm.listTime[i].span % 60,
preset: 255,
},
{
hour: this.ruleForm.listTime[i].startTime.getHours(),
minute: this.ruleForm.listTime[i].startTime.getMinutes(),
preset: 255,
},
{
hour: this.ruleForm.listTime[i].endTime.getHours(),
minute: this.ruleForm.listTime[i].endTime.getMinutes(),
preset: 255,
}
);
}
console.log(arr);
this.ruleForm.list = arr;
if (this.title == "新增") {
addScheduleRulel(this.ruleForm)
.then((res) => {

@ -13,7 +13,7 @@
<div class="deviceTable">
<el-table
ref="multipleTable"
:data="deviceTableData"
:data="newList"
stripe
tooltip-effect="dark"
style="width: 100%"
@ -30,39 +30,18 @@
<el-table-column label="名称" show-overflow-tooltip>
<template slot-scope="scope">{{ scope.row.name }}</template>
</el-table-column>
<!-- <el-table-column label="时间表类型" show-overflow-tooltip>
<template>时间表类型</template>
</el-table-column> -->
<el-table-column label="时间表规则">
<template slot-scope="scope">
<p
class="timeGz"
v-for="(val, index) in scope.row.list"
v-for="(val, index) in scope.row.listTime"
:key="index"
>
<span>
{{
val.startTime.substring(0, val.startTime.lastIndexOf(":"))
}}</span
>
<span> {{ val.startTime }}</span>
~
<span>{{
val.endTime.substring(0, val.endTime.lastIndexOf(":"))
}}</span>
<span>{{ val.endTime }}</span>
间隔<b>{{ val.span }}分钟</b>
</p>
<!-- <ul
class="rulesBox"
v-for="(item, value) in scope.row.list"
:key="value"
>
<li><span>开始时间</span>{{ item.startTime }}</li>
<li><span>结束时间</span>{{ item.endTime }}</li>
<li>
<span>时间间隔:</span>
<el-tag>{{ item.span }}</el-tag>
</li>
</ul> -->
</template>
</el-table-column>
@ -127,6 +106,8 @@ export default {
return {
title: "", //
deviceTableData: [],
newList: [],
listTime: [],
//multipleSelection: [], //
page: 1, //
pageSize: 20, //
@ -146,9 +127,56 @@ export default {
pagesize: this.pageSize,
})
.then((res) => {
this.newList = [];
this.deviceTableData = res.data.list;
this.total = res.data.total;
this.loading = false;
// for (var i = 0; i < this.deviceTableData.list.length; i++) {
// console.log(this.deviceTableData.list[i]);
// }
// console.log(this.deviceTableData);
for (var i = 0; i < this.deviceTableData.length; i++) {
var arr = [];
console.log(this.deviceTableData[i]);
for (var k = 0; k < this.deviceTableData[i].list.length; k++) {
if (k % 3 == 0) {
var obj = {};
obj.span =
this.deviceTableData[i].list[k].hour * 60 +
this.deviceTableData[i].list[k].minute;
console.log("时间间隔");
} else if (k % 3 == 1) {
console.log("开始时间");
console.log("a");
// obj.startTime =
// this.deviceTableData[i].list[k].hour +
// ":" +
// this.deviceTableData[i].list[k].minute;
obj.startTime = new Date().toISOString();
} else if (k % 3 == 2) {
console.log("结束时间");
obj.endTime =
this.deviceTableData[i].list[k].hour +
":" +
this.deviceTableData[i].list[k].minute;
arr.push(obj);
console.log("2222222222222222222222222222");
console.log(arr);
console.log("2222222222222222222222222222");
}
console.log(this.deviceTableData[i].list[k]);
}
this.newList.push({
id: this.deviceTableData[i].id,
list: this.deviceTableData[i].list,
name: this.deviceTableData[i].name,
remark: this.deviceTableData[i].remark,
listTime: arr,
});
}
console.log("this.newList");
console.log(this.newList);
})
.catch((err) => {});
},

Loading…
Cancel
Save