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, }); } }, }, });