const { api_leads_selects, api_get_country_city } = require('../../utils/api.js'); const { net } = require('../../utils/net.js'); const util = require('../../utils/util.js'); Page({ data: { businessRole: '', searchCode: "", sourceUserIds: [], searchTimeType: "", creatTimeArr: [{ name: "周", typeArr: [{ name: "本周", value: "2" }, { name: "上周", value: "1" }] }, { name: "月", typeArr: [{ name: "本月", value: "4" }, { name: "上月", value: "3" }] }], // 国家城市 loadingCountry: true, cityArr: [], cityId: "", countryArr: [], countryId: '', // 创建时间 createTimeStart: "", createTimeEnd: "", currentFilter: 'searchScenarioSels', filterObj: { searchScenarioSels: { checked: 1, name: '筛选场景', value: "", typeArr: [] }, leadsStatusSels: { checked: '', name: '状态', value: "2", typeArr: [] }, sourceUser: { name: '来源人', value: "4" }, countryAndCity: { name: '国家城市', value: "5" }, createTime: { name: '创建时间', value: "6" } }, }, onLoad: function (options) { // 个人分销商和顾问没有场景筛选 this.setData({ businessRole: util.getStorageSync('userInfo').businessRole }, () => { const { businessRole } = this.data if (businessRole == 2) { let filterObj = this.data.filterObj delete filterObj.searchScenarioSels delete filterObj.sourceUser this.setData({ filterObj: filterObj, currentFilter: 'leadsStatusSels' }) } }) // 筛选条件回显 const resultData = options.resultData ? JSON.parse(options.resultData) : {} const { countryId, cityId, searchScenario, status, sourceUserIds, searchTimeType, createTimeStart, createTimeEnd } = resultData this.setData({ sourceUserIds: sourceUserIds ? JSON.parse(sourceUserIds) : [], [`filterObj.sourceUser.checked`]: sourceUserIds ? true : '', [`filterObj.searchScenarioSels.checked`]: searchScenario || '', [`filterObj.leadsStatusSels.checked`]: status || '', cityId: cityId || '', countryId: countryId || '', [`filterObj.countryAndCity.checked`]: cityId || countryId ? true : '' }) if (searchTimeType || createTimeStart || createTimeEnd) { this.setData({ searchTimeType: searchTimeType, [`filterObj.createTime.checked`]: true }) if (searchTimeType == 0) { this.setData({ createTimeStart: createTimeStart ? util.formatTimeStr(createTimeStart) : '', createTimeEnd: createTimeEnd ? util.formatTimeStr(createTimeEnd - 23 * 3600 + 59 * 60 + 59) : '' }) } } this.getCountryAndCity() this.getLeadsSelects() }, onReady: function () { wx.setNavigationBarTitle({ title: '客户搜索' }) wx.setBackgroundColor({ backgroundColorBottom: '#fafafa' }); }, onShow: function () { }, onHide: function () { }, getCountryAndCity() { let params = { url: api_get_country_city } net.req(params).then((res) => { let countryList = [] if (res && res.data && Array.isArray(res.data) && res.data.length) { countryList = res.data.slice(1) } else { countryList = [] } this.setData({ countryArr: countryList, loadingCountry: false }, () => { if (this.data.countryId) { res.data.forEach(element => { if (element.id == this.data.countryId && element.son && element.son.length > 0) { let cityList = [] element.son.forEach(item => { cityList = cityList.concat(item.citys) }) this.setData({ cityArr: cityList }) } }); } }) }) }, filterTypeTap(e) { this.setData({ currentFilter: e.currentTarget.dataset.index }) }, filterTypeClassifyTap(e) { const value = e.currentTarget.dataset.value const { currentFilter, filterObj } = this.data const setChecked = `filterObj.${currentFilter}.checked` this.setData({ [setChecked]: value }) }, // 确定 sureTap() { const { countryId, cityId, filterObj, createTimeStart, createTimeEnd, searchTimeType, sourceUserIds } = this.data const resultData = {} if (countryId) resultData.countryId = countryId if (cityId) resultData.cityId = cityId const { searchScenarioSels, leadsStatusSels } = filterObj if (searchScenarioSels && searchScenarioSels.checked) resultData.searchScenario = searchScenarioSels.checked if (leadsStatusSels && leadsStatusSels.checked) resultData.status = leadsStatusSels.checked if (searchTimeType || (searchTimeType === 0)) resultData.searchTimeType = searchTimeType if (createTimeStart) resultData.createTimeStart = new Date(createTimeStart.split('-').join("/")).getTime() if (createTimeEnd) resultData.createTimeEnd = new Date(createTimeEnd.split('-').join("/")).getTime() + (23 * 3600 + 59 * 60 + 59) if (sourceUserIds && sourceUserIds.length) resultData.sourceUserIds = JSON.stringify(sourceUserIds) let pages = getCurrentPages(); let prevPage = pages[pages.length - 2]; if (prevPage && prevPage.getResultDataCallack) { prevPage.getResultDataCallack(resultData); wx.navigateBack(); } }, // 重置 resetTap() { const { businessRole } = this.data this.setData({ createTimeStart: "", createTimeEnd: "", searchTimeType: "", currentFilter: (businessRole == 2) ? 'leadsStatusSels' : "searchScenarioSels", [`filterObj.searchScenarioSels.checked`]: '', [`filterObj.leadsStatusSels.checked`]: "", [`filterObj.countryAndCity.checked`]: "", [`filterObj.sourceUser.checked`]: "", [`filterObj.createTime.checked`]: "", cityId: "", countryId: "", cityArr: [], sourceUserIds: [], createTimeStart: "", createTimeEnd: "" }) }, creatTimeTap(e) { this.setData({ searchTimeType: e.currentTarget.dataset.value, createTimeStart: "", createTimeEnd: "", [`filterObj.createTime.checked`]: true }) }, createTimeStartChange(event) { this.setData({ createTimeStart: event.detail.value, searchTimeType: 0, [`filterObj.createTime.checked`]: true }) }, createTimeEndChange(event) { this.setData({ createTimeEnd: event.detail.value, searchTimeType: 0, [`filterObj.createTime.checked`]: true }) }, selectCountryTap(e) { const { index, id } = e.currentTarget.dataset const cityData = this.data.countryArr[index] && this.data.countryArr[index].son let cityList = [] if (cityData && Array.isArray(cityData) && cityData.length > 0) { cityData.forEach(item => { cityList = cityList.concat(item.citys) }) } this.setData({ searchCode: '', countryId: id, cityArr: cityList, cityId: "", [`filterObj.countryAndCity.checked`]: true }) }, touchSearch(event) { this.setData({ searchCode: event.detail.value }) let _this = this; clearTimeout(this.timer) this.timer = setTimeout(() => { _this.searchCityHandle(event); }, 500) }, searchCityHandle(event) { const { value } = event.detail let cityData = this.data.countryArr.filter(item => item.id == this.data.countryId)[0].son let cityList = [] if (cityData && Array.isArray(cityData) && cityData.length > 0) { cityData.forEach(item => { cityList = cityList.concat(item.citys) }) } if (value) { // 获取筛选后的值 let result = [] cityList.forEach(element => { const { name, enName } = element if ((name.indexOf(value) !== -1) || (enName.toLowerCase().indexOf(value.toLowerCase()) !== -1)) { result.push(element) } }) this.setData({ cityArr: result }) } else { this.setData({ cityArr: cityList }) } }, selectCityTap(e) { const { id } = e.currentTarget.dataset this.setData({ [`filterObj.countryAndCity.checked`]: true, cityId: id, }) }, getLeadsSelects() { let params = { url: api_leads_selects, } this.setData({ loadingFlag: true }) net.req(params).then((res) => { const { leadsStatusSels, searchScenarioSels } = res.data this.setData({ [`filterObj.searchScenarioSels.typeArr`]: searchScenarioSels, [`filterObj.leadsStatusSels.typeArr`]: leadsStatusSels, loadingFlag: false }) }) }, goSourceUserList() { wx.navigateTo({ url: `/pages/sourcePersonList/sourcePersonList?sourceUserIds=${JSON.stringify(this.data.sourceUserIds)}&checkType=2` }) }, // 来源人 getSourcePersonCallack(data) { this.setData({ sourceUserIds: data, [`filterObj.sourceUser.checked`]: data.length ? true : '' }) } })