微信小程序实现-单选-以及全选功能。 - 教程

news/2025/9/18 22:18:15/文章来源:https://www.cnblogs.com/yxysuanfa/p/19099831

在这里插入图片描述
html:

<view class="list"><view class="operation-buttons"><button class="btn add-btn" bindtap="addNew">新增</button><button class="btn delete-btn" bindtap="deleteSelected">删除</button><button class="btn publish-btn" bindtap="publish">发布</button><button class="btn task-btn" bindtap="assignTask">异常任务</button></view><!-- 说明文字 --><view class="note"><text class="star">*</text>以下"时间"为开始时间</view><!-- 列表头部(带全选) --><view class="list-header"><view class="list-item header"><checkbox-group bindchange="onCheckAllChange"><checkboxchecked="{{allChecked}}"value="all"class="checkbox"/></checkbox-group></view><view class="header-item">车牌号</view><view class="header-item">班次</view><view class="header-item">套班</view><view class="header-item">时间</view></view><view class="vehicle-list"><view class="list-container"><checkbox-group bindchange="onItemCheck"><view class="vehicle-item" wx:for="{{items}}" wx:key="id"><checkboxchecked="{{item.checked}}"value="{{item.id}}"class="item-checkbox"/><view class="item-content">{{item.plateNumber}}</view><view class="item-content">{{item.shiftTypeStr}}</view><view class="item-content">{{item.mainShiftFlagStr}}</view><view class="item-content">{{item.beginTime}}</view></view></checkbox-group></view></view></view>

js:

const requestApi = require('../../../../utils/request.js');
const app = getApp();
Page({
data: {
items: [],//渲染的数据
// 全选状态
allChecked: false,
// 选中的项目
selectedItems: [],
isFilterShow: false,
routeName:'',
startPoint:'',
endPoint:'',
pageNum:1,
routeid:'',
date:'',
endDate:'',
operationDateArray:["星期一","星期二","星期三","星期四","星期五"],
},
onLoad(options) {
this.setData({
routeName: options.routeName?options.routeName:'',
startPoint: options.startPoint?options.startPoint:'',
endPoint: options.endPoint?options.endPoint:'',
routeid: options.id
});
const newModel = this.data.items.map(item =>
{
return {
...item,
checked: false
};
});
this.setData({
items: newModel
});
this.getList();
},
getList: function () {
},
// 全选框状态改变
onCheckAllChange(e) {
const checked = e.detail.value.includes('all');
console.log('全选状态改变:', checked);
// 更新所有选项的选中状态
const updatedItems = this.data.items.map(item =>
({
...item,
checked: checked
}));
// 更新数据
this.setData({
allChecked: checked,
items: updatedItems,
selectedItems: checked ? [...updatedItems] : []
});
},
// 列表项状态改变
onItemCheck(e) {
const selectedIds = e.detail.value;
console.log('选中的ID:', selectedIds);
// 更新每个选项的选中状态
const updatedItems = this.data.items.map(item =>
({
...item,
checked: selectedIds.includes(item.id)
}));
// 检查是否所有选项都被选中
const allChecked = updatedItems.every(item => item.checked);
// 获取选中的项目
const selectedItems = updatedItems.filter(item => item.checked);
// 更新数据
this.setData({
items: updatedItems,
allChecked: allChecked,
selectedItems: selectedItems
});
},
deleteSelected() {
if (this.data.selectedItems.length === 0) {
wx.showToast({
title: '没有选中任何删除项',
icon: 'none'
});
return;
}
const plateNumber = this.data.selectedItems.map(item => item.plateNumber).join(', ');
const shanchuid = this.data.selectedItems.map(item => item.id).join(', ');
wx.showModal({
title: '提示',
content: `确定要删除选中的 ${plateNumber
} 辆车吗?`,
success: function (res) {
if (res.confirm) {
} else {
console.log('用户点击取消')
}
}
})
},
//确定按钮
confirmDispatch(){
if (this.data.selectedItems.length === 0) {
wx.showToast({
title: '没有选中任何项',
icon: 'none'
});
return;
}
const shanchuid = this.data.selectedItems.map(item => item.id).join(', ');
console.log(shanchuid,'8552221');
var that = this;
wx.showLoading({
title: '加载中...',
});
requestApi.post("", {
ids:[shanchuid],
operationDateArray:this.data.operationDateArray,
dateTimeValue:[this.data.endDate,this.data.date],
}).then(res =>
{
wx.showToast({
title: '发布成功',
icon: 'success',
duration: 2000
})
this.getList();
}).catch(err =>
{
wx.hideLoading();
wx.hideNavigationBarLoading();
wx.stopPullDownRefresh();
wx.showToast({
title: '数据获取异常',
icon: 'none',
duration: 3000,
});
});
},
publish() {
const isShow = !this.data.isFilterShow;
this.setData({ isFilterShow: isShow
});
},
hideModal(){
this.setData({
isFilterShow: false
});
},
bindDateChange(e) {
this.setData({
date: e.detail.value
});
},
bindendDateChange(e){
this.setData({
endDate: e.detail.value
});
},
addNew(){
wx.navigateTo({
url: '../addShift/addShift',
})
},
assignTask(){
wx.navigateTo({
url: '../exceptionalTask/exceptionalTask',
})
},
});

