Commit 61cba9a3 by lishengfu

udpate

parent e3a1f5b8
<template> <template>
<div> <div>
<van-picker show-toolbar title="标题" :columns="columns" @change="updateCity" /> <van-picker show-toolbar title="标题" :columns="columns" @change="onChange" />
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
...@@ -15,6 +15,7 @@ import { Component } from "vue-property-decorator"; ...@@ -15,6 +15,7 @@ import { Component } from "vue-property-decorator";
}) })
export default class cityList extends Vue { export default class cityList extends Vue {
private data: any = ""; private data: any = "";
private province: any = ""; //省份 private province: any = ""; //省份
private city: any = []; //市份 private city: any = []; //市份
private area: any = ""; //区,县 private area: any = ""; //区,县
...@@ -22,57 +23,52 @@ export default class cityList extends Vue { ...@@ -22,57 +23,52 @@ export default class cityList extends Vue {
private columns: any = [ private columns: any = [
{ {
text: "", text: "",
children: [] children: [
{
text: "",
children: [{ text: "" }]
}
]
} }
]; ];
created() { created() {
this.$server.EmployeeService.getCityList({}).then(res => { this.$server.EmployeeService.getCityList({}).then(res => {
this.data = res; this.data = res;
//展示省份数据 this.data.find((item: any) => {
Object.values(this.data).map((item: any) => { let obj = {};
if (item.parentId == 0) { if (item.parentId == 0) {
this.province = { this.province = {
text: item.name, text: item.name,
id: item.id id: item.id
}; };
this.columns.push(this.province); this.columns.push(this.province);
} else {
obj = {
text: item.name,
id: item.id,
parentId: item.parentId
};
this.city.push(obj);
} }
}); });
//展示市级数据
this.columns.map((i: any) => {
Object.values(this.data).map((item: any) => {
let obj = {};
if (item.parentId != 0) {
obj = {
text: item.name,
id: item.id,
parentId: item.parentId
};
// console.log(this.city)
this.city.push(obj);
// this.columns.children[0].push(this.city);
}
});
});
// console.log(this.city)
}); });
} }
updateCity(picker: any, values: any, index: any) { onChange(picker: any, values: any) {
console.log(values); // console.log(values[0]);
picker.setColumnValues(1, this.cityData(this.city, values[0])); // console.log(this.city)
// picker.setColumnValues(1, this.cityData(this.city,35));
picker.setColumnValues(2, this.city);
picker.setColumnValues(1, this.city);
} }
cityData(data: any, provinceId: any) { cityData(city: any, provinceId: any) {
data.map((item: any) => { // console.log(city)
if (item.text == provinceId) { // city.find((item: any) => {
console.log(provinceId); // if (item.parentId == provinceId) {
this.city = item; // console.log(item);
} // this.city = item;
}); // }
return this.city.map((res: any) => { // });
console.log(res)
// return { text: res.name, code: res.code };
});
} }
} }
</script> </script>
......
...@@ -137,6 +137,15 @@ export default [ ...@@ -137,6 +137,15 @@ export default [
meta: { meta: {
title: '测试页面', title: '测试页面',
} }
},
{
// 测试城市选择
path: '/cityTest',
name: 'cityTest',
component: () => import("@/views/cityTest.vue"),
meta: {
title: '测试城市列表',
}
} }
] ]
\ No newline at end of file
<template>
<div class="content">
<city-list />
</div>
</template>
<script lang="ts">
import Vue from "vue";
import { Button, Icon, Popup, Form, Picker, Field, Toast } from "vant";
import { Component } from "vue-property-decorator";
import cityList from "@/components/common/cityList.vue"
@Component({
components: {
[Button.name]: Button,
[Icon.name]: Icon,
[Popup.name]: Popup,
[Form.name]: Form,
[Picker.name]: Picker,
[Field.name]: Field,
cityList
}
})
export default class socialInfo extends Vue {
}
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment