You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

280 lines
8.1 KiB

1 week ago
  1. "use strict";
  2. const common_vendor = require("../../../common/vendor.js");
  3. const pages_index_comp_allCity = require("./allCity.js");
  4. const pages_index_comp_HotCity = require("./HotCity.js");
  5. const store_modules_car = require("../../../store/modules/car.js");
  6. const config_site_config = require("../../../config/site.config.js");
  7. const common_assets = require("../../../common/assets.js");
  8. let usecarStore = store_modules_car.carStore();
  9. let {
  10. mapKey
  11. } = config_site_config.obj;
  12. const _sfc_main = {
  13. data() {
  14. return {
  15. letter: [],
  16. selectLetter: "",
  17. searchValue: "",
  18. scrollIntoId: "",
  19. list: [],
  20. tId: null,
  21. searchList: [],
  22. showMask: false,
  23. disdingwei: true,
  24. Visit: [],
  25. //最近访问
  26. currentCity: " ",
  27. longitude: "",
  28. //经度
  29. latitude: "",
  30. //纬度
  31. seconds: 3,
  32. po_tips: "重新定位",
  33. citys: [],
  34. hotCity: pages_index_comp_HotCity.HotCity
  35. };
  36. },
  37. created() {
  38. console.log(usecarStore);
  39. this.initcity();
  40. var that = this;
  41. common_vendor.index.getStorage({
  42. key: "Visit_key",
  43. success: function(res) {
  44. that.Visit = res.data;
  45. }
  46. });
  47. that.getWarpweft();
  48. var mu = [
  49. "a",
  50. "b",
  51. "c",
  52. "d",
  53. "e",
  54. "f",
  55. "g",
  56. "h",
  57. "j",
  58. "k",
  59. "l",
  60. "m",
  61. "n",
  62. "p",
  63. "q",
  64. "r",
  65. "s",
  66. "t",
  67. "w",
  68. "x",
  69. "y",
  70. "z"
  71. ];
  72. var tmp = [];
  73. for (var i = 0; i < mu.length; i++) {
  74. var item = mu[i];
  75. for (var j = 0; j < this.citys.length; j++) {
  76. var py = this.citys[j].py;
  77. if (py.substring(0, 1) == item) {
  78. if (tmp.indexOf(item) == -1) {
  79. this.list[i] = [this.citys[j]];
  80. tmp.push(item);
  81. this.letter.push(item.toUpperCase());
  82. } else {
  83. this.list[i].push(this.citys[j]);
  84. }
  85. }
  86. }
  87. }
  88. },
  89. methods: {
  90. initcity() {
  91. let cityArr = pages_index_comp_allCity.allCity.map((arr) => {
  92. return arr.cityInfoList.map((item) => {
  93. let obj = {
  94. cityName: item.cityName,
  95. pinYin: item.cityPinyin,
  96. py: item.cityAcronym.toLocaleLowerCase(),
  97. code: item.cityCode,
  98. cityInitial: item.cityInitial
  99. };
  100. return obj;
  101. });
  102. });
  103. this.citys = cityArr.flat();
  104. console.log(this.citys);
  105. },
  106. getId(index) {
  107. return this.letter[index];
  108. },
  109. scrollTo(letter) {
  110. this.showMask = true;
  111. this.selectLetter = letter == "hot" ? "最" : letter;
  112. setTimeout(() => {
  113. this.showMask = false;
  114. }, 300);
  115. this.scrollIntoId = letter;
  116. },
  117. query(source, text) {
  118. console.log(source, text);
  119. let res = [];
  120. var self = this;
  121. res = source.filter((item) => {
  122. const arr = [];
  123. let isHave = false;
  124. Object.keys(item).forEach((prop) => {
  125. const itemStr = item[prop];
  126. self.isString(itemStr) && itemStr.split(",").forEach((val) => {
  127. arr.push(val);
  128. });
  129. });
  130. arr.some((val) => {
  131. isHave = new RegExp("^" + text).test(val);
  132. return isHave;
  133. });
  134. return isHave;
  135. });
  136. console.log(JSON.stringify(res));
  137. return res;
  138. },
  139. isString(obj) {
  140. return typeof obj === "string";
  141. },
  142. onInput(e) {
  143. const value = e.detail.value;
  144. console.log(value);
  145. if (value !== "" && this.citys && this.citys.length > 0) {
  146. const queryData = this.query(this.citys, String(value).trim());
  147. this.searchList = queryData;
  148. this.disdingwei = false;
  149. } else {
  150. this.searchList = [];
  151. this.disdingwei = true;
  152. }
  153. },
  154. back_city(item) {
  155. if (item) {
  156. console.log(item);
  157. usecarStore.setCar("city", item.code);
  158. usecarStore.setCar("cityName", item.cityName);
  159. common_vendor.index.navigateBack();
  160. return;
  161. } else {
  162. this.$emit("back_city", "no");
  163. }
  164. },
  165. // IDZBZ-L5GCZ-EQXXA-ZR5K4-JTSXH-IQBLO
  166. getWarpweft() {
  167. var that = this;
  168. that.po_tips = "定位中...";
  169. let countdown = setInterval(
  170. () => {
  171. that.seconds--;
  172. common_vendor.index.getLocation({
  173. type: "wgs84",
  174. success: function(res) {
  175. console.log("当前位置的经度:" + res.longitude);
  176. console.log("当前位置的纬度:" + res.latitude);
  177. that.longitude = res.longitude;
  178. that.latitude = res.latitude;
  179. let url = "https://apis.map.qq.com/ws/geocoder/v1/";
  180. common_vendor.o$1(url, {
  181. key: mapKey,
  182. location: res.latitude + "," + res.longitude,
  183. output: "jsonp"
  184. }).then((res2) => {
  185. console.log("jsonp", res2.result.address_component);
  186. let {
  187. province,
  188. city,
  189. district
  190. } = res2.result.address_component;
  191. that.province = province;
  192. that.city = city;
  193. that.area = district;
  194. console.log(province, city, district);
  195. that.currentCity = that.citys.find((item) => item.cityName == city);
  196. if (!that.currentCity) {
  197. common_vendor.index.$u.toast("获取定位失败,请手动选择城市");
  198. }
  199. console.log(that.currentCity, "当前城市");
  200. }).catch(() => {
  201. common_vendor.index.$u.toast("获取定位失败,请手动选择城市");
  202. });
  203. },
  204. fail() {
  205. common_vendor.index.$u.toast("获取定位失败,请手动选择城市");
  206. }
  207. });
  208. if (that.seconds <= 0) {
  209. that.seconds = 3;
  210. that.po_tips = "重新定位";
  211. clearInterval(countdown);
  212. }
  213. },
  214. 1e3
  215. );
  216. }
  217. }
  218. };
  219. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  220. return common_vendor.e({
  221. a: common_vendor.o([($event) => $data.searchValue = $event.detail.value, (...args) => $options.onInput && $options.onInput(...args)]),
  222. b: $data.searchValue,
  223. c: $data.disdingwei
  224. }, $data.disdingwei ? common_vendor.e({
  225. d: $data.currentCity.cityName
  226. }, $data.currentCity.cityName ? {
  227. e: common_vendor.t($data.currentCity.cityName),
  228. f: common_vendor.o(($event) => $options.back_city($data.currentCity))
  229. } : {}, {
  230. g: common_assets._imports_0$1,
  231. h: common_vendor.t($data.po_tips),
  232. i: common_vendor.o((...args) => $options.getWarpweft && $options.getWarpweft(...args)),
  233. j: common_vendor.f($data.hotCity, (item, index, i0) => {
  234. return {
  235. a: common_vendor.t(item.cityName),
  236. b: common_vendor.o(($event) => $options.back_city(item))
  237. };
  238. })
  239. }) : {}, {
  240. k: $data.searchValue == ""
  241. }, $data.searchValue == "" ? {
  242. l: common_vendor.f($data.list, (item, index, i0) => {
  243. return {
  244. a: common_vendor.t($options.getId(index)),
  245. b: common_vendor.f(item, (city, i, i1) => {
  246. return {
  247. a: common_vendor.t(city.cityName),
  248. b: i,
  249. c: common_vendor.o(($event) => $options.back_city(city), i)
  250. };
  251. }),
  252. c: $options.getId(index),
  253. d: index
  254. };
  255. })
  256. } : {}, {
  257. m: common_vendor.f($data.searchList, (item, index, i0) => {
  258. return {
  259. a: common_vendor.t(item.cityName),
  260. b: common_vendor.o(($event) => $options.back_city(item))
  261. };
  262. }),
  263. n: $data.scrollIntoId,
  264. o: $data.searchValue == ""
  265. }, $data.searchValue == "" ? {
  266. p: common_vendor.f($data.letter, (item, k0, i0) => {
  267. return {
  268. a: common_vendor.t(item),
  269. b: item,
  270. c: common_vendor.o(($event) => $options.scrollTo(item), item)
  271. };
  272. })
  273. } : {}, {
  274. q: $data.showMask
  275. }, $data.showMask ? {
  276. r: common_vendor.t($data.selectLetter)
  277. } : {});
  278. }
  279. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-123c04c7"]]);
  280. wx.createPage(MiniProgramPage);