微信小程序 列表多选 下拉分页 滑动切换分类

这篇具有很好参考价值的文章主要介绍了微信小程序 列表多选 下拉分页 滑动切换分类。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1、卡片列表

2、分页(下拉页面加载分页数据)

3、分类(页面间互不干扰,数据也不干扰)

4、左右滑动可切换分类

5、列表搜索

6、单选模式(默认单选模式,即点击卡片,回写所选数据)

7、多选模式(实现微信聊天多选效果)

  • 长按列表或点击多选,进入多选模式;
  • 切换分类或搜索则退出多选模式
  • 点击确定按钮,回写所选数据
  • 指定数据不可勾选
  • 点击复选框和卡片,实现相同效果(冒泡问题坑死人T_T,checkbox的点击事件优先级太高了,只能选后再重置)
  • 复选框改成圆形样式

        

微信小程序实现点击下拉筛选,微信小程序,小程序,javascript微信小程序实现点击下拉筛选,微信小程序,小程序,javascript

 微信小程序实现点击下拉筛选,微信小程序,小程序,javascript微信小程序实现点击下拉筛选,微信小程序,小程序,javascript

JS:

const app = getApp();
Page({
  data: {
    pageSize: 10, //每页查询大小
    currPage: 1, //当前页码
    searchParam: '',
    warehouseName: null,


    nav: { //滚动导航
      list: [{
          name: '本部门仓',
          id: 0,
          currPage: 1,
          wareList: [],
          type: 'self'
        },
        {
          name: '总仓/子仓',
          id: 1,
          currPage: 1,
          wareList: [],
          type: 'total'
        },
        {
          name: '其他部门仓',
          id: 2,
          currPage: 1,
          wareList: [],
          type: 'other'
        }
      ],
      active: 0, //当前选中的导航下标
      left: 0, //滚动值
      width: 130,
      offsetLeft: 0,

      todoTipNum: 0,
    },

    curUsername: '',
    scrollHeight: 0,

    navtop: 97,
    reduceHeight: 80,


    showRadio: false,
    showRadioText: '多选',
    choseNames: [], //选中的名字列表
  },

  onLoad: function (options) {
    var that = this;
    if (options.warehouseName != null && options.warehouseName != undefined && options.warehouseName != '') {
      that.setData({
        warehouseName: options.warehouseName
      });
    }
    if (options.isall != null && options.isall == "1") {
      // 其他入库
      that.setData({
        [`nav.list`]: [{
          name: '无',
          id: 0,
          currPage: 1,
          wareList: []
        }],
        navtop: 57,
        reduceHeight: 70
      });
    }
    wx.getSystemInfo({
      success: function (res) {
        //console.log('系统信息:', res);
        that.setData({
          windowWidth: res.windowWidth,
          [`nav.width`]: res.windowWidth / 3
        })
      }
    });

    that.getTaskList(1, 1);

    let res = wx.getSystemInfoSync();
    that.setData({
      scrollHeight: res.windowHeight - that.data.reduceHeight
    });
  },

  onShow: function () {},

  //点击导航 - 选中监听
  select: function (e) {
    this.changetab(e.currentTarget.dataset.idx);
  },

  //滚动页面,切换导航
  bindchange(e) {
    this.changetab(e.detail.current);
  },

  changetab: function (idx) {
    let _this = this,
      nav = this.data.nav,
      // idx = e.currentTarget.dataset.idx,
      windowWidth = this.data.windowWidth,
      width = windowWidth / 3,
      offsetLeft = this.data.nav.offsetLeft;
    
    _this.cancelRadio();
    if (offsetLeft < windowWidth) {
      // nav.left = width - windowWidth + offsetLeft;
      nav.offsetLeft = width * idx;
    } else {
      nav.offsetLeft = width * idx - windowWidth;
    }
    nav.active = idx;
    _this.setData({
      nav: nav,
    })
  },

  /**
   * 查询
   */
  onSearch: function () {
    var that = this;
    that.cancelRadio();
    that.getTaskList(1, 1);
  },


  getTaskList: function (isfirst, notshowtip) {
    var that = this;
    if (isfirst == 1) {
      that.data.nav.list.forEach((val, key) => {
        that.setData({
          [`nav.list[${key}].currPage`]: 1
        });
      })
      that.data.nav.list.forEach((val, key) => {
        let notshow = key == 0 ? 1 : -1;
        that.getTaskListByType(isfirst, notshow, key);
      })
    } else {
      that.getTaskListByType(isfirst, notshowtip, that.data.nav.active);
    }
  },

  /**
   * 列表
   */
  getTaskListByType: function (isfirst, notshowtip, querytab) {
    var that = this;
    var preList = that.data.nav.list[querytab].wareList;
    if (isfirst == 1) {
      preList = [];
      that.setData({
        [`nav.list[${querytab}].wareList`]: []
      });
    }
    if (notshowtip !== -1) {
      wx.showLoading({
        title: '查询中,请稍候',
        mask: true
      })
    }
    let param = {
      page: that.data.nav.list[querytab].currPage + '',
      size: that.data.pageSize + '',
      orgname: app.globalData.comName,
      username: app.globalData.userName,
    }
    if (that.data.searchParam != null && that.data.searchParam.length > 0) {
      param.name = that.data.searchParam;
    }
    if (!app.util.Empty(that.data.nav.list[querytab].type)) {
      param.type = that.data.nav.list[querytab].type;
    }

    app.globalData.$wsdl.ncWsdl('XXXXXXX', 'xxxxx', param).then(res => {
      // console.log('xxxxx 返回', res);

      if (notshowtip !== -1) {
        wx.hideLoading();
      }
      if (res.code == '1' && res.data) {
        if (res.data.length < that.data.pageSize) { // 分页结束
          // 停止上拉查询
          that.setData({
            [`nav.list[${querytab}].stopQuery`]: 1,
          });
          if (res.data.length == 0) {
            // 恢复页码
            let cp = that.data.nav.list[querytab].currPage;
            if (cp > 1) {
              --cp;
              that.setData({
                [`nav.list[${querytab}].currPage`]: cp
              });
            }
            return;
          }
        }

        var tempItems = [];
        res.data.forEach((val, key) => {
          if (val.materialtype == '' || val.materialtype == '暂无' || val.materialtype == '无') {
            val.materialtype = null;
          }
          tempItems.push(val);
        })

        that.setData({
          [`nav.list[${querytab}].wareList`]: preList.concat(app.globalData.$wsdl.oa2wx(tempItems, {
            pk_material: 'wareid',
            materialname: 'warename',
            code: 'warecode',
            materialtype: 'model',
            materialspec: 'specification',
            whname: 'from',
            nonhandnum: 'sum',
            jldw: 'unit',
            racks: 'location'
          })),
        });

        //分页加载后会删掉已选,此处重新设置已选项
        that.data.nav.list.forEach((pval, pkey) => {
          pval.wareList.forEach((val, key) => {
            val.checked=val.realchecked;
            that.setData({
              [`nav.list[${pkey}].wareList[${key}]`]: val,
            });
          })
        });
      } else {
        wx.showToast({
          title: '物料列表接口调用失败:' + res.msg,
          icon: 'none',
          duration: 3000
        })
      }
    })
  },

  /**
   * 查询框输入事件监听
   * @param {*} e 
   */
  onSearchParamInput(e) {
    this.setData({
      searchParam: e.detail.value
    })
  },

  // 点击键盘上的搜索
  bindconfirm: function (e) {
    var that = this;
    that.onSearch();
  },

  /**
   * 查询框输入事件监听
   * @param {*} e 
   */
  onSearchParamInput(e) {
    this.setData({
      searchParam: e.detail.value
    })
  },

  selware: function (e) {
    var that = this;
    let item = e.currentTarget.dataset.item;
    let pass = true;
    if (this.data.warehouseName != null && this.data.warehouseName !== item.from) {
      wx.showToast({
        title: '已选定仓库,不可选其它仓库物料',
        icon: 'none',
        duration: 1500,
        mask: true
      })
      pass = false;
    } else if (item.sum == 0) {
      wx.showToast({
        title: '当前库存为0',
        icon: 'none',
        duration: 1500,
        mask: true
      })
      pass = false;
    }
    if (!pass) {
      if (!that.data.showRadio) {
        return;
      } else {
        if (e.fromcheck == 1) {
          that.data.nav.list.forEach((pval, pkey) => {
            pval.wareList.forEach((val, key) => {
              if (val.wareid == item.wareid) {
                val.realchecked = false;
                val.checked = false;
                that.setData({
                  [`nav.list[${pkey}].wareList[${key}]`]: val
                });
              }
            })
          });
        }
        return;
      }
    }
    if (that.data.showRadio) { //多选时
      that.triggerCheckboxChange(item);
    } else {
      that.backEmit([item]);
    }
  },

  loadMore: function () {
    var that = this;
    if (that.data.nav.list[that.data.nav.active].stopQuery == 1) {
      return;
    }

    var page = that.data.nav.list[that.data.nav.active].currPage + 1;
    this.setData({
      [`nav.list[${that.data.nav.active}].currPage`]: page,
    });
    this.getTaskList();
  },
  
  //标签长按事件逻辑
  longPress: function (e) { 
    var that = this;
    if (!that.data.showRadio) {
      that.showCheckRadio();
    }
  },

  //取消多选模式
  cancelRadio: function (e) { 
    var that = this;
    if (that.data.showRadio) {
      that.showCheckRadio();
    }
  },
  

  /**
   * 重置
   */
  resetCheckRadio: function () {
    var that = this;
    that.data.nav.list.forEach((pval, pkey) => {
      pval.wareList.forEach((val, key) => {
        // if (pval.realchecked) {
          val.checked = false;
          val.realchecked = false;
          that.setData({
            [`nav.list[${pkey}].wareList[${key}]`]: val,
          });
        // }
      })
    });
    that.setData({
      choseNames:[]
    });
  },

  triggerCheckboxChange: function(item) {
    var that = this;

    that.data.nav.list.forEach((pval, pkey) => {
      pval.wareList.forEach((val, key) => {
        if (val.wareid == item.wareid) {
          val.realchecked=!val.checked;
          val.checked=!val.checked;
          that.setData({
            [`nav.list[${pkey}].wareList[${key}]`]: val
          });
        }
      })
    });

    // 有则删除,无则添加
    let newChoseNames=that.data.choseNames;
    let index = newChoseNames.indexOf(item.wareid);
    if(index>-1){
      newChoseNames.splice(index, 1);
    } else {
      newChoseNames.push(item.wareid);
    }
    this.setData({
      choseNames: newChoseNames, //单个选中的值
    });
  },

  // 单选
  changeRadio: function (e) {
    var that = this;
    console.log(e.detail.value);
    this.setData({
      choseNames: e.detail.value, //单个选中的值
    });
    var values = e.detail.value;
    that.data.nav.list.forEach((pval, pkey) => {
      pval.wareList.forEach((val, key) => {
        var itemCheck = false;
        for (var i = 0; i < values.length; i++) {
          if (val.wareid == values[i]) {
            itemCheck = true;
            break
          }
        }
        that.setData({
          [`nav.list[${pkey}].wareList[${key}].realchecked`]: itemCheck
        });
      })
    });
  },

  /**
   * 多选按钮点击
   * @param {} params 
   */
  showCheckRadio: function (params) {
    var that = this;
    if (that.data.showRadio) {
      that.setData({
        showRadio: false,
        showRadioText: '多选'
      });
      that.resetCheckRadio();
    } else {
      that.setData({
        showRadio: true,
        showRadioText: '取消'
      });
    }
  },


  // 多选确定
  comfirmsel(e) {
    var that = this;
    let selItems = [];
    if (that.data.choseNames.length === 0) {
      return wx.showToast({
        title: '请选择',
        icon: 'none'
      })
    }

    that.data.nav.list[that.data.nav.active].wareList.forEach((val, key) => {
      for (var i = 0; i < that.data.choseNames.length; i++) {
        if (val.wareid == that.data.choseNames[i]) {
          selItems.push(val);
          break
        }
      }
    })
    that.backEmit(selItems);
  },

  backEmit : function(selItems){
    //返回并回写上一页面
    let pages = getCurrentPages();
    let prePage = pages[pages.length - 2];
    prePage.emit(selItems)
    wx.navigateBack({
      delta: 1
    })
  },

  bindcheck : function(e){
    e.fromcheck=1;
    this.selware(e)
  },
})

