You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1013 lines
28 KiB

2 years ago
<template>
<div>
<div class="select">
2 years ago
<div class="date">
<el-date-picker
size="small"
v-model="date"
:type="createType === 1 ? 'date' : 'week'"
value-format="yyyy-MM-dd"
:picker-options="pickerOptions"
placeholder="日期选择"
:format="createType === 1 ? 'yyyy-MM-dd' : 'yyyy第WW周'"
2 years ago
style="width: 160px"
2 years ago
@input="pickDate"
></el-date-picker>
<p style="margin-left: 14px">
您正在为
<span style="color: red">{{ date }}</span>
创建
2 years ago
<span style="color: red">
{{
abilities.find((i) => i.value === ability)
? abilities.find((i) => i.value === ability).key
: ""
}}
</span>
2 years ago
调令
</p>
<!-- <el-radio-group size="small" style="margin-left: 14px;" v-model="createType">-->
<!-- <el-radio-button :label="1"></el-radio-button>-->
<!-- <el-radio-button :label="2"></el-radio-button>-->
<!-- </el-radio-group>-->
</div>
2 years ago
2 years ago
<div class="select-item">
2 years ago
<div class="select-item__title">选择范围</div>
2 years ago
<el-checkbox-group size="small" v-model="select.area">
<el-checkbox-button v-for="item in areas" :label="item.value">{{
item.key
}}</el-checkbox-button>
</el-checkbox-group>
</div>
<div class="select-item">
2 years ago
<div class="select-item__title">选择泵闸</div>
2 years ago
<el-checkbox-group size="small" v-model="select.type">
<el-checkbox-button v-for="item in types" :label="item.value">{{
item.key
}}</el-checkbox-button>
</el-checkbox-group>
</div>
2 years ago
<div class="select-item">
2 years ago
<div class="select-item__title">选择类别</div>
2 years ago
<el-radio-group
size="small"
v-model="ability"
@input="(e) => data.forEach((i) => (i.leibie = e))"
>
2 years ago
<el-radio-button v-for="item in abilities" :label="item.value">{{
2 years ago
item.key
}}</el-radio-button>
2 years ago
</el-radio-group>
</div>
2 years ago
<div class="select-item">
<Button type="primary" style="margin-left: 10px" @click="clear"
>清空筛选</Button
>
2 years ago
<el-popover
placement="top-start"
title="模板"
width="300"
trigger="click"
@show="getTemplates"
>
<template>
<Table
:loading="templateLoading"
:data="templates"
size="small"
:columns="templateTable"
></Table>
<div style="display: flex; justify-content: center; padding: 8px 0">
<el-pagination
small
:current-page.sync="templateSelect.page"
:page-size="templateSelect.page_size"
layout="prev, pager, next"
:total="templateTotal"
@current-change="getTemplates"
>
</el-pagination>
</div>
</template>
<Button
slot="reference"
type="primary"
style="margin-left: 10px"
>模板选择</Button
>
</el-popover>
2 years ago
</div>
</div>
<Table
2 years ago
ref="dataTable"
2 years ago
style="margin-top: 20px"
2 years ago
:columns="columns"
:data="mergeData"
stripe
:span-method="objectSpanMethod"
></Table>
<div class="btns">
<Button type="primary" @click="submit"></Button>
<Button type="primary" ghost @click="reset"></Button>
2 years ago
<Button type="primary" ghost @click="clone"></Button>
2 years ago
</div>
</div>
</template>
<script>
2 years ago
import { uuid } from "@/utils";
2 years ago
import { index, save } from "@/api/system/baseForm";
import { deepCopy } from "@/utils";
import { mergeTableRow } from "@/utils/mergeTableRow";
import { show } from "@/api/system/customFormField";
export default {
inject: ["equipments"],
2 years ago
props: {},
2 years ago
data() {
return {
2 years ago
templateLoading: false,
templates: [],
templateTotal: 0,
templateSelect: {
table_name: "transfer_templates",
page: 1,
page_size: 20,
},
templateTable: [
{
type: "index",
width: 46,
title: " ",
},
{
title: "名称",
key: "name",
},
{
title: "操作",
key: "operate",
render: (h, { row }) =>
h(
"Button",
{
props: {
type: "primary",
size: "small",
},
on: {
["click"]: (_) => {
this.handleClone(JSON.parse(row.content))
},
},
},
"选择"
),
},
],
2 years ago
dispatches: [],
transferDispatches: [],
2 years ago
createType: 1,
pickerOptions: {
2 years ago
firstDayOfWeek: 1,
2 years ago
shortcuts: [
{
text: "今天",
onClick(picker) {
picker.$emit("pick", new Date());
},
},
{
text: "明天",
onClick(picker) {
const date = new Date();
date.setTime(date.getTime() + 3600 * 1000 * 24);
picker.$emit("pick", date);
},
},
{
text: "下周",
onClick(picker) {
const date = new Date();
date.setTime(date.getTime() + 3600 * 1000 * 24 * 7);
picker.$emit("pick", date);
},
},
],
2 years ago
},
areas: [],
types: [],
2 years ago
abilities: [],
2 years ago
select: {
area: [],
type: [],
2 years ago
leibie: [],
2 years ago
},
weather: [],
copyOriginalData: [],
date: this.$moment().format("YYYY-MM-DD"),
2 years ago
ability: 1,
2 years ago
data:
this.equipmentList?.map((i) => ({
2 years ago
equipment: i,
2 years ago
equipment_id: i.id,
start_time: "",
end_time: "",
content: "",
level: 1,
2 years ago
leibie: this.ability,
2 years ago
})) || [],
columns: [
// {
// width: 50,
// title: ' ',
// type: 'index',
// key: 'index'
// },
{
title: "点位",
width: 240,
key: "equipment_id",
align: "center",
render: (h, { row, index }) => {
2 years ago
const text = row.equipment ? row.equipment.name : "";
const num = this.dispatches.reduce((pre, cur) => {
return cur.equipment_id === row.equipment_id
? ++pre
: pre;
}, 0)
2 years ago
return h("div", [
2 years ago
h(
"el-popover",
{
props: {
placement: "top-start",
title: "今日调令",
width: "400px",
},
on: {
show: (_) => {
this.transferDispatches = this.dispatches.filter(
(i) => i.equipment_id === row.equipment_id
);
},
2 years ago
},
2 years ago
},
[
h(
"span",
{
slot: "reference",
// props: {
// type: "ios-list-box"
// },
style: {
"border-radius": "100%",
"margin-right": "4px",
cursor: "pointer",
width: "20px",
height: "20px",
2 years ago
display: (num && num !== 0) ? "inline-block" : "none",
2 years ago
background: "#367bc7",
color: "#fff",
},
},
2 years ago
num
2 years ago
),
h("Table", {
style: {
2 years ago
width: "540px",
2 years ago
},
props: {
size: "small",
data: this.transferDispatches,
columns: [
{
title: " ",
type: "index",
width: 46,
},
{
title: "开始时间",
key: "start_time",
align: "center",
2 years ago
width: 170,
2 years ago
render: (h, { row }) =>
h(
"span",
this.$moment(row.start_time).format(
"YYYY-MM-DD HH:mm"
)
),
},
{
title: "结束时间",
key: "end_time",
2 years ago
width: 170,
2 years ago
align: "center",
render: (h, { row }) =>
h(
"span",
this.$moment(row.end_time).format(
"YYYY-MM-DD HH:mm"
)
),
},
2 years ago
{
title: "调令等级",
width: 90,
key: "level",
align: "center",
render: (h, { row }) => {
let type = new Map([
[1,'一般'],
[2,'紧急']
])
return h('span',type.get(row.level));
},
},
{
title: '类别',
width: 80,
key: 'leibie',
align: 'center',
render: (h,{ row }) => h('span', (this.abilities.find(i => i.value === row.leibie))?.key)
},
2 years ago
{
title: "内容",
2 years ago
minWidth: 120,
2 years ago
key: "content",
},
],
},
}),
]
),
h("span", text),
h(
"Button",
{
2 years ago
props: {
size: "small",
2 years ago
type: "primary",
icon: "ios-add",
},
style: {
"margin-left": "6px",
},
on: {
["click"]: (e) => {
this.data.splice(index, 0, deepCopy(row));
},
},
2 years ago
},
2 years ago
"新增"
),
2 years ago
]);
},
2 years ago
},
{
2 years ago
title: "机组运行状态",
2 years ago
width: 200,
2 years ago
render: (h, { row }) => {
2 years ago
const create = () => {
let dom = [];
2 years ago
for (let i = 0; i <= row._random; i++) {
dom.push(
h("div", {
style: {
width: "14px",
height: "14px",
background: i === row._random - 1 ? "red" : "green",
"border-radius": "100%",
"margin-left": "6px",
},
})
);
2 years ago
}
return dom;
2 years ago
};
return h(
"div",
{
style: {
display: "flex",
},
},
create()
);
},
2 years ago
},
{
2 years ago
title: "类别",
key: "yinpaishui",
2 years ago
width: 100,
2 years ago
align: "center",
render: (h, { row }) =>
h("span", this.abilities.find((i) => i.value === row.leibie)?.key),
2 years ago
},
{
title: "开启时间",
width: 140,
align: "center",
key: "start_time",
render: (h, { row, index }) => {
return h("TimePicker", {
props: {
value: row.start_time,
type: "time",
size: "small",
transfer: true,
2 years ago
format: "HH:mm",
2 years ago
},
on: {
2 years ago
["on-change"]: (e) => {
2 years ago
this.data[index].start_time = e;
2 years ago
if (this.data[index]._last) {
2 years ago
const [hour, min] = this.data[index].start_time
.split(":")
.map((i) => Number(i));
2 years ago
let addTime = {
hour: Math.floor(this.data[index]._last),
2 years ago
min: (this.data[index]._last % 1) * 60,
};
2 years ago
let resTime = {
2 years ago
hour:
hour + addTime.hour + (min + addTime.min >= 60 ? 1 : 0),
min: (min + addTime.min) % 60,
};
this.data[index].end_time = `${resTime.hour
.toString()
.padStart(2, "0")}:${resTime.min
.toString()
.padStart(2, "0")}`;
2 years ago
}
},
2 years ago
},
});
},
},
2 years ago
{
title: "持续时间(时)",
width: 140,
align: "center",
key: "last",
2 years ago
render: (h, { row, index }) => {
const getValue = () => {
if (row.start_time && row.end_time) {
const [start_hour,start_min] = row.start_time.split(':')
const [end_hour,end_min] = row.end_time.split(':')
const diffMins = (Number(end_hour) - Number(start_hour)) * 60 + (Number(end_min) - Number(start_min))
return diffMins / 60
}
return 0
}
return h("InputNumber", {
2 years ago
props: {
2 years ago
value: getValue(),
2 years ago
min: 0,
step: 0.5,
size: "small",
2 years ago
precision: 1,
2 years ago
},
on: {
2 years ago
["on-change"]: (e) => {
this.data[index]._last = e;
const [hour, min] = this.data[index].start_time
.split(":")
.map((i) => Number(i));
2 years ago
let addTime = {
hour: Math.floor(e),
2 years ago
min: (e % 1) * 60,
};
2 years ago
let resTime = {
2 years ago
hour:
hour + addTime.hour + (min + addTime.min >= 60 ? 1 : 0),
min: (min + addTime.min) % 60,
};
this.data[index].end_time = `${resTime.hour
.toString()
.padStart(2, "0")}:${resTime.min
.toString()
.padStart(2, "0")}`;
},
},
});
},
2 years ago
},
2 years ago
{
title: "结束时间",
width: 140,
align: "center",
key: "end_time",
render: (h, { row, index }) => {
return h("TimePicker", {
props: {
value: row.end_time,
type: "time",
size: "small",
transfer: true,
2 years ago
format: "HH:mm",
2 years ago
},
on: {
["on-change"]: (e) => (this.data[index].end_time = e),
},
});
},
},
{
title: "调令内容",
minWidth: 200,
key: "content",
align: "center",
render: (h, { row, index }) => {
return h("Input", {
style: {
padding: "6px 0",
},
props: {
size: "small",
value: row.content,
type: "textarea",
},
on: {
["input"]: (e) => (this.data[index].content = e),
},
});
},
},
{
title: "调令等级",
width: 140,
key: "level",
align: "center",
2 years ago
render: (h, { row, index }) => {
2 years ago
return h(
"Select",
{
props: {
value: row.level,
filterable: true,
size: "small",
transfer: true,
},
on: {
["on-select"]: (e) => {
row.level = e.value;
2 years ago
this.data[index].level = e.value;
2 years ago
},
},
},
[
{ label: "一般", value: 1 },
{ label: "紧急", value: 2 },
].map((i) => {
return h(
"Option",
{
props: {
value: i.value,
},
},
i.label
);
})
);
},
},
{
title: "操作",
width: 140,
key: "operate",
render: (h, { row, index }) => {
return h(
"Poptip",
{
props: {
title: "确认要删除吗?",
confirm: true,
transfer: true,
},
on: {
["on-ok"]: (e) => {
this.data.splice(index, 1);
},
},
},
[
h(
"Button",
{
props: {
type: "primary",
size: "small",
},
},
"删除"
),
]
);
},
},
],
};
},
methods: {
2 years ago
handleClone (content) {
if (!content) return;
const groupTemplateData = new Map();
content.sort((a, b) => a.equipment_id - b.equipment_id)
.forEach(item => {
const group = groupTemplateData.get(item.equipment_id) || [];
group.push(item);
groupTemplateData.set(item.equipment_id, group);
});
const dataMap = new Map(this.data.map((item, index) => [item.equipment_id, index]));
groupTemplateData.forEach((group, equipment_id) => {
const findIndex = dataMap.get(equipment_id);
if (findIndex !== undefined) {
const findData = this.data[findIndex];
this.data.splice(findIndex, 0, ...group.map(i => ({ ...findData, ...i })));
}
});
},
async getTemplates() {
this.templateLoading = true;
const res = await index(this.templateSelect);
this.templates = res.data;
this.templateTotal = res.total;
this.templateLoading = false;
},
clone() {
const submitData = this.data.filter(
(i) => i.start_time || i.end_time || i.content
);
let verify = submitData.length > 0;
submitData.forEach((item) => {
if (!item.start_time || !item.end_time) {
2 years ago
verify = false;
}
2 years ago
});
2 years ago
if (!verify) {
this.$message({
2 years ago
type: "warning",
message: "请填写完整信息",
});
return;
2 years ago
}
2 years ago
submitData.forEach((i) => {
delete i["equipment_id-span"];
delete i["_index"];
delete i["_rowKey"];
});
this.$prompt("请输入模板名称", "模板", {
confirmButtonText: "确定",
cancelButtonText: "取消",
inputValidator: (value) => {
return !!value;
},
inputErrorMessage: "请输入模板名称",
}).then(({ value }) => {
save({
table_name: "transfer_templates",
name: value,
content: JSON.stringify(
submitData.map((i) => ({
equipment_id: i.equipment_id,
start_time: i.start_time,
end_time: i.end_time,
content: i.content,
level: i.level,
}))
),
}).then((_) => {
this.$message({
type: "success",
message: "保存成功",
});
});
});
2 years ago
},
2 years ago
clear() {
2 years ago
this.select = {
area: [],
2 years ago
type: [],
2 years ago
};
},
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
const span = column["key"] + "-span";
if (row[span]) {
return row[span];
}
},
2 years ago
reset() {
2 years ago
this.clear();
this.data =
this.equipmentList?.map((i) => ({
2 years ago
equipment: i,
2 years ago
equipment_id: i.id,
start_time: "",
end_time: "",
content: "",
level: 1,
2 years ago
leibie: this.ability,
2 years ago
})) || [];
},
2 years ago
async submit() {
2 years ago
const submitData = this.data.filter(
(i) => i.start_time || i.end_time || i.content
);
let verify = submitData.length > 0;
submitData.forEach((item) => {
2 years ago
if (!item.start_time || !item.end_time || !item.level) {
verify = false;
}
2 years ago
});
2 years ago
if (!verify) {
this.$message({
2 years ago
type: "warning",
message: "请填写完整信息",
});
return;
2 years ago
}
2 years ago
let isNeed = 0;
try {
await this.$confirm("是否需要走流程?","提示",{
confirmButtonText: "需要",
cancelButtonText: "不需要",
type: "info",
closeOnClickModal: false,
distinguishCancelAndClose: true
})
isNeed = 1;
} catch (e) {
if (e === 'cancel') {
isNeed = 0;
} else {
return
}
}
2 years ago
const uid = uuid();
2 years ago
let promiseAll = [];
2 years ago
submitData.forEach((i) => {
delete i["equipment_id-span"];
delete i["_index"];
delete i["_rowKey"];
2 years ago
2 years ago
if (this.createType === 2) {
2 years ago
const startDay = this.$moment(this.date).startOf("week");
2 years ago
let weekArr = [];
2 years ago
for (let a = 1; a <= 7; a++) {
weekArr.push(
this.$moment(startDay).add(a, "days").format("YYYY-MM-DD")
);
2 years ago
}
2 years ago
weekArr.forEach((j) => {
promiseAll.push(
save(
{
...i,
table_name: "transfers",
start_time: `${j} ${i.start_time}`,
end_time: `${j} ${i.end_time}`,
no: uid,
status: 1,
2 years ago
shifouzouliucheng: isNeed
2 years ago
},
false
)
);
});
2 years ago
} else {
i.start_time = `${this.date} ${i.start_time}`;
i.end_time = `${this.date} ${i.end_time}`;
i.no = uid;
i.status = 1;
2 years ago
promiseAll.push(
save(
{
table_name: "transfers",
...i,
2 years ago
shifouzouliucheng: isNeed
2 years ago
},
false
)
);
2 years ago
}
2 years ago
});
2 years ago
let loadingInstance = this.$loading({
2 years ago
lock: true,
background: "rgba(0,0,0,0.4)",
text: "正在加载中...",
});
Promise.all(promiseAll)
.then((res) => {
this.reset();
loadingInstance.close();
this.$message({
type: "success",
message: `成功创建${res.length}条调令`,
});
this.$bus.$emit("createdTransfer");
2 years ago
if (isNeed) {
this.$router.push('/dispatch/handle')
}
2 years ago
})
2 years ago
.catch((_) => {
loadingInstance.close();
});
2 years ago
},
async getArea() {
const obj = (await show({ id: 4 }, false))?.select_item;
if (obj && typeof obj === "object") {
let keys = Object.keys(obj);
if (keys.length > 0) {
this.areas = keys.map((key) => {
return {
key,
value: /^\d*$/.test(obj[key]) ? Number(obj[key]) : obj[key],
};
});
}
}
2 years ago
this.$bus.$emit("areas", this.areas);
2 years ago
},
async getType() {
const obj = (await show({ id: 1 }, false))?.select_item;
if (obj && typeof obj === "object") {
let keys = Object.keys(obj);
if (keys.length > 0) {
this.types = keys.map((key) => {
return {
key,
value: /^\d*$/.test(obj[key]) ? Number(obj[key]) : obj[key],
};
});
}
}
},
2 years ago
async getAbility() {
2 years ago
const obj = (await show({ id: 31 }, false))?.select_item;
2 years ago
if (obj && typeof obj === "object") {
let keys = Object.keys(obj);
if (keys.length > 0) {
this.abilities = keys.map((key) => {
return {
key,
value: /^\d*$/.test(obj[key]) ? Number(obj[key]) : obj[key],
};
});
}
}
2 years ago
this.$bus.$emit("yinpaishui", this.abilities);
2 years ago
},
2 years ago
pickDate() {
this.$bus.$emit("pickDate", this.date);
},
2 years ago
},
computed: {
mergeData() {
return mergeTableRow({
data: this.data.map((i) => {
delete i["equipment_id-span"];
return i;
}),
mergeColNames: ["equipment_id"], // 需要合并的列,默认合并列相同的数据
firstMergeColNames: ["equipment_id"], // 受影响的列只合并以firstMerge为首的同类型数据
firstMerge: "equipment_id", // 以哪列为基础进行合并,一般为第一列
});
},
equipmentList() {
return this.equipments() || [];
2 years ago
},
2 years ago
},
watch: {
equipmentList(val) {
this.data =
val?.map((i) => ({
2 years ago
equipment: i,
2 years ago
equipment_id: i.id,
start_time: "",
end_time: "",
content: "",
level: 1,
2 years ago
leibie: this.ability,
2 years ago
_random: Math.round(Math.random() * 8),
2 years ago
})) || [];
2 years ago
this.handleClone(this.$route.params.cloneTransfer)
2 years ago
},
select: {
handler: function (val) {
if (val.area.length > 0 || val.type.length > 0) {
let list1 = [];
let list2 = [];
if (val.area.length > 0) {
2 years ago
list1 = this.equipments().filter((i) =>
val.area.find((j) => j === i.area)
);
2 years ago
}
if (val.type.length > 0) {
2 years ago
list2 = this.equipments().filter((i) =>
val.type.find((j) => j === i.type)
);
2 years ago
}
2 years ago
this.data =
Array.from(new Set([...list1, ...list2].map(JSON.stringify)))
.map(JSON.parse)
.map((i) => ({
equipment: i,
equipment_id: i.id,
start_time: "",
end_time: "",
content: "",
level: 1,
leibie: this.ability,
})) || [];
2 years ago
} else {
2 years ago
this.data =
this.equipments()?.map((i) => ({
equipment: i,
equipment_id: i.id,
start_time: "",
end_time: "",
content: "",
level: 1,
leibie: this.ability,
})) || [];
2 years ago
}
},
2 years ago
deep: true,
},
2 years ago
},
mounted() {},
created() {
2 years ago
this.$bus.$on(
"getDispatches",
(dispatches) => (this.dispatches = dispatches)
);
2 years ago
this.getArea();
this.getType();
2 years ago
this.getAbility();
2 years ago
},
2 years ago
destroyed() {
2 years ago
this.$bus.$off("getDispatches");
},
2 years ago
};
</script>
<style scoped lang="scss">
.flex-center {
display: flex;
align-items: center;
justify-content: center;
}
.select {
&-item {
display: flex;
align-items: center;
&__title {
2 years ago
width: 80px;
2 years ago
flex-shrink: 0;
font-weight: 600;
text-align: center;
}
& + & {
margin-top: 10px;
}
}
.date {
display: flex;
align-items: center;
padding: 10px;
}
}
.btns {
margin-top: 10px;
padding-left: 10px;
}
</style>