mirror of
https://gitee.com/java110/WechatOwnerService.git
synced 2026-02-23 21:36:38 +08:00
优化代码
This commit is contained in:
parent
bb3fc8854e
commit
e3a1abd921
@ -79,8 +79,30 @@ export function getUserAddress(_data){
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* add by wuxw
|
||||
* @param {Object} _data 保存 用户地址
|
||||
*/
|
||||
export function saveUpdateUserAddress(_data){
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if(_data.userId == ''){
|
||||
reject("用户不能为空");
|
||||
return ;
|
||||
}else if(_data.areaCode == ''){
|
||||
reject("地区不能为空");
|
||||
return ;
|
||||
}else if(_data.tel == ''){
|
||||
reject("手机号不能为空");
|
||||
return ;
|
||||
}else if(_data.address == ''){
|
||||
reject("地址不能为空");
|
||||
return ;
|
||||
}else if(_data.isDefault == ''){
|
||||
reject("默认地址不能为空");
|
||||
return ;
|
||||
}
|
||||
let moreRooms = [];
|
||||
request({
|
||||
url: url.saveUserAddress,
|
||||
@ -100,3 +122,37 @@ export function saveUpdateUserAddress(_data){
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* add by wuxw
|
||||
* @param {Object} _data 保存 用户地址
|
||||
*/
|
||||
export function deleteUserAddress(_data){
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if(_data.userId == ''){
|
||||
reject("用户不能为空");
|
||||
return ;
|
||||
}else if(_data.addressId == ''){
|
||||
reject("地址不能为空");
|
||||
return ;
|
||||
}
|
||||
request({
|
||||
url: url.deleteUserAddress,
|
||||
method: "POST",
|
||||
data: _data, //动态数据
|
||||
success: function(res) {
|
||||
let _data = res.data;
|
||||
if (_data.code == 0) {
|
||||
resolve(_data);
|
||||
return ;
|
||||
}
|
||||
reject(_data.msg);
|
||||
},
|
||||
fail: function(e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
@ -98,6 +98,7 @@ export default {
|
||||
queryStoreCart: baseUrl +'app/storeOrder/queryStoreCart',
|
||||
queryUserAddress: baseUrl + 'app/userAddress/queryUserAddress',
|
||||
saveUserAddress: baseUrl + 'app/userAddress/saveUserAddress',
|
||||
deleteUserAddress: baseUrl+'app/userAddress/deleteUserAddress',
|
||||
|
||||
NEED_NOT_LOGIN_PAGE: [
|
||||
'/pages/login/login',
|
||||
|
||||
@ -20,10 +20,10 @@
|
||||
</view>
|
||||
<view class="default-box flex justify-between align-center">
|
||||
<text class="title">设为默认地址</text>
|
||||
<switch class="olive switch" @tap="onSwitch" :class="{ checked: isDefault }" :checked="isDefault"></switch>
|
||||
<switch class="olive switch" @tap="onSwitch" :class="{ checked: isDefault=='T' }" :checked="isDefault=='T'"></switch>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="addressId != 0" class="foot_box x-bc">
|
||||
<view v-if="addressId != 0" class="foot_box flex justify-between">
|
||||
<button class="cu-btn delete-btn" @tap="deleteAddress">删除收货地址</button>
|
||||
<button class="cu-btn save-btn" @tap="editAddress">保存收货地址</button>
|
||||
</view>
|
||||
@ -35,7 +35,7 @@
|
||||
<script>
|
||||
import pickerAddress from '../../components/pickerAddress/pickerAddress.vue';
|
||||
|
||||
import {saveUpdateUserAddress} from '../../api/owner/ownerApi.js';
|
||||
import {saveUpdateUserAddress,getCurOwner,getUserAddress,deleteUserAddress} from '../../api/owner/ownerApi.js';
|
||||
|
||||
export default {
|
||||
components: {pickerAddress},
|
||||
@ -47,19 +47,50 @@
|
||||
tel: '',
|
||||
areaCode: '',
|
||||
address: '',
|
||||
isDefault: false,
|
||||
isDefault: 'F',
|
||||
areaName:'请选择地区'
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
|
||||
},
|
||||
onLoad() {
|
||||
onLoad(options) {
|
||||
let that = this;
|
||||
getCurOwner()
|
||||
.then(_owner=>{
|
||||
that.userId = _owner.userId;
|
||||
let addressId = options.addressId;
|
||||
|
||||
if(addressId != '-1'&& !this.vc.isEmpty(addressId)){
|
||||
return that.getAddressInfo(addressId);
|
||||
}
|
||||
|
||||
return null;
|
||||
})
|
||||
.then((data)=>{
|
||||
|
||||
if(data == null){
|
||||
return ;
|
||||
}
|
||||
let _data = data.data[0]
|
||||
that.addressId = _data.addressId,
|
||||
that.username = _data.username;
|
||||
that.userId = _data.userId;
|
||||
that.areaCode= _data.areaCode;
|
||||
that.tel= _data.tel;
|
||||
that.address = _data.address;
|
||||
that.isDefault = _data.isDefault;
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
methods: {
|
||||
onSwitch() {
|
||||
this.isDefault = !this.isDefault;
|
||||
if(this.isDefault == 'T'){
|
||||
this.isDefault = 'F';
|
||||
} else{
|
||||
this.isDefault = 'T';
|
||||
}
|
||||
},
|
||||
change: function(data) {
|
||||
let _that = this;
|
||||
@ -71,36 +102,42 @@
|
||||
_that.areaCode = data.data[2].code;
|
||||
},
|
||||
// 编辑添加地址
|
||||
editAddress() {
|
||||
editAddress:function() {
|
||||
let that = this;
|
||||
|
||||
let data = {
|
||||
addressId:that.addressId == 0 ? '-1':that.addressId,
|
||||
userId:that.userId,
|
||||
areaCode:that.areaCode,
|
||||
username:that.username,
|
||||
tel:that.tel,
|
||||
address:that.address,
|
||||
isDefault:that.isDefault
|
||||
};
|
||||
saveUpdateUserAddress(data)
|
||||
.then((data) =>{
|
||||
|
||||
uni.navigateBack({
|
||||
delta:1
|
||||
})
|
||||
},(error)=>{
|
||||
uni.showToast({
|
||||
icon:'none',
|
||||
title:error
|
||||
});
|
||||
})
|
||||
|
||||
},
|
||||
// 地址信息
|
||||
getAddressInfo() {
|
||||
this.$api('address.info', {
|
||||
id: this.addressData.id
|
||||
}).then(res => {
|
||||
if (res.code === 1) {
|
||||
let data = res.data;
|
||||
let areaText = `${data.province_name}-${data.city_name}-${data.area_name}`;
|
||||
let is_default = data.is_default === '1' ? true : false;
|
||||
this.addressData = res.data;
|
||||
this.area_text = areaText;
|
||||
this.addressData.is_default = is_default;
|
||||
}
|
||||
});
|
||||
getAddressInfo(addressId) {
|
||||
let that = this;
|
||||
let param = {
|
||||
page:1,
|
||||
row:1,
|
||||
addressId:addressId,
|
||||
userId:that.userId
|
||||
}
|
||||
return getUserAddress(param);
|
||||
|
||||
},
|
||||
onConfirm(e) {
|
||||
this.addressData.area_id = e.cityCode;
|
||||
@ -112,10 +149,11 @@
|
||||
},
|
||||
// 删除收货地址
|
||||
deleteAddress() {
|
||||
this.$api('address.del', {
|
||||
id: this.addressData.id
|
||||
deleteUserAddress({
|
||||
addressId: this.addressId,
|
||||
userId:this.userId
|
||||
}).then(res => {
|
||||
if (res.code === 1) {
|
||||
if (res.code === 0) {
|
||||
uni.showToast({
|
||||
title: '删除成功',
|
||||
icon: 'none',
|
||||
|
||||
@ -4,16 +4,16 @@
|
||||
<view class="content_box">
|
||||
<view class="address-list" v-for="(address,index) in addressList" :key="index" @tap="useAddress(address)">
|
||||
<view class="top flex justify-start">
|
||||
<text class="name">{{ address.consignee }}</text>
|
||||
<text class="phone">{{ address.phone }}</text>
|
||||
<text class="tag" v-if="address.is_default === '1'">默认</text>
|
||||
<text class="name">{{ address.username }}</text>
|
||||
<text class="phone">{{ address.tel }}</text>
|
||||
<text class="tag" v-if="address.isDefault === 'T'">默认</text>
|
||||
</view>
|
||||
<view class="detail">{{ address.province_name }}{{ address.city_name }}{{ address.area_name }}{{ address.address }}</view>
|
||||
<button class="cu-btn set-btn" @tap.stop="jump('/pages/user/address/edit', { id: address.id })">编辑</button>
|
||||
<view class="detail">{{ address.address }}</view>
|
||||
<button class="cu-btn set-btn" @tap.stop="jump('/pages/addressEdit/addressEdit',address)">编辑</button>
|
||||
</view>
|
||||
</view>
|
||||
<view class="foot_box flex justify-around">
|
||||
<button class="cu-btn add-btn" @tap="jump('/pages/addressEdit/addressEdit')">添加收货地址</button>
|
||||
<button class="cu-btn add-btn" @tap="jump('/pages/addressEdit/addressEdit',{addressId:'-1'})">添加收货地址</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@ -60,9 +60,9 @@
|
||||
});
|
||||
},
|
||||
// 路由跳转
|
||||
jump(path) {
|
||||
jump(path,param) {
|
||||
this.vc.navigateTo({
|
||||
url:path
|
||||
url:path+'?addressId='+param.addressId
|
||||
})
|
||||
},
|
||||
getAddressList() {
|
||||
|
||||
@ -1,21 +1,20 @@
|
||||
<template>
|
||||
<view class="page_box">
|
||||
<view class="head_box">
|
||||
<view class="add-address-box " v-if="!addressId" @tap="jump('/pages/addressList/addressList')">
|
||||
<view class="add-address-box " v-if="!address.addressId" @tap="jump('/pages/addressList/addressList')">
|
||||
<view class="box-bg flex justify-between align-center padding">
|
||||
<text class="select-notice">请选择收货地址</text>
|
||||
<text class="cuIcon-right"></text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="address-list" v-else @tap="jump('/pages/user/address/list', { from: 'order' })">
|
||||
<image class="address-bg" src="http://shopro.7wpp.com/imgs/address_line.png" mode=""></image>
|
||||
<view class="top x-f">
|
||||
<text class="name">{{ address.consignee }}</text>
|
||||
<text class="phone">{{ address.phone }}</text>
|
||||
<text class="tag" v-if="address.is_default == 1">默认</text>
|
||||
<view class="address-list" v-else @tap="jump('/pages/addressList/addressList')">
|
||||
<view class="top flex justify-start">
|
||||
<text class="name">{{ address.username }}</text>
|
||||
<text class="phone">{{ address.tel }}</text>
|
||||
<text class="tag" v-if="address.isDefault == 'T'">默认</text>
|
||||
</view>
|
||||
<view class="detail x-bc">
|
||||
<view class="address">{{ address.province_name }}{{ address.city_name }}{{ address.area_name }}{{ address.address }}</view>
|
||||
<view class="detail flex justify-between">
|
||||
<view class="address">{{ address.address }}</view>
|
||||
<text class="cuIcon-right"></text>
|
||||
</view>
|
||||
</view>
|
||||
@ -117,7 +116,7 @@
|
||||
showPicker: false,
|
||||
isSubOrder: false,
|
||||
address: {
|
||||
is_default: 0
|
||||
isDefault: 0
|
||||
},
|
||||
addressId: 0,
|
||||
from: '',
|
||||
@ -142,16 +141,9 @@
|
||||
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
address(val, oldVal) {
|
||||
if (this.address) {
|
||||
this.addressId = this.address.id;
|
||||
this.getPre();
|
||||
}
|
||||
}
|
||||
},
|
||||
async onLoad(options) {
|
||||
let _that = this;
|
||||
this.perGoodsList = [];
|
||||
if (options.hasOwnProperty("productId")) {
|
||||
this.perGoodsList.push({
|
||||
checked:true,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user