riku
2024-07-26 c827d70bd16535e103f4bcdd9f3ed53a5fd324e8
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { useScenePicker } from '../../../../../../behaviors/picker/scene/scene';
import { useDistrictPicker } from '../../../../../../behaviors/picker/district/district';
import { useTownPicker } from '../../../../../../behaviors/picker/town/town';
import { useLoading } from '../../../../../../behaviors/loading';
import { fetchSearchUser } from '../../../../../../services/usercenter/fetchUser';
 
Component({
  behaviors: [useScenePicker, useDistrictPicker, useTownPicker, useLoading],
  options: {
    addGlobalClass: true,
    multipleSlots: true,
  },
  /**
   * 组件的属性列表
   */
  properties: {
    refresh: {
      type: Boolean,
      observer(value) {
        this.startLoad();
      },
    },
  },
 
  /**
   * 组件的初始数据
   */
  data: {
    placeholder: '请输入关键字搜索',
    searchValue: '',
    searchOption: {},
    list: [],
    selectedList: [],
  },
 
  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
      this._startLoad();
    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },
 
  /**
   * 组件的方法列表
   */
  methods: {
    startLoad() {
      this.setData({ selectedList: [] });
      this._startLoad();
    },
 
    onCancel() {
      const { selectedList, list } = this.data;
      if (selectedList.length > 0) {
        list.forEach(s => {
          s.checked = false;
        });
        this.setData({ selectedList: [], list });
        this.triggerEvent('clickConfirm', []);
      } else {
        this.triggerEvent('clickCancel');
      }
    },
 
    onConfirm() {
      this.triggerEvent('clickConfirm', this.data.selectedList);
    },
 
    // 下拉框选择事件
    _confirm(key) {
      this._startLoad();
    },
 
    onCheckBoxChange(e) {
      const { checked } = e.detail;
      const { index } = e.currentTarget.dataset;
      const user = this.data.list[index];
      user.checked = checked;
      const { selectedList } = this.data;
      if (checked) {
        selectedList.push(user);
      } else {
        const i = selectedList.indexOf(user);
        if (i != -1) {
          selectedList.splice(i, 1);
        }
      }
      this.setData({
        selectedList,
        [`list[${index}]`]: user,
      });
      console.log(selectedList);
    },
 
    _fetchData(page) {
      const { sceneValue, districtValue, townValue, searchValue } = this.data;
      const data = {
        sceneTypes: sceneValue,
        districtCode: districtValue[0],
        townCode: townValue[0],
        searchText: searchValue,
        userTypeId: 3,
      };
      return fetchSearchUser({ page, data }).then(res => {
        this.setData({
          list: page == 1 ? res.data : this.data.list.concat(res.data),
        });
        return res.head;
      });
    },
  },
});