schangxiang@126.com
2024-12-20 01c3a4658026e9c3ed9daaf1f1b27da368ab11a9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// uniapp -原生复选框-解决点击复选框卡顿现象  --- 供PO越库 入库越库按钮用途
export default {
  data() {
    return {
      arrIds: [],
    };
  },
  watch: {
    // 监听复选框
    arrIds(newVal, oldVal) {
      console.log("newVal----" + newVal);
      console.log("oldVal----" + oldVal);
      if (newVal.length < oldVal.length) {
        for (var i = 0, lenI = oldVal.length; i < lenI; ++i) {
          const item = oldVal[i];
          if (!newVal.includes(item)) {
            console.log("取消了一个--------" + item);
            // this.handleCart(0, item);
          }
        }
      } else {
        for (var i = 0, lenI = newVal.length; i < lenI; ++i) {
          const item = newVal[i];
          if (!oldVal.includes(item)) {
            console.log("选中了一个--------" + item);
            // this.handleCart(1, item);
          }
        }
      }
    },
  },
  methods: {
    // 选中复选框
    checkboxChange: function (e) {
      var values = e.detail.value; //存放所有选中的id
      this.arrIds = values;
    },
 
    // 根据选中的key,更新提交的列表
    handleCart(type, itemHandle) {
      console.log(itemHandle);
      if (type == 1) {
        //选中
        let idx = this.singlist.findIndex((v) => v.key == itemHandle);
        if (idx > -1) {
          let idx3 = this.arr.findIndex((v) => v.key == itemHandle);
          if (idx3 == -1) {
            this.arr.push(this.singlist[idx]);
          }
        }
      }
      if (type == 0) {
        //取消
        let idx2 = this.arr.findIndex((v) => v.key == itemHandle);
        if (idx2 > -1) {
          this.arr.splice(idx2, 1);
        }
      }
    },
  },
};