Commit e6107e5d authored by 高铭波's avatar 高铭波

编辑地址功能调整

parent 881b1ab3
...@@ -4,17 +4,17 @@ ...@@ -4,17 +4,17 @@
<view class="top"> <view class="top">
<view class="item"> <view class="item">
<view class="left">收货人</view> <view class="left">收货人</view>
<input disabled v-model="name" type="text" placeholder-class="line" placeholder="请填写收货人姓名" /> <input :disabled="nameStatus" v-model="name" type="text" placeholder-class="line" placeholder="请填写收货人姓名" />
</view> </view>
<view class="item"> <view class="item">
<view class="left">手机号码</view> <view class="left">电话号码</view>
<input disabled v-model="mobile" type="text" placeholder-class="line" placeholder="请填写收货人手机号" /> <input :disabled="mobileStatus" v-model="mobile" type="text" placeholder-class="line" placeholder="请填写收货人手机号" />
</view> </view>
<view class="item"> <view class="item">
<view class="left">所在地区</view> <view class="left">所在地区</view>
<input @tap="showRegionPicker" disabled v-model="region" type="text" placeholder-class="line" placeholder="省市区县、乡镇等" /> <input @tap="showRegionPicker" disabled v-model="formatRegion" type="text" placeholder-class="line" placeholder="省市区县、乡镇等" />
<u-icon @click="autoLocation" class="right" name="map" label="定位" label-size="24" label-color="#2272FF" /> <u-icon @click="autoLocation" class="right" name="map" label="定位" label-size="24" label-color="#2272FF" />
</view> </view>
<u-field <u-field
class="item-address" class="item-address"
...@@ -26,13 +26,10 @@ ...@@ -26,13 +26,10 @@
type="textarea" type="textarea"
:auto-height="false" :auto-height="false"
:border-bottom="false" :border-bottom="false"
> ></u-field>
</u-field>
</view> </view>
<view class="bottom"> <view class="bottom">
<button class="btn, bottom-btn" @click="show = true"> <button class="btn, bottom-btn" @click="show = true"><text class="button-text">保存</text></button>
<text class="button-text">保存</text>
</button>
<!-- <view class="default"> <!-- <view class="default">
<view class="left"> <view class="left">
<view class="set">设置默认地址</view> <view class="set">设置默认地址</view>
...@@ -41,149 +38,211 @@ ...@@ -41,149 +38,211 @@
<view class="right"><switch color="red" @change="setDefault" /></view> <view class="right"><switch color="red" @change="setDefault" /></view>
</view> --> </view> -->
</view> </view>
<u-picker mode="region" ref="uPicker" v-model="showPicker" :params="params" @confirm="confirmRegion" /> <u-picker mode="region" v-model="showPicker" :default-region="region" @confirm="confirmRegion" />
<u-popup <u-popup border-radius="12" width="690" height="520" v-model="show" mode="center">
border-radius="12"
width="690"
height="520"
v-model="show"
mode="center">
<view class="save-pop"> <view class="save-pop">
<view class="header">确认保存信息</view> <view class="header">确认保存信息</view>
<view class="content"> <view class="content"><view class="tips">您填写的信息尚未保存,是否保存</view></view>
<view class="tips">您填写的信息尚未保存,是否保存</view>
</view>
</view> </view>
<view class="pop-bottom"> <view class="pop-bottom">
<button class="plain" @click="show = false" shape="circle" :plain="true">不保存</button> <button class="plain" @click="show = false" shape="circle" :plain="true">不保存</button>
<button <u-button :custom-style="submitBtn" shape="circle" @click="submitForm" :disabled="disabledSubmit">保存</u-button>
class="solid"
shape="circle"
@click="$u.throttle(submitForm, 500)"
:loading="submiting"
:disabled="disabledSubmit">保存</button>
</view> </view>
</u-popup> </u-popup>
</view> </view>
</template> </template>
<script> <script>
let r = require("libs/bmap-wx.min.js"); /**
* addSite 新增地址|修改地址|选择地址(返回选择地址信息)
* @description 编辑地址共通页
* @property {String} type 编辑类型(默认为修改,add--新增、edit--修改、select--选择)
* @property {String} info 地址信息(json字符串:包含地址信息)
*/
let r = require('libs/bmap-wx.min.js');
let h = new r.BMapWX({ let h = new r.BMapWX({
ak: process.uniEnv.bmapAK // ak: process.uniEnv.bmapAK,
ak: 'G1wPip2Oj62NnoUctXhiE1faZVHbeo2A'
}); });
export default { export default {
data() { data() {
return { return {
title: '新增地址', title: '修改地址',
siteInfo: null,
siteType: 'edit',
show: false, show: false,
location: '', location: '',
address: '', address: '',
type: '充电桩安装', type: '充电桩安装',
name: '--', name: '',
mobile: '', mobile: '',
nameStatus: true,
mobileStatus: true,
settled: null, settled: null,
region: [], adcode: '',
regionObj: [], regionObj: [],
region: [],
showPicker: false, showPicker: false,
params: { loading: true
province: true,
city: true,
area: true
},
}; };
}, },
computed: {}, computed: {
formatRegion() {
return this.region.join(' ');
},
submitBtn() {
return {
color: '#FFFFFF',
backgroundColor: '#2272FF'
};
}
},
async onLoad(e) { async onLoad(e) {
getApp().trackPage('我的收获地址修改页') getApp().trackPage('我的收获地址修改页');
if(e && e.title) { if (!this.vuex_token) {
this.title = decodeURIComponent(e.title) this.$u.route({ url: 'pages/login/index' });
} }
if(!this.vuex_token) { if (e) {
this.$u.route({url: 'pages/login/index'}) if (e.type === 'add') {
this.title = '新增地址';
this.siteType = 'add';
} else if (e.type === 'select') {
this.title = '选择地址';
this.siteType = 'select';
} else if (e.info && this.$u.test.jsonString(e.info)) {
// 默认修改我的地址
this.siteInfo = JSON.parse(decodeURIComponent(e.info));
} else if (e.type == 'edit') {
this.title = '修改地址';
this.siteType = 'edit';
}
} }
},
onShow() {
this.getData(); this.getData();
}, },
methods: { methods: {
async getData() { getData() {
const callback = (vm, res) => { if (this.siteType == 'add' || this.siteType == 'select') {
vm.settled = res.record this.nameStatus = false;
vm.address = vm.settled.address this.mobileStatus = false;
vm.name = vm.settled.id_card_name } else if (this.siteType == 'edit') {
vm.mobile = vm.settled.mobile let address = '';
} if (this.$u.test.isEmpty(this.siteInfo)) {
if(this.vuex_settled && this.vuex_settled.record || null) { const callback = (vm, res) => {
callback(this, this.vuex_settled) this.settled = res.record;
if (this.loading) {
this.name = this.settled.id_card_name;
this.mobile = this.settled.mobile;
this.address = this.settled.address;
this.geocoding();
}
this.loading = this.$u.test.isEmpty(this.settled);
};
if (this.vuex_settled && this.vuex_settled.record) {
callback(this, this.vuex_settled);
} else {
getApp().getBaseInfo(this, callback);
}
} else {
if (this.loading) {
this.loading = false;
this.name = this.siteInfo.name;
this.mobile = this.siteInfo.mobile;
this.address = this.siteInfo.address;
this.geocoding();
}
}
} }
getApp().getBaseInfo(this, callback);
}, },
showRegionPicker() { showRegionPicker() {
this.showPicker = true this.showPicker = true;
}, },
confirmRegion(params) { confirmRegion(params) {
this.regionObj = params this.regionObj = params;
this.region = params.province.label+params.city.label+params.area.label this.region = [params.province.label, params.city.label, params.area.label];
}, },
/** /**
* 百度定位 * 百度定位
* @param {Object} long * @param {Object} long
* @param {Object} lat * @param {Object} lat
*/ */
baiduLocation(long, lat) { regeocoding(lat, long) {
console.log("11111111111", this.title)
let t = {
success: (res) => {
console.log('success:', res)
let e = res.wxMarkerData[0];
let i = e.address;
this.location = i;
},
fail: (res) => {
console.log('fail:', res)
}
}
if (lat && long) { if (lat && long) {
let e = lat + "," + long h.regeocoding({
t.location = e location: lat + ',' + long,
// t.coordtype = 'wgs84' success: data => {
// t.latitude = lat console.log('regeocoding[success]:', data);
// t.longitude = long this.location = data.wxMarkerData[0];
console.log('regeocoding:', t) let regeocod = data.originalData.result.addressComponent;
h.regeocoding(t); this.adcode = regeocod.adcode;
this.region = [regeocod.province, regeocod.city, regeocod.district];
let region = this.region.join('');
if (this.$u.test.contains(this.address, region)) {
this.address = this.address.replace(region, '');
}
},
fail: res => {
console.log('regeocoding[fail]:', res);
}
});
} }
}, },
geocoding() {
if (this.address) {
let t = {
success: res => {
console.log('[geocoding][success]:', res);
let e = res.wxMarkerData[0];
if (e.longitude && e.latitude) {
this.regeocoding(e.latitude, e.longitude);
}
},
fail: res => {
console.log('[geocoding][fail]:', res);
}
};
t.address = this.address;
h.geocoding(t);
}
},
/** /**
* 自动定位 * 自动定位
*/ */
autoLocation() { autoLocation() {
let that = this let that = this;
uni.chooseLocation({ uni.chooseLocation({
success: (res) => { success: res => {
this.baiduLocation(res.longitude, res.latitude) this.address = res.address + res.name;
this.regeocoding(res.latitude, res.longitude);
}, },
fail: function(res) { fail: function(res) {
// uni.showToast({ console.log('chooseLocation[fail]:', res);
// title: '定位失败'
// })
} }
}); });
}, },
async submitForm() { async submitForm() {
let self = this if (this.siteType === 'add') {
let params = { } else if (this.siteType === 'select') {
type: self.type, } else if (this.siteType === 'edit') {
address: self.address if (this.$u.test.isEmpty(this.siteInfo)) {
} let params = {
let res = await self.$u.api.syncAddress(params) type: this.type,
const callback = (vm, res) => { address: this.region.join("") + this.address
vm.$u.route({type: 'back'}) };
} let res = await this.$u.api.syncAddress(params);
if(res && res.code == 200) { const callback = (vm, res) => {
getApp().getBaseInfo(this, callback); this.$u.route({ type: 'back' });
this.show = false
};
if (res && res.code == 200) {
getApp().getBaseInfo(this, callback);
}
} else {
}
} }
} }
} }
...@@ -196,7 +255,7 @@ export default { ...@@ -196,7 +255,7 @@ export default {
font-size: 28rpx; font-size: 28rpx;
} }
.wrap { .wrap {
background-color: #FFFFFF; background-color: #ffffff;
width: 750rpx; width: 750rpx;
height: 100vh; height: 100vh;
.top { .top {
...@@ -209,7 +268,7 @@ export default { ...@@ -209,7 +268,7 @@ export default {
color: #333333; color: #333333;
line-height: 88rpx; line-height: 88rpx;
align-items: center; align-items: center;
border-bottom: solid 2rpx #F4F5F7; border-bottom: solid 2rpx #f4f5f7;
.left { .left {
width: 160rpx; width: 160rpx;
color: #999999; color: #999999;
...@@ -218,15 +277,14 @@ export default { ...@@ -218,15 +277,14 @@ export default {
text-align: left; text-align: left;
flex: auto; flex: auto;
} }
.textarea { .textarea {
} }
.right { .right {
margin-left: 30rpx; margin-left: 30rpx;
font-size: 30rpx; font-size: 30rpx;
font-weight: 400; font-weight: 400;
color: #2272FF; color: #2272ff;
} }
} }
.item-address { .item-address {
...@@ -236,7 +294,7 @@ export default { ...@@ -236,7 +294,7 @@ export default {
/deep/ .u-field { /deep/ .u-field {
padding: 0; padding: 0;
padding-top: 30rpx; padding-top: 30rpx;
border-bottom: solid 2rpx #F4F5F7; border-bottom: solid 2rpx #f4f5f7;
.u-label { .u-label {
color: #999999; color: #999999;
line-height: normal; line-height: normal;
...@@ -257,7 +315,7 @@ export default { ...@@ -257,7 +315,7 @@ export default {
margin-left: 30rpx; margin-left: 30rpx;
font-size: 30rpx; font-size: 30rpx;
font-weight: 400; font-weight: 400;
color: #2272FF; color: #2272ff;
align-self: top; align-self: top;
} }
} }
...@@ -281,7 +339,7 @@ export default { ...@@ -281,7 +339,7 @@ export default {
} }
} }
} }
.save-pop { .save-pop {
padding: 0 30rpx; padding: 0 30rpx;
.header { .header {
...@@ -289,7 +347,7 @@ export default { ...@@ -289,7 +347,7 @@ export default {
font-size: 40rpx; font-size: 40rpx;
font-weight: bold; font-weight: bold;
color: #333333; color: #333333;
border-bottom: solid 2rpx #F4F5F7; border-bottom: solid 2rpx #f4f5f7;
line-height: 40rpx; line-height: 40rpx;
padding: 60rpx 0 40rpx 0; padding: 60rpx 0 40rpx 0;
} }
...@@ -304,8 +362,6 @@ export default { ...@@ -304,8 +362,6 @@ export default {
line-height: 28rpx; line-height: 28rpx;
} }
} }
} }
/deep/ .pop-bottom { /deep/ .pop-bottom {
padding: 0 16rpx; padding: 0 16rpx;
...@@ -319,12 +375,12 @@ export default { ...@@ -319,12 +375,12 @@ export default {
padding: 0; padding: 0;
} }
.plain { .plain {
border: 2px solid #2272FF; border: 2px solid #2272ff;
color: #2272FF; color: #2272ff;
} }
.solid { .solid {
color: #FFFFFF; color: #ffffff;
background-color: #2272FF; background-color: #2272ff;
} }
} }
} }
......
...@@ -58,9 +58,9 @@ export default { ...@@ -58,9 +58,9 @@ export default {
toAddSite(title){ toAddSite(title){
this.$u.route({ this.$u.route({
url: 'pages/mine/address/addSite', url: 'pages/mine/address/addSite',
params: { // params: {
title: title // title: title
} // }
}) })
} }
} }
......
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 to comment