|
|
@@ -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)
|
|
|
+
|
|
|
+
|
|
|
+ })
|
|
|
+ },
|
|
|
})
|