微信小程序之标签多选效果,取消多选,wxs判断是否包含元素,标签添加删除

效果图:
微信小程序之标签多选效果,取消多选,wxs判断是否包含元素,标签添加删除_第1张图片

	<wxs module="m1">
        var baohan = function(loupanlistact,index) {
          var boo;
          var index = loupanlistact.indexOf(index)
          if (index <0){
            boo = false;
          }else{
            boo = true;
          }          
          return boo;       
        }
        module.exports.baohan = baohan;
    wxs>
	<view class="selconbox">
        <view class="seltit">客户标签view>
        <view class="selulbox">
          <view class="selli {{m1.baohan(kehutapact,index) ? 'selact' : ''}}"
                wx:for="{{kehutaparr}}" 
                  wx:key="id" 
                  data-index="{{index}}"
                  data-tagid="{{item.id}}"
                  bindtap="kehutiptap">
            <text class="tagtxt">{{item.tag}}text>
            <image src="../../images/lpsel-xx.png" 
                    mode="widthFix" 
                    class="khgsdel"
                    wx:if="{{isdeltag}}" />
          view>
          <block wx:if="{{zywxid == ''}}">
            <view class="selli" bindtap="addtanshow" data-addtantit="添加标签">添加+view>
            <view class="selli {{isdeltag ? 'selact':''}}" wx:if="{{isnotag}}" bindtap="deltagshow">删除-view>
          block>
        view>
      view>

	
  <view class="addloupantan" wx:if="{{isaddtan}}">
    <view class="addmain">
      <image src="../../images/lpsel-xx.png" mode="widthFix" class="addxx" bindtap="addtanxx" />
      <view class="addtit">{{addtantit}}view>
      <input type="text" class="addinp" value="{{addinptxt}}" bindinput="addinptxt" placeholder="请填写名称" />
      <view class="addqueding" bindtap="addposttap">确定view>
    view>
  view>

js

data:{
	isdeltag:0,
	kehutapact:[],
	
}
  // add添加标签、楼盘、销售、地址
  deltagshow: function () { //删除标签
    this.setData({
      isdeltag: !this.data.isdeltag
    })
  },
  addtanshow: function (e) {
    this.setData({
      isaddtan: 1,
      addtantit: e.currentTarget.dataset.addtantit,
      addinptxt: ''
    })
  },
  addtanxx: function () {
    this.setData({
      isaddtan: 0,
      addinptxt: ''
    })
  },
  addinptxt: function (e) {
    this.setData({
      addinptxt: e.detail.value
    })
  },
  addposttap: function () {
    if (this.data.addinptxt != '') {
      if (this.data.addtantit == '添加标签' || this.data.addtantit == '添加组员客户标签') {
        let params = {
          wx_id: this.data.wxid,
          token: this.data.token,
          tag: this.data.addinptxt,
          is_leader: this.data.is_leader
        }
        addTags(params).then(res => {
          console.log(res);
          if (res.data.message == 'ok') {
            wx.showToast({
              title: '添加成功',
              icon: 'none'
            })
            this.getgetTagsList();
          } else {
            wx.showToast({
              title: res.data.message,
              icon: 'none'
            })
          }
          this.setData({
            isaddtan: 0,
            addinptxt: ''
          })
        })
      }else {
      wx.showToast({
        title: '内容不能为空!',
        icon: 'none'
      })
    }
  },
  kehutiptap: function (e) {
    let index = e.currentTarget.dataset.index;
    if (this.data.isdeltag) { //删除标签
      this.setData({
        deltagid: e.currentTarget.dataset.tagid
      })
      wx.showModal({
        title: '确定删除标签吗?',
        // content:'如删除该标签,其他与之关联的客户均会删除该标签',
        success: (res) => {
          if (res.confirm) {
            this.postdelTags();
            // console.log('用户点击确定')
          } else if (res.cancel) {
            // console.log('用户点击取消')
          }
        }
      })
    } else {
      let arr = this.data.kehutapact;
      if (arr.includes(index)) {
        let spliceidx = arr.indexOf(index);
        arr.splice(spliceidx, 1);
        this.setData({
          kehutapact: arr
        })
      } else {
        arr.push(index);
        this.setData({
          kehutapact: arr
        })
      }
    }
  },
  postdelTags: function () {
    let params = {
      tag_id: this.data.deltagid,
      wx_id: this.data.wxid,
      token: this.data.token,
    }
    delTags(params).then(res => {
      console.log(res);
      if (res.data.message == 'ok') {
        wx.showToast({
          title: '已删除!',
          icon: 'none'
        })
        this.getgetTagsList();
      }
    })
  },

你可能感兴趣的:(微信小程序)