WXML:

<!-- <view> -->
<view class="cu-bar bg-white search " style="height: 100rpx;width: 100%;position: fixed;top: 0;z-index: 998;padding-bottom: 10px;">
  <view class="search-form round">
    <text class="cuIcon-search"></text>
    <input value="{{ searchParam }}" confirm-type="search" bindconfirm="bindconfirm" bindinput="onSearchParamInput" placeholder="搜索添加物料" type="text">
    </input>
    <button class="cu-btn  cu-btn-lamp icon shadow" style='width:15vw;background-color: #4BCCB9;color: white;' bindtap="onSearch">查询</button>
  </view>
</view>

<view class="top_nav" wx:if="{{nav.list.length==3}}">
  <!-- <view class="numtip" wx:if="{{todoTipNum!=0}}">{{todoTipNum}}</view> -->
  <view class="scroll_item scroll_item{{index}} {{nav.active == index ? 'active' : ''}}" data-idx="{{index}}" wx:for="{{nav.list}}" wx:key="id" bindtap='select' style="width: 100%;text-align: center;">
    {{item.name}}
  </view>
  <view class="sub" style="width:{{nav.width}}px; left:{{nav.offsetLeft}}px;">
    <view style="background-color: #4BCCB9;margin: 0 20px;height: 100%;">
    </view>
  </view>
