[Improvement] AddressEdit: add focus、change-area、select-search events (#426)

This commit is contained in:
neverland
2017-12-13 17:36:25 +08:00
committed by GitHub
parent a19cfe51ca
commit c2bef6ef15
6 changed files with 148 additions and 30 deletions
+2 -1
View File
@@ -16,7 +16,7 @@
>
<div slot="icon">
<span v-if="showIcon && isAndroid" class="van-address-edit-detail__finish-edit">{{ $t('complete') }}</span>
<icon v-else-if="showIcon" name="clear" />
<icon v-else-if="showIcon" name="clear" />
</div>
</field>
@@ -101,6 +101,7 @@ export default create({
onSuggestSelect(express) {
this.$emit('input', `${express.address || ''} ${express.name || ''}`.trim());
this.$emit('select-search', express);
},
isString(str) {
+28 -3
View File
@@ -30,6 +30,7 @@
@focus="onFocus('address_detail')"
@blur="onDetailBlur"
@input="onChangeDetail"
@select-search="$emit('select-search', $event)"
/>
<field
v-if="showPostal"
@@ -41,8 +42,8 @@
maxlength="6"
class="van-hairline--top"
:error="errorInfo.postal_code"
@focus="onFocus('postal_code')">
</field>
@focus="onFocus('postal_code')"
/>
<switch-cell
v-if="showSetDefault"
v-show="!hideBottomFields"
@@ -60,6 +61,7 @@
</div>
<popup v-model="showAreaSelect" position="bottom">
<van-area
ref="area"
:value="currentInfo.area_code"
:areaList="areaList"
@confirm="onAreaConfirm"
@@ -164,6 +166,7 @@ export default create({
onFocus(key) {
this.errorInfo[key] = false;
this.detailFocused = key === 'address_detail';
this.$emit('focus', key);
},
onDetailBlur() {
@@ -179,13 +182,18 @@ export default create({
if (values.length !== 3 || +values[0].code === -1 || +values[1].code === -1 || +values[2].code === -1) {
return Toast(this.$t('areaWrong'));
}
this.assignAreaValues(values);
this.showAreaSelect = false;
this.$emit('change-area', values);
},
assignAreaValues(values) {
Object.assign(this.currentInfo, {
province: values[0].name,
city: values[1].name,
county: values[2].name,
area_code: values[2].code
});
this.showAreaSelect = false;
},
onSaveAddress() {
@@ -242,6 +250,23 @@ export default create({
}).then(() => {
this.$emit('delete', this.currentInfo);
});
},
// get values of area component
getArea() {
const { area } = this.$refs;
return area ? area.getValues() : [];
},
// set area code to area component
setAreaCode(code) {
this.currentInfo.area_code = code;
this.$nextTick(() => {
const { area } = this.$refs;
if (area) {
this.assignAreaValues(area.getValues());
}
});
}
}
});
+5
View File
@@ -145,6 +145,11 @@ export default create({
[DEFAULT_COUNTY].concat(this.computedAreaList(COUNTY_TYPE, code.slice(0, 4)))
);
}
},
getValues() {
const { picker } = this.$refs;
return picker ? picker.getValues() : [];
}
}
});