// miniprogram/subpages/organization/pages/searchInfo/searchInfo.js import {getSearchOfficer,getSearchDept} from '../../../../api/organization' Page({ /** * 页面的初始数据 */ data: { isClick:'person', keyWords:'', personList:[], departmentList:[], callNumber:'', locked:false,//是否发请求 false发送 true不发送 loadVisible: false, loadType: 'more', isShowNoData:false }, onLoad: function () { }, triggle(e:any){ let {currentTarget}=e if(currentTarget.dataset.index=="联系人"){ this.setData({ isClick:'person', personList:[], departmentList:[], // keyWords:'', loadVisible:false, isShowNoData:false }) this.getSearchOfficer() }else if(currentTarget.dataset.index=="部门"){ this.setData({ isClick:'department', personList:[], departmentList:[], // keyWords:'', loadVisible:false, isShowNoData:false }) this.getSearchDept() } }, goCall(e:any){ this.setData({ callNumber:e.currentTarget.dataset.number }) wx.showModal({ title: '拨打电话', content: `您确定拨打${this.data.callNumber}`, cancelColor:'#29B9A5', confirmColor:'#29B9A5', success:(res)=> { if (res.confirm) { console.log('用户点击确定') wx.makePhoneCall({ phoneNumber: this.data.callNumber }) } else if (res.cancel) { console.log('用户点击取消') } } }) }, /***获取搜索框的内容 ****/ bindKeyInput(e:any){ this.setData({ keyWords: e.detail.value }) if(this.data.isClick=="person"){ this.getSearchOfficer() }else if(this.data.isClick == "department"){ this.getSearchDept() } }, /*****搜索联系人的请求 *****/ async getSearchOfficer(){ if(this.data.keyWords=='') return if(this.data.locked) return //代表上一次的请求还没发送完 不进行下一次的请求 this.setData({ loadVisible:true, personList:[], loadType:'more', isShowNoData:false }) let obj = { keyWords:this.data.keyWords, } this.setData({ locked:true,//将要开始发送请求 }) try{ let res:any = await getSearchOfficer(obj) this.setData({ personList:res.data, locked:false, loadType:'none' }) if(this.data.personList.length==0){ this.setData({ loadVisible:false, isShowNoData:true }) } console.log('res',res) }catch{ this.setData({ locked:false, loadVisible:false }) } }, /*****搜索部门的请求 *****/ async getSearchDept(){ if(this.data.keyWords=='') return if(this.data.locked) return //代表上一次的请求还没发送完 不进行下一次的请求 this.setData({ loadVisible:true, departmentList:[], loadType:'more', isShowNoData:false }) let obj = { keyWords:this.data.keyWords, } this.setData({ locked:true,//将要开始发送请求 }) try{ let res:any = await getSearchDept(obj) this.setData({ departmentList:res.data, locked:false, loadType:'none' }) if(this.data.departmentList.length==0){ this.setData({ loadVisible:false, isShowNoData:true }) } console.log('res',res) }catch{ this.setData({ locked:false, loadVisible:false }) } }, goIndex(e:any){ if(e.currentTarget.dataset.key=='2'){ wx.navigateTo({ url: `/subpages/organization/pages/streeUnfold/streeUnfold?communityId=${e.currentTarget.dataset.id}` }); }else if(e.currentTarget.dataset.key=='0'){ wx.navigateTo({ url: `/subpages/organization/pages/organizationStree/organizationStree` }); }else if(e.currentTarget.dataset.key=='1'){ wx.navigateTo({ url: `/subpages/organization/pages/organizationStree/organizationStree?id=${e.currentTarget.dataset.id}` }); } } })