</view>

<view class="content" style="height:100%;font-family: '微软雅黑';top:{{navtop}}px">
  <swiper current="{{nav.active}}" style='height:100%' bindchange="bindchange">
    <swiper-item wx:for="{{nav.list}}" item-id="{{item.id}}" wx:key="id">
      <scroll-view scroll-y="true" style="height:{{scrollHeight}}px;" bindscrolltolower="loadMore">
        <!-- <view catchtap="donothing"> -->
        <checkbox-group data-itemid="{{item.wareid}}" style="{{showRadio?'display: block;':''}}">
          <view wx:for-items='{{item.wareList}}' bindlongpress="longPress" wx:for-index="index" wx:key="index" data-item="{{item}}" data-id='{{item.wareid}}' data-index="{{index}}" bindtap="selware" class="cu-card dynamic" style="padding: 10rpx 20rpx 8rpx 20rpx;display: flex;">
            <view wx:if="{{showRadio}}" style="height: 180rpx;display: flex;align-items: center;padding-right: 10rpx;">
              <checkbox value="{{item.wareid}}" checked="{{item.checked}}" data-item="{{item}}" catchtap="bindcheck"></checkbox>
            </view>
            <view data-item="{{item}}" style="width: 100%;border-radius: 20rpx;padding: 24rpx;padding-bottom: 14rpx;display: flex;{{(warehouseName !==null&&warehouseName !== item.from)||item.sum==0?'background-color: #ddd;color: #999':'background-color: white;color: black'}}">
              <view style="width: 100%;">
                <view style="font-size: 16px;font-weight: bold;margin-bottom: 10rpx;">
                  <!-- {{item.name!==null&&item.name!=='undefined'?item.name+' ':''}} -->
                  编号:{{item.warecode}}
                </view>
                <view style="font-size: 15px;margin-bottom: 10rpx;">
                  物品:{{item.warename}} {{item.model!=null?item.model:''}} {{item.specification!=null?item.specification:''}}
                </view>
                <view style="font-size: 15px;margin-bottom: 10rpx;">
                  库存:{{item.from}}({{item.location}}) {{item.sum}}{{item.unit}}
                </view>
              </view>
            </view>
          </view>

        </checkbox-group>
        <!-- </view> -->
      </scroll-view>
    </swiper-item>
  </swiper>
