// pages/city/index.js const app = getApp(); import { customRequest } from '../../utils/request.js'; Page({ /** * 页面的初始数据 */ data: { inputShowed: false, inputVal: "", statusBarHeight: wx.getStorageSync("statusBarHeight"), // 状态栏高度 navigationBarHeight: wx.getStorageSync("navigationBarHeight"), // 导航栏高度 menuButtonHeight: wx.getStorageSync("menuButtonHeight"), // 胶囊按钮高度 menuButton: wx.getStorageSync("menuButtonInfo"), // 胶囊信息 toped: 1, hotCity: [ { id: 1, name: "郑州" }, { id: 2, name: "上海" }, { id: 3, name: "昆山" }, { id: 4, name: "苏州" }, { id: 5, name: "无锡" }, { id: 6, name: "深圳" }, { id: 7, name: "南京" }, { id: 8, name: "东莞" }, { id: 9, name: "常州" }, ], hotCitySelect: -1, toView: "", from: "", cityList: [], provinceList: [], letter: ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"], selectedQuanGuo: { name: "全国", shortName: "全国", checked: true, }, selectedCityLocal: { name: "", shortName: "", checked: false, }, selectedProvinceLocal: { name: "", shortName: "", checked: false, }, selectedCity: { name: "", shortName: "", checked: false, }, selectedCityTemp: { name: "", shortName: "", checked: false, }, alpha: "", plShow: false, pltop: 70, selectedQuanGuoStorage: { name: "全国", shortName: "全国", checked: true, }, selectedCityStorage: { name: "", shortName: "", checked: false, }, selectedCityLocalStorage: { name: "", shortName: "", checked: false, }, selectedCityTempStorage: { name: "", shortName: "", checked: false, }, placeholderText: "搜索省份/拼音", }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that = this; console.log(options); if (options.from) { this.setData({ from: options.from, }); } if (options.isCity) { if (options.isCity == 0) { this.setData({ toped: 2, }); } else { this.setData({ toped: 1, }); } } try { var searchCityParamStorage = wx.getStorageSync("searchCityParamStorage"); console.log("searchCityParamStorage======", searchCityParamStorage); var selectedCityTempParamStorage = wx.getStorageSync("selectedCityTempParamStorage"); console.log("selectedCityTempParamStorage======", selectedCityTempParamStorage); var tag = wx.getStorageSync("selectedQuanGuoStorage"); if (tag && app.isNotEmptyCheck(tag.name)) { that.data.selectedQuanGuoStorage = wx.getStorageSync("selectedQuanGuoStorage"); console.log("selectedQuanGuoStorage======", that.data.selectedQuanGuoStorage); that.data.selectedCityStorage = wx.getStorageSync("selectedCityStorage"); console.log("selectedCityStorage======", that.data.selectedCityStorage); that.data.selectedCityLocalStorage = wx.getStorageSync("selectedCityLocalStorage"); console.log("selectedCityLocalStorage======", that.data.selectedCityLocalStorage); that.data.selectedCityTempStorage = wx.getStorageSync("selectedCityTempStorage"); console.log("selectedCityTempStorage======", that.data.selectedCityTempStorage); } if (searchCityParamStorage && app.isNotEmptyCheck(searchCityParamStorage.name)) { that.setData({ selectedQuanGuo: JSON.parse(JSON.stringify(that.data.selectedQuanGuoStorage)), selectedCity: JSON.parse(JSON.stringify(that.data.selectedCityStorage)), selectedCityTemp: JSON.parse(JSON.stringify(that.data.selectedCityTempStorage)), selectedCityLocal: JSON.parse(JSON.stringify(that.data.selectedCityTempStorage)), }); } else { that.setData({ selectedQuanGuo: that.data.selectedQuanGuo, selectedCityLocal: that.data.selectedCityLocal, selectedCity: that.data.selectedCity, selectedCityTemp: that.data.selectedCityTemp, }); } } catch (e) { console.log("获取缓存设置的查询职位列表参数错误:", e); } this.getAllCityLevel2(); this.getAllProvinceLevel1(); // that.getProvinceLocation() that.getLocation() }, leftMove (e) { this.setData({ toView: "", }); }, handlerAlphaTap (e) { console.log(e.target.dataset.item); this.setData({ toView: e.target.dataset.item, alpha: e.target.dataset.item, plShow: true, }); }, touchEnd (e) { this.setData({ plShow: false, }); }, touchMove (e) { var that = this; // console.log(e) console.log(e.changedTouches[0].clientY); let moveY = e.changedTouches[0].clientY; let rY = moveY - 80; // toView:'hot' // toView:e.target.dataset.item if (rY >= 0) { let index = Math.ceil(rY / 22); // console.log(index); if (index == 1) { this.setData({ toView: "top", alpha: "查", plShow: true }); } else if (index == 2) { this.setData({ toView: "hot", alpha: "热", plShow: true, pltop: 92 }); } else { let nonwAp = that.data.letter[index - 3]; let hg = (index - 2) * 22; this.setData({ toView: nonwAp, alpha: nonwAp, plShow: true, pltop: 92 + hg }); } // if(0 <= index < list.length) { // let nonwAp = list[index]; // nonwAp && this.setData({alpha: nonwAp.alphabet}); // } } // let {list} = this.data; // console.log(list) // console.log(this.data.alphabet) // let moveY = e.touches[0].clientY; // let rY = moveY - this.offsetTop; // if(rY >= 0) { // let index = Math.ceil((rY - this.apHeight)/ this.apHeight); // if(0 <= index < list.length) { // let nonwAp = list[index]; // nonwAp && this.setData({alpha: nonwAp.alphabet}); // } // } }, getLocation () { var that = this; if (app.isNotEmptyCheck(app.globalData.lng) && app.isNotEmptyCheck(app.globalData.lat)) { that.getCityNameByLatLng(app.globalData.lng, app.globalData.lat, 1); } else { wx.getSetting({ success: (res) => { console.log(res); // res.authSetting.location if (res.authSetting["scope.userLocation"]) { wx.getLocation({ type: "gcj02", success (res1) { console.log("获取位置"); console.log(res1); app.globalData.lng = res1.longitude; app.globalData.lat = res1.latitude; that.getCityNameByLatLng(res1.longitude, res1.latitude, 1); }, fail () { }, }); that.getCityNameByLatLng(app.globalData.lng, app.globalData.lat, 1); } else { console.log("11111111"); wx.openSetting({ success (res) { console.log(res.authSetting); }, }); } }, }); } }, getProvinceLocation () { let that = this; if (app.isNotEmptyCheck(app.globalData.lng) && app.isNotEmptyCheck(app.globalData.lat)) { that.getProvinceNameByLatLng(app.globalData.lng, app.globalData.lat, 1); } else { wx.getSetting({ success: (res) => { console.log(res); // res.authSetting.location if (res.authSetting["scope.userLocation"]) { wx.getLocation({ type: "gcj02", success (res1) { console.log("获取位置"); console.log(res1); app.globalData.lng = res1.longitude; app.globalData.lat = res1.latitude; that.getProvinceNameByLatLng(res1.longitude, res1.latitude, 1); }, fail () { }, }); that.getProvinceNameByLatLng(app.globalData.lng, app.globalData.lat, 1); } else { console.log("11111111"); wx.openSetting({ success (res) { console.log(res.authSetting); }, }); } }, }); } }, selectQuanGuo: function (e) { var that = this; that.data.selectedQuanGuo.checked = true; that.data.selectedCity.checked = false; that.data.selectedCityLocal.checked = false; that.data.selectedProvinceLocal.checked = false; that.data.selectedCityTemp.checked = false; this.setData({ selectedQuanGuo: that.data.selectedQuanGuo, selectedCity: that.data.selectedCity, selectedCityTemp: that.data.selectedCityTemp, selectedCityLocal: that.data.selectedCityLocal, selectedProvinceLocal: that.data.selectedProvinceLocal, }); }, selectOld: function (e) { var that = this; that.clearAllChecked(); that.data.selectedCity.checked = true; this.setData({ selectedQuanGuo: that.data.selectedQuanGuo, selectedCity: that.data.selectedCity, selectedCityTemp: that.data.selectedCityTemp, selectedCityLocal: that.data.selectedCityLocal, }); }, reset: function (e) { this.clearAllChecked(); this.data.selectedQuanGuo.checked = true; this.setAllSelected(); }, selectCity: function (e) { var city = e.currentTarget.dataset.city; console.log(city); this.data.selectedCityLocal.checked = false; var that = this; if (this.data.selectedCity.id != city.id) { this.data.selectedCity.checked = false; } this.data.selectedCityTemp = city; this.data.selectedCityTemp.checked = true; this.data.selectedQuanGuo.checked = false; this.setData({ selectedCity: that.data.selectedCity, selectedCityTemp: that.data.selectedCityTemp, selectedQuanGuo: that.data.selectedQuanGuo, selectedCityLocal: this.data.selectedCityLocal, }); }, loginOut: function () { var that = this; var temp; if (that.data.toped == 1) { if (that.data.selectedCityTemp.checked) { that.clearAllChecked(); that.data.selectedCityTemp.checked = true; temp = that.data.selectedCityTemp; that.data.selectedCity = that.data.selectedCityTemp; } else if (that.data.selectedQuanGuo.checked) { that.clearAllChecked(); that.data.selectedQuanGuo.checked = true; temp = that.data.selectedQuanGuo; } else if (that.data.selectedCity.checked) { that.clearAllChecked(); that.data.selectedCity.checked = true; temp = that.data.selectedCity; } else if (that.data.selectedCityLocal.checked) { that.clearAllChecked(); that.data.selectedCityLocal.checked = true; temp = that.data.selectedCityLocal; } try { wx.setStorageSync("searchCityParamStorage", { ...temp, isCity: true }); wx.setStorageSync("selectedCityTempParamStorage", that.data.selectedCity); wx.setStorageSync("selectedQuanGuoStorage", that.data.selectedQuanGuo); wx.setStorageSync("selectedCityStorage", that.data.selectedCity); wx.setStorageSync("selectedCityLocalStorage", that.data.selectedCityLocal); wx.setStorageSync("selectedCityTempStorage", that.data.selectedCityTemp); wx.setStorageSync("FROMCITY", true); } catch (e) { console.log("index-设置查询职位列表参数错误", e); } } else if (that.data.toped == 2) { if (that.data.selectedCityTemp.checked) { that.clearAllChecked(); that.data.selectedCityTemp.checked = true; temp = that.data.selectedCityTemp; that.data.selectedCity = that.data.selectedCityTemp; } else if (that.data.selectedQuanGuo.checked) { that.clearAllChecked(); that.data.selectedQuanGuo.checked = true; temp = that.data.selectedQuanGuo; } else if (that.data.selectedCity.checked) { that.clearAllChecked(); that.data.selectedCity.checked = true; temp = that.data.selectedCity; } else if (that.data.selectedProvinceLocal.checked) { that.clearAllChecked(); that.data.selectedProvinceLocal.checked = true; temp = that.data.selectedProvinceLocal; } try { wx.setStorageSync("searchCityParamStorage", { ...temp, isCity: false }); wx.setStorageSync("selectedCityTempParamStorage", that.data.selectedCity); wx.setStorageSync("selectedQuanGuoStorage", that.data.selectedQuanGuo); wx.setStorageSync("selectedCityStorage", that.data.selectedCity); wx.setStorageSync("selectedCityLocalStorage", that.data.selectedCityLocal); wx.setStorageSync("selectedCityTempStorage", that.data.selectedCityTemp); wx.setStorageSync("FROMCITY", true); } catch (e) { console.log("index-设置查询职位列表参数错误", e); } } // if (this.data.from == "search") { // var pages = getCurrentPages(); // var prevPage = pages[pages.length - 2]; // 上一个页面 // prevPage.data.storeJobListSearchForm.cityName = temp.name; // prevPage.setData({ // storeJobListSearchForm: prevPage.data.storeJobListSearchForm, // searchCityParamStorage: temp, // }); // wx.navigateBack({ // delta: 1, // }); // // wx.reLaunch({ // // url: "../jobListSearch/index?fromSearchPage=1", // // }); // } else { var pages = getCurrentPages(); var prevPage = pages[pages.length - 2]; // 上一个页面 if (that.data.toped == 1) { if (temp) { prevPage.data.storeJobListSearchForm.cityName = temp.name; prevPage.data.storeJobListSearchForm.provinceName = ""; } else { wx.showToast({ title: '当前未选择省市', icon: 'none' }) return } } else if (that.data.toped == 2) { if (temp) { prevPage.data.storeJobListSearchForm.cityName = ""; prevPage.data.storeJobListSearchForm.provinceName = temp.name; } else { wx.showToast({ title: '当前未选择省市', icon: 'none' }) return } } prevPage.setData({ storeJobListSearchForm: prevPage.data.storeJobListSearchForm, searchCityParamStorage: temp, }); wx.navigateBack({ delta: 1, }); // var pages = getCurrentPages(); // var prevPage = pages[pages.length - 2]; // 上一个页面 // console.log(prevPage); // console.log(temp); // prevPage.data.storeJobListSearchForm.cityName = temp.name; // prevPage.setData({ // storeJobListSearchForm: prevPage.data.storeJobListSearchForm, // searchCityParamStorage: temp, // }); // wx.navigateBack({ // delta: 1, // }); // wx.reLaunch({ // url: "../firstBill/index?fromSearchPage=1", // }); // } }, showInput: function () { this.setData({ inputShowed: true, }); }, hideInput: function () { this.setData({ inputVal: "", inputShowed: false, }); }, clearInput: function () { this.setData({ inputVal: "", }); }, inputTyping: function (e) { this.setData({ inputVal: e.detail.value, }); }, clickHot: function (e) { this.setData({ toView: "hot", }); }, goTop: function (e) { this.setData({ toView: "top", }); }, chooseLetter: function (e) { console.log(e.target.dataset.item); this.setData({ toView: e.target.dataset.item, }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 获取城市列表 * * */ getAllCityLevel2: function () { var that = this; customRequest("/city/getAllCityLevel2", { header: 'headers', method: 'GET', data: {} }).then((res) => { that.setData({ cityList: res.data.data, }); console.log(that.data.cityList); if (app.isNotEmptyCheck(app.globalData.lng) && app.isNotEmptyCheck(app.globalData.lat)) { that.getCityNameByLatLng(app.globalData.lng, app.globalData.lat, 0); } else { wx.getLocation({ type: "gcj02", success (res) { console.log(res); app.globalData.lng = res.longitude; app.globalData.lat = res.latitude; that.getCityNameByLatLng(res.longitude, res.latitude, 0); }, }); } }) // wx.request({ // url: app.globalData.ip + "/city/getAllCityLevel2", // data: {}, // header: app.globalData.headers, // method: "GET", // success: function (res) { // console.log(res); // that.setData({ // cityList: res.data.data, // }); // console.log(that.data.cityList); // if (app.isNotEmptyCheck(app.globalData.lng) && app.isNotEmptyCheck(app.globalData.lat)) { // that.getCityNameByLatLng(app.globalData.lng, app.globalData.lat, 0); // } else { // wx.getLocation({ // type: "gcj02", // success (res) { // console.log(res); // app.globalData.lng = res.longitude; // app.globalData.lat = res.latitude; // that.getCityNameByLatLng(res.longitude, res.latitude, 0); // }, // }); // } // }, // }); }, /** * 获取省份列表 * * */ getAllProvinceLevel1: function () { var that = this; customRequest("/city/getAllProvinceLevel1", { header: 'headers', method: 'GET', data: {} }).then((res) => { that.setData({ provinceList: res.data.data, }); if (app.isNotEmptyCheck(app.globalData.lng) && app.isNotEmptyCheck(app.globalData.lat)) { that.getProvinceNameByLatLng(app.globalData.lng, app.globalData.lat, 0); } else { wx.getLocation({ type: "gcj02", success (res) { console.log(res); app.globalData.lng = res.longitude; app.globalData.lat = res.latitude; that.getProvinceNameByLatLng(res.longitude, res.latitude, 0); }, }); } }) // wx.request({ // url: app.globalData.ip + "/city/getAllProvinceLevel1", // data: {}, // header: app.globalData.headers, // method: "GET", // success: function (res) { // console.log(res); // that.setData({ // provinceList: res.data.data, // }); // if (app.isNotEmptyCheck(app.globalData.lng) && app.isNotEmptyCheck(app.globalData.lat)) { // that.getProvinceNameByLatLng(app.globalData.lng, app.globalData.lat, 0); // } else { // wx.getLocation({ // type: "gcj02", // success (res) { // console.log(res); // app.globalData.lng = res.longitude; // app.globalData.lat = res.latitude; // that.getProvinceNameByLatLng(res.longitude, res.latitude, 0); // }, // }); // } // }, // }); }, /** * 生命周期函数--监听页面显示 */ onShow: function () { let that = this }, getCityNameByLatLng: function (longitude, latitude, comeFrom) { var that = this; customRequest("/location/getCityNameByLatLng", { header: 'headers', method: 'GET', data: { lng: longitude, lat: latitude, } }).then((res) => { if (res.data.status == 200) { var cityName = res.data.data; var tag = false; that.data.cityList.forEach((item) => { item.list.forEach((item1) => { if (item1.name == cityName) { // if (that.data.selectedCityLocalStorage) {} // debugger; if (comeFrom == 1) { //主动点击获取位置 that.clearAllChecked(); that.data.selectedCityLocal = item1; that.data.selectedCityLocal.checked = true; that.setAllSelected(); } else { if (that.data.selectedCityLocalStorage.checked) { that.clearAllChecked(); that.data.selectedCityLocal = item1; that.data.selectedCityLocal.checked = true; that.setAllSelected(); } else { // that.clearAllChecked(); that.data.selectedCityLocal = item1; that.data.selectedCityLocal.checked = false; that.setAllSelected(); } } } }); }); } }) // wx.request({ // url: app.globalData.ip + "/location/getCityNameByLatLng", // data: { // lng: longitude, // lat: latitude, // }, // header: app.globalData.headers, // method: "GET", // success: function (res) { // console.log(res); // if (res.data.status == 200) { // var cityName = res.data.data; // var tag = false; // that.data.cityList.forEach((item) => { // item.list.forEach((item1) => { // if (item1.name == cityName) { // // if (that.data.selectedCityLocalStorage) {} // // debugger; // if (comeFrom == 1) { // //主动点击获取位置 // that.clearAllChecked(); // that.data.selectedCityLocal = item1; // that.data.selectedCityLocal.checked = true; // that.setAllSelected(); // } else { // if (that.data.selectedCityLocalStorage.checked) { // that.clearAllChecked(); // that.data.selectedCityLocal = item1; // that.data.selectedCityLocal.checked = true; // that.setAllSelected(); // } else { // // that.clearAllChecked(); // that.data.selectedCityLocal = item1; // that.data.selectedCityLocal.checked = false; // that.setAllSelected(); // } // } // } // }); // }); // } // }, // }); }, getProvinceNameByLatLng: function (longitude, latitude, comeFrom) { var that = this; customRequest("/location/getProvinceNameByLatLng",{header:'headers', method: 'GET', data: { lng: longitude, lat: latitude,}}).then((res)=>{ if (res.data.status == 200) { var cityName = res.data.data; var tag = false; // console.log(); that.data.provinceList.shift(); // 处理返回的第一个空对象 that.data.provinceList.forEach((item) => { item.list.forEach((item1) => { if (item1.name == cityName) { // if (that.data.selectedCityLocalStorage) {} // debugger; if (comeFrom == 1) { //主动点击获取位置 that.clearAllChecked(); that.data.selectedProvinceLocal = item1; that.data.selectedProvinceLocal.checked = true; that.setAllSelected(); } else { if (that.data.selectedCityLocalStorage.checked) { that.clearAllChecked(); that.data.selectedProvinceLocal = item1; that.data.selectedProvinceLocal.checked = true; that.setAllSelected(); } else { // that.clearAllChecked(); that.data.selectedProvinceLocal = item1; that.data.selectedProvinceLocal.checked = false; that.setAllSelected(); } } } }); }); } }) // wx.request({ // url: app.globalData.ip + "/location/getProvinceNameByLatLng", // data: { // lng: longitude, // lat: latitude, // }, // header: app.globalData.headers, // method: "GET", // success: function (res) { // console.log(res); // if (res.data.status == 200) { // var cityName = res.data.data; // var tag = false; // // console.log(); // that.data.provinceList.shift(); // 处理返回的第一个空对象 // that.data.provinceList.forEach((item) => { // item.list.forEach((item1) => { // if (item1.name == cityName) { // // if (that.data.selectedCityLocalStorage) {} // // debugger; // if (comeFrom == 1) { // //主动点击获取位置 // that.clearAllChecked(); // that.data.selectedProvinceLocal = item1; // that.data.selectedProvinceLocal.checked = true; // that.setAllSelected(); // } else { // if (that.data.selectedCityLocalStorage.checked) { // that.clearAllChecked(); // that.data.selectedProvinceLocal = item1; // that.data.selectedProvinceLocal.checked = true; // that.setAllSelected(); // } else { // // that.clearAllChecked(); // that.data.selectedProvinceLocal = item1; // that.data.selectedProvinceLocal.checked = false; // that.setAllSelected(); // } // } // } // }); // }); // } // }, // }); }, clearAllChecked: function () { var that = this; that.data.selectedQuanGuo.checked = false; that.data.selectedCity.checked = false; that.data.selectedCityLocal.checked = false; that.data.selectedCityTemp.checked = false; }, setAllSelected: function () { var that = this; this.setData({ selectedQuanGuo: that.data.selectedQuanGuo, selectedCity: that.data.selectedCity, selectedCityTemp: that.data.selectedCityTemp, selectedCityLocal: that.data.selectedCityLocal, selectedProvinceLocal: that.data.selectedProvinceLocal, }); }, goBack () { wx.navigateBack({ delta: 1, }); }, choosenTop (e) { var that = this; // that.data.storeJobListSearchForm.pageNum = 1; let id = e.currentTarget.dataset.id; console.log(id); setTimeout(() => { that.setData({ toped: id, placeholderText: e.currentTarget.dataset.id == 1 ? "搜索城市/拼音" : "搜索省份/拼音", // isScrollTop: false, }); }, 0); // 切换标准 简版 重新查询列表 // that.data.storeJobListSearchForm.pageNum = 1; // that.setData({ // toped: id, // recordList: [], // }); // that.getJobList(); }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ // onShareAppMessage1: function () { // } });