Authored by 肖亚东

1、区域选择控件添加以及修改使用 2、地址的添加、删除、编辑更新等接口联调以及流程处理 — review by 李其昌

// import { getYHStorageSync } from '../../../utils/util';
// import objectAssign from '../../../vendors/object-assign';
// import { API_HOST, SERVICE_HOST } from '../../../libs/config';
// import { GET, POST } from '../../../libs/request';
// import Promise from '../../../vendors/es6-promise';
import AddressService from '../addressService.js'
import user from '../../../../utils/user';
... ... @@ -69,23 +64,24 @@ Page({
},
editPageOnLoad: function (level,id) {
let param = {
method: APP_ADDRESS_PROVINCES,
uid: app.getUid(),
let params = {
fromPage: 'addressEditer',
id: id
id: id,
uid: '500031152',
debug: 'XYZ'
};
let that = this;
let api = new AddressService().yohoApi();
return new Promise(function (resolve, reject) {
GET(API_HOST, param)
api.fetchAddressProvinces(params)
.then(json => {
if (json && json.code && json.code == 200) {
let value = json.data;
if (json) {
let value = json;
let newEditeAddressPage = that.data.editeAddressPage;
let key = 'address_' + level;
newEditeAddressPage[key] = value;
//比对_area_code 解决 “其他” 被选中后,后台自动过滤掉address文字的返回但是_area_code没过滤的情况,导致我们显示上就没有选中 “其他”
if (level == 3) {
let list = value;
... ... @@ -97,16 +93,16 @@ Page({
}
}
}
that.setData({
editeAddressPage: newEditeAddressPage,
});
resolve(json);
}
resolve(json);
})
.catch(error => {
reject(error);
});
})
});
},
... ... @@ -126,26 +122,15 @@ Page({
},
defaultButtonTapped: function(e) {
let id = e.currentTarget.dataset.id;
let params = {
id: id,
uid: '500031152',
debug: 'XYZ'
};
let that = this;
let api = new AddressService().yohoApi();
api.fetchAddressDefault(params)
.then(data => {
let editeAddressPage = that.data.editeAddressPage;
editeAddressPage._is_default = 'Y';
that.setData({
editeAddressPage
});
})
.catch(error => {
console.log(error);
})
let editeAddressPage = this.data.editeAddressPage;
if (editeAddressPage._is_default == 'Y') {
editeAddressPage._is_default = 'N';
} else {
editeAddressPage._is_default = 'Y';
}
this.setData({
editeAddressPage
});
},
onDeleteButtonTapped: function () {
... ... @@ -158,30 +143,28 @@ Page({
confirmColor: '#000000',
success: function (res) {
if (res.confirm) {
let param = {
method: "app.address.del",
uid: app.getUid(),
id: that.data.editeAddressPage._id
let params = {
id: that.data.editeAddressPage._id,
uid: "500031152",
debug: 'XYZ'
};
POST(API_HOST, param).then((json) => {
let api = new AddressService().yohoApi();
api.delAddressRequest(params)
.then(data => {
let prePage = getCurrentPages();
if (prePage.length > 1 && prePage[prePage.length - 2].getAddressList != undefined) {
prePage[prePage.length - 2].getAddressList();
}
wx.navigateBack({
delta: 1
})
}).catch((e) => {
// console.log(e);
if (prePage.length > 1 && prePage[prePage.length - 2].getAddressList != undefined) {
prePage[prePage.length - 2].getAddressList();
}
wx.navigateBack({
delta: 1
})
})
.catch(error => {
})
}
else {
}
}
})
},
/**
* 保存按钮点击事件
... ... @@ -190,18 +173,19 @@ Page({
this.hiddenPicker();
if (this.data.editeAddressPage.currentEditMode == modeAdd) {
let param = {
method: "app.address.add",
let params = {
consignee: this.data.editeAddressPage._consignee,
mobile: this.data.editeAddressPage._mobile,
area_code: this.data.editeAddressPage._area_code,
address: this.data.editeAddressPage._detailAddress,
uid: app.getUid()
is_default:this.data.editeAddressPage._is_default,
uid: "500031152",
debug: 'XYZ'
};
POST(API_HOST, param).then((json) => {
if (json.code == 200) {
let api = new AddressService().yohoApi();
api.addAddressRequest(params)
.then(data => {
let prePage = getCurrentPages();
if (prePage.length > 1 && prePage[prePage.length - 2].getAddressList != undefined) {
prePage[prePage.length - 2].getAddressList();
... ... @@ -209,31 +193,30 @@ Page({
wx.navigateBack({
delta: 1
})
} else {
})
.catch(error => {
console.log(error);
// this.wetoast.toast({
// title: json.message,
// titleClassName: 'wetoast-title',
// duration: 1500
// });
}
}).catch((e) => {
// console.log(e);
})
})
}
else if (this.data.editeAddressPage.currentEditMode == modeEdit) {
let param = {
method: "app.address.update",
let params = {
consignee: this.data.editeAddressPage._consignee,
mobile: this.data.editeAddressPage._mobile,
area_code: this.data.editeAddressPage._area_code,
address: this.data.editeAddressPage._detailAddress,
uid: app.getUid(),
id: this.data.editeAddressPage._id
is_default:this.data.editeAddressPage._is_default,
id: this.data.editeAddressPage._id,
uid: "500031152",
debug: 'XYZ'
};
POST(API_HOST, param).then((json) => {
if (json.code == 200) {
let api = new AddressService().yohoApi();
api.updateAddressRequest(params)
.then(data => {
let prePage = getCurrentPages();
if (prePage.length > 1 && prePage[prePage.length - 2].getAddressList != undefined) {
prePage[prePage.length - 2].getAddressList();
... ... @@ -241,18 +224,16 @@ Page({
wx.navigateBack({
delta: 1
})
} else {
})
.catch(error => {
console.log(error);
// this.wetoast.toast({
// title: json.message,
// titleClassName: 'wetoast-title',
// duration: 1500
// });
}
}).catch((e) => {
// console.log(e);
})
})
}
},
/**
* 页面选址触发事件
... ... @@ -303,6 +284,9 @@ Page({
let newEditeAddressPage3 = that.data.editeAddressPage;
newEditeAddressPage3.isShow = true;
newEditeAddressPage0.currentLevel = 3;
console.log('====================================');
console.log(newEditeAddressPage3);
console.log('====================================');
that.setData({
editeAddressPage: newEditeAddressPage3,
});
... ... @@ -384,7 +368,7 @@ Page({
},
hiddenPicker: function () {
let newEditeAddressPage = objectAssign(this.data.editeAddressPage, {
let newEditeAddressPage = Object.assign(this.data.editeAddressPage, {
isShow: false, // 显示区域选择框
});
this.setData({
... ...
... ... @@ -16,8 +16,8 @@
</view>
<view class="cell-container cell-bottom-border" >
<text class="cell-title">所在区域</text>
<input class="cell-input" disabled="disabled" placeholder-class='cell-placeholder' placeholder="请选择" value="{{editeAddressPage._address}}"/>
<view class="cell-float-over" catchtap="choosearea"></view>
<button wx:if="{{editeAddressPage._address}}" class="cell-input cell-placeholder select-area black" catchtap="choosearea">{{editeAddressPage._address}}</button>
<button wx:else class="cell-input cell-placeholder select-area" catchtap="choosearea">请选择</button>
</view>
<view class="cell-container cell-bottom-border">
<text class="cell-title">详细地址</text>
... ...
... ... @@ -54,10 +54,26 @@
color: #CCCCCC;
}
.addressEditerContainer .cell-float-over {
.addressEditerContainer .page-container .cell-container .select-area {
text-align: left;
padding-left: 0;
border-radius: 0;
background-color: white;
}
button::after {
border-radius: 0;
border-style: none;
}
.addressEditerContainer .page-container .cell-container .black {
color: black;
}
.addressEditerContainer .page-container .cell-container .cell-float-over {
position: relative;
background:transparent;
z-index:900;
height: 60rpx;
}
.addressEditerContainer .operation {
... ... @@ -113,17 +129,4 @@
position: fixed;
left: 0;
bottom: 0;
}
.addressEditerContainer .addr-item {
line-height: 100rpx;
text-align: center;
}
.addressEditerContainer .show {
text-align: center;
margin: 40rpx;
height: 100rpx;
}
.addressEditerContainer .choose {
margin: 40rpx 0;
}
}
\ No newline at end of file
... ...
<view class="container">
<view class="my-address-page">
<view class="page-wrap clearfix">
<block wx:if="{{showContainer}}">
<view wx:if="{{showContainer}}" class="address-container">
<radio-group class="radio-group" bindchange="">
<label class="radio" wx:for="{{items}}" wx:key="{{address_id}}" wx:for-index="index">
<view class="address-item" bindtap="selectAddress" data-index='{{index}}'>
<image wx:if="{{currentMode != modeEdit && currentSelectedIndex == index}}" src='../../../assets/images/current-select@3x.png' class='current-select-image'></image>
<view class='name-container'>
<view class="name">{{item.consignee}}</view>
<view class="tel">{{item.mobile}}</view>
<view class="default" wx:if="{{item.is_default=='Y'}}">默认</view>
<view catchtap="editButtonTapped" class="edit" data-id="{{item.address_id}}" data-consignee="{{item.consignee}}" data-mobile="{{item.mobile}}" data-area_code="{{item.area_code}}" data-address="{{item.area}}" data-detail_address="{{item.address}}" data-is_default="{{item.is_default}}">编辑</view>
</view>
<view class="address-info">{{item.area + ' ' + item.address}}</view>
<view class='separator'></view>
<!-- <view class="action">
<view class='left' catchtap="setDefaultButtonTapped" data-id="{{item.address_id}}">
<image src='{{item.is_default=="Y"?"../../../assets/images/default-select@3x.png":"../../../assets/images/default-normal@3x.png"}}' class='select-image'></image>
<text class='opt-text'>设为默认</text>
</view>
<view class='right'>
<view catchtap="editButtonTapped" class="edit" data-id="{{item.address_id}}" data-consignee="{{item.consignee}}" data-mobile="{{item.mobile}}" data-area_code="{{item.area_code}}" data-address="{{item.area}}" data-detail_address="{{item.address}}">
<image src='../../../assets/images/edit@3x.png' class='select-image'></image>
<text class='opt-text'>编辑</text>
</view>
<view catchtap="deleteButtonTapped" class="delete" data-id="{{item.address_id}}" data-index="{{index}}">
<image src='../../../assets/images/delete@3x.png' class='select-image'></image>
<text class='opt-text'>删除</text>
</view>
</view>
</view> -->
</view>
</label>
</radio-group>
</view>
</block>
<block wx:else>
<view class='emptyClass' style='width:100%;height:100%;margin-top:200rpx'>
<image src="../../../assets/images/noad@3x.png" style="width:143rpx;height:190rpx;margin-top:80rpx"></image>
<view style="font-size:30rpx;text-align:center;margin-top:30rpx;color:#444444;">尚无地址,点击底部新增</view>
</view>
</block>
</view>
</view>
</view>
<view catchtap="addButtonTapped" class='add-addressButton'>添加地址</view>
<scroll-view scroll-y='true' class="my-address-page">
<block wx:if="{{showContainer}}">
<view wx:if="{{showContainer}}" class="address-container">
<radio-group class="radio-group" bindchange="">
<label class="radio" wx:for="{{items}}" wx:key="{{address_id}}" wx:for-index="index">
<view class="address-item" bindtap="selectAddress" data-index='{{index}}'>
<image wx:if="{{currentMode != modeEdit && currentSelectedIndex == index}}" src='../../../assets/images/current-select@3x.png' class='current-select-image'></image>
<view class='name-container'>
<view class="name">{{item.consignee}}</view>
<view class="tel">{{item.mobile}}</view>
<view class="default" wx:if="{{item.is_default=='Y'}}">默认</view>
<view catchtap="editButtonTapped" class="edit" data-id="{{item.address_id}}" data-consignee="{{item.consignee}}" data-mobile="{{item.mobile}}" data-area_code="{{item.area_code}}" data-address="{{item.area}}" data-detail_address="{{item.address}}" data-is_default="{{item.is_default}}">编辑</view>
</view>
<view class="address-info">{{item.area + ' ' + item.address}}</view>
<view class='separator'></view>
</view>
</label>
</radio-group>
</view>
</block>
<block wx:else>
<view class='emptyClass' style='width:100%;height:100%;margin-top:200rpx'>
<image src="../../../assets/images/noad@3x.png" style="width:143rpx;height:190rpx;margin-top:80rpx"></image>
<view style="font-size:30rpx;text-align:center;margin-top:30rpx;color:#444444;">尚无地址,点击底部新增</view>
</view>
</block>
</scroll-view>
<view catchtap="addButtonTapped" class='add-addressButton'>添加地址</view>
<!-- <import src="../../vendors/toast/wetoast.wxml"/>
<template is="wetoast" data="{{...__wetoast__}}"/> -->
... ...
page {
display: block;
min-height: 100%;
background-color: #fff;
}
.my-address-page {
width: 100%;
background: #fff;
/* background: lightblue; */
overflow: hidden;
/* margin-bottom: 170rpx; */
height: 1000rpx;
}
.add-addressButton {
position: absolute;
margin-left: 40rpx;
margin-right: 40rpx;
bottom: 40rpx;
height: 100rpx;
width: 670rpx;
display: flex;
justify-content: center;
align-items: center;
color: white;
background-color: #002B47;
font-size: 32rpx;
font-family: PingFang-SC-Regular;
}
.empty-style {
text-align: center;
margin-left: auto;
margin-right:auto;
color: #444;
margin-top:50%;
font-size: 34rpx;
}
.emptyClass{
display: flex;
flex-direction: column;
align-items: center
}
.address-container {
margin-bottom: 120rpx;
}
... ... @@ -144,35 +170,3 @@ page {
.my-address-page .address-item .action .delete{
margin-left: 64rpx;
}
.add-addressButton {
position: absolute;
margin-left: 40rpx;
margin-right: 40rpx;
bottom: 40rpx;
height: 100rpx;
width: 670rpx;
display: flex;
justify-content: center;
align-items: center;
color: white;
background-color: #002B47;
font-size: 32rpx;
font-family: PingFang-SC-Regular;
}
.empty-style {
text-align: center;
margin-left: auto;
margin-right:auto;
color: #444;
margin-top:50%;
font-size: 34rpx;
}
.emptyClass{
display: flex;
flex-direction: column;
align-items: center
}
\ No newline at end of file
... ...
import BaseService from '../../../libs/services/baseService.js';
const UFO_ADDRESS_LIST = 'app.address.gethidden';
const UFO_ADDRESS_SET_DEFAULT = 'app.address.setdefault';
const UFO_ADDRESS_ADD = 'app.address.add';
const UFO_ADDRESS_UPDATE = 'app.address.update';
const APP_ADDRESS_DEL = "app.address.del";
const APP_ADDRESS_PROVINCES = "app.address.provinces";
export default class AddressService extends BaseService {
async fetchAddressList(params, complete) {
... ... @@ -21,11 +24,62 @@ export default class AddressService extends BaseService {
})
}
async fetchAddressDefault(params, complete) {
async updateAddressRequest(params, complete) {
return await this.GET(
{
...params,
method: UFO_ADDRESS_SET_DEFAULT
method: UFO_ADDRESS_UPDATE
},
{
complete
}
).then((data) => {
return data;
}).catch((error) => {
// 这里请抛出异常,不要return
throw error;
})
}
async addAddressRequest(params, complete) {
return await this.GET(
{
...params,
method: UFO_ADDRESS_ADD
},
{
complete
}
).then((data) => {
return data;
}).catch((error) => {
// 这里请抛出异常,不要return
throw error;
})
}
async delAddressRequest(params, complete) {
return await this.GET(
{
...params,
method: APP_ADDRESS_DEL
},
{
complete
}
).then((data) => {
return data;
}).catch((error) => {
// 这里请抛出异常,不要return
throw error;
})
}
async fetchAddressProvinces(params, complete) {
return await this.GET(
{
...params,
method: APP_ADDRESS_PROVINCES
},
{
complete
... ...