</view>

<button wx:if="{{showRadio}}" class="round shadow cu-btn" bindtap='comfirmsel' style="background-color: #4BCCB9;color: white;width: 100px;position: fixed;bottom: 15px;right: {{showRadio?'30vw':'6vw'}};z-index: 999;font-weight: 500;font-size: 16px;">确定{{choseNames.length>0?('('+choseNames.length+')'):''}}</button>
<button class=" round shadow cu-btn" bindtap='showCheckRadio' style="background-color: {{showRadio?'#aaa':'#4BCCB9'}};color: {{showRadio?'#fff':'#fff'}};width: 90px;position: fixed;bottom: 15px;right: 5vw;z-index: 999;font-weight: 500;font-size: 16px;"><text decode="true">&nbsp;{{showRadioText}}</text> </button>

WXSS:

.top_nav {
  width: 100%;
  height: 82rpx;
  line-height: 80rpx;
  border-bottom: 1px olid #ddd;
  background-color: #FFF;
  position: fixed;
  top: 50px;
  left: 0;
  z-index: 999;
  display: flex;
  justify-content: space-around;
}

.top_nav .scroll_list {
  height: 82rpx;
  white-space: nowrap;
}

.top_nav .scroll_item {
  display: inline-block;
  padding: 0 10px;
  font-size: 14px;
  vertical-align: top;
}

