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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
Component({
  options: {
    addGlobalClass: true,
  },
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      observer(show) {
        this.setData({ visible: show });
      },
    },
    closeBtn: {
      type: Boolean,
      value: false,
    },
    // 设置行政区域的值
    location: {
      type: Object,
    },
    // 设置集中区的值
    area: {
      type: String,
    },
    // 设置行政区域的值
    management: {
      type: String,
    },
  },
 
  /**
   * 组件的初始数据
   */
  data: {
    visible: false,
    // 初始值传递事件计数
    confirmCount: 0,
  },
 
  /**
   * 组件的方法列表
   */
  methods: {
    reset() {},
    confirm() {
      const {
        provinceText,
        cityText,
        districtText,
        townText,
        areaText,
        areaValue,
        managementText,
        managementValue,
        locationValue,
      } = this.data;
      this.triggerEvent('confirm', {
        provinceText,
        cityText,
        districtText,
        townText,
        areaText,
        areaValue,
        managementText,
        managementValue,
        locationValue,
      });
    },
    close(e) {
      this.triggerEvent('showFilterPopupClose');
      this.setData({ visible: e.detail.visible });
    },
 
    // 行政区划选项初始化及变更
    setLocation(e) {
      this.setData(e.detail);
    },
    initLocation(e) {
      this.setLocation(e);
      this.initValue();
    },
    onLocationChange(e) {
      this.setLocation(e);
    },
 
    setArea(e) {
      const { areaText, areaValue } = e.detail;
      this.setData({
        areaText: areaValue[0] ? areaText : null,
        areaValue: areaValue[0],
      });
    },
    initArea(e) {
      this.setArea(e);
      this.initValue();
    },
    onAreaChange(e) {
      this.setArea(e);
    },
 
    setManagement(e) {
      const { managementText, managementValue } = e.detail;
      this.setData({
        managementText: managementValue[0] ? managementText : null,
        managementValue: managementValue[0],
      });
    },
    initManagement(e) {
      this.setManagement(e);
      this.initValue();
    },
    onManagementChange(e) {
      this.setManagement(e);
    },
 
    // 初始值传递事件
    initValue() {
      let { confirmCount } = this.data;
      // onLocationChange, onAreaChange, onManagementChange 都触发过后,不再执行
      if (confirmCount == 3) return;
      confirmCount++;
      this.setData({ confirmCount });
      // onLocationChange, onAreaChange, onManagementChange 分别首次触发时,表示对应组件初始化完成,并传递初始值,此处同步将初始值传递下去
      if (confirmCount == 3) {
        const { provinceText, cityText, districtText, townText, areaText, areaValue, managementText, managementValue } =
          this.data;
        this.triggerEvent('initValue', {
          provinceText,
          cityText,
          districtText,
          townText,
          areaText,
          areaValue,
          managementText,
          managementValue,
        });
      }
    },
  },
});