<template>
<view>
<view class="flex-row align-center" @click="set_picker()">
<view class="flex-grow">{{ value }}</view>
<view class="align-center">
<u-icon color="#999797" size="14" name="arrow-right"></u-icon>
</view>
</view>
<u-picker
:closeOnClickOverlay="true"
:show="picker_show"
:immediateChange="true"
:defaultIndex="picker_index"
ref="uPicker"
title="所在地区"
:columns="columns"
keyName="regionName"
@confirm="confirm"
@change="changeHandler"
@close="picker_show = false"
@cancel="picker_show = false"
>
</u-picker>
</view>
</template>
<script>
import Area from "../../common/area.js";
export default {
data() {
return {
picker_show: false,
columns: [[], [], []],
picker_value: "",
picker_index: [],
pramas: {
province: "",
city: "",
area: "",
province_dictText: "",
city_dictText: "",
area_dictText: "",
picker_value: "",
picker_idx: [],
},
province: [],
city: [],
county:[],
};
},
props: {
apiData: {
type: [String, Object],
default: "",
},
block: {
type: Boolean,
default: true,
},
info: {
type: Boolean,
default: false,
},
value: {
type: String,
default: "",
},
address_data: {
type: [String, Object],
default: () => {},
},
edit_btn: {
type: Boolean,
default: false,
},
},
methods: {
async set_picker() {
var idx = this.picker_index;
this.picker_show = true;
console.log(idx);
const picker = this.$refs.uPicker;
console.log("picker", picker);
if (idx.length == 0) {
picker.setColumnValues(0, this.province);
await this.get_city_list(this.province[0]);
picker.setColumnValues(1, this.city);
await this.get_county_list(this.city[0])
picker.setColumnValues(2, this.county);
}
this.$emit("on-show", this.picker_show);
},
confirm(e) {
this.pramas.province = e.value[0].regionCode;
this.pramas.city = e.value[1].regionCode;
this.pramas.area = e.value[2].regionCode;
this.pramas.province_dictText = e.value[0].regionName;
this.pramas.city_dictText = e.value[1].regionName;
this.pramas.area_dictText = e.value[2].regionName;
this.pramas.picker_idx = e.indexs;
this.picker_index = e.indexs;
this.pramas.picker_value =
this.pramas.province_dictText +
this.pramas.city_dictText +
this.pramas.area_dictText;
this.picker_show = false;
this.$emit("on-confirm", this.pramas);
},
async changeHandler(e) {
const {
columnIndex,
value,
values,
index,
indexs,
picker = this.$refs.uPicker,
} = e;
if (columnIndex === 0) {
console.log("第1联级", e);
await this.get_city_list(this.province[e.indexs[0]]);
picker.setColumnValues(1, this.city);
this.get_county_list(this.city[0])
picker.setColumnValues(2, this.county);
}
if (columnIndex === 1) {
console.log("第2联级", e);
await this.get_county_list(this.city[e.indexs[1]])
picker.setColumnValues(2,this.county);
}
this.$emit("on-change");
},
get_province_list() {
let province_list = [];
for (let x in Area.province_list) {
let item = {
regionCode: x,
regionName: Area.province_list[x],
level: 1,
children: [],
};
province_list.push(item);
}
this.province = province_list;
},
get_city_list(pramas) {
console.log("get_city_list----pramas->", pramas);
let city_list = [];
for (let y in Area.city_list) {
if (y.substr(0, 2) == pramas.regionCode.substr(0, 2)) {
let item = {
regionCode: y,
regionName: Area.city_list[y],
level: 2,
children: [],
};
city_list.push(item);
}
}
this.city = city_list;
},
get_county_list(pramas) {
console.log("get_county_list----pramas->", pramas);
let county_list = [];
for (let z in Area.county_list) {
if (z.substr(0, 4) == pramas.regionCode.substr(0, 4)) {
let item = {
regionCode: z,
regionName: Area.county_list[z],
level: 3,
children: [],
};
county_list.push(item);
}
}
this.county = county_list;
},
},
mounted() {
this.get_province_list();
},
};
</script>
<style scoped>
.info {
color: #c4c4d6;
}
</style>

- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248