chore(分包): 拆分pages_tooll子包
This commit is contained in:
615
pages_tool/member/address/address.vue
Normal file
615
pages_tool/member/address/address.vue
Normal file
@@ -0,0 +1,615 @@
|
||||
<template>
|
||||
<view :style="themeColor">
|
||||
<mescroll-uni ref="mescroll" @getData="getListData" v-if="storeToken">
|
||||
<block slot="list">
|
||||
<view class="address-list">
|
||||
<template v-if="addressList.length !== 0">
|
||||
<view class="address-item" v-for="(item, index) in addressList" :key="index">
|
||||
<view class="address-item-top" v-if="localType == 2 && item.local_data">
|
||||
<view class="address-item-left">
|
||||
<view class="address-top-info">
|
||||
<view class="address-name">{{ item.name }}</view>
|
||||
<view class="address-tel">{{ item.mobile }}</view>
|
||||
<view class="address-status" v-if="localType == 2 && item.local_data">{{
|
||||
item.local_data }}</view>
|
||||
</view>
|
||||
<view class="address-info">{{ item.full_address }}{{ item.address }}</view>
|
||||
</view>
|
||||
<view class="address-item-edit" @click="addAddress('edit', item.id)">
|
||||
{{ $lang('modify') }}
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="address-item-top" v-else @click="setDefault(item.id)">
|
||||
<view class="address-item-left">
|
||||
<view class="address-top-info">
|
||||
<view class="address-name">{{ item.name }}</view>
|
||||
<view class="address-tel">{{ item.mobile }}</view>
|
||||
</view>
|
||||
<view class="address-info">{{ item.full_address }}{{ item.address }}</view>
|
||||
</view>
|
||||
<view class="address-item-edit" @click.stop="addAddress('edit', item.id)">
|
||||
{{ $lang('modify') }}
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="address-item-bottom">
|
||||
<view class="address-default" @click="setDefault(item.id, item.is_default)">
|
||||
<text class="default" v-if="localType == 2 && item.local_data">设为默认地址</text>
|
||||
<text class="default" v-else>设为默认地址</text>
|
||||
<switch v-if="item.is_default == 1" checked disabled style="transform:scale(0.7)"
|
||||
:color="themeStyle.main_color" />
|
||||
<switch v-else style="transform:scale(0.7)" :color="themeStyle.main_color" />
|
||||
</view>
|
||||
<view class="address-btn">
|
||||
<text class="delete" v-if="item.is_default != 1"
|
||||
@click="deleteAddress(item.id, item.is_default)">
|
||||
<text class="iconfont icon-icon7"></text>
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
</template>
|
||||
|
||||
<view v-if="addressList.length == 0 && showEmpty" class="empty-box">
|
||||
<image :src="$util.img('public/uniapp/member/address/empty.png')" mode="widthFix" />
|
||||
<view class="tips">暂无收货地址,请添加</view>
|
||||
|
||||
<button type="primary" class="add-address" @click="addAddress('add')">{{ $lang('newAddAddress')
|
||||
}}</button>
|
||||
|
||||
<!-- #ifdef H5 -->
|
||||
<button type="primary" class="get-address" @click="getChooseAddress()"
|
||||
v-if="$util.isWeiXin() && local != 1">{{
|
||||
$lang('getAddress') }}</button>
|
||||
<!-- #endif -->
|
||||
<!-- #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO -->
|
||||
<button type="primary" class="get-address" @click="getChooseAddress()" v-if="local != 1">{{
|
||||
$lang('getAddress')
|
||||
}}</button>
|
||||
<!-- #endif -->
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
</mescroll-uni>
|
||||
|
||||
<view class="btn-add" v-if="addressList.length !== 0">
|
||||
<!-- #ifdef MP-WEIXIN -->
|
||||
<view class="wx-add" @click="getChooseAddress()" v-if="local != 1">
|
||||
<text>{{ $lang('getAddress') }}</text>
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
<!-- #ifdef H5 -->
|
||||
<button type="primary" class="add-address" @click="getChooseAddress()"
|
||||
v-if="$util.isWeiXin() && local != 1">{{
|
||||
$lang('getAddress') }}</button>
|
||||
<!-- #endif -->
|
||||
<button type="primary" class="add-address" @click="addAddress('add')">
|
||||
<text class="iconfont icon-add1"></text>
|
||||
{{ $lang('newAddAddress') }}
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<ns-login ref="login"></ns-login>
|
||||
<loading-cover ref="loadingCover"></loading-cover>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { Weixin } from 'common/js/wx-jssdk.js';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
MescrollUni: () => import('@/components/mescroll/my-list-mescroll.vue'),
|
||||
nsLogin: () => import('@/components/ns-login/ns-login.vue'),
|
||||
loadingCover: () => import('@/components/loading-cover/loading-cover.vue'),
|
||||
nsEmpty: () => import('@/components/ns-empty/ns-empty.vue'),
|
||||
// #ifdef MP-WEIXIN
|
||||
privacyPopup: () => import('@/components/wx-privacy-popup/privacy-popup.vue'),
|
||||
// #endif
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
addressList: [],
|
||||
back: '', // 返回页
|
||||
redirect: 'redirectTo', // 跳转方式
|
||||
isIndex: false,
|
||||
showEmpty: false,
|
||||
local: 0, //定位是否显示
|
||||
localType: 1,
|
||||
};
|
||||
},
|
||||
onLoad(option) {
|
||||
if (option.back) {
|
||||
this.back = option.back;
|
||||
uni.setStorageSync('addressBack', option.back);
|
||||
} else {
|
||||
if (uni.getStorageSync('addressBack')) {
|
||||
this.back = uni.getStorageSync('addressBack');
|
||||
uni.removeStorageSync('addressBack');
|
||||
}
|
||||
}
|
||||
if (option.redirect) this.redirect = option.redirect;
|
||||
if (option.local) this.local = option.local;
|
||||
if (option.type) this.localType = option.type;
|
||||
},
|
||||
onShow() {
|
||||
uni.removeStorageSync('addressInfo');
|
||||
|
||||
if (this.storeToken) {
|
||||
if (this.$refs.mescroll) this.$refs.mescroll.refresh();
|
||||
} else {
|
||||
this.$nextTick(() => {
|
||||
this.$refs.login.open('/pages_tool/member/address');
|
||||
});
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getListData(mescroll) {
|
||||
let storeId = 0;
|
||||
let delivery = uni.getStorageSync('delivery');
|
||||
if (delivery && delivery.delivery_type == 'local') {
|
||||
storeId = delivery.store_id || 0;
|
||||
}
|
||||
this.showEmpty = false;
|
||||
this.$api.sendRequest({
|
||||
url: '/api/memberaddress/page',
|
||||
data: {
|
||||
page: mescroll.num,
|
||||
page_size: mescroll.size,
|
||||
type: this.localType,
|
||||
store_id: storeId
|
||||
},
|
||||
success: res => {
|
||||
this.showEmpty = true;
|
||||
let newArr = [];
|
||||
let msg = res.message;
|
||||
if (res.code == 0 && res.data) {
|
||||
newArr = res.data.list;
|
||||
} else {
|
||||
this.$util.showToast({
|
||||
title: msg
|
||||
});
|
||||
}
|
||||
mescroll.endSuccess(newArr.length);
|
||||
//设置列表数据
|
||||
if (mescroll.num == 1) this.addressList = []; //如果是第一页需手动制空列表
|
||||
this.addressList = this.addressList.concat(newArr); //追加新数据
|
||||
this.$forceUpdate();
|
||||
if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
|
||||
},
|
||||
fail: res => {
|
||||
mescroll.endErr();
|
||||
if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/* 地址跳转 */
|
||||
addAddress(type, id) {
|
||||
let data = {
|
||||
type: this.localType
|
||||
};
|
||||
if (type == 'edit') data.id = id;
|
||||
if (this.back) data.back = this.back;
|
||||
|
||||
this.$util.redirectTo('/pages_tool/member/address_edit', data);
|
||||
},
|
||||
/* 删除地址信息 */
|
||||
deleteAddress(id, is_default) {
|
||||
uni.showModal({
|
||||
title: '操作提示',
|
||||
content: '确定要删除该地址吗?',
|
||||
success: res => {
|
||||
if (res.confirm) {
|
||||
if (is_default == 1) {
|
||||
this.$util.showToast({
|
||||
title: '默认地址,不能删除'
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.$api.sendRequest({
|
||||
url: '/api/memberaddress/delete',
|
||||
data: {
|
||||
id: id
|
||||
},
|
||||
success: res => {
|
||||
if (res.code == 0) {
|
||||
this.$util.showToast({
|
||||
title: '删除成功'
|
||||
});
|
||||
} else {
|
||||
this.$util.showToast({
|
||||
title: '删除失败'
|
||||
});
|
||||
}
|
||||
this.$refs.mescroll.refresh();
|
||||
},
|
||||
fail: res => {
|
||||
mescroll.endErr();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
setDefault(id, is_default) {
|
||||
if (is_default == 1) return;
|
||||
this.$api.sendRequest({
|
||||
url: '/api/memberaddress/setdefault',
|
||||
data: {
|
||||
id
|
||||
},
|
||||
success: res => {
|
||||
if (res.data > 0) {
|
||||
this.$refs.mescroll.refresh();
|
||||
if (this.back != '') {
|
||||
this.$util.redirectTo(this.back, {}, 'redirectTo');
|
||||
} else {
|
||||
if (this.$refs.loadingCover) this.$refs.loadingCover.show();
|
||||
this.addressList = [];
|
||||
this.$refs.mescroll.refresh();
|
||||
this.$util.showToast({
|
||||
title: '修改默认地址成功'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
this.$util.showToast({
|
||||
title: res.message
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 一键获取地址
|
||||
*/
|
||||
getChooseAddress() {
|
||||
// #ifdef H5
|
||||
if (this.$util.isWeiXin()) {
|
||||
if (uni.getSystemInfoSync().platform == 'ios') {
|
||||
var url = uni.getStorageSync('initUrl');
|
||||
} else {
|
||||
var url = location.href;
|
||||
}
|
||||
// 获取jssdk配置
|
||||
this.$api.sendRequest({
|
||||
url: '/wechat/api/wechat/jssdkconfig',
|
||||
data: {
|
||||
url: url
|
||||
},
|
||||
success: jssdkRes => {
|
||||
if (jssdkRes.code == 0) {
|
||||
var wxJS = new Weixin();
|
||||
wxJS.init(jssdkRes.data);
|
||||
wxJS.openAddress(res => {
|
||||
if (res.errMsg == 'openAddress:ok') {
|
||||
this.saveAddress({
|
||||
name: res.userName, // 收货人姓名,
|
||||
mobile: res.telNumber, // 手机号
|
||||
province: res.provinceName, // 省
|
||||
city: res.cityName, // 市
|
||||
district: res.countryName, // 县
|
||||
address: res.detailInfo, // 详细地址
|
||||
full_address: res.provinceName + '-' + res.cityName + '-' + res.countryName,
|
||||
is_default: 1
|
||||
});
|
||||
} else {
|
||||
this.$util.showToast({
|
||||
title: res.errMsg == 'openAddress:function not implement' ? 'PC端微信不支持一键获取地址' : res.errMsg
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.$util.showToast({
|
||||
title: jssdkRes.message
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO
|
||||
uni.chooseAddress({
|
||||
success: res => {
|
||||
if (res.errMsg == 'chooseAddress:ok') {
|
||||
this.saveAddress({
|
||||
name: res.userName, // 收货人姓名,
|
||||
mobile: res.telNumber, // 手机号
|
||||
province: res.provinceName, // 省
|
||||
city: res.cityName, // 市
|
||||
district: res.countyName, // 县
|
||||
address: res.detailInfo, // 详细地址
|
||||
full_address: res.provinceName + '-' + res.cityName + '-' + res.countyName,
|
||||
is_default: 1
|
||||
});
|
||||
} else {
|
||||
this.$util.showToast({
|
||||
title: res.errMsg
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: res => {
|
||||
console.log('fail', res);
|
||||
}
|
||||
});
|
||||
// #endif
|
||||
},
|
||||
/**
|
||||
* 保存微信地址
|
||||
* @param {Object} params
|
||||
*/
|
||||
saveAddress(params) {
|
||||
this.$api.sendRequest({
|
||||
url: '/api/memberaddress/addthreeparties',
|
||||
data: params,
|
||||
success: res => {
|
||||
if (res.code >= 0) {
|
||||
|
||||
if (this.back != '') {
|
||||
this.$util.redirectTo(this.back, {}, 'redirectTo');
|
||||
} else {
|
||||
this.$refs.mescroll.refresh();
|
||||
}
|
||||
|
||||
} else {
|
||||
this.$util.showToast({
|
||||
title: res.message
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
storeToken: function (nVal, oVal) {
|
||||
if (nVal) {
|
||||
this.$refs.mescroll.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/deep/ .fixed {
|
||||
position: relative;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.cart-empty {
|
||||
padding-top: 208rpx !important;
|
||||
}
|
||||
|
||||
.address-list {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding-bottom: 40rpx;
|
||||
|
||||
.local {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin: $margin-updown $margin-both;
|
||||
background-color: #fff;
|
||||
padding: 30rpx;
|
||||
border-radius: $border-radius;
|
||||
|
||||
text {
|
||||
margin-right: 10rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.address-item {
|
||||
margin: $padding 0 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #ffffff;
|
||||
padding: 24rpx 30rpx;
|
||||
box-sizing: border-box;
|
||||
border-radius: 0;
|
||||
|
||||
.address-item-top {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
border-bottom: 1rpx solid $color-line;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
.address-item-left {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: calc(100% - 100rpx);
|
||||
}
|
||||
|
||||
.address-item-edit {
|
||||
color: #999;
|
||||
font-size: 24rpx;
|
||||
width: 100rpx;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.address-top-info {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
position: relative;
|
||||
|
||||
.address-name {
|
||||
color: #333333;
|
||||
font-size: 30rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.address-tel {
|
||||
color: #333333;
|
||||
font-size: 30rpx;
|
||||
margin-left: 26rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.address-status {
|
||||
color: #f00;
|
||||
font-size: $font-size-base;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.address-info {
|
||||
font-size: 26rpx;
|
||||
color: #888888;
|
||||
margin-top: 10rpx;
|
||||
margin-bottom: 28rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.address-item-bottom {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding-top: 24rpx;
|
||||
|
||||
.address-default {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 24rpx;
|
||||
line-height: 1;
|
||||
color: #666666;
|
||||
|
||||
.default {}
|
||||
|
||||
.iconfont {
|
||||
line-height: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.address-btn {
|
||||
font-size: $font-size-base;
|
||||
line-height: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.edit {
|
||||
text {
|
||||
vertical-align: center;
|
||||
margin-right: 10rpx;
|
||||
font-size: 30rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.delete {
|
||||
background: #F1F1F1;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
border-radius: 50%;
|
||||
padding: 10rpx;
|
||||
text-align: center;
|
||||
width: 48rpx;
|
||||
height: 48rpx;
|
||||
box-sizing: border-box;
|
||||
|
||||
text {
|
||||
font-size: 26rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.btn-add {
|
||||
margin-top: 60rpx;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
background: #fff;
|
||||
position: fixed;
|
||||
padding: 0 30rpx;
|
||||
box-sizing: border-box;
|
||||
padding-bottom: constant(safe-area-inset-bottom);
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
z-index: 10;
|
||||
|
||||
.add-address {
|
||||
height: 80rpx;
|
||||
line-height: 80rpx;
|
||||
border-radius: 80rpx;
|
||||
margin: 30rpx 0 30rpx;
|
||||
font-size: $font-size-toolbar;
|
||||
|
||||
text {
|
||||
margin-right: 10rpx;
|
||||
font-size: $font-size-base;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.wx-add {
|
||||
margin-top: 30rpx;
|
||||
margin-bottom: 30rpx;
|
||||
text-align: center;
|
||||
border-radius: 80rpx;
|
||||
height: 80rpx;
|
||||
line-height: 80rpx;
|
||||
background-color: var(--main-color);
|
||||
border: 2rpx solid var(--main-color);
|
||||
color: #FFFFFF;
|
||||
font-size: $font-size-toolbar;
|
||||
}
|
||||
|
||||
.empty-box {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
image {
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.tips {
|
||||
color: #999999;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.get-address,
|
||||
.add-address {
|
||||
width: 50%;
|
||||
height: 78rpx;
|
||||
line-height: 78rpx;
|
||||
border-radius: 78rpx;
|
||||
margin-top: 50rpx;
|
||||
|
||||
font-size: $font-size-toolbar;
|
||||
}
|
||||
|
||||
.get-address {
|
||||
width: 50%;
|
||||
border: 2rpx solid $base-color;
|
||||
margin-top: 20rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
}
|
||||
|
||||
.mescroll-downwarp+.empty-box {
|
||||
height: calc(100vh - 260rpx);
|
||||
}
|
||||
</style>
|
||||
<style>
|
||||
.address-item>>>.uni-switch-wrapper .uni-switch-input {
|
||||
height: 48rpx !important;
|
||||
width: 88rpx !important;
|
||||
}
|
||||
|
||||
.address-item>>>.uni-switch-wrapper .uni-switch-input:after {
|
||||
height: 44rpx !important;
|
||||
width: 44rpx !important;
|
||||
}
|
||||
|
||||
.address-item>>>.uni-switch-wrapper .uni-switch-input:before {
|
||||
background-color: #EDEDED !important;
|
||||
height: 44rpx !important;
|
||||
width: 90rpx !important;
|
||||
}
|
||||
</style>
|
||||
496
pages_tool/member/address/address_edit.vue
Normal file
496
pages_tool/member/address/address_edit.vue
Normal file
@@ -0,0 +1,496 @@
|
||||
<template>
|
||||
<view class="address-edit-content" :style="themeColor">
|
||||
<view class="edit-wrap">
|
||||
<view class="tip">地址信息</view>
|
||||
<view class="edit-item">
|
||||
<text class="tit">
|
||||
{{ $lang('consignee') }}
|
||||
<text>*</text>
|
||||
</text>
|
||||
<input class="uni-input" type="text" placeholder-class="placeholder-class"
|
||||
:placeholder="$lang('consigneePlaceholder')" maxlength="30" name="name" v-model="formData.name" />
|
||||
</view>
|
||||
<view class="edit-item">
|
||||
<text class="tit">
|
||||
{{ $lang('mobile') }}
|
||||
<text>*</text>
|
||||
</text>
|
||||
<input class="uni-input" type="number" placeholder-class="placeholder-class"
|
||||
:placeholder="$lang('mobilePlaceholder')" maxlength="11" v-model="formData.mobile" />
|
||||
</view>
|
||||
<view class="edit-item">
|
||||
<text class="tit">{{ $lang('telephone') }}</text>
|
||||
<input class="uni-input" type="text" placeholder-class="placeholder-class"
|
||||
:placeholder="$lang('telephonePlaceholder')" maxlength="20" v-model="formData.telephone" />
|
||||
</view>
|
||||
<!-- 外卖地址区分 -->
|
||||
<block v-if="localType == 2">
|
||||
<view class="edit-item">
|
||||
<text class="tit">
|
||||
{{ $lang('receivingCity') }}
|
||||
<text>*</text>
|
||||
</text>
|
||||
<view class="text_inp"
|
||||
:class="{ empty: !formData.full_address, 'color-tip': !formData.full_address }"
|
||||
@click="selectAddress">
|
||||
{{ formData.full_address ? formData.full_address : '请选择省市区县' }}
|
||||
</view>
|
||||
|
||||
<text @click="selectAddress" class="padding-left iconfont icon-location"></text>
|
||||
</view>
|
||||
</block>
|
||||
<block v-else>
|
||||
<view class="edit-item">
|
||||
<text class="tit">
|
||||
{{ $lang('receivingCity') }}
|
||||
<text>*</text>
|
||||
</text>
|
||||
<pick-regions :default-regions="defaultRegions" @getRegions="handleGetRegions">
|
||||
<text class="select-address "
|
||||
:class="{ empty: !formData.full_address, 'color-tip': !formData.full_address }">
|
||||
{{ formData.full_address ? formData.full_address : '请选择省市区县' }}
|
||||
</text>
|
||||
</pick-regions>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<view class="edit-item">
|
||||
<text class="tit" style="">
|
||||
{{ $lang('address') }}
|
||||
<text>*</text>
|
||||
</text>
|
||||
<input class="uni-input" type="text" placeholder-class="placeholder-class"
|
||||
:placeholder="$lang('addressPlaceholder')" maxlength="50" v-model="formData.address" />
|
||||
<!-- <textarea class="uni-input " type="text" placeholder-class="placeholder-class" :placeholder="$lang('addressPlaceholder')" maxlength="50" v-model="formData.address" ></textarea> -->
|
||||
</view>
|
||||
</view>
|
||||
<view class="btn">
|
||||
<button type="primary" class="add" @click="saveAddress">{{ $lang('save') }}</button>
|
||||
</view>
|
||||
|
||||
<loading-cover ref="loadingCover"></loading-cover>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import validate from 'common/js/validate.js';
|
||||
import Config from '@/common/js/config.js';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
pickRegions: () => import('@/components/pick-regions/pick-regions.vue'),
|
||||
loadingCover: () => import('@/components/loading-cover/loading-cover.vue'),
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
formData: {
|
||||
id: 0,
|
||||
name: '',
|
||||
mobile: '',
|
||||
telephone: '',
|
||||
province_id: '',
|
||||
city_id: '',
|
||||
district_id: '',
|
||||
community_id: '',
|
||||
address: '',
|
||||
full_address: '',
|
||||
latitude: 0,
|
||||
longitude: 0,
|
||||
is_default: 1
|
||||
},
|
||||
address: '',
|
||||
addressValue: '',
|
||||
back: '', // 返回页
|
||||
redirect: 'redirectTo', // 跳转方式
|
||||
flag: false, //防重复标识
|
||||
defaultRegions: [],
|
||||
localType: 1
|
||||
};
|
||||
},
|
||||
onLoad(option) {
|
||||
if (option.back) this.back = option.back;
|
||||
if (option.redirect) this.redirect = option.redirect;
|
||||
if (option.type) this.localType = option.type;
|
||||
if (option.id && !option.name) {
|
||||
this.formData.id = option.id;
|
||||
this.getAddressDetail();
|
||||
} else if (option.name) {
|
||||
if (uni.getStorageSync('addressInfo')) this.formData = uni.getStorageSync('addressInfo');
|
||||
this.formData.address = option.name;
|
||||
this.localType = 2;
|
||||
this.getAddress(option.latng);
|
||||
//给formData复制
|
||||
var tempArr = this.getQueryVariable('latng').split(',');
|
||||
this.formData.latitude = tempArr[0];
|
||||
this.formData.longitude = tempArr[1];
|
||||
} else {
|
||||
if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
|
||||
}
|
||||
},
|
||||
onBackPress() {
|
||||
uni.setStorageSync('addressInfo', '');
|
||||
},
|
||||
onShow() {
|
||||
if (this.formData.id) {
|
||||
uni.setNavigationBarTitle({
|
||||
title: '编辑收货地址'
|
||||
});
|
||||
} else {
|
||||
uni.setNavigationBarTitle({
|
||||
title: '新增收货地址'
|
||||
});
|
||||
}
|
||||
},
|
||||
onReady() {
|
||||
this.$refs.loadingCover.hide();
|
||||
},
|
||||
onHide() {
|
||||
this.flag = false;
|
||||
},
|
||||
methods: {
|
||||
// 获取地址信息
|
||||
getAddressDetail() {
|
||||
this.$api.sendRequest({
|
||||
url: '/api/memberaddress/info',
|
||||
data: {
|
||||
id: this.formData.id
|
||||
},
|
||||
success: res => {
|
||||
let data = res.data;
|
||||
if (data != null) {
|
||||
this.formData.name = data.name;
|
||||
this.formData.mobile = data.mobile;
|
||||
this.formData.telephone = data.telephone;
|
||||
this.formData.address = data.address;
|
||||
this.formData.full_address = data.full_address;
|
||||
this.formData.latitude = data.latitude;
|
||||
this.formData.longitude = data.longitude;
|
||||
this.formData.is_default = data.is_default;
|
||||
this.localType = data.type;
|
||||
this.defaultRegions = [data.province_id, data.city_id, data.district_id];
|
||||
}
|
||||
if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
|
||||
},
|
||||
fail: res => {
|
||||
if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
|
||||
}
|
||||
});
|
||||
},
|
||||
//获取详细地址
|
||||
getAddress(value) {
|
||||
this.$api.sendRequest({
|
||||
url: '/api/memberaddress/tranAddressInfo',
|
||||
data: {
|
||||
latlng: value
|
||||
},
|
||||
success: res => {
|
||||
if (res.code == 0) {
|
||||
this.formData.full_address = '';
|
||||
this.formData.full_address += res.data.province != undefined ? res.data.province : '';
|
||||
this.formData.full_address += res.data.city != undefined ? '-' + res.data.city : '';
|
||||
this.formData.full_address += res.data.district != undefined ? '-' + res.data.district : '';
|
||||
this.addressValue = '';
|
||||
this.addressValue += res.data.province_id != undefined ? res.data.province_id : '';
|
||||
this.addressValue += res.data.city_id != undefined ? '-' + res.data.city_id : '';
|
||||
this.addressValue += res.data.district_id != undefined ? '-' + res.data.district_id : '';
|
||||
} else {
|
||||
this.showToast({
|
||||
title: '数据有误'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
// 获取选择的地区
|
||||
handleGetRegions(regions) {
|
||||
this.formData.full_address = '';
|
||||
this.formData.full_address += regions[0] != undefined ? regions[0].label : '';
|
||||
this.formData.full_address += regions[1] != undefined ? '-' + regions[1].label : '';
|
||||
this.formData.full_address += regions[2] != undefined ? '-' + regions[2].label : '';
|
||||
this.addressValue = '';
|
||||
this.addressValue += regions[0] != undefined ? regions[0].value : '';
|
||||
this.addressValue += regions[1] != undefined ? '-' + regions[1].value : '';
|
||||
this.addressValue += regions[2] != undefined ? '-' + regions[2].value : '';
|
||||
},
|
||||
|
||||
selectAddress() {
|
||||
// #ifdef MP
|
||||
/* uni.chooseLocation({
|
||||
success: res => {
|
||||
this.formData.latitude = res.latitude;
|
||||
this.formData.longitude = res.longitude;
|
||||
this.formData.address = res.name;
|
||||
this.getAddress(res.latitude + ',' + res.longitude);
|
||||
},
|
||||
fail(res) {
|
||||
uni.getSetting({
|
||||
success: function(res) {
|
||||
var statu = res.authSetting;
|
||||
if (!statu['scope.userLocation']) {
|
||||
uni.showModal({
|
||||
title: '是否授权当前位置',
|
||||
content: '需要获取您的地理位置,请确认授权,否则地图功能将无法使用',
|
||||
success(tip) {
|
||||
if (tip.confirm) {
|
||||
uni.openSetting({
|
||||
success: function (data) {
|
||||
if (data.authSetting['scope.userLocation'] === true) {
|
||||
this.$util.showToast({
|
||||
title: '授权成功'
|
||||
});
|
||||
//授权成功之后,再调用chooseLocation选择地方
|
||||
setTimeout(function () {
|
||||
uni.chooseLocation({
|
||||
success: data => {
|
||||
this.formData.latitude = res.latitude;
|
||||
this.formData.longitude = res.longitude;
|
||||
this.formData.address = res.name;
|
||||
this.getAddress(res.latitude + ',' + res.longitude);
|
||||
}
|
||||
});
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.$util.showToast({
|
||||
title: '授权失败'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});*/
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
var urlencode = this.formData;
|
||||
uni.setStorageSync('addressInfo', urlencode);
|
||||
let backurl = Config.h5Domain + '/pages_tool/member/address_edit?type=' + this.localType;
|
||||
if (this.formData.id) backurl += '&id=' + this.formData.id;
|
||||
if (this.back) backurl += '&back=' + this.back;
|
||||
|
||||
window.location.href = 'https://apis.map.qq.com/tools/locpicker?search=1&type=0&backurl=' + encodeURIComponent(backurl) + '&key=' + Config.mpKey + '&referer=myapp';
|
||||
// #endif
|
||||
},
|
||||
|
||||
getQueryVariable(variable) {
|
||||
var query = window.location.search.substring(1);
|
||||
var vars = query.split('&');
|
||||
for (var i = 0; i < vars.length; i++) {
|
||||
var pair = vars[i].split('=');
|
||||
if (pair[0] == variable) {
|
||||
return pair[1];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
vertify() {
|
||||
this.formData.name = this.formData.name.trim();
|
||||
this.formData.mobile = this.formData.mobile.trim();
|
||||
this.formData.address = this.formData.address.trim();
|
||||
var rule = [{
|
||||
name: 'name',
|
||||
checkType: 'required',
|
||||
errorMsg: '请输入姓名'
|
||||
},
|
||||
{
|
||||
name: 'mobile',
|
||||
checkType: 'required',
|
||||
errorMsg: '请输入手机号'
|
||||
},
|
||||
{
|
||||
name: 'mobile',
|
||||
checkType: 'phoneno',
|
||||
errorMsg: '请输入正确的手机号'
|
||||
},
|
||||
{
|
||||
name: 'full_address',
|
||||
checkType: 'required',
|
||||
errorMsg: '请选择省市区县'
|
||||
},
|
||||
{
|
||||
name: 'address',
|
||||
checkType: 'required',
|
||||
errorMsg: '详细地址不能为空'
|
||||
}
|
||||
];
|
||||
var checkRes = validate.check(this.formData, rule);
|
||||
if (checkRes) {
|
||||
return true;
|
||||
} else {
|
||||
this.$util.showToast({
|
||||
title: validate.error
|
||||
});
|
||||
this.flag = false;
|
||||
return false;
|
||||
}
|
||||
},
|
||||
saveAddress() {
|
||||
if (this.flag) return;
|
||||
this.flag = true;
|
||||
if (this.vertify()) {
|
||||
let addressValueArr = this.addressValue.split('-'),
|
||||
data = {},
|
||||
url = '';
|
||||
|
||||
data = {
|
||||
name: this.formData.name,
|
||||
mobile: this.formData.mobile,
|
||||
telephone: this.formData.telephone,
|
||||
province_id: addressValueArr[0],
|
||||
city_id: addressValueArr[1],
|
||||
district_id: addressValueArr[2] ? addressValueArr[2] : '',
|
||||
community_id: 0,
|
||||
address: this.formData.address,
|
||||
full_address: this.formData.full_address,
|
||||
latitude: this.formData.latitude,
|
||||
longitude: this.formData.longitude,
|
||||
is_default: this.formData.is_default,
|
||||
type: this.localType
|
||||
};
|
||||
|
||||
url = 'add';
|
||||
if (this.formData.id) {
|
||||
url = 'edit';
|
||||
data.id = this.formData.id;
|
||||
if (this.back != '') data.is_default = 1;
|
||||
}
|
||||
this.$api.sendRequest({
|
||||
url: '/api/memberaddress/' + url,
|
||||
data: data,
|
||||
success: res => {
|
||||
this.flag = false;
|
||||
|
||||
if (res.code == 0) {
|
||||
if (this.back != '') {
|
||||
this.$util.redirectTo(this.back, {}, 'redirectTo');
|
||||
} else {
|
||||
this.$util.showToast({
|
||||
title: res.message
|
||||
});
|
||||
uni.navigateBack({
|
||||
delta: 1
|
||||
});
|
||||
}
|
||||
uni.removeStorageSync('addressInfo');
|
||||
} else {
|
||||
this.$util.showToast({
|
||||
title: res.message
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: res => {
|
||||
this.flag = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
/deep/ pick-regions,
|
||||
.pick-regions {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.edit-wrap {
|
||||
background: #fff;
|
||||
overflow: hidden;
|
||||
|
||||
.tip {
|
||||
padding: 20rpx 30rpx 10rpx;
|
||||
background-color: #f8f8f8;
|
||||
color: $color-tip;
|
||||
}
|
||||
}
|
||||
|
||||
.edit-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin: 0 30rpx;
|
||||
min-height: 100rpx;
|
||||
background-color: #fff;
|
||||
|
||||
.text_inp {
|
||||
margin-left: $margin-updown;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.tit {
|
||||
width: 148rpx;
|
||||
|
||||
text {
|
||||
margin-left: 10rpx;
|
||||
color: #ff4544;
|
||||
}
|
||||
|
||||
&.margin_tit {
|
||||
align-self: flex-start;
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.icon-location {
|
||||
color: #606266;
|
||||
align-self: flex-start;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.select-address {
|
||||
display: block;
|
||||
margin-left: 10rpx;
|
||||
|
||||
&.empty {
|
||||
color: #808080;
|
||||
}
|
||||
}
|
||||
|
||||
textarea,
|
||||
input {
|
||||
flex: 1;
|
||||
font-size: $font-size-base;
|
||||
margin-left: 20rpx;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
textarea {
|
||||
margin-top: 6rpx;
|
||||
height: 100rpx;
|
||||
padding-bottom: 20rpx;
|
||||
padding-top: 20rpx;
|
||||
line-height: 50rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.edit-wrap>.edit-item+.edit-item {
|
||||
border-top: 2rpx solid #ebedf0;
|
||||
}
|
||||
|
||||
.add {
|
||||
margin-top: 60rpx;
|
||||
height: 80rpx;
|
||||
line-height: 80rpx !important;
|
||||
border-radius: 80rpx;
|
||||
font-weight: 500;
|
||||
width: calc(100% - 60rpx);
|
||||
margin-left: 30rpx;
|
||||
font-size: 32rpx;
|
||||
}
|
||||
|
||||
.btn {
|
||||
position: fixed;
|
||||
width: 100%;
|
||||
bottom: 30rpx;
|
||||
height: auto;
|
||||
padding-bottom: constant(safe-area-inset-bottom);
|
||||
/*兼容 IOS<11.2*/
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
/*兼容 IOS>11.2*/
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user