<template>
|
<div class="search-box-test" :class="{ 'is-expand': isExpand }">
|
<el-form :model="searchForm" inline>
|
<div class="search-first">
|
<el-form-item>
|
<el-input class="ztzf-input" v-model="searchForm.key_word" placeholder="请输入任务/机巢名称" clearable />
|
</el-form-item>
|
<el-form-item label="行政区划:">
|
<el-select :teleported="false" class="ztzf-select" v-model="searchForm.area_code" @change="deptChange" placeholder="请选择部门" clearable>
|
<el-option v-for="item in deptTreeData" :key="item.area_code" :label="item.area_name" :value="item.area_code" />
|
</el-select>
|
</el-form-item>
|
<el-form-item label="所属机巢:">
|
<el-select :teleported="false" class="ztzf-select" v-model="searchForm.device_sn" placeholder="请选择机巢" clearable>
|
<el-option v-for="item in machineData" :key="item.device_sn" :label="item.nickname" :value="item.device_sn" />
|
</el-select>
|
</el-form-item>
|
<el-form-item>
|
<el-date-picker
|
popper-class="custom-date-picker"
|
class="ztzf-date-picker"
|
v-model="dateRange"
|
type="daterange"
|
range-separator="至"
|
start-placeholder="开始日期"
|
end-placeholder="结束日期"
|
value-format="YYYY-MM-DD"
|
@change="handleDateChange"
|
/>
|
</el-form-item>
|
<el-form-item>
|
<div class="time-card">
|
<div
|
class="card-item"
|
:class="item === checked ? 'active' : ''"
|
v-for="(item, index) in timeList"
|
@click="timeClick(item,index)"
|
>
|
{{ timeListStr[index] }}
|
</div>
|
</div>
|
</el-form-item>
|
<el-form-item label="任务算法:" v-if="isExpand">
|
<TaskAlgorithmBusiness :setWidth="186" :showAlgorithm="true" @algorithmChange="algorithmChange"/>
|
</el-form-item>
|
<el-form-item label="所属部门:" v-if="isExpand">
|
<el-select :teleported="false" class="ztzf-select" v-model="searchForm.create_dept" placeholder="请选择部门" clearable>
|
<el-option v-for="item in deptData" :key="item.id" :label="item.deptName" :value="item.id" />
|
</el-select>
|
</el-form-item>
|
<el-form-item label="任务状态:" v-if="isExpand">
|
<el-select :teleported="false" class="ztzf-select" v-model="searchForm.status" placeholder="请选择状态" clearable>
|
<el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value" />
|
</el-select>
|
</el-form-item>
|
<el-form-item label="任务类型:" v-if="isExpand">
|
<TaskAlgorithmBusiness :setWidth="186" :showBusiness="true" @businessChange="businessChange"/>
|
</el-form-item>
|
<div class="more" v-if="isExpand" @click="toggleExpand">收起</div>
|
<div class="more" v-else @click="toggleExpand">更多</div>
|
<div class="search-btn">
|
<img @click="handleReset" src="@/assets/images/task/reset.png" alt="">
|
<img @click="handleSearch" src="@/assets/images/task/search.png" alt="">
|
<img @click="addTask" src="@/assets/images/task/create.png" alt="">
|
</div>
|
</div>
|
</el-form>
|
</div>
|
</template>
|
<script setup>
|
import { pxToRem } from '@/utils/rem'
|
import { ElMessage } from 'element-plus'
|
import { deptsByAreaCode, getDockInfo } from '@/api/home/common';
|
import TaskAlgorithmBusiness from './components/TaskAlgorithmBusiness.vue';
|
import dayjs from 'dayjs';
|
import { useStore } from 'vuex'
|
|
const store = useStore()
|
const isExpand = ref(false);
|
const toggleExpand = () => {
|
isExpand.value = !isExpand.value;
|
};
|
|
const dateRange = ref([]);
|
const searchForm = reactive({
|
ai_types: [], // 算法类型
|
area_code: '', // 区域code
|
create_dept: '', // 创建部门
|
date_enum: 'TODAY', // 日期枚举,可用值:TODAY,CURRENT_WEEK,CURRENT_MONTH,CURRENT_YEAR
|
device_sn: '', // 设备编号
|
end_date: null, // 结束时间
|
industry_type: '', // 行业key
|
key_word: '', // 模糊搜索关键词(匹配名称/昵称/设备sn)
|
start_date: null, // 开始时间
|
status: '' // 作业状态
|
});
|
|
const statusOptions = [
|
{ label: '待执行', value: 1 },
|
{ label: '执行中', value: 2 },
|
{ label: '已完成', value: 3 },
|
{ label: '已取消', value: 4 },
|
{ label: '执行失败', value: 5 }
|
];
|
|
const emit = defineEmits(['search','addTask']);
|
|
const algorithmChange = (val) => {
|
searchForm.ai_types = val;
|
};
|
|
const businessChange = (val) => {
|
searchForm.industry_type = val;
|
};
|
|
let deptData = ref([]);
|
// 所属部门信息
|
const getDeptsByAreaCode = () => {
|
deptsByAreaCode(searchForm.area_code).then((res) => {
|
if (res.code !== 0) {
|
deptData.value = res.data.data;
|
}
|
});
|
};
|
|
// 部门
|
let deptTreeData = ref([]);
|
// 机巢
|
let machineData = ref([]);
|
|
// 部门下得机巢
|
const requestDockInfo = () => {
|
getDockInfo().then((res) => {
|
if (res.data.code !== 0) return;
|
// handleDeptData(res.data.data);
|
deptTreeData.value = res.data.data;
|
});
|
};
|
const deptChange = (value) => {
|
// 处理机巢数据
|
searchForm.device_sn = '';
|
machineData.value = '';
|
machineData.value = deptTreeData.value.find(item => item.area_code === value)?.devices || [];
|
// 所属部门重新请求值
|
searchForm.create_dept = '';
|
deptData.value = [];
|
getDeptsByAreaCode();
|
};
|
|
// 日期 和周期
|
let timeList = ['today', 'week', 'month', 'year'];
|
let timeListStr = ['今日', '本周', '本月', '本年'];
|
let timeListEnum = ['TODAY', 'CURRENT_WEEK', 'CURRENT_MONTH', 'CURRENT_YEAR'];
|
let checked = ref('today');
|
|
const getDateRange = unit => {
|
if (unit === 'today') {
|
return [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')];
|
}
|
return [dayjs().startOf(unit).format('YYYY-MM-DD'), dayjs().endOf(unit).format('YYYY-MM-DD')];
|
};
|
|
const dateRanges = {
|
today: getDateRange('today'),
|
week: getDateRange('week'),
|
month: getDateRange('month'),
|
year: getDateRange('year'),
|
};
|
|
let timeClick = (item,index) => {
|
checked.value = item;
|
// dateRange.value = dateRanges[item];
|
dateRange.value = [];
|
// emit('change', dateRanges[item],timeListEnum[index]);
|
searchForm.date_enum = timeListEnum[index];
|
handleSearch();
|
};
|
// 搜索
|
const handleSearch = () => {
|
if (!dateRange.value) { dateRange.value = []; }
|
if (dateRange.value && dateRange.value.length) {
|
// 有值时 清除 日 本周 本月 本年状态
|
checked.value = '';
|
}
|
// 提交至store
|
let params = {
|
...searchForm,
|
start_date: dateRange.value.length ? `${dateRange?.value[0]} 00:00:00` : null,
|
end_date: dateRange.value.length ? `${dateRange?.value[1]} 23:59:59` : null
|
}
|
store.commit('setTaskSearchParams', params);
|
emit('search', params);
|
};
|
const handleDateChange = (val) => {
|
if (val && val.length === 2) {
|
const start = dayjs(val[0])
|
const end = dayjs(val[1])
|
const diff = end.diff(start, 'day')
|
|
if (diff > 30) {
|
ElMessage.warning('日期范围不能超过30天')
|
dateRange.value = []
|
return
|
}
|
}
|
handleSearch()
|
};
|
// 重置
|
const handleReset = () => {
|
dateRange.value = [];
|
Object.keys(searchForm).forEach(key => {
|
searchForm[key] = '';
|
});
|
searchForm.ai_types = [];
|
searchForm.date_enum = 'TODAY';
|
checked.value = 'today';
|
handleSearch();
|
};
|
|
// 新增任务
|
const addTask = () => {
|
emit('addTask');
|
};
|
|
onMounted(() => {
|
getDeptsByAreaCode();
|
requestDockInfo();
|
// 查询一次
|
handleSearch();
|
});
|
</script>
|
<style lang="scss">
|
/* 修改日期单元格背景色 */
|
.custom-date-picker .el-picker-panel__body {
|
background: #012350 !important;
|
color: #fff !important;
|
}
|
</style>
|
<style lang="scss" scoped>
|
.search-box-test {
|
transition: all 0.3s;
|
.search-first {
|
position: relative;
|
display: flex;
|
flex-wrap: wrap;
|
align-items: center;
|
gap: 20px 12px; // 设置行间距和列间距
|
.more {
|
cursor: pointer;
|
width: 32px;
|
height: 32px;
|
color: #60B2FF;
|
line-height: 32px;
|
font-size: 16px;
|
}
|
.search-btn {
|
position: absolute;
|
right: 0;
|
bottom: 2px;
|
cursor: pointer;
|
img {
|
width: 82px;
|
height: 32px;
|
margin-right: 10px;
|
}
|
}
|
.time-card {
|
text-align: center;
|
background: linear-gradient(270deg, #195bad 0%, rgba(25, 91, 173, 0) 100%);
|
border: 1px solid #306fca;
|
font-family: Source Han Sans CN, Source Han Sans CN, serif;
|
font-weight: 400;
|
font-size: 14px;
|
color: #ffffff;
|
display: flex;
|
height: 32px;
|
|
.card-item {
|
width: 66px;
|
height: 100%;
|
line-height: 32px;
|
cursor: pointer;
|
}
|
|
.active {
|
background: linear-gradient(270deg, #19ad8d 0%, rgba(25, 173, 141, 0) 100%);
|
box-shadow: inset 0px 0px 8px 0px rgba(0, 255, 200, 0.6);
|
border-radius: 0px 0px 0px 0px;
|
}
|
}
|
}
|
:deep(.el-form) {
|
:deep(.el-input__wrapper.is-disabled) {
|
background-color: #021740;
|
box-shadow: 0 0 0 1px #026AD6;
|
}
|
.el-form-item {
|
margin-bottom: 0;
|
margin-right: 20px;
|
width: 260px;
|
|
.el-form-item__label {
|
color: #fff;
|
line-height: 32px;
|
}
|
|
}
|
}
|
}
|
</style>
|