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.

104 lines
2.2 KiB

2 years ago
<template>
<view>
<city-select
2 years ago
@cityClick="cityClick"
formatName="cityName"
:activeCity="activeCity"
:hotCity="hotCity"
:obtainCitys="obtainCitys"
:isSearch="true"
:is-refresh="true"
ref="citys"
@refreshLocation="refreshLocation"
2 years ago
></city-select>
</view>
</template>
<script>
2 years ago
import citys from "@/component/CitySelect/citys.js";
import CitySelect from "@/component/CitySelect/city-select.vue";
2 years ago
export default {
components: {
2 years ago
CitySelect,
2 years ago
},
data() {
return {
//需要构建索引参数的名称(注意:传递的对象里面必须要有这个名称的参数)
//当前城市
2 years ago
activeCity: {},
2 years ago
//热门城市
2 years ago
hotCity: [],
2 years ago
//显示的城市数据
2 years ago
obtainCitys: [],
2 years ago
};
},
2 years ago
watch: {
vuex_location: {
2 years ago
handler: function (newVal, oldVal) {
2 years ago
this.activeCity = {
cityName: newVal.city,
2 years ago
cityCode: newVal.cityCode,
};
2 years ago
},
deep: true,
2 years ago
immediate: true,
},
2 years ago
},
mounted() {
2 years ago
if (this.$store.state.vuex_location.status !== 2) {
this.$store.dispatch("getLocation");
}
2 years ago
},
2 years ago
onLoad() {
2 years ago
//动态更新数据
setTimeout(() => {
//修改需要构建索引参数的名称
2 years ago
this.formatName = "cityName";
2 years ago
//修改当前城市
this.activeCity = {
2 years ago
cityName: this.vuex_location.city,
2 years ago
cityCode: this.vuex_location.cityCode,
};
2 years ago
//修改热门城市
this.hotCity = [
{
2 years ago
cityName: "南京",
cityCode: 320100,
},
{
cityCode: "320400",
cityName: "常州",
2 years ago
},
{
2 years ago
cityCode: "320500",
cityName: "苏州",
},
{
cityCode: "310100",
cityName: "上海",
},
{
cityCode: "320200",
cityName: "无锡",
},
];
2 years ago
//修改构建索引数据
2 years ago
this.obtainCitys = citys;
}, 0);
2 years ago
},
methods: {
2 years ago
refreshLocation() {
2 years ago
this.$store.dispatch("getLocation");
2 years ago
},
2 years ago
cityClick(item) {
2 years ago
this.$store.commit("SET_CITY", {
2 years ago
cityName: item.cityName,
2 years ago
cityCode: item.cityCode,
});
},
},
};
2 years ago
</script>
2 years ago
<style lang="scss"></style>