123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- 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 : ''
- })
- }
- })
|