uniapp heckbox-group实现多选

news/2025/3/5 2:05:23/

文章目录

  • html 代码
  • JS 代码

混了业务逻辑,谨慎观看

html 代码

<view><!--可滚动视图区域。用于区域滚动 --><scroll-view :style="{ height: clientHeight + 'px' }" :scroll-top="scrollTop" scroll-y="true"@scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll"><!--多项选择器--><checkbox-group @change="checkboxChange"><!-- 多内容pendingList 卡片 --><view v-for="(item, index) in pendingList" :key="index"><uni-card :title="item.deliveryCode" :extra="item.dbilldate.substring(0,10)"><view class="checkbox_collapse"><!--多选项目 checkbox 和 view同级--><!-- value绑定的值;checked当前是否选中,可用来设置默认选中 --><checkbox :value="item.checkboxValue" :checked="item.checked" color="#1d99ff" /><view style="margin-left: 10px;width: 100%;"><view v-for="(array,index3) in item.detail" :key="index3"><u-row><u-col span="1" v-if="item.detail.length > 1">{{index3+1}}</u-col><u-col span="11"><view class="uni-body order_detail_product_name">{{array.materialName}}{{array.castUnit}}</view><view class="uni-body order_detail_product_name"><text style="color: #5d5d5d;">订单:</text>{{array.saleCode}}</view><view class="uni-body order_detail_product_name bottom-border"><text style="color: #5d5d5d;">单项金额:</text>¥{{array.norigtaxmny}}</view></u-col></u-row></view><view class="order_detail"><view style="color: black;">¥{{item.totalPrice}}</view></view></view></view></uni-card></view></checkbox-group></scroll-view><view class="foot_view"><u-row><u-col><u-row><u-col span="5" class="foot_view_checkbox"><!--全选选择器--><checkbox-group placement="column" @change="groupChange"><checkbox :value="allRadio.name" :checked="allRadio.checked" color="#1d99ff"style="margin-left: 25px;">全选</checkbox></checkbox-group></u-col><u-col span="9" justify="end"><view class="foot_view_but_box"><button type="primary" class="foot_view_but" @click="submitTicket">提交申请</button></view></u-col></u-row></u-col></u-row></view>
</view>

JS 代码

