Authored by hongyong.zhao

Merge branch 'UFO_1.0.0' of git.yoho.cn:mobile/yoho-miniapp-ufo into UFO_1.0.0

... ... @@ -33,16 +33,11 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// new app.WeToast;
let timestamp = options.timestamp;
let value = user.getYHStorageSync(timestamp, 'addressEditer');
let addressTitle = (value && (value.currentEditMode === 'modeEdit')) ? '编辑地址' : '添加地址';
let address = value && value._address ? value._address : '';
let originAddressList = address ? address.split(" ") : [];
console.log('====================================');
console.log(value);
console.log('====================================');
this.setData({
editeAddressPage: value,
... ... @@ -173,6 +168,16 @@ Page({
return;
}
var reg = /^1\d{10}$/;//校验11位数字
if (!reg.test(this.data.editeAddressPage._mobile)) {
wx.showToast({
title: '请输入正确的手机号',
icon: 'none',
duration: 1500
})
return;
}
if (this.data.editeAddressPage.currentEditMode == modeAdd) {
let params = {
consignee: this.data.editeAddressPage._consignee,
... ... @@ -196,12 +201,11 @@ Page({
})
})
.catch(error => {
console.log(error);
// this.wetoast.toast({
// title: json.message,
// titleClassName: 'wetoast-title',
// duration: 1500
// });
wx.showToast({
title: json.message,
icon: 'none',
duration: 1500,
})
})
}
else if (this.data.editeAddressPage.currentEditMode == modeEdit) {
... ... @@ -227,12 +231,11 @@ Page({
})
})
.catch(error => {
console.log(error);
// this.wetoast.toast({
// title: json.message,
// titleClassName: 'wetoast-title',
// duration: 1500
// });
wx.showToast({
title: json.message,
icon: 'none',
duration: 1500,
})
})
}
},
... ...
... ... @@ -45,8 +45,6 @@ Page({
},
onLoad:function(options){
// 生命周期函数--监听页面加载
// new app.WeToast;
this.data.currentMode = modeEdit;
if (options.currentMode == modeEdit || options.currentMode == modeSelect || options.currentMode == modeChange){
this.data.currentMode = options.currentMode
... ... @@ -96,8 +94,6 @@ Page({
if (addType == 'normal') {
this.addButtonTapped();
} else if (addType == 'wechat') {
this.addFromWechatButtonTapped();
}
},
onReady:function(){
... ... @@ -121,14 +117,14 @@ Page({
},
onPullDownRefresh: function() {
// 页面相关事件处理函数--监听用户下拉动作
let params = {
PAGE_NAME: this.data.current_page_name,
PAGE_PARAM: this.data.current_page_param,
FROM_PAGE_NAME: this.data.from_page_name,
FROM_PAGE_PARAM: this.data.from_page_param,
PV_ID: PV_ID,
};
logEvent(YB_PAGE_OPEN_L, params);
// let params = {
// PAGE_NAME: this.data.current_page_name,
// PAGE_PARAM: this.data.current_page_param,
// FROM_PAGE_NAME: this.data.from_page_name,
// FROM_PAGE_PARAM: this.data.from_page_param,
// PV_ID: PV_ID,
// };
// logEvent(YB_PAGE_OPEN_L, params);
},
onReachBottom: function() {
// 页面上拉触底事件的处理函数
... ... @@ -148,8 +144,10 @@ Page({
}
else if (this.data.currentMode == modeChange) {
var _self = this;
var that = this;
var addressID = this.data.items[index].address_id;
let api = new AddressService().yohoApi();
wx.showModal({
title: '提示',
content: '关联订单的收货地址将一起修改且不可修改第二次,请确认是否修改',
... ... @@ -158,15 +156,15 @@ Page({
confirmColor: '#000000',
success: function(res) {
if (res.confirm) {
let param = {
method: "app.SpaceOrders.updateDeliveryAddress",
order_code: _self.data.order_code,
uid: app.getUid(),
address_id: addressID
let params = {
order_code: that.data.order_code,
address_id: addressID,
uid: "500031152",
debug: 'XYZ'
}
GET(API_HOST, param)
.then((json) => {
if (json && json.code && json.code == 200) {
api.delAddressRequest(params)
.then(data => {
if (data) {
wx.navigateBack({
delta: 1
})
... ... @@ -185,31 +183,6 @@ Page({
}
},
setDefaultButtonTapped: function(e) {
let id = e.currentTarget.dataset.id;
let param = {
method: "app.address.setdefault",
uid: app.getUid(),
id: id
};
let that = this;
POST(API_HOST, param).then((json) => {
let newItems = that.data.items;
newItems.map((item, index) => {
if (id == item.address_id) {
item.is_default = 'Y';
} else {
item.is_default = 'N';
}
});
that.setData({
items: newItems
});
}).catch((e) => {
})
},
editButtonTapped: function(e) {
// console.log(e)
let id = e.currentTarget.dataset.id;
... ... @@ -242,47 +215,16 @@ Page({
})
},
deleteButtonTapped: function(e) {
let id = e.currentTarget.dataset.id;
let index = e.currentTarget.dataset.index;
let that = this;
wx.showModal({
title: '提示',
content: '确认删除收货地址?',
cancelText: '取消',
confirmText: '确认',
confirmColor: '#000000',
success: function (res) {
if (res.confirm) {
let param = {
method: "app.address.del",
uid: app.getUid(),
id: id
};
POST(API_HOST, param).then((json) => {
that.getAddressList();
if (that.data.currentSelectedIndex == index) {
let prePage = getCurrentPages();
if (prePage.length > 1 && prePage[prePage.length - 2].selectComplete != undefined) {
prePage[prePage.length - 2].selectComplete(null);
}
that.setData({
currentSelectedIndex: -1,
})
}
}).catch((e) => {
})
}
else {
}
}
})
},
addButtonTapped: function() {
if (this.data.items.length >= 5) {
wx.showToast({
title: '地址不能超过5个',
icon: 'none',
duration: 1500,
})
return;
}
// if (app.globalData.userInfo.uid == 0 || app.globalData.userInfo.uid == undefined){
// //未登录状态
// wx.showModal({
... ... @@ -333,84 +275,6 @@ Page({
})
},
addFromWechatButtonTapped: function() {
if (wx.getSetting) {
let that = this;
wx.getSetting({
success(res) {
if (!res.authSetting['scope.address']) {
wx.authorize({
scope: 'scope.address',
success() {
that.chooseAddress();
},
fail(error) {
if (res.authSetting['scope.address'] == false) {
wx.showModal({
title: '',
content: '需要打开小程序的设置,重新授权获取您的收货地址',
confirmText: "去开启",
confirmColor: "#000000",
success: function (res) {
if (res.confirm) {
wx.openSetting({
success: function (res) {
}
});
}
}
});
}
},
})
} else {
that.chooseAddress();
}
}
})
} else {
wx.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
},
chooseAddress: function() {
let that = this;
wx.chooseAddress({
success: function (res) {
let param = {
method: "app.address.sync",
uid: app.getUid(),
userName: res.userName,
postalCode: res.postalCode,
provinceName: res.provinceName,
cityName: res.cityName,
countyName: res.countyName,
detailInfo: res.detailInfo,
nationalCode: res.nationalCode,
telNumber: res.telNumber,
};
GET(API_HOST, param).then((json) => {
// console.log(json)
if (json.code == 200) {
that.getAddressList();
} else {
// that.wetoast.toast({
// title: json.message,
// titleClassName: 'wetoast-title',
// duration: 1500
// });
}
}).catch((e) => {
})
}
})
},
/**
* 获取地址列表
*/
... ...
... ... @@ -5,6 +5,7 @@ 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";
const APP_ADDRESS_UPDATEDELIVERYADDRESS = "app.SpaceOrders.updateDeliveryAddress";
export default class AddressService extends BaseService {
async fetchAddressList(params, complete) {
... ... @@ -91,4 +92,22 @@ export default class AddressService extends BaseService {
throw error;
})
}
//待付款订单修改地址
async apaceOrdersUpdateDeliveryAddress(params, complete) {
return await this.GET(
{
...params,
method: APP_ADDRESS_UPDATEDELIVERYADDRESS
},
{
complete
}
).then((data) => {
return data;
}).catch((error) => {
// 这里请抛出异常,不要return
throw error;
})
}
}
\ No newline at end of file
... ...