"use strict"; const common_vendor = require("../../../common/vendor.js"); const pages_index_comp_allCity = require("./allCity.js"); const pages_index_comp_HotCity = require("./HotCity.js"); const store_modules_car = require("../../../store/modules/car.js"); const config_site_config = require("../../../config/site.config.js"); const common_assets = require("../../../common/assets.js"); let usecarStore = store_modules_car.carStore(); let { mapKey } = config_site_config.obj; const _sfc_main = { data() { return { letter: [], selectLetter: "", searchValue: "", scrollIntoId: "", list: [], tId: null, searchList: [], showMask: false, disdingwei: true, Visit: [], //最近访问 currentCity: " ", longitude: "", //经度 latitude: "", //纬度 seconds: 3, po_tips: "重新定位", citys: [], hotCity: pages_index_comp_HotCity.HotCity }; }, created() { console.log(usecarStore); this.initcity(); var that = this; common_vendor.index.getStorage({ key: "Visit_key", success: function(res) { that.Visit = res.data; } }); that.getWarpweft(); var mu = [ "a", "b", "c", "d", "e", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "w", "x", "y", "z" ]; var tmp = []; for (var i = 0; i < mu.length; i++) { var item = mu[i]; for (var j = 0; j < this.citys.length; j++) { var py = this.citys[j].py; if (py.substring(0, 1) == item) { if (tmp.indexOf(item) == -1) { this.list[i] = [this.citys[j]]; tmp.push(item); this.letter.push(item.toUpperCase()); } else { this.list[i].push(this.citys[j]); } } } } }, methods: { initcity() { let cityArr = pages_index_comp_allCity.allCity.map((arr) => { return arr.cityInfoList.map((item) => { let obj = { cityName: item.cityName, pinYin: item.cityPinyin, py: item.cityAcronym.toLocaleLowerCase(), code: item.cityCode, cityInitial: item.cityInitial }; return obj; }); }); this.citys = cityArr.flat(); console.log(this.citys); }, getId(index) { return this.letter[index]; }, scrollTo(letter) { this.showMask = true; this.selectLetter = letter == "hot" ? "最" : letter; setTimeout(() => { this.showMask = false; }, 300); this.scrollIntoId = letter; }, query(source, text) { console.log(source, text); let res = []; var self = this; res = source.filter((item) => { const arr = []; let isHave = false; Object.keys(item).forEach((prop) => { const itemStr = item[prop]; self.isString(itemStr) && itemStr.split(",").forEach((val) => { arr.push(val); }); }); arr.some((val) => { isHave = new RegExp("^" + text).test(val); return isHave; }); return isHave; }); console.log(JSON.stringify(res)); return res; }, isString(obj) { return typeof obj === "string"; }, onInput(e) { const value = e.detail.value; console.log(value); if (value !== "" && this.citys && this.citys.length > 0) { const queryData = this.query(this.citys, String(value).trim()); this.searchList = queryData; this.disdingwei = false; } else { this.searchList = []; this.disdingwei = true; } }, back_city(item) { if (item) { console.log(item); usecarStore.setCar("city", item.code); usecarStore.setCar("cityName", item.cityName); common_vendor.index.navigateBack(); return; } else { this.$emit("back_city", "no"); } }, // IDZBZ-L5GCZ-EQXXA-ZR5K4-JTSXH-IQBLO getWarpweft() { var that = this; that.po_tips = "定位中..."; let countdown = setInterval( () => { that.seconds--; common_vendor.index.getLocation({ type: "wgs84", success: function(res) { console.log("当前位置的经度:" + res.longitude); console.log("当前位置的纬度:" + res.latitude); that.longitude = res.longitude; that.latitude = res.latitude; let url = "https://apis.map.qq.com/ws/geocoder/v1/"; common_vendor.o$1(url, { key: mapKey, location: res.latitude + "," + res.longitude, output: "jsonp" }).then((res2) => { console.log("jsonp", res2.result.address_component); let { province, city, district } = res2.result.address_component; that.province = province; that.city = city; that.area = district; console.log(province, city, district); that.currentCity = that.citys.find((item) => item.cityName == city); if (!that.currentCity) { common_vendor.index.$u.toast("获取定位失败,请手动选择城市"); } console.log(that.currentCity, "当前城市"); }).catch(() => { common_vendor.index.$u.toast("获取定位失败,请手动选择城市"); }); }, fail() { common_vendor.index.$u.toast("获取定位失败,请手动选择城市"); } }); if (that.seconds <= 0) { that.seconds = 3; that.po_tips = "重新定位"; clearInterval(countdown); } }, 1e3 ); } } }; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return common_vendor.e({ a: common_vendor.o([($event) => $data.searchValue = $event.detail.value, (...args) => $options.onInput && $options.onInput(...args)]), b: $data.searchValue, c: $data.disdingwei }, $data.disdingwei ? common_vendor.e({ d: $data.currentCity.cityName }, $data.currentCity.cityName ? { e: common_vendor.t($data.currentCity.cityName), f: common_vendor.o(($event) => $options.back_city($data.currentCity)) } : {}, { g: common_assets._imports_0$1, h: common_vendor.t($data.po_tips), i: common_vendor.o((...args) => $options.getWarpweft && $options.getWarpweft(...args)), j: common_vendor.f($data.hotCity, (item, index, i0) => { return { a: common_vendor.t(item.cityName), b: common_vendor.o(($event) => $options.back_city(item)) }; }) }) : {}, { k: $data.searchValue == "" }, $data.searchValue == "" ? { l: common_vendor.f($data.list, (item, index, i0) => { return { a: common_vendor.t($options.getId(index)), b: common_vendor.f(item, (city, i, i1) => { return { a: common_vendor.t(city.cityName), b: i, c: common_vendor.o(($event) => $options.back_city(city), i) }; }), c: $options.getId(index), d: index }; }) } : {}, { m: common_vendor.f($data.searchList, (item, index, i0) => { return { a: common_vendor.t(item.cityName), b: common_vendor.o(($event) => $options.back_city(item)) }; }), n: $data.scrollIntoId, o: $data.searchValue == "" }, $data.searchValue == "" ? { p: common_vendor.f($data.letter, (item, k0, i0) => { return { a: common_vendor.t(item), b: item, c: common_vendor.o(($event) => $options.scrollTo(item), item) }; }) } : {}, { q: $data.showMask }, $data.showMask ? { r: common_vendor.t($data.selectLetter) } : {}); } const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-123c04c7"]]); wx.createPage(MiniProgramPage);