.top_nav .scroll_item.active {
  color: #4BCCB9;
}

.top_nav .sub {
  /* width: 56rpx; */
  height: 4rpx;
  position: absolute;
  top: 78rpx;
  transition: left .5s;
}

/* .content{margin-top: 84rpx; line-height: 80rpx; font-size: 28rpx;width: 100%;} */
.content {
  position: fixed;
  top: 183rpx;
  font-size: 28rpx;
  width: 100%;
}

/* .swiper_box{ border: 1px solid red;height: 90%;margin: 0 20rpx;} */

.map_container {
  height: 40vh;
  width: 100vw;
}

.map {
  height: 100%;
  width: 100%;
}

.weui-cell__hd {
  font-size: 0
}

.weui-cell__hd image {
  margin-right: 16px;
  vertical-align: middle;
  width: 20px;
  height: 20px
}

.minicell {
  padding: 30rpx 16rpx;
}

.text_too_long {
  width: 500rpx;
  word-break: break-all;
}

.text_too_long480 {
  width: 480rpx;
  word-break: break-all;
  font-size: 15px;
}

.numtip {

  background-color: red;
  position: absolute;
  top: 0p;
  left: 160rpx;
  width: fit-content;
  height: 36rpx;
  border-radius: 2em;
  display: flex;
  justify-content: center;
  align-items: center;
  color: white;
  font-size: 12px;

  padding: 0 12rpx;
}

.btnview {
  position: fixed;
  bottom: 0;
  height: 100rpx;
  line-height: 100rpx;
  background-color: white;
  width: 100%;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.newbtn {
  width: 90%;
  border-radius: 50px;
  height: 70rpx;
  line-height: 70rpx;
  background-color: #4BCCB9;
  color: white;
}



checkbox .wx-checkbox-input {
  width: 46rpx;
  height: 46rpx;
  border-radius: 50%;
}

/*checkbox选中后样式  */
checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  background: #fed6e3;
}

/*checkbox选中后图标样式  */
checkbox .wx-checkbox-input.wx-checkbox-input-checked::before {
  width: 40rpx;
  height: 40rpx;
  line-height: 28rpx;
  text-align: center;
  font-size: 18rpx;
  color: #fff;
  background: transparent;
  transform: translate(-50%, -50%) scale(1);
  -webkit-transform: translate(-50%, -50%) scale(1);
}

样式引用:

         GitHub - weilanwl/coloruicss: 鲜亮的高饱和色彩,专注视觉的小程序组件库

如果我的文章帮助到了你,点赞,评论,关注下吧

谢谢,欢迎多多交流!

