亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

微信小程序?qū)崿F(xiàn)左滑修改、刪除功能

 更新時(shí)間:2020年10月19日 11:26:15   作者:阡路陌人  
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)左滑修改、刪除功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)左滑修改、刪除的具體代碼,供大家參考,具體內(nèi)容如下

wxml:

<view class="offer-item" wx:for-items='{{offerList}}'>
 <!--這里綁定了剛才說(shuō)的3個(gè)函數(shù)分別為 touchS,touchM touchE-->
 <!--這里注意這個(gè) style="{{item.txtStyle}}" ,這是我們一會(huì)再js中 將要設(shè)置的樣式 -->
 <view style="{{item.txtStyle}}">
 <view class="offer-item-top fl clearfix" bindtouchstart="touchS" bindtouchmove="touchM" bindtouchend="touchE" data-index="{{index}}">
 <navigator bindtap='navigatorTo' data-index="{{item.id}}">
  <view class='content'>
  <view class='title clearfix'>
  <view class='fl'>
  {{item.title}}黨建項(xiàng)目報(bào)價(jià)表
  </view>
  <image src='../../images/right.png' class='fr'></image>
  </view>
  <view class='note clearfix'>
  <view class='price fl'>
  {{item.create_time}}
  </view>
  </view>
  </view>
 </navigator>
 </view>

 <!--這里是左滑按鈕部分----start-->
 <view bindtap="delItem" class='posit fr isMove' hidden='{{!item.isMove}}'>
  <view class="ref" data-offerid="{{item.id}}" data-index="{{item.id}}" catchtap="ref">
  <image src='../../images/ref.png'></image>
  </view>
  <view class="del" data-offerid="{{item.id}}" data-index="{{item.id}}" catchtap="del">
  <image src='../../images/default.png'></image>
  </view>
 </view>
 <!--這里是左滑按鈕部分----end-->
 </view>
</view>

wxss:

.offer-item {
 height: 150rpx;
 width: 100vw;
 overflow-x: hidden;
 border-bottom: 1px solid #f0f0f0;
}

.offer-item>view {
 position: absolute;
 /* width: calc(100% + 200rpx); */
 height: 150rpx; 
}

.offer-item .offer-item-top {
 height: 100%;
}

.offer-item .offer-item-top navigator {
 display: inline-block;
 width: 100vw; 
 height: 100%;
}

.offer-item .content {
 padding: 35rpx 30rpx;
 position: relative;
 height: calc(100% - 70rpx);
}

.offer-item .title .fl {
 display: inline-block;
 width: 78%;
 overflow: hidden;
 text-overflow: ellipsis;
 white-space: nowrap;
 font-size: 30rpx;
 color: #333;
}

.offer-item .title .fr {
 display: inline-block;
 width: 20rpx;
 height: 26rpx;
 margin-top: 5rpx;
}

.offer-item .note {
 position: absolute;
 left: 30rpx;
 bottom: 35rpx;
 width: calc(100vw - 60rpx);
 font-size: 24rpx;
 color: #999;
}

.offer-item .posit {
 width: 200rpx;
 height: 150rpx;
 line-height: 150rpx;
 text-align: center;
 display: none
}

.posit.isMove {
 display: inline-block;
 position: absolute;
}

.posit.isMove[hidden] {
 display: none
}

.offer-item .posit>view {
 display: inline-block;
 width: 100rpx;
}

.offer-item .posit>view:first-of-type {
 background-color: #FED847;
}

.offer-item .posit>view:last-of-type {
 background-color: #C71B1B;
}

.offer-item .posit image {
 display: inline-block;
 width: 36rpx;
 height: 36rpx;
}

js:

let len = 0;  // 初次加載長(zhǎng)度
let hadLastPage = false; // 判斷是否到最后一頁(yè)

var initdata = function (that) {
 var list = that.data.offerList
 for (var i = 0; i < list.length; i++) {
 list[i].txtStyle = "";
 list[i].isMove = false;
 }
 that.setData({ 
 offerList: list
 })
}

