319 lines
7.2 KiB
Vue
319 lines
7.2 KiB
Vue
<template>
|
||
<view class="content">
|
||
<!-- <view style="width: 100%; height: 44px;"></view>-->
|
||
<!-- <view class="top-heder">-->
|
||
<!-- <view class="t-left" @click="getback()">-->
|
||
<!-- <uni-icons type="left" size="18"></uni-icons>-->
|
||
<!-- </view>-->
|
||
<!-- <view class="t-title">-->
|
||
<!-- <text>选择检测内容</text>-->
|
||
<!-- </view>-->
|
||
<!-- <view class="t-you"></view>-->
|
||
<!-- </view>-->
|
||
<headersVue titles="选择检测内容" style="position: static !important;">
|
||
<u-icon name="arrow-left" color="#fff" size="18"></u-icon>
|
||
</headersVue>
|
||
<view class="cont_box">
|
||
|
||
<view class="title_" style="display: flex;justify-content: space-between">
|
||
可选检测内容:
|
||
<view style="display: flex">
|
||
双燃料
|
||
<u-switch v-model="value" @change="change"></u-switch>
|
||
</view>
|
||
</view>
|
||
<view class="box_">
|
||
<view class="box_button " :class="{ 'box_button_x' :isItemSelected(item) }"
|
||
v-for="item in inpectionProjects" @click="clickProject(item)">{{ item.projectName }}
|
||
</view>
|
||
</view>
|
||
|
||
<view class="title_">
|
||
已选检测内容:
|
||
</view>
|
||
<view style="margin-bottom: 15px;" v-for="(item,index) in selectProject" :key="index">
|
||
<view class="steps_" style="justify-content: space-between;">
|
||
<view style="display: flex;">
|
||
<view class="index_">{{ index + 1 }}</view>
|
||
<view style="font-size: 20px; font-weight: bold;">{{ item.projectName }}</view>
|
||
</view>
|
||
<u-number-box v-model="item.change" :max="2"></u-number-box>
|
||
</view>
|
||
<view class="xb_" v-if="index != selectProject.length - 1 ">↓</view>
|
||
</view>
|
||
|
||
<!-- <u-steps activeColor="#0D2E8D" direction="column">
|
||
<u-steps-item :iconSize="iconSize" v-for="item in selectProject" :title="item.projectName">
|
||
</u-steps-item>
|
||
|
||
</u-steps> -->
|
||
|
||
|
||
</view>
|
||
|
||
|
||
<view class="dlanniu" @click="sureChoose()">
|
||
<text>确定选择</text>
|
||
</view>
|
||
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import request from '../../utils/request';
|
||
import {
|
||
getDictDataByType
|
||
} from '../../utils/utils';
|
||
import headersVue from "@/components/header/headers.vue";
|
||
|
||
export default {
|
||
components: {
|
||
headersVue
|
||
},
|
||
data() {
|
||
return {
|
||
iconSize: 130,
|
||
inpectionProjects: [],
|
||
selectProject: [],
|
||
defaultProjects: ['登录', '环保'],
|
||
value: false
|
||
}
|
||
},
|
||
onShow() {
|
||
this.getProjects()
|
||
|
||
},
|
||
async onLoad(options) {
|
||
const projects = await getDictDataByType("inspection_defalut_project")
|
||
if (projects.length != 0) {
|
||
this.defaultProjects = projects
|
||
.filter(item => item.value !== undefined)
|
||
.map(item => item.value);
|
||
}
|
||
if (options.selectProject) {
|
||
this.selectProject = JSON.parse(options.selectProject);
|
||
// 去重(假设用 id 作为唯一标识)
|
||
this.selectProject = this.selectProject.reduce((acc, current) => {
|
||
const exists = acc.some(item => item.id === current.id);
|
||
if (!exists) {
|
||
acc.push(current);
|
||
}
|
||
return acc;
|
||
}, []);
|
||
}
|
||
},
|
||
methods: {
|
||
sureChoose() {
|
||
if (this.selectProject.length === 0) {
|
||
uni.showToast({
|
||
title: '请选择项目!',
|
||
icon: 'none'
|
||
});
|
||
return;
|
||
}
|
||
|
||
const newList = [];
|
||
|
||
this.selectProject.forEach(item => {
|
||
item.projectId = item.id;
|
||
newList.push(item);
|
||
|
||
if (item.change === 2) {
|
||
const copiedItem = JSON.parse(JSON.stringify(item));
|
||
// 如有需要,可为复制项设置新 id 或做其他标记
|
||
newList.push(copiedItem);
|
||
}
|
||
});
|
||
|
||
this.selectProject = newList;
|
||
console.log(this.selectProject);
|
||
uni.$emit('selectProject', this.selectProject);
|
||
this.getback();
|
||
},
|
||
isItemSelected(item) {
|
||
return this.selectProject.findIndex(project => project.id === item.id) > -1;
|
||
},
|
||
getback() {
|
||
uni.navigateBack()
|
||
},
|
||
change(e) {
|
||
console.log('switch changed', e); // 开关状态变化
|
||
|
||
if (e) { // 当双燃料开关打开时(e为true)
|
||
// 必须选中的项目(登录、环保)
|
||
|
||
this.defaultProjects.forEach(projectName => {
|
||
// 检查是否已选中该项目
|
||
const existingProject = this.selectProject.find(
|
||
project => project.projectName.includes(projectName)
|
||
);
|
||
|
||
if (existingProject) {
|
||
// 如果已选中,设置 change=2(强制选中状态)
|
||
this.$set(existingProject, 'change', 2);
|
||
} else {
|
||
// 如果未选中,从全部项目中查找并添加
|
||
const projectToAdd = this.inpectionProjects.find(
|
||
project => project.projectName.includes(projectName)
|
||
);
|
||
|
||
if (projectToAdd) {
|
||
projectToAdd.change = 2; // 标记为必须选中
|
||
this.selectProject.push(projectToAdd);
|
||
}
|
||
}
|
||
});
|
||
|
||
this.$forceUpdate(); // 强制更新视图
|
||
console.log('selected projects', this.selectProject); // 打印当前选中项目
|
||
}
|
||
},
|
||
async getProjects() {
|
||
let res = await request({
|
||
url: '/inspection/dl-inspection-project/page',
|
||
method: 'get',
|
||
params: {
|
||
pageNo: 1,
|
||
pageSize: 100
|
||
}
|
||
|
||
})
|
||
this.inpectionProjects = res.data.records
|
||
},
|
||
clickProject(data) {
|
||
let idx = this.selectProject.findIndex(project => project.id === data.id)
|
||
if (idx > -1) {
|
||
// 如果元素存在于数组中,则使用splice方法来删除它
|
||
this.selectProject.splice(idx, 1);
|
||
} else {
|
||
data.change = 1
|
||
this.selectProject.push(data)
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style scoped>
|
||
.steps_ {
|
||
display: flex;
|
||
align-items: center;
|
||
|
||
}
|
||
|
||
.cont_box {
|
||
box-sizing: border-box;
|
||
padding: 10px;
|
||
}
|
||
|
||
.title_ {
|
||
font-weight: bold;
|
||
margin-bottom: 5px;
|
||
}
|
||
|
||
.box_ {
|
||
width: 100%;
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
.box_button_x {
|
||
border-radius: 6px;
|
||
border: 1px solid #0174F6;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 18px;
|
||
box-sizing: border-box;
|
||
padding: 10px 15px;
|
||
margin-right: 15px;
|
||
margin-bottom: 15px;
|
||
background: #0174F6;
|
||
color: #fff;
|
||
}
|
||
|
||
.box_button {
|
||
|
||
border-radius: 6px;
|
||
border: 1px solid #999;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 18px;
|
||
box-sizing: border-box;
|
||
padding: 10px 15px;
|
||
margin-right: 15px;
|
||
margin-bottom: 15px;
|
||
}
|
||
|
||
.dlanniu {
|
||
width: 80%;
|
||
height: 45px;
|
||
background: linear-gradient(180deg, #3F61C0 0%, #0174F6 100%);
|
||
border-radius: 50px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
margin: 20px auto;
|
||
color: white;
|
||
}
|
||
|
||
.t-you {
|
||
height: 100%;
|
||
width: 20%;
|
||
}
|
||
|
||
.content {
|
||
box-sizing: border-box;
|
||
width: 100%;
|
||
height: calc(100vh);
|
||
background: white;
|
||
}
|
||
|
||
.top-heder {
|
||
width: 100%;
|
||
height: 46px;
|
||
background: white;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
box-sizing: border-box;
|
||
padding: 5px 15px;
|
||
}
|
||
|
||
.t-title {
|
||
font-size: 17px;
|
||
font-weight: bold;
|
||
color: #333333;
|
||
}
|
||
|
||
.t-left {
|
||
width: 10%;
|
||
}
|
||
|
||
.index_ {
|
||
width: 35px;
|
||
height: 35px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
color: #fff;
|
||
font-weight: bold;
|
||
font-size: 18px;
|
||
background: #0174F6;
|
||
border-radius: 50%;
|
||
margin-right: 10px;
|
||
}
|
||
|
||
.xb_ {
|
||
width: 35px;
|
||
height: 35px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
color: #0174F6;
|
||
font-size: 22px;
|
||
font-weight: bold;
|
||
}
|
||
</style> |