需求:点击解绑按钮的时候,会删除当前所点击的列表.
点击试驾按钮的时候,左侧的图标会变成按钮一样的颜色。
代码片段:
删除和试驾的方法
wxml:
<view class="inner del"> <span class="draw" data-index="{{index}}" data-name="{{item.carNum}}" bindtap="tryDriver" >试驾</span> <span class="delete" data-name="{{item.carNum}}" bindtap="unBind">解绑</span> </view>
js:
//点击删除 unBind: function(e) { var that = this; console.log(e.currentTarget.dataset.name) //获取列表中要删除项的下标 wx.showModal({ title: '提示', content: '是否确认解绑', success(res) { if (res.confirm) { //解绑 wx.request({ url: app.globalData.root +"car/unBind.do", data: { "openid": app.globalData.openid, "carNum": e.currentTarget.dataset.name }, method: 'GET', header: { 'Content-type': 'application/json' }, success: function(res) { that.getCars(app.globalData.openid); } }); } } }) }, //点击试驾 tryDriver: function(e) { var that = this; var index = e.currentTarget.dataset.index; var list = that.data.carList; if (list[index].state == 5) return; wx.showModal({ title: '提示', content: '是否确认试驾', success(res) { if (res.confirm) { //试驾 wx.request({ url: app.globalData.root +"car/driver.do", data: { "openid": app.globalData.openid, "carNum": e.currentTarget.dataset.name }, method: 'GET', header: { 'Content-type': 'application/json' }, success: function(res) { if(res.data == 0){ wx.showToast({ title: '车辆维修尚未结束、不可试驾', icon: 'none', }) return; } //切换图标 for (var ix in list) { if (ix == index) list[ix].state = 5; } //更新列表的状态 that.setData({ carList: list }); } }); } } }) },