Page({
 data: {
 offerList: [

 ],
 delBtnWidth: 100, // 刪除按鈕寬度單位(rpx)
 },


 // 手指剛放到屏幕觸發(fā)
 touchS: function (e) {
 console.log("touchS" + e);
 // initdata(this);
 // 判斷是否只有一個(gè)觸摸點(diǎn)
 if (e.touches.length == 1) {
 this.setData({
 // 記錄觸摸起始位置的X坐標(biāo)
 startX: e.touches[0].clientX
 });
 };
 return false;
 },

 // 觸摸時(shí)觸發(fā),手指在屏幕上每移動(dòng)一次,觸發(fā)一次
 touchM: function (e) {
 var that = this;
 initdata(that);
 if (e.touches.length == 1) {
 // 記錄觸摸點(diǎn)位置的X坐標(biāo)
 var moveX = e.touches[0].clientX;
 // 計(jì)算手指起始點(diǎn)的X坐標(biāo)與當(dāng)前觸摸點(diǎn)的X坐標(biāo)的差值
 var disX = that.data.startX - moveX;
 // delBtnWidth 為右側(cè)按鈕區(qū)域的寬度
 var delBtnWidth = that.data.delBtnWidth;
 var txtStyle = "";
 if (disX == 0 || disX < 0) { // 如果移動(dòng)距離小于等于0,文本層位置不變
 txtStyle = "left:0px";
 } else if (disX > 0) {  // 移動(dòng)距離大于0,文本層left值等于手指移動(dòng)距離
 txtStyle = "left:-" + disX + "px";
 if (disX >= delBtnWidth) {
  // 控制手指移動(dòng)距離最大值為刪除按鈕的寬度
  txtStyle = "left:-" + delBtnWidth + "px";
 }
 }
 // 獲取手指觸摸的是哪一個(gè)item
 var index = e.currentTarget.dataset.index;
 var list = that.data.offerList;
 // 將拼接好的樣式設(shè)置到當(dāng)前item中
 list[index].txtStyle = txtStyle;

 list[index].isMove = true;
 // 更新列表的狀態(tài)
 this.setData({
 offerList: list
 });
 }
 },
 touchE: function (e) {
 console.log( e);
 var that = this
 if (e.changedTouches.length == 1) {
 // 手指移動(dòng)結(jié)束后觸摸點(diǎn)位置的X坐標(biāo)
 var endX = e.changedTouches[0].clientX;
 // 觸摸開(kāi)始與結(jié)束,手指移動(dòng)的距離
 var disX = that.data.startX - endX;
 var delBtnWidth = that.data.delBtnWidth;
 // 如果距離小于刪除按鈕的1/2,不顯示刪除按鈕
 var txtStyle = disX > delBtnWidth / 2 ? "left:-" + delBtnWidth + "px" : "left:0px";
 // 獲取手指觸摸的是哪一項(xiàng)
 var index = e.currentTarget.dataset.index;
 var list = that.data.offerList;
 list[index].txtStyle = txtStyle;
 // 更新列表的狀態(tài)
 that.setData({
 offerList: list
 });
 }
 },

 /**
 * 
 */
 navigatorTo: function (event) {

 },

 /**
 * 刪除操作
 */
 del: function (e) {
 var that = this;
 var data = {
 id: e.currentTarget.dataset.index
 };
 wx.showModal({
 title: '',
 content: '確定選擇刪除么?',
 confirmColor: '#C71B1B',
 cancelColor: '#666666',
 success: function (res) {
 if (res.confirm) {
  utils.requestFun("接口url", data, 'POST', function (msg) {
  console.log(msg)

  wx.showToast({
  title: '刪除成功',
  icon: 'success',
  duration: 1500
  })
  var lists = that.data.offerList;
  var list1 = [];
  for (let i = 0; i < lists.length; i++) {
  if (lists[i].id != e.currentTarget.dataset.index) {
  list1.push(lists[i])
  }
  }
  len--;
  that.setData({
  offerList: list1
  })
  })
 } else if (res.cancel) {

 }
 }
 })
 },

 /**
 * 修改操作
 */
 ref: function (e) {
 wx.navigateTo({
 url: '修改頁(yè)面路徑?id=' + e.currentTarget.dataset.index,
 })
 },

 /**
 * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載
 */
 onLoad: function (options) {
 page = 0;
 this.loadList();
 },


 /**
 * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面初次渲染完成
 */
 onReady: function () {

 },

 /**
 * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面顯示
 */
 onShow: function () {

 },

 /**
 * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面隱藏
 */
 onHide: function () {

 },

 /**
 * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面卸載
 */
 onUnload: function () {
 hadLastPage = false;
 len = 0; 
 },

 /**
 * 頁(yè)面相關(guān)事件處理函數(shù)--監(jiān)聽(tīng)用戶(hù)下拉動(dòng)作
 */
 onPullDownRefresh: function () {

 },

 /**
 * 頁(yè)面上拉觸底事件的處理函數(shù)
 */
 onReachBottom: function (event) {
 console.log("上拉事件")
 this.loadList();
 }, 

 /** 
 * 數(shù)據(jù)請(qǐng)求封裝
 */
 loadList: function (event) {
 if (hadLastPage != false) {
 wx.showToast({
 title: '到底啦',
 });
 return;
 }
 var that = this;
 // 顯示加載圖標(biāo) 
 wx.showLoading({
 title: '玩命加載中',
 })

 let data = {
 length: len,
 openId: 'openid'
 };
 utils.requestFun("接口url", data, 'POST', function (msg) {

 if (msg.data.length != 0) {
 var lists = that.data.offerList;
 for (let i = 0; i < msg.data.length; i++) {
  msg.data[i].isMove = false;
  lists.push(msg.data[i]);
 }

 // len 
 len = len + msg.data.length;

 // 設(shè)置數(shù)據(jù) 
 that.setData({
  offerList: lists
 })
 } else {
 hadLastPage = true;
 }
 wx.hideLoading();
 })
 }

})

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論