样式:

.container {
padding: 16rpx;
}
/* 线路信息样式 */
.route-info {
width: 95%;
background-color: white;
border-radius: 14rpx;
padding: 20rpx;
margin-bottom: 20rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
}
.route-title {
font-size: 34rpx;
font-weight: bold;
color: #333;
margin-bottom: 16rpx;
}
.route-details {
display: flex;
flex-direction: column;
gap: 12rpx;
}
.route-item {
display: flex;
font-size: 30rpx;
}
.label {
font-size: 35rpx;
color: #3f3f3f;
min-width: 120rpx;
}
.value {
color: #333;
flex: 1;
}
/* 操作按钮样式 */
.operation-buttons {
display: flex;
gap: 16rpx;
flex-wrap: wrap;
padding: 20rpx 20rpx 0rpx 20rpx;
}
.btn {
flex: 1;
min-width: 160rpx;
height: 75rpx;
line-height:75rpx;
text-align: center;
border-radius: 50rpx;
border: none;
padding: 0;
font-weight: 400;
font-size: 33rpx;
color: #FFFFFF;
}
.add-btn {
background-color: #1A73E8;
}
.delete-btn {
background-color: #F44336;
}
.publish-btn {
background-color: #4CAF50;
}
.task-btn {
background-color: #FF9800;
}
/* 说明文字样式 */
.note {
width: 100%;
color: #D90B0B;
font-size: 30rpx;
margin-bottom: 20rpx;
padding-left: 45rpx;
}
.star {
color: #F44336;
}
/* 列表样式 */
.list {
width: 100%;
background-color: white;
border-radius: 14rpx;
}
.list-header {
display: flex;
align-items: center;
padding: 0 20rpx;
height: 80rpx;
font-size: 28rpx;
font-weight: bold;
color: #333;
}
.select-all {
margin-right: 16rpx;
}
.header-item {
flex: 1;
text-align: center;
font-family: Source Han Sans CN;
font-weight: bold;
font-size: 33rpx;
color: #000000;
line-height: 50rpx;
}
.vehicle-list {
width: 100%;
background-color: white;
border-radius: 0 0 8rpx 8rpx;
margin-bottom: 20rpx;
}
.vehicle-item {
display: flex;
align-items: center;
padding: 0 20rpx;
height: 90rpx;
border-bottom: 1px solid #eee;
font-size: 33rpx;
color: #333;
}
.vehicle-item:last-child {
border-bottom: none;
}
.item-checkbox {
margin-right: 16rpx;
}
.item-content {
color: #000000;
flex: 1;
text-align: center;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* 弹出层和筛选区域样式 */
.modal-mask {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}
.filter-area {
position: fixed;
background-color: #fff;
width: 90%;
height: 40%;
z-index: 999;
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 20rpx;
text-align: center;
padding-top: 20rpx;
}
.modal-form-item {
display: flex;
align-items: center;
margin: 20rpx;
padding: 10rpx;
background-color: #f5f7f9;
}
.modal-label {
width: 217rpx;
font-size: 35rpx;
color: #000;
}
.filter-picker {
flex: 1;
padding: 10rpx;
border-radius: 5rpx;
font-size: 35rpx;
/* border: 1rpx solid #eee; */
}
.modal-btn-group {
display: flex;
justify-content: flex-end;
margin-top: 40rpx;
}
.modal-btn {
width: 280rpx !important;
height: 80rpx;
line-height: 50rpx;
text-align: center;
margin-left: 20rpx;
}
.cancel-btn {
background-color: #fff;
border: 1rpx solid #ccc;
}
.confirm-btn {
background-color: #007aff;
color: #fff;
}
.module-icon {
width: 70rpx;
height: 70rpx;
margin-right:12rpx;
/* margin-top:15rpx; */
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/907471.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Typescript中闭包的原理 - 教程

Typescript中闭包的原理 - 教程pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco&quo…

CF2048H Kevin and Strange Operation

操作的自由度很大,打表可以发现限制操作的位置只增不减也是对的。 考虑怎么判断一个串 \(t\) 是否合法。 观察到对于一个位置 \(i\) 满足 \(s_i=0\),想要通过操作使 \(s_i\) 变为 \(1\),只需要 \(>i\) 的位置删掉…

Hadoop本地库加载问题分析与解决方案

主要问题分析 ​​本地库加载警告​​: WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable 这表明Hadoop无法正确加载本地优化库…

GO基础总结

环境搭建 基本语法 参见:https://www.cnblogs.com/vonlinee/p/19005628 工具链

Visual Studio 离线安装0x80131509

Visual Studio 2026在本月发布了,它最大的特点是集成了GitHub Copilot,内置AI编程,空了要尝尝鲜(使用过Visual Studio Code的Copilot,还是挺有用的)。目前,VS2022很少使用,像VS2012一样被跳过,主要使用VS2019…

dash 从入门到精通

dash 从入门到精通目录 官方地址:https://plotly.com/dash/ Github 开源地址:https://github.com/plotly/dash Dash 官方文档:https://dash.plotly.com/

Oracle备份恢复:backup as copy保留文件名不变化,只更改路径名

我们的文章会在微信公众号IT民工的龙马人生和博客网站( www.htz.pw )同步更新 ,欢迎关注收藏,也欢迎大家转载,但是请在文章开始地方标注文章出处,谢谢! 由于博客中有大量代码,通过页面浏览效果更佳。Oracle备份恢…

读书笔记:数据库中的预连接神器:位图连接索引

我们的文章会在微信公众号IT民工的龙马人生和博客网站( www.htz.pw )同步更新 ,欢迎关注收藏,也欢迎大家转载,但是请在文章开始地方标注文章出处,谢谢! 由于博客中有大量代码,通过页面浏览效果更佳。本文为个人学…

飞算JavaAI:专为Java开发者打造的智能编程革命 - 实践

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

故障处理:CRS无法随操作系统自动启动故障案例分享

我们的文章会在微信公众号IT民工的龙马人生和博客网站( www.htz.pw )同步更新 ,欢迎关注收藏,也欢迎大家转载,但是请在文章开始地方标注文章出处,谢谢! 由于博客中有大量代码,通过页面浏览效果更佳。今天分享一个…

02020401 EF Core基础01-EF Core简介和开发环境搭建、实体类、配置类、继承DbContex的类、Migration包的使用

02020401 EF Core基础01-EF Core简介和开发环境搭建、实体类、配置类、继承DbContex的类、Migration包的使用 1. EF Core简介(视频3-1)本课程需要你有数据库、SQL等基础知识。关系数据库:MySql、SQL Server、Oracle…

专用通路方式

-取址周期 1.从pc取址到mar (pc)->mar 此时c0有效 2.把刚才的值交给内存 (mar)->内存 c1 3.让内存读取mar中保存的值 1->r 4.让mdr获取内存刚刚读取的mar中保存的代码值 MEM(MAR)->MDR C2 5.再让IR(指令…

typeof()

C# 中的 typeof() 是啥?一句话讲清楚:typeof() 就是“问编译器:这个类型长啥样?”它不是运行时去查对象,而是编译时就确定你写的那个“类名、接口名、结构名”到底是谁,然后返回一个叫 Type 的对象,这个对象里装…

详细介绍:【C++】C++类和对象—(中)

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

【未完成】2025.9 做题记录

CF1310C CF616F CF1065G CF1536F. Omkar and Akmar *2600 题意 Alice 和 Bob 在一个 \(n\) 个格子的环上玩游戏,环上的格子编号为 \(1\sim n\)。 每一轮中,玩家可选择一个空格子填入字母 A 或 B,同时要求不能存在两…

【9月中】

【9月中】rating:1173 已经好几个月没更新近况了,期末月,暑假回来 3 场 XCPC 初体验,意料之外,未曾想过,受宠若惊,还是菜鸡,JXCPC 垫底,网络赛爆零 我到底为什么还要走这条路啊,明明没有希望,而且就算自己这…

08-分组函数

08-分组函数$(".postTitle2").removeClass("postTitle2").addClass("singleposttitle");介绍 分组函数的执行原则:先分组,然后对每一组数据执行分组函数。如果没有分组语句group by的…

Stanford CS336 | Assignment 1 - Transformer Language Model Architecture - 详解

Stanford CS336 | Assignment 1 - Transformer Language Model Architecture - 详解2025-09-18 21:47 tlnshuju 阅读(0) 评论(0) 收藏 举报pre { white-space: pre !important; word-wrap: normal !important; ove…

2025.8 做题记录

P4064 [JXOI2017] 加法 蓝 题意 可怜有一个长度为 \(n\) 的正整数序列 \(A\),但是她觉得 \(A\) 中的数字太小了,这让她很不开心。 于是她选择了 \(m\) 个区间 \([l_i,r_i]\) 和两个正整数 \(a,k\)。她打算从这 \(m\)…

关于 “Thinking Machines Lab首次发长文” 的一些知识的学习和补充

1. 前言砚上三五笔,落墨鹧鸪啼原文链接: https://thinkingmachines.ai/ 相关分析链接:https://www.gongjiyun.com/blog/2025/9/fu1xw1spci9vnokjipecs9y9nzn/最近看到一篇名为《击败 LLM 推理中的非确定性:从“玄学…