export default {name: "pending",data() {return {pendingList: [],scrollTop: 0,allRadio: { name: '全选',checked: false},selectPending: [], //选中的经销商数据selectPendingCode: [],//选中的出库单编号和订单编号数据dealerRadio: false, //选择开票客户和发票类型对话框dealerRadioList: [], //开票客户selectDealerRadio: '', //对话框中选择的经销商totalAmount: 0,//总金额showDealerRadio: false, // 开票客户对话框}},methods: {checkboxChange(e) {this.totalAmount = 0 //总金额this.selectPending = [] //选中的经销商数据this.selectPendingCode = []//选中的出库单编号和订单编号数据let dealerList = new Set() //这步业务需要,过滤重复经销商//  e.detail.value是checkbox选中的值:"XC2022121000000002-SO302022121000000001"let selectData = e.detail.value//pendingList循环的数据for (var i = 0, lenI = this.pendingList.length; i < lenI; ++i) {const item = this.pendingList[i]//判断selectData和pendingList.checkboxValue是否相等,相等则把checked设为trueif (selectData.includes(item.checkboxValue)) {this.$set(this.pendingList[i], 'checked', true)} else {this.$set(this.pendingList[i], 'checked', false)}}//  商品是否全部勾选,判断全选与否状态var offCarArr = []//this.pendingList.whether 属性值是true,则把itempush到offCarArrthis.pendingList.forEach(item => item.whether == true ? offCarArr.push(item) : '')//offCarArr的checked都是true,则allChecks = true,否则反之//every 若有一个不满足条件,则返回false,后面的元素都不会再执行。不会对空数组进行检测,不会改变原始数组let allChecks = offCarArr.every(item => item.checked == true)//如果allChecks等于true就反allRadio改为选中状态allChecks ? this.$set(this.allRadio, 'checked', true) : this.$set(this.allRadio, 'checked', false)//往dealerList添加经销商数据for (let ii in selectData) {this.selectPendingCode.push(selectData[ii])const temp = selectData[ii].split('-')for (let i in this.pendingList) {if (temp[0] === this.pendingList[i].deliveryCode) {this.totalAmount += this.pendingList[i].totalPricefor (let j in this.pendingList[i].detail) {let item = this.pendingList[i].detail[j]const str = item.invoiceCustCode + '-' + item.invoiceCustNamedealerList.add(str)}}}}this.selectPending = [...dealerList]},groupChange(n) {//全选按钮是否选中if (n.detail.value.length == 0) { //未选中this.pendingList.map(item => this.$set(item, 'checked', false))this.$set(this.allRadio, 'checked', false)//清空业务数据this.totalAmount = 0this.selectPending = []this.selectPendingCode = []} else {// 选中for (var i in this.pendingList) {this.$set(this.pendingList[i], 'checked', true)}this.$set(this.allRadio, 'checked', true)//清空业务数据this.totalAmount = 0this.selectPending = []this.selectPendingCode = []let dealerList = new Set()//往dealerList添加经销商数据for (let i in this.pendingList) {if (this.pendingList[i].checked) {this.selectPendingCode.push(this.pendingList[i].checkboxValue)this.totalAmount += this.pendingList[i].totalPricefor (let j in this.pendingList[i].detail) {let item = this.pendingList[i].detail[j]const str = item.invoiceCustCode + '-' + item.invoiceCustNamedealerList.add(str)}}}this.selectPending = [...dealerList]}},}
}

http://www.ppmy.cn/news/1228477.html

相关文章

C#有关里氏替换原则的经典问题答疑

目录 理解创建类型与变量类型很关键 先来理解变量类型。 再来理解创建类型。 有了正确的理解再来看疑问 里氏替换原则是面向对象七大原则中最重要的原则。 语法表现&#xff1a;父类容器装子类对象。 namespace 里氏替换原则 {class GameObject { } class Player : GameO…

Linux管道的工作过程

常用的匿名管道&#xff08;Anonymous Pipes&#xff09;&#xff0c;也即将多个命令串起来的竖线。管道的创建&#xff0c;需要通过下面这个系统调用。 int pipe(int fd[2]) 我们创建了一个管道 pipe&#xff0c;返回了两个文件描述符&#xff0c;这表示管道的两端&#xff…

在Java代码中指定用JAXB的XmlElement注解的元素的顺序

例如&#xff0c;下面的类RegisterResponse 使用了XmlRootElement注解&#xff0c;同时也使用XmlType注解&#xff0c;并用XmlType注解的propOrder属性&#xff0c;指定了两个用XmlElement注解的元素出现的顺序&#xff0c;先出现flag&#xff0c;后出现enterpriseId&#xff0…

【c++随笔13】多态

【c随笔13】多态 多态性&#xff08;Polymorphism&#xff09;在面向对象编程中是一个重要概念&#xff0c;它允许以统一的方式处理不同类型的对象&#xff0c;并在运行时动态确定实际执行的方法或函数。一、什么是多态性&#xff1f;1、关键概念&#xff1a;C的多态性2、多态定…

高精度算法【Java】(待更新中~)

高进度加法 在Java中可以使用BigInteger进行高精度计算&#xff0c;除此也可以仿照竖式相加的计算原理进行计算。 BigInteger 提供所有 Java 的基本整数操作符的对应物&#xff0c;并提供 java.lang.Math 的所有相关方法。另外&#xff0c;BigInteger 还提供以下运算&#xff1…

【自然语言处理】【大模型】赋予大模型使用工具的能力:Toolformer与ART

赋予大模型使用工具的能力&#xff1a;Toolformer与ART ​ 本文介绍两种赋予大模型使用外部工具能力的方法&#xff1a;Toolformer和ART。 Toolformer论文地址&#xff1a;https://arxiv.org/pdf/2302.04761.pdf ART论文地址&#xff1a;https://arxiv.org/pdf/2303.09014.pd…

开源更安全? yum源配置/rpm 什么是SSH?

文章目录 1.开放源码有利于系统安全2.yum源配置&#xff0c;这一篇就够了&#xff01;(包括本地&#xff0c;网络&#xff0c;本地共享yum源)3.rpm包是什么4.SSH是什么意思&#xff1f;有什么功能&#xff1f; 1.开放源码有利于系统安全 开放源码有利于系统安全 2.yum源配置…

C++中结构体的初始化

C中结构体的初始化 结构体是一个由程序员定义的数据类型&#xff0c;可以容纳许多不同的数据值。在过去&#xff0c;面向对象编程的应用尚未普及之前&#xff0c;程序员通常使用这些从逻辑上连接在一起的数据组合到一个单元中。一旦结构体类型被声明并且其数据成员被标识&…