zhaoxiaohai 3 年之前
父節點
當前提交
f4e40c3de8

+ 98 - 49
packageA/tags/index.js

@@ -1,55 +1,104 @@
+const _Http = getApp().globalData.http;
+
 Page({
-    data: {
-        list: [
-            "标签1",
-            "标签2",
-            "标签22",
-            "标签21231231",
-            "标签212胜多负少",
-            "标签223423SDf",
-            "标签2dsf sdf让他水电费",
-            "标签3"
-        ],
-        copy: [
-            "标签1",
-            "标签2",
-            "标签22",
-            "标签21231231",
-            "标签212胜多负少",
-            "标签223423SDf",
-            "标签2dsf sdf让他水电费",
-            "标签3"
-        ],
-        ownerid: 0,
-        ownertable: 0,
-        actives: [],
-    },
-    onLoad(options) {
-        if (options.ownertable) this.setData({
-            ...options
-        })
-    },
-    onChange(e) {
-        const {
-            tag
-        } = e.target.dataset;
-        if (!tag) return;
-        let actives = this.data.actives;
-        if (actives.some(v => v == tag)) {
-            actives = actives.filter(v => v != tag)
-        } else {
-            actives.push(tag)
+  data: {
+    ownerid: 0,
+    ownertable: 0,
+    list: [], //全部标签
+    copy: [], //全部标签拷贝 用来模糊搜索
+    forbiddens: [], //相斥禁用
+    actives: [], //选中数组
+  },
+  onLoad(options) {
+    if (options.ownertable) {
+      _Http.basic({
+        "id": 20220929085401,
+        "content": {
+          "ownertable": options.ownertable,
+          "ownerid": options.ownerid
         }
-        this.setData({
-            actives
+      }).then(res => {
+        let forbiddens = [];
+        res.data.datatag.filter(value => {
+          let item = res.data.option.find(v => value == v.tag);
+          if (!item || item.mutextag.length == 0) return;
+          forbiddens = forbiddens.concat(item.mutextag)
         })
-    },
-    /* 搜索 */
-    onInput({
-        detail
-    }) {
         this.setData({
-            list: detail == '' ? this.data.copy : this.data.copy.filter(v => v.includes(detail))
+          list: res.data.option, //全部标签
+          copy: res.data.option, //全部标签拷贝 用来模糊搜索
+          actives: res.data.datatag, //选中数组
+          forbiddens
         })
-    },
+      })
+      this.setData({
+        ...options
+      })
+    }
+  },
+  //选中标签
+  onChange(e) {
+    const {
+      tag,
+      mutextag
+    } = e.target.dataset.item;
+    if (!tag || e.target.dataset.disabled) return;
+    let actives = this.data.actives,
+      forbiddens = this.data.forbiddens;
+    if (actives.some(v => v == tag)) {
+      //已经选中
+      actives = actives.filter(v => v != tag)
+      if (mutextag.length != 0) mutextag.forEach(v => {
+        let index = forbiddens.findIndex(value => value == v);
+        if (index != -1) forbiddens.splice(index, 1);
+      })
+    } else {
+      //未选中
+      actives.push(tag)
+      if (mutextag.length != 0) forbiddens = forbiddens.concat(mutextag);
+    }
+    this.setData({
+      actives,
+      forbiddens
+    })
+  },
+  /* 搜索 */
+  onInput({
+    detail
+  }) {
+    this.setData({
+      list: detail == '' ? this.data.copy : this.data.copy.filter(v => v.tag.includes(detail))
+    })
+  },
+  /* 提交 */
+  submit() {
+    _Http.basic({
+      "id": 20220929090901,
+      "content": {
+        "ownertable": this.data.ownertable,
+        "ownerid": this.data.ownerid,
+        "datatag": this.data.actives
+      }
+    }).then(res => {
+      console.log("提交标签", res)
+      if (res.msg != '成功') return wx.showToast({
+        title: res.data,
+        icon: "none"
+      });
+
+      wx.showToast({
+        title: '保存成功!',
+        icon: "none"
+      });
+
+      setTimeout(() => {
+        let pages = getCurrentPages();
+        pages[pages.length - 2].getTags();
+
+        wx.navigateBack();
+      }, 300)
+
+
+    })
+  },
 })

+ 1 - 0
packageA/tags/index.scss

@@ -2,6 +2,7 @@
     width: 100vw;
     background-color: #fff;
     padding: 20rpx 30rpx;
+    box-sizing: border-box;
 
     .title {
         font-size: 28rpx;

+ 13 - 13
packageA/tags/index.wxml

@@ -1,24 +1,24 @@
 <van-search value="{{ value }}" shape="round" background="#fff" placeholder="请输入搜索关键词" bind:change='onInput' />
 
 <view class="content" style="margin-top: 20rpx;">
-    <view class="title">请选择添加标签</view>
-    <view class="tags" bindtap="onChange">
-        <van-button custom-class='basic {{active.que(item,actives)?"active":""}}' wx:for="{{list}}" wx:key="index" data-tag="{{item}}">{{item}}</van-button>
-    </view>
+  <view class="title">请选择添加标签</view>
+  <view class="tags" bindtap="onChange">
+    <van-button custom-class='basic {{active.que(item.tag,actives)?"active":""}}' disabled='{{active.que(item.tag,forbiddens)}}' wx:for="{{list}}" wx:key="item.sys_systemtagdetailid" data-item="{{item}}" data-disabled="{{active.que(item.tag,forbiddens)}}">{{item.tag}}</van-button>
+  </view>
 </view>
 
 <view style="height: 130rpx;" />
 <view class="footer">
-    <view class="count">
-        已选:{{actives.length}}
-    </view>
-    <van-button custom-class='but'>确定</van-button>
+  <view class="count">
+    已选:{{actives.length}}
+  </view>
+  <van-button custom-class='but' bindtap="submit">确定</van-button>
 </view>
 
 <wxs module="active">
-    module.exports.que = function (name, list) {
-        return list.some(function (v) {
-            return v === name
-        })
-    }
+  module.exports.que = function (name, list) {
+    return list.some(function (v) {
+      return v === name
+    })
+  }
 </wxs>

+ 32 - 38
packageA/tags/modules/Yl-tags/index.js

@@ -1,44 +1,38 @@
 const _Http = getApp().globalData.http;
 Component({
-    properties: {
-        add: Boolean, //是否允许新增
-        ownertable: {
-            type: String,
-            value: "sa_itemgroup"
-        },
-        ownerid: {
-            type: String,
-            value: 11
+  properties: {
+    add: Boolean, //是否允许新增
+    ownertable: String,
+    ownerid: String
+  },
+  data: {
+    datatag: [],
+    systemtag: [],
+  },
+  methods: {
+    /* 获取标签 */
+    getTags() {
+      _Http.basic({
+        "id": 20220929085401,
+        "content": {
+          ownertable: this.data.ownertable,
+          ownerid: this.data.ownerid
         }
+      }).then(res => {
+        console.log("标签列表", res)
+        if (res.msg != '成功') return wx.showToast({
+          title: res.data,
+          icon: "none"
+        });
+        this.setData({
+          ...res.data
+        })
+      })
     },
-    data: {
-        datatag: [],
-        systemtag: [],
-    },
-    methods: {
-        /* 获取标签 */
-        getTags() {
-            _Http.basic({
-                "id": 20220929085401,
-                "content": {
-                    ownertable: this.data.ownertable,
-                    ownerid: this.data.ownerid
-                }
-            }).then(res => {
-                console.log("标签列表", res)
-                if (res.msg != '成功') return wx.showToast({
-                    title: res.data,
-                    icon: "none"
-                });
-                this.setData({
-                    ...res.data
-                })
-            })
-        },
-        addTags() {
-            wx.navigateTo({
-                url: `/packageA/tags/index?ownertable=${this.data.ownertable}&ownerid=${this.data.ownerid}`
-            })
-        }
+    addTags() {
+      wx.navigateTo({
+        url: `/packageA/tags/index?ownertable=${this.data.ownertable}&ownerid=${this.data.ownerid}`
+      })
     }
+  }
 })

+ 1 - 0
packageA/tags/modules/Yl-tags/index.scss

@@ -11,6 +11,7 @@
         padding: 0 10rpx;
         border-radius: 20rpx;
         font-family: PingFang SC-Regular, PingFang SC;
+        margin-bottom: 8rpx;
     }
     .datatag {
         background: #FFEFD9;