——tanly文章来源地址https://www.toymoban.com/news/detail-774892.html

到了这里,关于微信小程序 列表多选 下拉分页 滑动切换分类的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 微信小程序实现滑动/点击切换Tab

    👏 swiper+scroll-view实现滑动/点击切换Tab,以及scroll-left的使用~ 🥇文末分享源代码。记得点赞+关注+收藏! 2.1 scroll-view实现tab列表 scroll-view: 可滚动视图区域。使用竖向滚动时,需要给scroll-view一个固定高度,通过 WXSS 设置 height。组件属性的长度单位默认为px。 scroll-x(bool

    2024年01月19日
    浏览(80)
  • 微信小程序———同一页面内左右滑动切换内容显示

    一、微信小程序事件  由于首先介绍一下微信小程序中的事件,可选择快速略过或者直接进去之后的重点内容 一、什么是事件 事件是视图层到逻辑层的通讯方式。 事件可以将用户的行为反馈到逻辑层进行处理。 事件可以绑定在组件上,当达到触发事件,就会执行逻辑层中对

    2024年02月03日
    浏览(44)
  • 快速掌握微信小程序 tab 切换的实现技巧(可滑动切换)

    微信小程序中的 tab 切换功能可以说是用户所需的一个基础功能。本文将介绍如何通过微信小程序实现 tab 切换功能,为用户带来更为便捷和高效的小程序体验。 其实这个小功能的实现非常简单,只需要通过一个标识控制选项的样式及显示的内容,当我们触发点击或者滑动事

    2024年02月11日
    浏览(30)
  • 微信小程序实现左右滑动进行切换数据页面(touchmove)

    手指触摸左右滑动进行切换数据 需要实现的是有一个tab栏,点选某一个tab的时候切换页面,手势滑动,左滑右滑效果和点击tab一样切换页面数据。 这里我们要先了解几个微信的事件属性 touchstart : 手指触摸动作开始 touchmove:手指触摸后移动 touchcancel:手指触摸动作被打断,

    2024年02月11日
    浏览(38)
  • 微信小程序中 使用swiper 滑动切换一级、二级导航

    其中遇到一个大问题使我放弃了swiper的使用,swiper有一个固定高度不太好处理,最终使用了touch事件去处理触摸移动,之后会再写一篇文章记录,处理不复杂的话还是可以用swiper的 效果根据手指滑动切换二级导航、二级切换完成切换一级导航   其中遇到一个大问题使我放弃了

    2024年02月17日
    浏览(27)
  • uniapp 微信小程序 Picker下拉列表数据回显问题

    效果图: 1、template 2、data 3、methods

    2024年02月16日
    浏览(26)
  • uniapp 微信小程序实现监听屏幕左右滑动实现tab标签切换效果

            实际的项目开发之中,有很多所谓的奇葩需求,当工程量相对较大的时候去更换组件会显得特别麻烦和费时。我这次的需求因为某些特殊原因,更换组件后也无法实现需要达到的效果,所以最后只能监听滑动事件,相信你看了我的代码也能轻松搞定!          

    2024年02月14日
    浏览(38)
  • 微信小程序实现tab切换和数据列表

    上篇文章介绍了微信小程序实现tab切换的一种方案(参考 https://blog.51cto.com/baorant24/6188157 ),感觉代码不是很精简,本文再用一个demo介绍微信小程序如何实现tab切换和数据列表。 微信小程序对应页面文件结构如下: 话不多说,直接上代码: (1)index.js文件,代码如下: (2)index.

    2024年02月05日
    浏览(28)
  • Uni-app实现左右滑动页面内容切换(兼容微信小程序)

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档         前言         整体思路         一、HTML部分         二、Script部分         三、Style部分           (先声明哦我可不是偷懒,只是想学术借鉴一下)因为最近有在做左右滑动功能,

    2024年02月07日
    浏览(53)
  • uniapp 微信小程序 自定义弹框+picker下拉选择列表+输入表单:拒绝-选择理由弹窗

    效果: 1、template 2、data: 3、methods: 4、style

    2024年01月20日
    浏览(35)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包