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.

596 lines
16 KiB

3 years ago
<template>
<div>
<div class="select">
3 years ago
3 years ago
<div class="select-item">
3 years ago
<div class="select-item__title">选择范围</div>
3 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">
3 years ago
<div class="select-item__title">选择泵闸</div>
3 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>
3 years ago
<div class="select-item">
3 years ago
<div class="select-item__title">选择类别</div>
<el-radio-group size="small" v-model="ability" @input="e => data.forEach(i => i.leibie = e)">
3 years ago
<el-radio-button v-for="item in abilities" :label="item.value">{{
item.key
}}</el-radio-button>
</el-radio-group>
</div>
3 years ago
<div class="select-item">
<Button type="primary" style="margin-left: 10px" @click="clear"
>清空筛选</Button
>
</div>
<div class="date">
<p>
您正在为
<span style="color: red">{{ date }}</span>
创建
3 years ago
<span style="color: red;"> {{ abilities.find(i => i.value === ability) ? abilities.find(i => i.value === ability).key : '' }} </span>
3 years ago
调令
</p>
2 years ago
<!-- <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>-->
2 years ago
<el-date-picker
2 years ago
size="small"
2 years ago
v-model="date"
:type="createType === 1 ? 'date' : 'week'"
value-format="yyyy-MM-dd"
:picker-options="pickerOptions"
3 years ago
placeholder="日期选择"
2 years ago
:format="createType === 1 ? 'yyyy-MM-dd' : 'yyyy第WW周'"
3 years ago
style="width: 160px; margin-left: 14px"
2 years ago
@input="pickDate"
2 years ago
></el-date-picker>
3 years ago
</div>
</div>
<Table
: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>
</div>
</div>
</template>
<script>
3 years ago
import { uuid } from "@/utils";
3 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: {
},
3 years ago
data() {
return {
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);
}
}]
3 years ago
},
areas: [],
types: [],
3 years ago
abilities: [],
3 years ago
select: {
area: [],
type: [],
3 years ago
leibie: [],
3 years ago
},
weather: [],
copyOriginalData: [],
date: this.$moment().format("YYYY-MM-DD"),
3 years ago
ability: 1,
3 years ago
data:
this.equipmentList?.map((i) => ({
3 years ago
equipment: i,
3 years ago
equipment_id: i.id,
start_time: "",
end_time: "",
content: "",
level: 1,
3 years ago
leibie: this.ability
3 years ago
})) || [],
columns: [
// {
// width: 50,
// title: ' ',
// type: 'index',
// key: 'index'
// },
{
title: "点位",
width: 240,
key: "equipment_id",
align: "center",
render: (h, { row, index }) => {
3 years ago
let text = row.equipment ? row.equipment.name : "";
3 years ago
return h("div", [
h('span',text),
h('Button',{
props: {
size: 'small',
type: 'primary',
icon: 'ios-add'
},
style: {
'margin-left': '6px'
},
on: {
['click']:e => {
this.data.splice(index,0,deepCopy(row))
}
}
},'新增')
]);
},
3 years ago
},
{
title: '机组运行状态',
width: 200,
2 years ago
render: (h,{ row }) => {
3 years ago
const create = () => {
let dom = [];
2 years ago
for (let i = 0;i<=row._random;i++) {
3 years ago
dom.push(h('div',{
style: {
width: '14px',
height: '14px',
2 years ago
background: i === row._random-1 ? 'red' : 'green',
3 years ago
'border-radius': '100%',
'margin-left': '6px'
}
}))
}
return dom;
}
return h('div',{
style: {
display: 'flex'
}
},create())
}
},
{
3 years ago
title: '类别',
3 years ago
key: 'yinpaishui',
width: 100,
align: 'center',
3 years ago
render: (h,{ row }) => (h('span',this.abilities.find(i => i.value === row.leibie)?.key))
3 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"
3 years ago
},
on: {
["on-change"]: (e) => (this.data[index].start_time = e),
},
});
},
},
{
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"
3 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 }) => {
3 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;
3 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: {
clear () {
this.select = {
area: [],
3 years ago
type: []
3 years ago
};
},
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
const span = column["key"] + "-span";
if (row[span]) {
return row[span];
}
},
reset () {
this.clear();
this.data =
this.equipmentList?.map((i) => ({
3 years ago
equipment: i,
3 years ago
equipment_id: i.id,
start_time: "",
end_time: "",
content: "",
level: 1,
3 years ago
leibie: this.ability
3 years ago
})) || [];
},
submit () {
let verify = true;
const submitData = this.data.filter(i => (i.start_time || i.end_time || i.content));
submitData.forEach(item => {
if (!item.start_time || !item.end_time || !item.level) {
verify = false;
}
})
if (!verify) {
this.$message({
type: 'warning',
message: '请填写完整信息'
})
return
}
3 years ago
const uid = uuid();
2 years ago
let promiseAll = [];
submitData.forEach(i => {
3 years ago
delete i['equipment_id-span']
delete i['_index']
delete i['_rowKey']
2 years ago
if (this.createType === 2) {
const startDay = this.$moment(this.date).startOf('week')
let weekArr = [];
for(let a = 1;a <= 7;a++) {
weekArr.push(this.$moment(startDay).add(a,'days').format('YYYY-MM-DD'))
}
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
},false))
})
} else {
i.start_time = `${this.date} ${i.start_time}`;
i.end_time = `${this.date} ${i.end_time}`;
i.no = uid;
i.status = 1;
promiseAll.push(save({
table_name: 'transfers',
...i
},false))
}
3 years ago
})
let loadingInstance = this.$loading({
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}条调令`
})
3 years ago
this.$bus.$emit('createdTransfer')
3 years ago
}).catch(_ => {
loadingInstance.close();
})
},
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],
};
});
}
}
3 years ago
this.$bus.$emit('areas',this.areas)
3 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],
};
});
}
}
},
3 years ago
async getAbility () {
3 years ago
const obj = (await show({ id: 31 }, false))?.select_item;
3 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],
};
});
}
}
this.$bus.$emit('yinpaishui',this.abilities)
2 years ago
},
pickDate () {
this.$bus.$emit('pickDate',this.date)
3 years ago
}
3 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() || [];
},
},
watch: {
equipmentList(val) {
this.data =
val?.map((i) => ({
3 years ago
equipment: i,
3 years ago
equipment_id: i.id,
start_time: "",
end_time: "",
content: "",
level: 1,
2 years ago
leibie: this.ability,
_random: Math.round(Math.random() * 8)
3 years ago
})) || [];
},
select: {
handler: function (val) {
if (val.area.length > 0 || val.type.length > 0) {
let list1 = [];
let list2 = [];
if (val.area.length > 0) {
3 years ago
list1 = this.equipments().filter(i => val.area.find(j => j === i.area))
3 years ago
}
if (val.type.length > 0) {
3 years ago
list2 = this.equipments().filter(i => val.type.find(j => j === i.type))
3 years ago
}
this.data = Array.from(new Set([...list1,...list2].map(JSON.stringify))).map(JSON.parse).map((i) => ({
3 years ago
equipment: i,
3 years ago
equipment_id: i.id,
start_time: "",
end_time: "",
content: "",
level: 1,
3 years ago
leibie: this.ability
3 years ago
})) || [];
} else {
this.data = this.equipments()?.map((i) => ({
3 years ago
equipment: i,
3 years ago
equipment_id: i.id,
start_time: "",
end_time: "",
content: "",
level: 1,
3 years ago
leibie: this.ability
3 years ago
})) || [];
3 years ago
}
},
deep: true
}
},
mounted() {},
created() {
this.getArea();
this.getType();
3 years ago
this.getAbility();
3 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 {
3 years ago
width: 80px;
3 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>