Commit e73dad75 by jscat

nyx weapp: 功能更新 & 页面更新

1. 添加city选择函数
2. 添加最近访问城市清单(最多3个)
3. 从城市选择页面回到activity.wxml页面,数据自动刷新; onUpdateData()
parent 291befb2
//app.js
//app.js
......@@ -52,6 +52,9 @@ App({
//activity-submit跳转后需要带上category的index
switchId : "",
defaultCity: '上海',
defaultCounty: '静安区'
},
onLaunch: function () {
......
{
{
......@@ -12,6 +12,7 @@
"pages/activity/quiz-result/quiz-result",
"pages/activity/quiz-info/quiz-info",
"pages/activity/activity-info/activity-info",
"pages/switchcity/switchcity",
"pages/my/my",
"pages/key/matchTest/matchTest",
"pages/my/my-points/my-points",
......
//城市检索的首字母
//城市检索的首字母
const LETTERS = ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "W", "X", "Y", "Z"]
// 城市信息
const CITY_LIST = [{ "id": "35", "provincecode": "150000", "city": "阿拉善盟", "code": "152900", "initial": "A", "short": "Alashanmeng" }, { "id": "38", "provincecode": "210000", "city": "鞍山", "code": "210300", "initial": "A", "short": "Anshan" }, { "id": "105", "provincecode": "340000", "city": "安庆", "code": "340800", "initial": "A", "short": "Anqing" }, { "id": "156", "provincecode": "410000", "city": "安阳", "code": "410500", "initial": "A", "short": "Anyang" }, { "id": "256", "provincecode": "510000", "city": "阿坝藏族羌族自治州", "code": "513200", "initial": "A", "short": "Aba" }, { "id": "262", "provincecode": "520000", "city": "安顺", "code": "520400", "initial": "A", "short": "Anshun" }, { "id": "289", "provincecode": "540000", "city": "阿里地区", "code": "542500", "initial": "A", "short": "Ali" }, { "id": "299", "provincecode": "610000", "city": "安康", "code": "610900", "initial": "A", "short": "Ankang" }, { "id": "335", "provincecode": "650000", "city": "阿克苏地区", "code": "652900", "initial": "A", "short": "Akesu" }, { "id": "341", "provincecode": "650000", "city": "阿勒泰地区", "code": "654300", "initial": "A", "short": "Aletai" }, { "id": "1", "provincecode": "110000", "city": "北京", "code": "110000", "initial": "B", "short": "Beijing" }, { "id": "7", "provincecode": "130000", "city": "保定", "code": "130600", "initial": "B", "short": "Baoding" }, { "id": "25", "provincecode": "150000", "city": "包头", "code": "150200", "initial": "B", "short": "Baotou" }, { "id": "31", "provincecode": "150000", "city": "巴彦淖尔", "code": "150800", "initial": "B", "short": "Bayannaoer" }, { "id": "40", "provincecode": "210000", "city": "本溪", "code": "210500", "initial": "B", "short": "Benxi" }, { "id": "55", "provincecode": "220000", "city": "白山", "code": "220600", "initial": "B", "short": "Baishan" }, { "id": "57", "provincecode": "220000", "city": "白城", "code": "220800", "initial": "B", "short": "Baicheng" }, { "id": "100", "provincecode": "340000", "city": "蚌埠", "code": "340300", "initial": "B", "short": "Bangbu" }, { "id": "150", "provincecode": "370000", "city": "滨州", "code": "371600", "initial": "B", "short": "Binzhou" }, { "id": "222", "provincecode": "450000", "city": "北海", "code": "450500", "initial": "B", "short": "Beihai" }, { "id": "227", "provincecode": "450000", "city": "百色", "code": "451000", "initial": "B", "short": "Baise" }, { "id": "254", "provincecode": "510000", "city": "巴中", "code": "511900", "initial": "B", "short": "Bazhong" }, { "id": "265", "provincecode": "520000", "city": "毕节地区", "code": "522400", "initial": "B", "short": "Bijie" }, { "id": "271", "provincecode": "530000", "city": "保山", "code": "530500", "initial": "B", "short": "Baoshan" }, { "id": "293", "provincecode": "610000", "city": "宝鸡", "code": "610300", "initial": "B", "short": "Baoji" }, { "id": "304", "provincecode": "620000", "city": "白银", "code": "620400", "initial": "B", "short": "Baiyin" }, { "id": "333", "provincecode": "650000", "city": "博尔塔拉蒙古自治州", "code": "652700", "initial": "B", "short": "Boertala" }, { "id": "334", "provincecode": "650000", "city": "巴音郭楞蒙古自治州", "code": "652800", "initial": "B", "short": "Bayinguoleng" }, { "id": "", "provincecode": "500000", "city": "重庆", "code": "500000", "initial": "C", "short": "Chongqing" }, { "id": "9", "provincecode": "130000", "city": "承德", "code": "130800", "initial": "C", "short": "Chengde" }, { "id": "10", "provincecode": "130000", "city": "沧州", "code": "130900", "initial": "C", "short": "Cangzhou" }, { "id": "16", "provincecode": "140000", "city": "长治", "code": "140400", "initial": "C", "short": "Changzhi" }, { "id": "27", "provincecode": "150000", "city": "赤峰", "code": "150400", "initial": "C", "short": "Chifeng" }, { "id": "48", "provincecode": "210000", "city": "朝阳", "code": "211300", "initial": "C", "short": "Chaoyang" }, { "id": "50", "provincecode": "220000", "city": "长春", "code": "220100", "initial": "C", "short": "Changchun" }, { "id": "77", "provincecode": "320000", "city": "常州", "code": "320400", "initial": "C", "short": "Changzhou" }, { "id": "107", "provincecode": "340000", "city": "滁州", "code": "341100", "initial": "C", "short": "Chuzhou" }, { "id": "110", "provincecode": "340000", "city": "巢湖", "code": "341400", "initial": "C", "short": "Chaohu" }, { "id": "113", "provincecode": "340000", "city": "池州", "code": "341700", "initial": "C", "short": "Chizhou" }, { "id": "183", "provincecode": "430000", "city": "长沙", "code": "430100", "initial": "C", "short": "Changsha" }, { "id": "189", "provincecode": "430000", "city": "常德", "code": "430700", "initial": "C", "short": "Changde" }, { "id": "192", "provincecode": "430000", "city": "郴州", "code": "431000", "initial": "C", "short": "Chenzhou" }, { "id": "215", "provincecode": "440000", "city": "潮州", "code": "445100", "initial": "C", "short": "Chaozhou" }, { "id": "231", "provincecode": "450000", "city": "崇左", "code": "451400", "initial": "C", "short": "Chongzuo" }, { "id": "238", "provincecode": "510000", "city": "成都", "code": "510100", "initial": "C", "short": "Chengdu" }, { "id": "276", "provincecode": "530000", "city": "楚雄彝族自治州", "code": "532300", "initial": "C", "short": "Chuxiong" }, { "id": "285", "provincecode": "540000", "city": "昌都地区", "code": "542100", "initial": "C", "short": "Changdu" }, { "id": "332", "provincecode": "650000", "city": "昌吉回族自治州", "code": "652300", "initial": "C", "short": "Changji" }, { "id": "14", "provincecode": "140000", "city": "大同", "code": "140200", "initial": "D", "short": "Datong" }, { "id": "37", "provincecode": "210000", "city": "大连", "code": "210200", "initial": "D", "short": "Dalian" }, { "id": "41", "provincecode": "210000", "city": "丹东", "code": "210600", "initial": "D", "short": "Dandong" }, { "id": "64", "provincecode": "230000", "city": "大庆", "code": "230600", "initial": "D", "short": "Daqing" }, { "id": "71", "provincecode": "230000", "city": "大兴安岭地区", "code": "232700", "initial": "D", "short": "Daxinganling" }, { "id": "139", "provincecode": "370000", "city": "东营", "code": "370500", "initial": "D", "short": "Dongying" }, { "id": "148", "provincecode": "370000", "city": "德州", "code": "371400", "initial": "D", "short": "Dezhou" }, { "id": "213", "provincecode": "440000", "city": "东莞", "code": "441900", "initial": "D", "short": "Dongguan" }, { "id": "242", "provincecode": "510000", "city": "德阳", "code": "510600", "initial": "D", "short": "Deyang" }, { "id": "252", "provincecode": "510000", "city": "达州", "code": "511700", "initial": "D", "short": "Dazhou" }, { "id": "280", "provincecode": "530000", "city": "大理白族自治州", "code": "532900", "initial": "D", "short": "Dali" }, { "id": "281", "provincecode": "530000", "city": "德宏傣族景颇族自治州", "code": "533100", "initial": "D", "short": "Dehong" }, { "id": "283", "provincecode": "530000", "city": "迪庆藏族自治州", "code": "533400", "initial": "D", "short": "Diqing" }, { "id": "311", "provincecode": "620000", "city": "定西", "code": "621100", "initial": "D", "short": "Dingxi" }, { "id": "29", "provincecode": "150000", "city": "鄂尔多斯", "code": "150600", "initial": "E", "short": "Eerduosi" }, { "id": "174", "provincecode": "420000", "city": "鄂州", "code": "420700", "initial": "E", "short": "Ezhou" }, { "id": "181", "provincecode": "420000", "city": "恩施土家族苗族自治州", "code": "422800", "initial": "E", "short": "Enshi" }, { "id": "39", "provincecode": "210000", "city": "抚顺", "code": "210400", "initial": "F", "short": "Fushun" }, { "id": "44", "provincecode": "210000", "city": "阜新", "code": "210900", "initial": "F", "short": "Fuxin" }, { "id": "108", "provincecode": "340000", "city": "阜阳", "code": "341200", "initial": "F", "short": "Fuyang" }, { "id": "115", "provincecode": "350000", "city": "福州", "code": "350100", "initial": "F", "short": "Fuzhou" }, { "id": "133", "provincecode": "360000", "city": "抚州", "code": "361000", "initial": "F", "short": "Fuzhou" }, { "id": "202", "provincecode": "440000", "city": "佛山", "code": "440600", "initial": "F", "short": "Foshan" }, { "id": "223", "provincecode": "450000", "city": "防城港", "code": "450600", "initial": "F", "short": "Fangchenggang" }, { "id": "130", "provincecode": "360000", "city": "赣州", "code": "360700", "initial": "G", "short": "Ganzhou" }, { "id": "197", "provincecode": "440000", "city": "广州", "code": "440100", "initial": "G", "short": "Guangzhou" }, { "id": "220", "provincecode": "450000", "city": "桂林", "code": "450300", "initial": "G", "short": "Guilin" }, { "id": "225", "provincecode": "450000", "city": "贵港", "code": "450800", "initial": "G", "short": "Guigang" }, { "id": "244", "provincecode": "510000", "city": "广元", "code": "510800", "initial": "G", "short": "Guangyuan" }, { "id": "251", "provincecode": "510000", "city": "广安", "code": "511600", "initial": "G", "short": "Guangan" }, { "id": "257", "provincecode": "510000", "city": "甘孜藏族自治州", "code": "513300", "initial": "G", "short": "Ganzi" }, { "id": "259", "provincecode": "520000", "city": "贵阳", "code": "520100", "initial": "G", "short": "Guiyang" }, { "id": "314", "provincecode": "620000", "city": "甘南藏族自治州", "code": "623000", "initial": "G", "short": "Gannan" }, { "id": "320", "provincecode": "630000", "city": "果洛藏族自治州", "code": "632600", "initial": "G", "short": "Guoluo" }, { "id": "326", "provincecode": "640000", "city": "固原", "code": "640400", "initial": "G", "short": "Guyuan" }, { "id": "5", "provincecode": "130000", "city": "邯郸", "code": "130400", "initial": "H", "short": "Handan" }, { "id": "12", "provincecode": "130000", "city": "衡水", "code": "131100", "initial": "H", "short": "Hengshui" }, { "id": "", "provincecode": "370000", "city": "菏泽", "code": "371700", "initial": "H", "short": "Heze" }, { "id": "24", "provincecode": "150000", "city": "呼和浩特", "code": "150100", "initial": "H", "short": "Huhehaote" }, { "id": "30", "provincecode": "150000", "city": "呼伦贝尔", "code": "150700", "initial": "H", "short": "Hulunbeier" }, { "id": "49", "provincecode": "210000", "city": "葫芦岛", "code": "211400", "initial": "H", "short": "Huludao" }, { "id": "59", "provincecode": "230000", "city": "哈尔滨", "code": "230100", "initial": "H", "short": "Haerbin" }, { "id": "62", "provincecode": "230000", "city": "鹤岗", "code": "230400", "initial": "H", "short": "Hegang" }, { "id": "69", "provincecode": "230000", "city": "黑河", "code": "231100", "initial": "H", "short": "Heihe" }, { "id": "81", "provincecode": "320000", "city": "淮安", "code": "320800", "initial": "H", "short": "Huaian" }, { "id": "87", "provincecode": "330000", "city": "杭州", "code": "330100", "initial": "H", "short": "Hangzhou" }, { "id": "91", "provincecode": "330000", "city": "湖州", "code": "330500", "initial": "H", "short": "Huzhou" }, { "id": "98", "provincecode": "340000", "city": "合肥", "code": "340100", "initial": "H", "short": "Hefei" }, { "id": "101", "provincecode": "340000", "city": "淮南", "code": "340400", "initial": "H", "short": "Huainan" }, { "id": "103", "provincecode": "340000", "city": "淮北", "code": "340600", "initial": "H", "short": "Huaibei" }, { "id": "106", "provincecode": "340000", "city": "黄山", "code": "341000", "initial": "H", "short": "Huangshan" }, { "id": "112", "provincecode": "340000", "city": "亳州", "code": "341600", "initial": "H", "short": "Bozhou" }, { "id": "157", "provincecode": "410000", "city": "鹤壁", "code": "410600", "initial": "H", "short": "Hebi" }, { "id": "170", "provincecode": "420000", "city": "黄石", "code": "420200", "initial": "H", "short": "Huangshi" }, { "id": "178", "provincecode": "420000", "city": "黄冈", "code": "421100", "initial": "H", "short": "Huanggang" }, { "id": "186", "provincecode": "430000", "city": "衡阳", "code": "430400", "initial": "H", "short": "Hengyang" }, { "id": "194", "provincecode": "430000", "city": "怀化", "code": "431200", "initial": "H", "short": "Huaihua" }, { "id": "207", "provincecode": "440000", "city": "惠州", "code": "441300", "initial": "H", "short": "Huizhou" }, { "id": "210", "provincecode": "440000", "city": "河源", "code": "441600", "initial": "H", "short": "Heyuan" }, { "id": "228", "provincecode": "450000", "city": "贺州", "code": "451100", "initial": "H", "short": "Hezhou" }, { "id": "229", "provincecode": "450000", "city": "河池", "code": "451200", "initial": "H", "short": "Hechi" }, { "id": "232", "provincecode": "460000", "city": "海口", "code": "460100", "initial": "H", "short": "Haikou" }, { "id": "277", "provincecode": "530000", "city": "红河哈尼族彝族自治州", "code": "532500", "initial": "H", "short": "Honghe" }, { "id": "297", "provincecode": "610000", "city": "汉中", "code": "610700", "initial": "H", "short": "Hanzhong" }, { "id": "316", "provincecode": "630000", "city": "海东地区", "code": "632100", "initial": "H", "short": "Haidong" }, { "id": "317", "provincecode": "630000", "city": "海北藏族自治州", "code": "632200", "initial": "H", "short": "Haibei" }, { "id": "318", "provincecode": "630000", "city": "黄南藏族自治州", "code": "632300", "initial": "H", "short": "Huangnan" }, { "id": "319", "provincecode": "630000", "city": "海南藏族自治州", "code": "632500", "initial": "H", "short": "Hainan" }, { "id": "322", "provincecode": "630000", "city": "海西蒙古族藏族自治州", "code": "632800", "initial": "H", "short": "Haixi" }, { "id": "331", "provincecode": "650000", "city": "哈密地区", "code": "652200", "initial": "H", "short": "Hami" }, { "id": "338", "provincecode": "650000", "city": "和田地区", "code": "653200", "initial": "H", "short": "Hetiandi" }, { "id": "17", "provincecode": "140000", "city": "晋城", "code": "140500", "initial": "J", "short": "Jincheng" }, { "id": "19", "provincecode": "140000", "city": "晋中", "code": "140700", "initial": "J", "short": "Jinzhong" }, { "id": "42", "provincecode": "210000", "city": "锦州", "code": "210700", "initial": "J", "short": "Jinzhou" }, { "id": "51", "provincecode": "220000", "city": "吉林", "code": "220200", "initial": "J", "short": "Jilin" }, { "id": "61", "provincecode": "230000", "city": "鸡西", "code": "230300", "initial": "J", "short": "Jixi" }, { "id": "66", "provincecode": "230000", "city": "佳木斯", "code": "230800", "initial": "J", "short": "Jiamusi" }, { "id": "90", "provincecode": "330000", "city": "嘉兴", "code": "330400", "initial": "J", "short": "Jiaxing" }, { "id": "93", "provincecode": "330000", "city": "金华", "code": "330700", "initial": "J", "short": "Jinhua" }, { "id": "125", "provincecode": "360000", "city": "景德镇", "code": "360200", "initial": "J", "short": "Jingdezhen" }, { "id": "127", "provincecode": "360000", "city": "九江", "code": "360400", "initial": "J", "short": "Jiujiang" }, { "id": "131", "provincecode": "360000", "city": "吉安", "code": "360800", "initial": "J", "short": "Jian" }, { "id": "135", "provincecode": "370000", "city": "济南", "code": "370100", "initial": "J", "short": "Jinan" }, { "id": "142", "provincecode": "370000", "city": "济宁", "code": "370800", "initial": "J", "short": "Jining" }, { "id": "159", "provincecode": "410000", "city": "焦作", "code": "410800", "initial": "J", "short": "Jiaozuo" }, { "id": "175", "provincecode": "420000", "city": "荆门", "code": "420800", "initial": "J", "short": "Jingmen" }, { "id": "177", "provincecode": "420000", "city": "荆州", "code": "421000", "initial": "J", "short": "Jingzhou" }, { "id": "203", "provincecode": "440000", "city": "江门", "code": "440700", "initial": "J", "short": "Jiangmen" }, { "id": "216", "provincecode": "440000", "city": "揭阳", "code": "445200", "initial": "J", "short": "Jieyang" }, { "id": "302", "provincecode": "620000", "city": "嘉峪关", "code": "620200", "initial": "J", "short": "Jiayuguan" }, { "id": "303", "provincecode": "620000", "city": "金昌", "code": "620300", "initial": "J", "short": "Jinchang" }, { "id": "309", "provincecode": "620000", "city": "酒泉", "code": "620900", "initial": "J", "short": "Jiuquan" }, { "id": "153", "provincecode": "410000", "city": "开封", "code": "410200", "initial": "K", "short": "Kaifeng" }, { "id": "268", "provincecode": "530000", "city": "昆明", "code": "530100", "initial": "K", "short": "Kunming" }, { "id": "329", "provincecode": "650000", "city": "克拉玛依", "code": "650200", "initial": "K", "short": "Kelamayi" }, { "id": "336", "provincecode": "650000", "city": "克孜勒苏柯尔克孜自治州", "code": "653000", "initial": "K", "short": "Kezile" }, { "id": "337", "provincecode": "650000", "city": "喀什地区", "code": "653100", "initial": "K", "short": "Kashidi" }, { "id": "11", "provincecode": "130000", "city": "廊坊", "code": "131000", "initial": "L", "short": "Langfang" }, { "id": "22", "provincecode": "140000", "city": "临汾", "code": "141000", "initial": "L", "short": "Linfen" }, { "id": "23", "provincecode": "140000", "city": "吕梁", "code": "141100", "initial": "L", "short": "Lvliang" }, { "id": "45", "provincecode": "210000", "city": "辽阳", "code": "211000", "initial": "L", "short": "Liaoyang" }, { "id": "53", "provincecode": "220000", "city": "辽源", "code": "220400", "initial": "L", "short": "Liaoyuan" }, { "id": "80", "provincecode": "320000", "city": "连云港", "code": "320700", "initial": "L", "short": "Lianyungang" }, { "id": "97", "provincecode": "330000", "city": "丽水", "code": "331100", "initial": "L", "short": "Lishui" }, { "id": "111", "provincecode": "340000", "city": "六安", "code": "341500", "initial": "L", "short": "Liuan" }, { "id": "122", "provincecode": "350000", "city": "龙岩", "code": "350800", "initial": "L", "short": "Longyan" }, { "id": "146", "provincecode": "370000", "city": "莱芜", "code": "371200", "initial": "L", "short": "Laiwu" }, { "id": "147", "provincecode": "370000", "city": "临沂", "code": "371300", "initial": "L", "short": "Linyi" }, { "id": "149", "provincecode": "370000", "city": "聊城", "code": "371500", "initial": "L", "short": "Liaocheng" }, { "id": "154", "provincecode": "410000", "city": "洛阳", "code": "410300", "initial": "L", "short": "Luoyang" }, { "id": "162", "provincecode": "410000", "city": "漯河", "code": "411100", "initial": "L", "short": "Luohe" }, { "id": "195", "provincecode": "430000", "city": "娄底", "code": "431300", "initial": "L", "short": "Loudi" }, { "id": "219", "provincecode": "450000", "city": "柳州", "code": "450200", "initial": "L", "short": "Liuzhou" }, { "id": "230", "provincecode": "450000", "city": "来宾", "code": "451300", "initial": "L", "short": "Laibin" }, { "id": "241", "provincecode": "510000", "city": "泸州", "code": "510500", "initial": "L", "short": "Luzhou" }, { "id": "247", "provincecode": "510000", "city": "乐山", "code": "511100", "initial": "L", "short": "Leshan" }, { "id": "258", "provincecode": "510000", "city": "凉山彝族自治州", "code": "513400", "initial": "L", "short": "Liangshan" }, { "id": "260", "provincecode": "520000", "city": "六盘水", "code": "520200", "initial": "L", "short": "Liupanshui" }, { "id": "273", "provincecode": "530000", "city": "丽江", "code": "530700", "initial": "L", "short": "Lijiang" }, { "id": "275", "provincecode": "530000", "city": "临沧", "code": "530900", "initial": "L", "short": "Lincang" }, { "id": "284", "provincecode": "540000", "city": "拉萨", "code": "540100", "initial": "L", "short": "Lasa" }, { "id": "290", "provincecode": "540000", "city": "林芝地区", "code": "542600", "initial": "L", "short": "Linzhi" }, { "id": "301", "provincecode": "620000", "city": "兰州", "code": "620100", "initial": "L", "short": "Lanzhou" }, { "id": "312", "provincecode": "620000", "city": "陇南", "code": "621200", "initial": "L", "short": "Longnan" }, { "id": "313", "provincecode": "620000", "city": "临夏回族自治州", "code": "622900", "initial": "L", "short": "Linxia" }, { "id": "68", "provincecode": "230000", "city": "牡丹江", "code": "231000", "initial": "M", "short": "Mudanjiang" }, { "id": "102", "provincecode": "340000", "city": "马鞍山", "code": "340500", "initial": "M", "short": "Maanshan" }, { "id": "205", "provincecode": "440000", "city": "茂名", "code": "440900", "initial": "M", "short": "Maoming" }, { "id": "208", "provincecode": "440000", "city": "梅州", "code": "441400", "initial": "M", "short": "Meizhou" }, { "id": "243", "provincecode": "510000", "city": "绵阳", "code": "510700", "initial": "M", "short": "Mianyang" }, { "id": "249", "provincecode": "510000", "city": "眉山", "code": "511400", "initial": "M", "short": "Meishan" }, { "id": "74", "provincecode": "320000", "city": "南京", "code": "320100", "initial": "N", "short": "Nanjing" }, { "id": "79", "provincecode": "320000", "city": "南通", "code": "320600", "initial": "N", "short": "Nantong" }, { "id": "88", "provincecode": "330000", "city": "宁波", "code": "330200", "initial": "N", "short": "Ningbo" }, { "id": "121", "provincecode": "350000", "city": "南平", "code": "350700", "initial": "N", "short": "Nanping" }, { "id": "123", "provincecode": "350000", "city": "宁德", "code": "350900", "initial": "N", "short": "Ningde" }, { "id": "124", "provincecode": "360000", "city": "南昌", "code": "360100", "initial": "N", "short": "Nanchang" }, { "id": "164", "provincecode": "410000", "city": "南阳", "code": "411300", "initial": "N", "short": "Nanyang" }, { "id": "218", "provincecode": "450000", "city": "南宁", "code": "450100", "initial": "N", "short": "Nanning" }, { "id": "246", "provincecode": "510000", "city": "内江", "code": "511000", "initial": "N", "short": "Neijiang" }, { "id": "248", "provincecode": "510000", "city": "南充", "code": "511300", "initial": "N", "short": "Nanchong" }, { "id": "282", "provincecode": "530000", "city": "怒江傈僳族自治州", "code": "533300", "initial": "N", "short": "Nujiang" }, { "id": "288", "provincecode": "540000", "city": "那曲地区", "code": "542400", "initial": "N", "short": "Naqu" }, { "id": "46", "provincecode": "210000", "city": "盘锦", "code": "211100", "initial": "P", "short": "Panjin" }, { "id": "117", "provincecode": "350000", "city": "莆田", "code": "350300", "initial": "P", "short": "Putian" }, { "id": "126", "provincecode": "360000", "city": "萍乡", "code": "360300", "initial": "P", "short": "Pingxiang" }, { "id": "155", "provincecode": "410000", "city": "平顶山", "code": "410400", "initial": "P", "short": "Pingdingshan" }, { "id": "160", "provincecode": "410000", "city": "濮阳", "code": "410900", "initial": "P", "short": "Puyang" }, { "id": "240", "provincecode": "510000", "city": "攀枝花", "code": "510400", "initial": "P", "short": "Panzhihua" }, { "id": "308", "provincecode": "620000", "city": "平凉", "code": "620800", "initial": "P", "short": "Pingliang" }, { "id": "4", "provincecode": "130000", "city": "秦皇岛", "code": "130300", "initial": "Q", "short": "Qinhuangdao" }, { "id": "60", "provincecode": "230000", "city": "齐齐哈尔", "code": "230200", "initial": "Q", "short": "Qiqihaer" }, { "id": "67", "provincecode": "230000", "city": "七台河", "code": "230900", "initial": "Q", "short": "Qitaihe" }, { "id": "94", "provincecode": "330000", "city": "衢州", "code": "330800", "initial": "Q", "short": "Quzhou" }, { "id": "119", "provincecode": "350000", "city": "泉州", "code": "350500", "initial": "Q", "short": "Quanzhou" }, { "id": "136", "provincecode": "370000", "city": "青岛", "code": "370200", "initial": "Q", "short": "Qingdao" }, { "id": "212", "provincecode": "440000", "city": "清远", "code": "441800", "initial": "Q", "short": "Qingyuan" }, { "id": "224", "provincecode": "450000", "city": "钦州", "code": "450700", "initial": "Q", "short": "Qinzhou" }, { "id": "264", "provincecode": "520000", "city": "黔西南布依族苗族自治州", "code": "522300", "initial": "Q", "short": "Qianxinan" }, { "id": "266", "provincecode": "520000", "city": "黔东南苗族侗族自治州", "code": "522600", "initial": "Q", "short": "Qiandong" }, { "id": "267", "provincecode": "520000", "city": "黔南布依族苗族自治州", "code": "522700", "initial": "Q", "short": "Qiannan" }, { "id": "269", "provincecode": "530000", "city": "曲靖", "code": "530300", "initial": "Q", "short": "Qujing" }, { "id": "310", "provincecode": "620000", "city": "庆阳", "code": "621000", "initial": "Q", "short": "Qingyang" }, { "id": "145", "provincecode": "370000", "city": "日照", "code": "371100", "initial": "R", "short": "Rizhao" }, { "id": "287", "provincecode": "540000", "city": "日喀则地区", "code": "542300", "initial": "R", "short": "Rikaze" }, { "id": "2", "provincecode": "130000", "city": "石家庄", "code": "130100", "initial": "S", "short": "Shijiazhuang" }, { "id": "", "provincecode": "310000", "city": "上海", "code": "310000", "initial": "S", "short": "Shanghai" }, { "id": "18", "provincecode": "140000", "city": "朔州", "code": "140600", "initial": "S", "short": "Shuozhou" }, { "id": "36", "provincecode": "210000", "city": "沈阳", "code": "210100", "initial": "S", "short": "Shenyang" }, { "id": "", "provincecode": "530000", "city": "普洱", "code": "530800", "initial": "P", "short": "Puer" }, { "id": "52", "provincecode": "220000", "city": "四平", "code": "220300", "initial": "S", "short": "Siping" }, { "id": "56", "provincecode": "220000", "city": "松原", "code": "220700", "initial": "S", "short": "Songyuan" }, { "id": "63", "provincecode": "230000", "city": "双鸭山", "code": "230500", "initial": "S", "short": "Shuangyashan" }, { "id": "70", "provincecode": "230000", "city": "绥化", "code": "231200", "initial": "S", "short": "Suihua" }, { "id": "78", "provincecode": "320000", "city": "苏州", "code": "320500", "initial": "S", "short": "Suzhou" }, { "id": "86", "provincecode": "320000", "city": "宿迁", "code": "321300", "initial": "S", "short": "Suqian" }, { "id": "92", "provincecode": "330000", "city": "绍兴", "code": "330600", "initial": "S", "short": "Shaoxing" }, { "id": "109", "provincecode": "340000", "city": "宿州", "code": "341300", "initial": "S", "short": "Suzhou" }, { "id": "118", "provincecode": "350000", "city": "三明", "code": "350400", "initial": "S", "short": "Sanming" }, { "id": "134", "provincecode": "360000", "city": "上饶", "code": "361100", "initial": "S", "short": "Shangrao" }, { "id": "163", "provincecode": "410000", "city": "三门峡", "code": "411200", "initial": "S", "short": "Sanmenxia" }, { "id": "165", "provincecode": "410000", "city": "商丘", "code": "411400", "initial": "S", "short": "Shangqiu" }, { "id": "171", "provincecode": "420000", "city": "十堰", "code": "420300", "initial": "S", "short": "Shiyan" }, { "id": "180", "provincecode": "420000", "city": "随州", "code": "421300", "initial": "S", "short": "Suizhou" }, { "id": "187", "provincecode": "430000", "city": "邵阳", "code": "430500", "initial": "S", "short": "Shaoyang" }, { "id": "198", "provincecode": "440000", "city": "韶关", "code": "440200", "initial": "S", "short": "Shaoguan" }, { "id": "199", "provincecode": "440000", "city": "深圳", "code": "440300", "initial": "S", "short": "Shenzhen" }, { "id": "201", "provincecode": "440000", "city": "汕头", "code": "440500", "initial": "S", "short": "Shantou" }, { "id": "209", "provincecode": "440000", "city": "汕尾", "code": "441500", "initial": "S", "short": "Shanwei" }, { "id": "233", "provincecode": "460000", "city": "三亚", "code": "460200", "initial": "S", "short": "Sanya" }, { "id": "245", "provincecode": "510000", "city": "遂宁", "code": "510900", "initial": "S", "short": "Suining" }, { "id": "286", "provincecode": "540000", "city": "山南地区", "code": "542200", "initial": "S", "short": "Shannan" }, { "id": "300", "provincecode": "610000", "city": "商洛", "code": "611000", "initial": "S", "short": "Shangluo" }, { "id": "324", "provincecode": "640000", "city": "石嘴山", "code": "640200", "initial": "S", "short": "Shizuishan" }, { "id": "3", "provincecode": "130000", "city": "唐山", "code": "130200", "initial": "T", "short": "Tangshan" }, { "id": "13", "provincecode": "140000", "city": "太原", "code": "140100", "initial": "T", "short": "Taiyuan" }, { "id": "28", "provincecode": "150000", "city": "通辽", "code": "150500", "initial": "T", "short": "Tongliao" }, { "id": "47", "provincecode": "210000", "city": "铁岭", "code": "211200", "initial": "T", "short": "Tieling" }, { "id": "54", "provincecode": "220000", "city": "通化", "code": "220500", "initial": "T", "short": "Tonghua" }, { "id": "85", "provincecode": "320000", "city": "泰州", "code": "321200", "initial": "T", "short": "Taizhou" }, { "id": "96", "provincecode": "330000", "city": "台州", "code": "331000", "initial": "T", "short": "Taizhou" }, { "id": "104", "provincecode": "340000", "city": "铜陵", "code": "340700", "initial": "T", "short": "Tongling" }, { "id": "143", "provincecode": "370000", "city": "泰安", "code": "370900", "initial": "T", "short": "Taian" }, { "id": "263", "provincecode": "520000", "city": "铜仁地区", "code": "522200", "initial": "T", "short": "Tongren" }, { "id": "292", "provincecode": "610000", "city": "铜川", "code": "610200", "initial": "T", "short": "Tongchuan" }, { "id": "305", "provincecode": "620000", "city": "天水", "code": "620500", "initial": "T", "short": "Tianshui" }, { "id": "330", "provincecode": "650000", "city": "吐鲁番地区", "code": "652100", "initial": "T", "short": "Tulufan" }, { "id": "340", "provincecode": "650000", "city": "塔城地区", "code": "654200", "initial": "T", "short": "Tachengdi" }, { "id": "343", "provincecode": "120000", "city": "天津", "code": "120000", "initial": "T", "short": "Tianjin" }, { "id": "26", "provincecode": "150000", "city": "乌海", "code": "150300", "initial": "W", "short": "Wuhai" }, { "id": "32", "provincecode": "150000", "city": "乌兰察布", "code": "150900", "initial": "W", "short": "Wulanchabu" }, { "id": "75", "provincecode": "320000", "city": "无锡", "code": "320200", "initial": "W", "short": "Wuxi" }, { "id": "89", "provincecode": "330000", "city": "温州", "code": "330300", "initial": "W", "short": "Wenzhou" }, { "id": "99", "provincecode": "340000", "city": "芜湖", "code": "340200", "initial": "W", "short": "Wuhu" }, { "id": "141", "provincecode": "370000", "city": "潍坊", "code": "370700", "initial": "W", "short": "Weifang" }, { "id": "144", "provincecode": "370000", "city": "威海", "code": "371000", "initial": "W", "short": "Weihai" }, { "id": "169", "provincecode": "420000", "city": "武汉", "code": "420100", "initial": "W", "short": "Wuhan" }, { "id": "221", "provincecode": "450000", "city": "梧州", "code": "450400", "initial": "W", "short": "Wuzhou" }, { "id": "278", "provincecode": "530000", "city": "文山壮族苗族自治州", "code": "532600", "initial": "W", "short": "Wenshan" }, { "id": "295", "provincecode": "610000", "city": "渭南", "code": "610500", "initial": "W", "short": "Weinan" }, { "id": "306", "provincecode": "620000", "city": "武威", "code": "620600", "initial": "W", "short": "Wuwei" }, { "id": "325", "provincecode": "640000", "city": "吴忠", "code": "640300", "initial": "W", "short": "Wuzhong" }, { "id": "328", "provincecode": "650000", "city": "乌鲁木齐", "code": "650100", "initial": "W", "short": "Wulumuqi" }, { "id": "6", "provincecode": "130000", "city": "邢台", "code": "130500", "initial": "X", "short": "Xingtai" }, { "id": "21", "provincecode": "140000", "city": "忻州", "code": "140900", "initial": "X", "short": "Xinzhou" }, { "id": "33", "provincecode": "150000", "city": "兴安盟", "code": "152200", "initial": "X", "short": "Xinganmeng" }, { "id": "34", "provincecode": "150000", "city": "锡林郭勒盟", "code": "152500", "initial": "X", "short": "Xilinguolemeng" }, { "id": "76", "provincecode": "320000", "city": "徐州", "code": "320300", "initial": "X", "short": "Xuzhou" }, { "id": "114", "provincecode": "340000", "city": "宣城", "code": "341800", "initial": "X", "short": "Xuancheng" }, { "id": "116", "provincecode": "350000", "city": "厦门", "code": "350200", "initial": "X", "short": "Xiamen" }, { "id": "128", "provincecode": "360000", "city": "新余", "code": "360500", "initial": "X", "short": "Xinyu" }, { "id": "158", "provincecode": "410000", "city": "新乡", "code": "410700", "initial": "X", "short": "Xinxiang" }, { "id": "161", "provincecode": "410000", "city": "许昌", "code": "411000", "initial": "X", "short": "Xuchang" }, { "id": "166", "provincecode": "410000", "city": "信阳", "code": "411500", "initial": "X", "short": "Xinyang" }, { "id": "173", "provincecode": "420000", "city": "襄樊", "code": "420600", "initial": "X", "short": "Xiangfan" }, { "id": "176", "provincecode": "420000", "city": "孝感", "code": "420900", "initial": "X", "short": "Xiaogan" }, { "id": "179", "provincecode": "420000", "city": "咸宁", "code": "421200", "initial": "X", "short": "Xianning" }, { "id": "185", "provincecode": "430000", "city": "湘潭", "code": "430300", "initial": "X", "short": "Xiangtan" }, { "id": "196", "provincecode": "430000", "city": "湘西土家族苗族自治州", "code": "433100", "initial": "X", "short": "Xiangxi" }, { "id": "279", "provincecode": "530000", "city": "西双版纳傣族自治州", "code": "532800", "initial": "X", "short": "Xishuangbanna" }, { "id": "291", "provincecode": "610000", "city": "西安", "code": "610100", "initial": "X", "short": "Xian" }, { "id": "294", "provincecode": "610000", "city": "咸阳", "code": "610400", "initial": "X", "short": "Xianyang" }, { "id": "315", "provincecode": "630000", "city": "西宁", "code": "630100", "initial": "X", "short": "Xining" }, { "id": "15", "provincecode": "140000", "city": "阳泉", "code": "140300", "initial": "Y", "short": "Yangquan" }, { "id": "20", "provincecode": "140000", "city": "运城", "code": "140800", "initial": "Y", "short": "Yuncheng" }, { "id": "43", "provincecode": "210000", "city": "营口", "code": "210800", "initial": "Y", "short": "Yingkou" }, { "id": "58", "provincecode": "220000", "city": "延边朝鲜族自治州", "code": "222400", "initial": "Y", "short": "Yanbian" }, { "id": "65", "provincecode": "230000", "city": "伊春", "code": "230700", "initial": "Y", "short": "Yichun" }, { "id": "82", "provincecode": "320000", "city": "盐城", "code": "320900", "initial": "Y", "short": "Yancheng" }, { "id": "83", "provincecode": "320000", "city": "扬州", "code": "321000", "initial": "Y", "short": "Yangzhou" }, { "id": "129", "provincecode": "360000", "city": "鹰潭", "code": "360600", "initial": "Y", "short": "Yingtan" }, { "id": "132", "provincecode": "360000", "city": "宜春", "code": "360900", "initial": "Y", "short": "Yichun" }, { "id": "140", "provincecode": "370000", "city": "烟台", "code": "370600", "initial": "Y", "short": "Yantai" }, { "id": "172", "provincecode": "420000", "city": "宜昌", "code": "420500", "initial": "Y", "short": "Yichang" }, { "id": "188", "provincecode": "430000", "city": "岳阳", "code": "430600", "initial": "Y", "short": "Yueyang" }, { "id": "191", "provincecode": "430000", "city": "益阳", "code": "430900", "initial": "Y", "short": "Yiyang" }, { "id": "193", "provincecode": "430000", "city": "永州", "code": "431100", "initial": "Y", "short": "Yongzhou" }, { "id": "211", "provincecode": "440000", "city": "阳江", "code": "441700", "initial": "Y", "short": "Yangjiang" }, { "id": "217", "provincecode": "440000", "city": "云浮", "code": "445300", "initial": "Y", "short": "Yunfu" }, { "id": "226", "provincecode": "450000", "city": "玉林", "code": "450900", "initial": "Y", "short": "Yulin" }, { "id": "250", "provincecode": "510000", "city": "宜宾", "code": "511500", "initial": "Y", "short": "Yibin" }, { "id": "253", "provincecode": "510000", "city": "雅安", "code": "511800", "initial": "Y", "short": "Yaan" }, { "id": "270", "provincecode": "530000", "city": "玉溪", "code": "530400", "initial": "Y", "short": "Yuxi" }, { "id": "296", "provincecode": "610000", "city": "延安", "code": "610600", "initial": "Y", "short": "Yanan" }, { "id": "298", "provincecode": "610000", "city": "榆林", "code": "610800", "initial": "Y", "short": "Yulin" }, { "id": "321", "provincecode": "630000", "city": "玉树藏族自治州", "code": "632700", "initial": "Y", "short": "Yushu" }, { "id": "323", "provincecode": "640000", "city": "银川", "code": "640100", "initial": "Y", "short": "Yinchuan" }, { "id": "339", "provincecode": "650000", "city": "伊犁哈萨克自治州", "code": "654000", "initial": "Y", "short": "Yilihasake" }, { "id": "8", "provincecode": "130000", "city": "张家口", "code": "130700", "initial": "Z", "short": "Zhangjiakou" }, { "id": "84", "provincecode": "320000", "city": "镇江", "code": "321100", "initial": "Z", "short": "Zhenjiang" }, { "id": "95", "provincecode": "330000", "city": "舟山", "code": "330900", "initial": "Z", "short": "Zhoushan" }, { "id": "120", "provincecode": "350000", "city": "漳州", "code": "350600", "initial": "Z", "short": "Zhangzhou" }, { "id": "137", "provincecode": "370000", "city": "淄博", "code": "370300", "initial": "Z", "short": "Zibo" }, { "id": "138", "provincecode": "370000", "city": "枣庄", "code": "370400", "initial": "Z", "short": "Zaozhuang" }, { "id": "152", "provincecode": "410000", "city": "郑州", "code": "410100", "initial": "Z", "short": "Zhengzhou" }, { "id": "167", "provincecode": "410000", "city": "周口", "code": "411600", "initial": "Z", "short": "Zhoukou" }, { "id": "168", "provincecode": "410000", "city": "驻马店", "code": "411700", "initial": "Z", "short": "Zhumadian" }, { "id": "184", "provincecode": "430000", "city": "株洲", "code": "430200", "initial": "Z", "short": "Zhuzhou" }, { "id": "190", "provincecode": "430000", "city": "张家界", "code": "430800", "initial": "Z", "short": "Zhangjiajie" }, { "id": "200", "provincecode": "440000", "city": "珠海", "code": "440400", "initial": "Z", "short": "Zhuhai" }, { "id": "204", "provincecode": "440000", "city": "湛江", "code": "440800", "initial": "Z", "short": "Zhanjiang" }, { "id": "206", "provincecode": "440000", "city": "肇庆", "code": "441200", "initial": "Z", "short": "Zhaoqing" }, { "id": "214", "provincecode": "440000", "city": "中山", "code": "442000", "initial": "Z", "short": "Zhongshan" }, { "id": "239", "provincecode": "510000", "city": "自贡", "code": "510300", "initial": "Z", "short": "Zigong" }, { "id": "255", "provincecode": "510000", "city": "资阳", "code": "512000", "initial": "Z", "short": "Ziyang" }, { "id": "261", "provincecode": "520000", "city": "遵义", "code": "520300", "initial": "Z", "short": "Zunyi" }, { "id": "272", "provincecode": "530000", "city": "昭通", "code": "530600", "initial": "Z", "short": "Zhaotong" }, { "id": "307", "provincecode": "620000", "city": "张掖", "code": "620700", "initial": "Z", "short": "Zhangye" }, { "id": "327", "provincecode": "640000", "city": "中卫", "code": "640500", "initial": "Z", "short": "Zhongwei" }]
const HOT_CITY_LIST = [{ cityCode: 110000, city: '北京' }, { cityCode: 310000, city: '上海' }, { cityCode: 440100, city: '广州' }, { cityCode: 440300, city: '深圳' }, { cityCode: 330100, city: '杭州' }, { cityCode: 320100, city: '南京' }, { cityCode: 420100, city: '武汉' }, { cityCode: 120000, city: '天津' }, { cityCode: 610100, city: '西安' },]
const CITY_NOT_FOUND = [{ city: '无匹配城', code: "000" }]
export { LETTERS, CITY_LIST, HOT_CITY_LIST, CITY_NOT_FOUND };
export const commonMessage = {
export const commonMessage = {
'location.getting': '定位中',
'location.city.getting': '正在定位城市',
'location.county.getting': '正在获取区县',
'location.city.fail': '定位失败,请重试',
'location.county.fail': '请求区县失败,请重试',
}
// pages/member/activity-post/activity-edit/activity-edit.js
// pages/member/activity-post/activity-edit/activity-edit.js
......@@ -79,7 +79,7 @@ Page({
title: '活动列表',
})
//初始载入四个推荐的竞答活动
//初始载入四个推荐的活动
if(_this.__data__.product_listData.length == 0)
{
var curDate = getCurDate()
......
// pages/activity/activity.js
// pages/activity/activity.js
......@@ -4,12 +4,18 @@ var config = wx.getStorageSync("config");
var util = require('./../../utils/util.js')
var event = require('./../../utils/event.js')
const { globalData: { defaultCity, defaultCounty } } = app
Page({
/**
* 页面的初始数据
*/
data: {
city: defaultCity,
county: defaultCounty,
category: [ // 导航栏内容数据
{ name: '点赞', order : 'like' },
{ name: '价格', order : 'price' },
......@@ -36,9 +42,6 @@ Page({
noteTop: 0,
noteHeight: 0,
//城市模块
city: "上海",
//搜索模块
inputShowed: false, //初始文本框不显示内容
strSearch : "", //搜索的字串
......@@ -190,6 +193,15 @@ Page({
*/
onShow: function () {
var _this = this;
const { globalData: { defaultCity, defaultCounty } } = app
console.log("===city, "+defaultCity)
console.log("===county, "+defaultCounty)
this.setData({
city: defaultCity,
county: defaultCounty
})
var likeDictSub = _this.__data__.likeDictSub;
var activities = _this.__data__.activities;
if(likeDictSub.hasOwnProperty('index_id'))
......@@ -535,6 +547,17 @@ Page({
})
},
// 刷新页面数据
onUpdateData: function(){
var _this = this;
var strCity = app.globalData.defaultCity
var curIndex = _this.__data__.curIndex
var strCategory = _this.__data__.category[curIndex].order
var strSearch = _this.__data__.strSearch
_this.getActivities(0, 1, 4, strCity, strCategory, strSearch);
}
......
<wxs module="tutil" src="./../../utils/date.wxs"></wxs>
<wxs module="tutil" src="./../../utils/date.wxs"></wxs>
......@@ -7,8 +7,10 @@
<!-- refer https://www.jb51.net/article/158292.htm -->
<!-- refer https://github.com/cinoliu/-selectCity -->
<view class="weui-search-bar">
<navigator url="../switchcity/switchcity?city={{city}}">
<text>{{city}}</text>
<image src='../../icon/down.png' style='width: 32rpx;height: 32rpx;' class='selecrtImg'></image>
</navigator>
<view class="weui-search-bar__form">
<view class="weui-search-bar__box">
<icon class="weui-icon-search_in-box" type="search" size="16"></icon>
......
import { LETTERS, HOT_CITY_LIST } from '../../locale/citydata'
import { LETTERS, HOT_CITY_LIST } from '../../locale/citydata'
import { commonMessage } from '../../locale/commonMessageZhCn'
import { AutoPredictor } from '../../utils/autoPredictor'
import utils from '../../utils/utils'
const {
isNotEmpty,
safeGet,
getCityListSortedByInitialLetter,
getLocationUrl,
getCountyListUrl,
getIndexUrl,
onFail,
} = utils;
const appInstance = getApp();
Page({
data: {
sideBarLetterList: [],
winHeight: 0,
cityList: [],
hotCityList: HOT_CITY_LIST,
showChosenLetterToast: false,
scrollTop: 0,//置顶高度
scrollTopId: '',//置顶id
city: commonMessage['location.getting'],
currentCityCode: '',
inputName: '',
completeList: [],
city: '',
county: '',
showCountyPicker: false,
auto: true, // 自动手动定位开关
LatestCityList: [{ cityCode: 310000, city: '上海' }, { cityCode: 110000, city: '北京' }],
},
onLoad: function (options) {
// 生命周期函数--监听页面加载
const cityListSortedByInitialLetter = getCityListSortedByInitialLetter();
const sysInfo = wx.getSystemInfoSync();
const winHeight = sysInfo.windowHeight;
const sideBarLetterList = LETTERS.map(letter => ({ name: letter }));
var city = ""
if (options.city != "")
{
city = options.city;
}
this.setData({
winHeight,
sideBarLetterList,
cityList: cityListSortedByInitialLetter,
city: city,
});
// 定位
// this.getLocation();
},
onShow: function() {
var _this = this;
// 获取历史搜索
_this.getRecentCity();
},
touchSideBarLetter: function (e) {
const chosenLetter = safeGet(['currentTarget', 'dataset', 'letter'], e)
this.setData({
toastShowLetter: chosenLetter,
showChosenLetterToast: true,
scrollTopId: chosenLetter,
})
// close toast of chosenLetter
setTimeout(() => { this.setData({ showChosenLetterToast: false }) }, 500)
},
//选择城市
chooseCity: function (e) {
const { city, code } = safeGet(['currentTarget', 'dataset'], e)
this.setData({
auto: false,
showCountyPicker: false,
city,
currentCityCode: code,
scrollTop: 0,
completeList: [],
county: ''
})
//无须再选择county
//this.getCountyList()
appInstance.globalData.defaultCity = city
appInstance.globalData.defaultCounty = ''
// start 记录最近访问
let LatestCityList = wx.getStorageSync('LatestCityList') || [];
var item = { cityCode: code, city: city }
LatestCityList.unshift(item);
var list = []
var result = {}
for(var i=0; i< LatestCityList.length && list.length != 3; i++)
{
var key = LatestCityList[i]['cityCode']
if(!result.hasOwnProperty(key))
{
result[key] = 1
list.push(LatestCityList[i])
}
}
wx.setStorageSync('LatestCityList', list)
result = {}
// end of 最近访问 去重
// 返回首页
var url = getIndexUrl()
wx.switchTab({
url: getIndexUrl(),
success: function (e) {
var page = getCurrentPages().pop();
if (page == undefined || page == null) return;
page.onUpdateData();
}
})
},
chooseCounty: function (e) {
const county = safeGet(['currentTarget', 'dataset', 'city'], e)
this.setData({ county })
appInstance.globalData.defaultCounty = county
// 返回首页
wx.switchTab({ url: getIndexUrl() })
},
//点击热门城市回到顶部
hotCity: function () {
this.setData({ scrollTop: 0 })
},
bindScroll: function (e) {
// console.log(e.detail)
},
getCountyList: function () {
console.log(commonMessage['location.county.getting']);
const code = this.data.currentCityCode
wx.request({
url: getCountyListUrl(code),
success: res => this.setCountyList(res),
fail: onFail(commonMessage['location.county.fail']),
})
},
setCountyList: function (res) {
const resultArray = safeGet(['data', 'result'], res)
const countyList = isNotEmpty(resultArray) ? resultArray[0] : []
this.setData({ countyList })
},
getLocation: function () {
//console.log(commonMessage['location.city.getting'])
this.setData({ county: '' })
wx.getLocation({
type: 'wgs84',
success: res => this.getLocationFromGeoCoord(res),
fail: onFail(commonMessage['location.city.fail']),
})
},
getLocationFromGeoCoord: function (geoCoord) {
const { latitude, longitude } = geoCoord
wx.request({
url: getLocationUrl(latitude, longitude),
success: location => this.setCityCounty(location)
})
},
setCityCounty: function (location) {
const { city, adcode, district } = safeGet(['data', 'result', 'ad_info'], location)
if (this.data.auto) { // 如果开始手动选择,以手动为准
this.setData({
city,
currentCityCode: adcode,
county: district
})
appInstance.globalData.defaultCity = city
// this.getCountyList();
}
},
// method2: from wxml
reGetLocation: function () {
const { city, county } = this.data
appInstance.globalData.defaultCity = city
appInstance.globalData.defaultCounty = county
console.log(appInstance.globalData.defaultCity);
//返回首页, 同时刷新首页数据
wx.switchTab({
url: getIndexUrl(),
success: function (e) {
var page = getCurrentPages().pop();
if (page == undefined || page == null) return;
page.onUpdateData();
}
})
},
// 失焦时清空输入框
bindBlur: function (e) {
this.setData({
inputName: '',
completeList: []
})
},
// 输入框输入时
bindKeyInput: function (e) {
let inputName = e.detail.value.trim()
this.setData({ inputName })
if (!inputName) {
this.setData({ completeList: [] })
}
this.useAutoPredictor(inputName)
},
// 输入框自动联想搜索
useAutoPredictor: function (content) {
let autoPredictor = new AutoPredictor(content)
let completeList = autoPredictor.associativeSearch()
this.setData({ completeList })
},
/*
与switchcity无关的自定义函数
*/
/**
* 获取历史搜索
*/
getRecentCity: function () {
var _this = this;
var LatestCityList = wx.getStorageSync('LatestCityList');
_this.setData({ LatestCityList });
},
})
<view class="input">
<view class="input">
<input bindinput="bindKeyInput" bindblur="bindBlur" placeholder="输入城市名或拼音查询" placeholder-style="font-size: 30rpx" value="{{inputName}}"></input>
</view>
<view class="container-inner">
<view class="side-bar-letter-list touch-class">
<view class="side-bar-hot-city" bindtap="hotCity">
<view style="margin-top:0;">当前</view>
<view style="margin-top:0;">热门</view>
</view>
<view wx:for="{{sideBarLetterList}}" style="color:#8BC34A;font-size:20rpx;" wx:key="*this" data-letter="{{item.name}}" catchtouchend="touchSideBarLetter">{{item.name}}</view>
</view>
<view class="container">
<block wx:if="{{showChosenLetterToast}}">
<view class="show-chosen-letter">
{{toastShowLetter}}
</view>
</block>
<scroll-view scroll-y="true" style="height:{{winHeight}}px" bindscroll="bindScroll" scroll-into-view="{{scrollTopId}}" scroll-top="{{scrollTop}}">
<ul class="ul">
<li wx:for="{{completeList}}" wx:key="*this" bindtap="chooseCity" data-city="{{item.city}}" data-code="{{item.code}}" class="li">{{item.city}}</li>
</ul>
<view class="city-picker">
<view class="hotcity-common">当前: {{city}}</view>
<!-- start 最近访问 -->
<view class="hotcity-common">最近访问</view>
<view class="hot-city" wx:key="initial">
<view wx:for="{{LatestCityList}}" wx:key="cityCode">
<view class="weui-grid" data-code="{{item.cityCode}}" data-city="{{item.city}}" bindtap="chooseCity">
<view class="weui-grid-label">{{item.city}}</view>
</view>
</view>
</view>
<!-- end 最近访问 -->
<!-- start 热门城市 -->
<view class="hotcity-common">热门城市</view>
<view class="hot-city" wx:key="initial">
<view wx:for="{{hotCityList}}" wx:key="cityCode">
<view class="weui-grid" data-code="{{item.cityCode}}" data-city="{{item.city}}" bindtap="chooseCity">
<view class="weui-grid-label">{{item.city}}</view>
</view>
</view>
</view>
<!-- end 热门城市 -->
</view>
<view class="selection" wx:for="{{cityList}}" wx:key="initial">
<view class="item-letter" id="{{item.initial}}">{{item.initial}}</view>
<view class="item-city" wx:for="{{item.cityInfo}}" wx:for-item="ct" wx:key="id" data-code="{{ct.code}}" data-city="{{ct.city}}" bindtap="chooseCity">
{{ct.city}}
</view>
</view>
</scroll-view>
</view>
</view>
.container-inner {
.container-inner {
display: flex;
flex-direction: row-reverse;
}
.container {
flex-grow: 1;
display: flex;
flex-direction: column;
padding: 10rpx;
}
input {
text-align: center;
font-size: 32rpx;
padding: 5px;
}
scroll-view {
padding-left:16rpx;
}
.side-bar-letter-list {
flex-shrink: 0;
width: 80rpx;
text-align: center;
display: flex;
flex-direction: column;
color: #666;
}
.side-bar-letter-list view {
margin-top: 20rpx;
}
.touch-class {
background-color: #fff;
color: #fff;
padding-top: 16rpx;
padding-bottom: 16rpx;
}
.show-chosen-letter {
background-color: rgba(0, 0, 0, 0.5);
color: #fff;
display: flex;
justify-content: center;
align-items: center;
position: fixed;
top: 50%;
left: 50%;
margin: -100rpx;
width: 200rpx;
height: 200rpx;
border-radius: 20rpx;
font-size: 52rpx;
z-index: 1;
}
.selection {
display: flex;
width: 100%;
flex-direction: column;
margin-top: 10rpx;
}
.city-picker {
padding: 16rpx 0 16rpx 16rpx;
background-color: #f5f5f5;
margin-bottom: -10rpx;
}
.county-picker {
padding-left: 20rpx;
margin-bottom: 10rpx;
}
.county-picker-title {
font-size: 24rpx;
color: #666;
padding-bottom: 0;
margin: 8rpx 0;
padding-left:4px;
}
.hot-city {
background-color: #f5f5f5;
margin-bottom: -10rpx;
display: flex;
flex-wrap: wrap;
}
.item-letter {
display: flex;
background-color: #f5f5f5;
height: 40rpx;
padding-left: 34rpx;
align-items: center;
font-size: 24rpx;
color: #666;
}
.item-city {
display: flex;
background-color: #fff;
height: 100rpx;
padding-left: 34rpx;
align-items: center;
border-bottom: 1rpx solid #ededed;
font-size: 24rpx;
color: #666;
}
.hotcity-common {
font-size: 24rpx;
color: #666;
padding-bottom: 0;
margin: 8rpx 0;
margin-left: 16rpx;
}
.county-picker-list {
padding-right: 50rpx;
margin: auto;
}
.current-city {
display: inline-block;
border: 1rpx solid #8BC34A;
border-radius: 8rpx;
padding: 10rpx;
font-size: 24rpx;
color: #8BC34A;
text-align: center;
min-width: 149.5rpx;
margin: 16rpx;
}
.side-bar-hot-city {
color: #8BC34A;
font-size: 20rpx;
margin: 0 !important;
}
.slectCity {
border-color: #8BC34A !important;
}
.slectCity view {
color: #8BC34A !important;
}
.weui-grid {
padding: 10rpx 0;
width: 200rpx;
box-sizing: border-box;
border: 1rpx solid #ececec;
border-radius: 8rpx;
background-color: white;
margin: 8rpx 0 8rpx 8rpx;
}
.weui-grids {
display: flex;
flex-direction: row;
justify-content: space-between;
}
.weui-grid-label {
display: block;
text-align: center;
color: #333;
font-size: 24rpx;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.ul {
display: block;
color: grey;
margin-left: 20rpx;
}
.li {
display: block;
font-weight: 100;
font-size: 28rpx;
padding: 16rpx 0;
}
input {
background-color: #eee;
}
.input {
padding: 16rpx;
border-bottom: 1rpx solid #f1f1f1;
}
.county {
display: flex;
flex-wrap: wrap;
}
import { CITY_LIST, CITY_NOT_FOUND } from '../locale/citydata'
import { CITY_LIST, CITY_NOT_FOUND } from '../locale/citydata'
import utils from 'utils'
const { isNotEmpty, isChinese, getSlicedName } = utils;
/*
* AutoPredictor 实例一定有两个对外的接口:
* 1. 接收 输入框输入的值
* 2. 返回 最终匹配到的数组
*/
export class AutoPredictor {
constructor(inputContent) {
this.content = inputContent.toLowerCase()
}
// 输入框自动联想搜索
associativeSearch() {
// search
let tempList = this.searchList(this.content)
// get final list to show
let resultList = this.showList(tempList)
return resultList
}
searchList(str) {
let targetCity
return CITY_LIST.filter(
city => {
targetCity = this.getTargetCity(str, city)
return (targetCity && targetCity == str)
}
)
}
getTargetCity(str, cityObj) {
if (isChinese(str)) {
const slicedChineseName = getSlicedName(cityObj, 'city', str.length)
return slicedChineseName
} else {
const slicedPinyinName = getSlicedName(cityObj, 'short', str.length).toLowerCase()
return slicedPinyinName
}
// 在城市数据中,添加简拼到“shorter”属性,就可以实现简拼搜索
// getSlicedName(cityObj, 'shorter', str.length).toLowerCase()
}
showList(array) {
return isNotEmpty(array) ? array.map(item => ({ city: item.city, code: item.code })) : CITY_NOT_FOUND
}
}
\ No newline at end of file
//应写入腾讯地图的key,并改文件名为config.js
//应写入腾讯地图的key,并改文件名为config.js
module.exports = {
key: "xxxxxxxxxxx",
}
import { LETTERS, CITY_LIST } from '../locale/citydata'
import { LETTERS, CITY_LIST } from '../locale/citydata'
import config from 'config'
// API
const getLocationUrl = (latitude, longitude) => (`https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${config.key}`)
const getCountyListUrl = code => (`https://apis.map.qq.com/ws/district/v1/getchildren?&id=${code}&key=${config.key}`)
const getIndexUrl = () => ('../activity/activity')
/**
* 安全地在深层嵌套对象中取值
* get deeply nested data from an object safely, return null if not found
* @param {Array} keyList an Array of keys
* @param {Object} obj
*/
const safeGet = (keyList, obj) => keyList.reduce((preValue, curKey) => ((preValue && preValue[curKey]) ? preValue[curKey] : null), obj)
const isNotEmpty = array => (Array.isArray(array) && array.length > 0)
const isChinese = str => (/^[\u4e00-\u9fa5]+$/.test(str))
// 城市名按首字母分组
const getCityListSortedByInitialLetter = () => (
LETTERS.map(
letter => ({
initial: letter,
cityInfo: CITY_LIST.filter(city => city.initial == letter)
})
)
)
const getSlicedName = (cityObj, key, sliceLen) => (cityObj[key] && cityObj[key].slice(0, sliceLen))
const onFail = (err) => { console.log(err) } // add your logic here e.g. show a toast
export default {
getLocationUrl,
getCountyListUrl,
getIndexUrl,
safeGet,
isNotEmpty,
isChinese,
getCityListSortedByInitialLetter,
getSlicedName,
onFail,
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论