小程序模仿订单多选删除
二话不说上代码
wxml
<block wx:if="{{boolean==true}}">
<view class='header1'>
<view class='header'>
<view class='header_con flex_between'>
<view class='left'>
共计{{list.length}}个设备
</view>
<view class='right flex_end'>
<view wx:if="{{!management_good}}" class='flex_center' bindtap='management'>
编辑
</view>
<view wx:if="{{management_good}}" class='flex_center' bindtap='finish_management'>
完成
</view>
</view>
</view>
</view>
</view>
<view class='onlinechoose'>
<view class='hotel_list flex_center' wx:for="{{list}}" wx:key="{{index}}" wx:for-item="i" data-id="{{index}}" bindtap='select'>
<view class='zrf'>
<view id='banner'>
<view id='a'>
<view wx:if="{{management_good}}" class='lefts'>
<block wx-if="{{!i.checked}}">
<view class='icon_none'></view>
</block>
<block wx-if="{{i.checked}}">
<icon type="success" size="22" color="red" />
</block>
</view>
</view>
<view id='b'>
<text>设备编号:{{list[index].deviceid}}\n</text>
<text decode="true">信 号 源:中国电信NB-IOT\n</text>
<text decode="true">区 域: {{list[index].deployment}}\n</text>
<text>详细地址:{{list[index].location}}\n</text>
</view>
<view id='c'>
<text style="color:{{list[index].colors}}">{{list[index].fireAlarmdeviceStatus}}</text>
</view>
</view>
<view id='flot'>
<view id='d'>
<text>安装位置:{{list[index].dLocation}}</text>
</view>
<view id='e'>
<image mode='scaleToFill' style=" height: 40rpx; width: 40rpx;" src='../../../images/zy4-sb-001.png'></image>
</view>
</view>
</view>
</view>
</view>
<view class='bottom flex_between' wx:if="{{management_good}}">
<view class='left flex_start'>
<block wx:if="{{select_all}}">
<view bindtap='select_none' class='flex_start'>
<icon type="success" size="22" color="red" />
<view>
取消全选
</view>
</view>
</block>
<block wx:if="{{!select_all}}">
<view bindtap='select_all' class='flex_start'>
<view class='select_none'>
</view>
<view>
全选
</view>
</view>
</block>
</view>
<view class='right flex_end'>
<view style='text-align:right'>
<view class='all'>
共选中{{middlearr.length}}件设备
</view>
</view>
<view bindtap='deleteitem' class='sure'>
删除
</view>
</view>
</view>
</block>
<block wx:elif="{{boolean==false}}">
<view class="bg_red">
<view id='null'>
<image src='../../../images/zhu-2.png' style=' width: 200rpx;height: 200rpx;'></image>
<text style='color:#000'>\n</text>
<text style='color:#000'>对不起\n</text>
<text style='color:#ccc'>当前暂无场所设备</text>
</view>
</view>
</block>
js页面
var app = getApp()
var website = app.globalData.website;
Page({
data: {
title_disabled: true,//控制修改表头名字
management_good: false,
select_all: false,
middlearr: [],
list: [],
page: 1,
aa: [],
},
onShow: function () {
this.data.page = 1;
this.data.aa = [];
this.selectgetdevice();
},
selectgetdevice:function(){
var thit = this;
var userid = app.globalData.id;
var token = app.globalData.token;
var getsite = app.globalData.getsite;
var page=String(this.data.page)
wx.request({
url: website + 'getdevice',
method: 'POST',
data: {
userid: userid,
page: page,
},
header: {
'token': token,
'content-type': 'application/json' // 默认值
},
success: (res) => {
console.log(res.data)
let list = res.data.object
if (res.data.message == "ok") {
var boolean = true
for (var i = 0; i, i < list.length; i++) {
list[i].checked = false
var fireAlarm = res.data.object[i].fireAlarm;
var deviceStatus = res.data.object[i].deviceStatus;
if (fireAlarm == 1 && deviceStatus == 8) {
//console.log("火警+故障" + res.service.data.deviceId)
list[i].fireAlarmdeviceStatus = '火警'
list[i].colors = '#F51A05'
thit.setData({
list: list,
})
} else if (deviceStatus != 8 && fireAlarm != 1) {
//console.log("正常+正常" + res.service.data.deviceId)
list[i].fireAlarmdeviceStatus = '正常'
list[i].colors = '#477BFC'
thit.setData({
list: list,
})
} else if (deviceStatus != 8 && fireAlarm == 1) {
//console.log("火警+正常" + res.service.data.deviceId)
list[i].fireAlarmdeviceStatus = '火警'
list[i].colors = '#F51A05'
thit.setData({
list: list,
})
} else if (deviceStatus == 8 && fireAlarm != 1) {
//console.log("故障+正常" + res.service.data.deviceId)
list[i].fireAlarmdeviceStatus = '故障'
list[i].colors = '#E88400'
thit.setData({
list: list,
})
}
this.data.aa.push(list[i]);
}
} else {
if (this.data.page > 1) {
var boolean = true
} else {
var boolean = false
}
}
thit.setData({
list: this.data.aa,
boolean: boolean,
})
}
})
},
// 改变类目的名字
change_classname: function () {
let that = this;
that.setData({
title_disabled: !that.data.title_disabled,
});
// 这里自动获取焦点
},
finish_classname: function () {
let that = this;
that.setData({
title_disabled: !that.data.title_disabled,
})
},
// 管理商品
management: function () {
let that = this;
that.setData({
management_good: true,
})
},
finish_management: function () {
let that = this;
that.setData({
management_good: false,
})
},
// 选择
select: function (e) {
var that = this;
let arr2 = [];
if (that.data.management_good == false) {
return;
} else {
var arr = that.data.list;
var index = e.currentTarget.dataset.id;
arr[index].checked = !arr[index].checked;
console.log(arr);
for (let i = 0; i < arr.length; i++) {
if (arr[i].checked) {
arr2.push(arr[i])
}
};
that.setData({
list: arr,
middlearr: arr2
})
}
},
// 删除
deleteitem: function () {
var that = this;
let arr = that.data.list;
let arr2 = [];
console.log(arr);
for (let i = 0; i < arr.length; i++) {
if (arr[i].checked == true) {
var id=arr[i].id
console.log("11111111+++"+id)
var thit = this;
var token = app.globalData.token;
wx.request({
url: website + 'deletedevice',
method: 'POST',
data: {
id: id,
page: "1",
},
header: {
'token': token,
'content-type': 'application/json' // 默认值
},
success: (res) => {
console.log(res.data)
}
})
} else if (arr[i].checked == false){
arr2.push(arr[i]);
}
}
that.setData({
list: arr2,
middlearr: []
})
},
// 全选
select_all: function () {
let that = this;
that.setData({
select_all: !that.data.select_all
})
if (that.data.select_all) {
let arr = that.data.list;
let arr2 = [];
for (let i = 0; i < arr.length; i++) {
if (arr[i].checked == true) {
arr2.push(arr[i]);
} else {
arr[i].checked = true;
arr2.push(arr[i]);
}
}
that.setData({
list: arr2,
middlearr: arr2
})
}
},
// 取消全选
select_none: function () {
let that = this;
that.setData({
select_all: !that.data.select_all
})
let arr = that.data.list;
let arr2 = [];
for (let i = 0; i < arr.length; i++) {
arr[i].checked = false;
arr2.push(arr[i]);
}
that.setData({
list: arr2,
middlearr: []
})
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
var that = this
console.log(that.data.item.length)
if (that.data.aa.length == that.data.page * 10) {
that.data.page = that.data.page + 1
this.selectgetdevice();
}
},
})
wxss页面
.zrf {
position: relative;
width: 100%;
height: 310rpx;
display: inline-block;
box-shadow: 0px 2px 5px 5px #ccc;
border-radius: 20rpx;
}
#banner {
border-bottom: 1px #ccc solid;
width: 100%;
height: 240rpx;
}
#flot {
width: 100%;
height: 60rpx;
}
#a {
width: 40rpx;
height: 40rpx;
margin-top: 5px;
margin-left: 30rpx;
}
#b {
width: 530rpx;
height: 160rpx;
margin-top: 10rpx;
margin-left: 30rpx;
float: left;
font-size: 26rpx;
}
#b text {
margin-top: 5rpx;
word-break: break-all;
text-overflow: -o-ellipsis-lastline;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
}
#c {
width: 60rpx;
height: 40rpx;
margin-top: 10rpx;
margin-left: 30rpx;
float: right;
margin-right: 30rpx;
font-size: 26rpx;
text-align: center;
}
#d {
width: 530rpx;
height: 40rpx;
margin-top: 10rpx;
margin-left: 30rpx;
float: left;
font-size: 26rpx;
}
#d text {
word-break: break-all;
text-overflow: -o-ellipsis-lastline;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
}
#e {
width: 40rpx;
height: 40rpx;
margin-top: 10rpx;
margin-left: 30rpx;
float: right;
margin-right: 30rpx;
}
.header1 {
background-color: #f5f5f5;
}
.header2 {
background-color: #fff;
}
.header {
width: 100%;
height: 80rpx;
border-bottom: 1rpx solid #d6d6d6;
}
.header .header_con {
width: 700rpx;
height: 80rpx;
margin: 0 auto;
color: #333;
font-size: 30rpx;
}
.header .header_con image {
width: 44rpx;
height: 44rpx;
}
.header .header_con .right {
color: #ff4965;
}
.bottom {
width: 100%;
height: 100rpx;
border-top: 1rpx solid #d6d6d6;
background-color: #fff;
position: fixed;
left: 0rpx;
bottom: 0rpx;
}
.bottom .left {
margin-left: 25rpx;
}
.bottom .left .select_none {
width: 40rpx;
height: 40rpx;
border: 1rpx solid #d6d6d6;
border-radius: 50%;
}
.bottom .right .all {
color: #ff830f;
font-size: 26rpx;
}
.bottom .right .gray {
color: #666;
font-size: 22rpx;
}
.bottom .right .sure {
margin-left: 22rpx;
width: 220rpx;
height: 100rpx;
line-height: 100rpx;
text-align: center;
background-color: #ff4965;
color: #fff;
}
/*列表*/
.onlinechoose {
width: 750rpx;
margin-top: 0rpx;
background-color: #fff;
font-size: 32rpx;
}
.onlinechoose .hotel_list {
width: 750rpx;
height: 360rpx;
background-color: #fff;
}
.onlinechoose .hotel_list .icon_none {
width: 40rpx;
height: 40rpx;
border: 1rpx solid #d6d6d6;
border-radius: 50%;
}
.onlinechoose .hotel_list .list_cons {
width: 700rpx;
height: 200rpx;
}
.onlinechoose .list_cons .lefts {
width: 80rpx;
}
.onlinechoose .list_cons image {
width: 200rpx;
height: 200rpx;
margin-right: 25rpx;
}
.list_cons .right {
width: 395rpx;
height: 200rpx;
}
.list_cons .right .name {
font-size: 32rpx;
color: #333;
font-weight: 700;
letter-spacing: 3rpx;
margin-bottom: 20rpx;
}
.list_cons .right .list1 {
margin-bottom: 17rpx;
}
.list_cons .right .list1 .condition1 {
font-size: 28rpx;
color: #999;
margin-bottom: 15rpx;
}
.list_cons .right .list1 .condition2 {
font-size: 24rpx;
color: #999;
}
.list_cons .right .list1 .act {
color: #2d8622;
}
.list_cons .right .list1 .r {
font-size: 24rpx;
color: #ff4965;
}
.list_cons .right .list1 .big {
font-size: 32rpx;
}
.list_cons .right .lists2 {
height: 36rpx;
line-height: 36rpx;
font-size: 22rpx;
}
.list_cons .right .lists2 .left {
width: 162rpx;
text-align: center;
color: #ff4965;
border: 1rpx solid #ff4965;
box-sizing: border-box;
border-radius: 5rpx;
}
.list_cons .right .lists2 .right2 {
color: #999;
}
.flex_center {
display: flex;
display: -webkit-flex;
justify-content: center;
align-items: center;
}
.flex_between {
display: flex;
display: -webkit-flex;
justify-content: space-between;
align-items: center;
}
.flex_start {
display: flex;
display: -webkit-flex;
justify-content: flex-start;
align-items: center;
}
.flex_end {
display: flex;
display: -webkit-flex;
justify-content: flex-end;
align-items: center;
}
#null {
font-size: 30rpx;
padding-top: 300rpx;
text-align: center;
}