From 972b300a12c7d671ac28490693d3affaa1c04f47 Mon Sep 17 00:00:00 2001 From: whycq <whycq> Date: 星期五, 01 四月 2022 17:09:23 +0800 Subject: [PATCH] # --- pages/basics/demo.vue | 142 +++++++++++++++++++++++++++++------------------ 1 files changed, 87 insertions(+), 55 deletions(-) diff --git a/pages/basics/demo.vue b/pages/basics/demo.vue index 18ce165..b108a74 100644 --- a/pages/basics/demo.vue +++ b/pages/basics/demo.vue @@ -1,28 +1,36 @@ <template> <view> <scroll-view> - <view class="demo-tab"> + <view> <checkbox-group @change="checkbox"> - <label v-for="(item,index) in data" :key="index" - @click="changeClass(index)" class="demo-list" :class="{'active':add_class==index}" > - - <view :class="'bg-'+item.checked"> - <view class="demo-list-left"><checkbox :value="item.id+''" :checked="item.checked" /> - </view> - <view class="demo-list-right"> - <view><text style="width: 90rpx;">璁㈠崟 | </text>{{item.orderNo}}<text>搴忓彿锛歿{index+1}}</text></view> - <view><text >鍟嗗搧缂栫爜锛�</text>{{item.matnr}}</view> - <view ><text>搴斿叆鏁伴噺锛�</text><view class="text-num">{{item.anfme}}</view><text>鍟嗗搧鍚嶇О锛�</text>{{item.maktx}}</view> - <view><text>宸插叆鏁伴噺锛�</text><view class="text-num">{{item.inQty}}</view><text>璁㈠崟鐘舵�侊細</text>{{item.state$}}</view> - </view> - </view> + <label v-for="(item,index) in data" :key="index" class="demo-list bg-false" :class="'bg-'+item.checked" > + <view class="demo-list-left"> + <checkbox :value="item.id+''" :checked="item.checked" style="display: block;" /> + </view> + <view class="demo-list-right"> + <view><text style="font-weight: bold;">搴忓彿锛歿{index+1}}</text><text>璁㈠崟 | </text>{{item.orderNo}}</view> + <view><text style="font-size: 15rpx;">鍟嗗搧缂栫爜锛�</text>{{item.matnr}}</view> + <view><text style="font-size: 15rpx;">搴斿叆鏁伴噺锛�</text><view class="text-num">{{item.anfme}}</view><text>鍟嗗搧鍚嶇О锛�</text>{{item.maktx}}</view> + <view><text>宸插叆鏁伴噺锛�</text><view class="text-num">{{item.inQty}}</view><text>璁㈠崟鐘舵�侊細</text>{{item.state$}}</view> + </view> </label> </checkbox-group> </view> </scroll-view> <view class="foot flex justify-around"> - <button class="cu-btn bg-yellow lg">涓婃灦</button> - <button class="cu-btn bg-yellow lg">鎾ら攢涓婃灦</button> + <label> + <checkbox :checked="check" @click="allChecked()">{{checkText}}</checkbox> + </label> + <label> + <text @click="reChecked()">鍙嶉��</text> + </label> + <label for=""> + <button class="cu-btn bg-yellow lg" @click="shangjia()">涓婃灦</button> + </label> + <label for=""> + <button class="cu-btn bg-yellow lg">鎾ら攢涓婃灦</button> + </label> + </view> </view> </template> @@ -32,9 +40,9 @@ data() { return { data: [], - background:'unCheck', - color:'', - add_class:'' + check:false, + checkText:'鍏ㄩ��', + checkedData:[], } }, mounted() { @@ -54,7 +62,6 @@ } else { that.getData(); } - }, getData() { let that = this @@ -66,49 +73,74 @@ var res = res.data if (res.code === 200) { that.data = res.data.records - // that.setCheck() - } } }) }, - // setCheck() { - // for (var i = 0; i < this.data.length; i++) { - // var key = 'checked', - // value = false - // this.data[i][key] = value - // } - // }, checkbox: function (e) { - var items = this.data, values = e.detail.value; for (var i = 0, lenI = items.length; i < lenI; ++i) { const item = items[i] - console.log(values) - console.log(values.indexOf(item.value)) + item.id = item.id + '' if(values.indexOf(item.id) >= 0){ this.$set(item,'checked',true) }else{ this.$set(item,'checked',false) } } - - - // var val = e.detail.value - // for (var j = 0; j < this.data.length;j++) { - // this.data[j].checked = false - // } - // for (var i = 0; i < val.length; i++) { - // val[i] = parseInt(val[i]) - // this.data[val[i]].checked = true - // console.log(val) - // console.log(this.data) - // } + if (values.length == items.length) { + this.check = true + this.checkText = "鍙栨秷鍏ㄩ��" + } else { + this.check = false + this.checkText = "鍏ㄩ��" + } }, - changeClass(index) { + reChecked() { // 鍙嶉�� + var checkArr = [] + for (var i = 0; i < this.data.length;i++) { + if (this.data[i].checked == true) { + this.$set(this.data[i],'checked',false) + }else{ + this.$set(this.data[i],'checked',true) + } + if (this.data[i].checked == true) { + checkArr.push(this.data[i].checked) + } + } + if (checkArr.length == this.data.length) { + this.check = true + this.checkText = "鍙栨秷鍏ㄩ��" + } else { + this.check = false + this.checkText = "鍏ㄩ��" + } + }, + allChecked(e){ // 鍏ㄩ�� + if (this.check == true) { + for (var i = 0; i < this.data.length;i++) { + this.$set(this.data[i],'checked',false) + } + this.check = false + this.checkText = "鍏ㄩ��" + } else { + for (var i = 0; i < this.data.length;i++) { + this.$set(this.data[i],'checked',true) + } + this.check = true + this.checkText = "鍙栨秷鍏ㄩ��" + } - this.add_class=index + }, + shangjia() { + this.checkedData = [] + for (var i = 0; i < this.data.length; i++) { + if (this.data[i].checked == true) { + this.checkedData.push(this.data[i]) + } + } + console.log(this.checkedData) } } } @@ -119,14 +151,12 @@ background-color: #FFFFFF; } .bg-true { - background-color: #d6d6d6; + background-color: #ebebeb; } - .demo-tab { - } + .demo-list { - border-bottom: 1px solid #d8d8d8; - height: 160rpx; + height: 150rpx; } .demo-list:last-child { margin-bottom: 99rpx; @@ -135,21 +165,23 @@ display: block; } .demo-list-left { + /* background-color: #007AFF; */ display: inline-block; - width: 100rpx; + float: left; text-align: center; + width: 100rpx; height: 150rpx; line-height: 150rpx; } .demo-list-right { + /* background-color: #55ffff; */ display: inline-block; - width: 650rpx; - float: right; + float: left; + height: 150rpx; } .demo-list-right text { display: inline-block; - width: 150rpx; } .text-num { display: inline-block; -- Gitblit v1.9.1