Commit 4d84cc0b by 谢中龙

抵用券优惠之后金额为负数

parent 2029db4c
......@@ -6,1081 +6,1132 @@ const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo;
wxService.page({
/**
* 页面的初始数据
*/
data: {
couponId: null, // 当前选中优惠券 id
couponSettingId: null, // 当前选中plus优惠券 id
checkByPremium: false,
addressInfo: [],
showSelectCoupon: false,
skuIds: [],
trolleySku2Buy: Array,
currentOrderList: Array,
isSelect: false,
selectPrice: '',
noSelectPrice: '',
plusSpread: '',
goodsAddress: false,
uAddress : {
name : '',
phone : '',
address : '',
},
citys: null,
cityView: '',
multiIndex: [0, 0, 0],
selectCityName: ['', ''],
wxAddress: false,
currentCoupon: '',
orderPrice: null, // 订单金额
orderInitPrice: 0,
plusMemberPrice: 0, // plus 默认价
plusMemberName: '',
defalutCoupon: '',
useNotUserCoupon: false,
defalutCouponId: '', // 默认第一项
addressId: '', // 收货地址id
totalGoodsPrice: 0,
buyerRemark: '',//备注信息
currentType: 'delivery',//delivery 快递 selfPickUp 门店自提
storeInfo: {
storeName: '',
storeId: '',
storeAddress: '',
storeCode: ''
},
orderStoreInfo: null,
couponDiscountPreviews : [],
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.hideShareMenu();
this.getMyLocationInfo();
/**
* 页面的初始数据
*/
data: {
couponId: null, // 当前选中优惠券 id
couponSettingId: null, // 当前选中plus优惠券 id
checkByPremium: false,
addressInfo: [],
showSelectCoupon: false,
skuIds: [],
trolleySku2Buy: Array,
currentOrderList: Array,
isSelect: false,
selectPrice: '',
noSelectPrice: '',
plusSpread: '',
goodsAddress: false,
uAddress: {
name: '',
phone: '',
address: '',
},
//输入
onInput(e){
let key = e.target.dataset.name;
let value = e.detail.value;
this.data.uAddress[key] = value;
citys: null,
cityView: '',
multiIndex: [0, 0, 0],
selectCityName: ['', ''],
wxAddress: false,
currentCoupon: '',
orderPrice: null, // 订单金额
orderInitPrice: 0,
plusMemberPrice: 0, // plus 默认价
plusMemberName: '',
defalutCoupon: '',
useNotUserCoupon: false,
defalutCouponId: '', // 默认第一项
addressId: '', // 收货地址id
totalGoodsPrice: 0,
buyerRemark: '', //备注信息
currentType: 'delivery', //delivery 快递 selfPickUp 门店自提
storeInfo: {
storeName: '',
storeId: '',
storeAddress: '',
storeCode: ''
},
////获取位置信息并获取附近门店信息
getMyLocationInfo(cb) {
let _this = this;
if (!envInfo.isNeedGetLocation) {
return;
}
orderStoreInfo: null,
couponDiscountPreviews: [],
},
//获取本地缓存的地址信息
let myLocation = wx.getStorageSync('myLocation') ? wx.getStorageSync('myLocation') : null;
if (!myLocation) {
wx.getLocation({
type: 'wgs84',
success(res) {
const latitude = res.latitude
const longitude = res.longitude
let obj = {
latitude: latitude,
longitude: longitude,
}
wx.setStorageSync('myLocation', obj);
_this.getMyStoreInfoByPosition(latitude, longitude);
}
});
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
wx.hideShareMenu();
this.getMyLocationInfo();
},
//输入
onInput(e) {
let key = e.target.dataset.name;
let value = e.detail.value;
this.data.uAddress[key] = value;
},
////获取位置信息并获取附近门店信息
getMyLocationInfo(cb) {
let _this = this;
if (!envInfo.isNeedGetLocation) {
return;
}
return;
//获取本地缓存的地址信息
let myLocation = wx.getStorageSync('myLocation') ? wx.getStorageSync('myLocation') : null;
if (!myLocation) {
wx.getLocation({
type: 'wgs84',
success(res) {
const latitude = res.latitude
const longitude = res.longitude
let obj = {
latitude: latitude,
longitude: longitude,
}
wx.setStorageSync('myLocation', obj);
_this.getMyStoreInfoByPosition(latitude, longitude);
}
});
this.getMyStoreInfoByPosition(myLocation.latitude, myLocation.longitude);
},
//获取附近门店信息
getMyStoreInfoByPosition(latitude, longitude) {
wxService.post(`/sale/trade/buyer/getMemberStore?latitude=${latitude}&longitude=${longitude}`).then(res => {
if (res) {
if (res.data.result == 0) {
let obj = res.data.data ? res.data.data : null;
if (obj) {
this.data.orderStoreInfo = {
storeId: obj.storeId,
storeInfo: obj.storeInfo
}
}
}
}
});
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
let pages = getCurrentPages();
let currPage = pages[pages.length - 1];
const { trolleySku2Buy } = this.options;
let tradeDto = {
trolleySku2Buy: JSON.parse(trolleySku2Buy)
}
return;
}
// 下单 && 计算优惠价
this.setData({
trolleySku2Buy: tradeDto.trolleySku2Buy
}, () => {
this.initCitys()
// 地址列表
if (this.data.currentType == 'delivery') {
this.getAddressList()
}
else {
// 获取本地选择的门店信息
this.getLocalStoreInfo();
this.getMyStoreInfoByPosition(myLocation.latitude, myLocation.longitude);
},
//获取附近门店信息
getMyStoreInfoByPosition(latitude, longitude) {
wxService.post(`/sale/trade/buyer/getMemberStore?latitude=${latitude}&longitude=${longitude}`).then(res => {
if (res) {
if (res.data.result == 0) {
let obj = res.data.data ? res.data.data : null;
if (obj) {
this.data.orderStoreInfo = {
storeId: obj.storeId,
storeInfo: obj.storeInfo
}
});
}
}
}
});
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
let pages = getCurrentPages();
let currPage = pages[pages.length - 1];
const {
trolleySku2Buy
} = this.options;
let tradeDto = {
trolleySku2Buy: JSON.parse(trolleySku2Buy)
}
//获取备注信息
this.getLocalRemarkInfo();
},
// 下单 && 计算优惠价
this.setData({
trolleySku2Buy: tradeDto.trolleySku2Buy
}, () => {
this.initCitys()
// 地址列表
if (this.data.currentType == 'delivery') {
this.getAddressList()
} else {
// 获取本地选择的门店信息
this.getLocalStoreInfo();
}
});
//获取备注信息
getLocalRemarkInfo() {
this.data.buyerRemark = wx.getStorageSync('orderRemark');
this.setData({
buyerRemark: this.data.buyerRemark
})
},
this.getLocalRemarkInfo();
},
//输入备注
onTapInputRemark() {
wx.navigateTo({
url: '/pages/remark/remark',
});
},
//获取备注信息
getLocalRemarkInfo() {
this.data.buyerRemark = wx.getStorageSync('orderRemark');
this.setData({
buyerRemark: this.data.buyerRemark
})
},
onUnload() {
wx.removeStorageSync('orderRemark');
wx.removeStorageSync('choosedStoreInfo');
},
//获取本地选择的门店信息
getLocalStoreInfo() {
let storeInfo = wx.getStorageSync('choosedStoreInfo') ? wx.getStorageSync('choosedStoreInfo') : null;
if (storeInfo) {
this.data.storeInfo.storeId = storeInfo.id;
this.data.storeInfo.storeName = storeInfo.name;
this.data.storeInfo.storeAddress = storeInfo.storeFullAddress;
this.data.storeInfo.storeCode = storeInfo.code;
}
else {
this.data.storeInfo = {
storeName: '',
storeId: '',
storeAddress: '',
storeCode: '',
}
}
//输入备注
onTapInputRemark() {
wx.navigateTo({
url: '/pages/remark/remark',
});
},
this.setData({
storeInfo: this.data.storeInfo
});
onUnload() {
wx.removeStorageSync('orderRemark');
wx.removeStorageSync('choosedStoreInfo');
},
const { memberId } = wx.getStorageSync('_baseUserInfo');
const { trolleySku2Buy, checkByPremium } = this.data;
let params = { checkByPremium, trolleySku2Buy };
params.orderType = 4;
params.storeId = this.data.storeInfo.storeId;
this.calPreferentialPrice(params)
},
//获取本地选择的门店信息
getLocalStoreInfo() {
let storeInfo = wx.getStorageSync('choosedStoreInfo') ? wx.getStorageSync('choosedStoreInfo') : null;
if (storeInfo) {
this.data.storeInfo.storeId = storeInfo.id;
this.data.storeInfo.storeName = storeInfo.name;
this.data.storeInfo.storeAddress = storeInfo.storeFullAddress;
this.data.storeInfo.storeCode = storeInfo.code;
} else {
this.data.storeInfo = {
storeName: '',
storeId: '',
storeAddress: '',
storeCode: '',
}
}
//切换tab
onTapChangeType(e) {
let type = e.currentTarget.dataset.type;
this.setData({
currentType: type
});
this.setData({
storeInfo: this.data.storeInfo
});
if (type == 'delivery') {
this.getAddressList()
}
else {
this.getLocalStoreInfo();
}
},
//选择门店去
onTapSelectStore() {
wx.navigateTo({
url: '/subPackage/page/pages/chooseStore/chooseStore?isFrom=order',
});
},
//订单备注输入
onBuyerRemarkInput(e) {
this.data.buyerRemark = e.detail.value;
this.setData({
buyerRemark: this.data.buyerRemark
});
},
// select 传过来
updateCoupon(e) {
// faceAmount 抵用多少钱(分) 1 抵用券 2 折扣券 3 定额券
if (!e.detail) {
this.setData({
useNotUserCoupon : true,
defalutCoupon: 0,
couponId: '',
couponSettingId: '',
defalutCouponId: '',
currentCoupon: 0,
}, () => {
this.setPayPrice();
this.reCallPreview();
});
return
}
const { faceAmount, type, id, couponDiscount, sid } = e.detail
const { defalutCouponId } = this.data
const { orderPrice } = this.data
// couponId---id couponSettingId --sid
let finCouponId = id ? id : sid
let finCouponName = id ? 'couponId' : 'couponSettingId';
if (type == 1) {
this.setData({
useNotUserCoupon: false,
defalutCoupon: true,
defalutCouponId: finCouponId ? '' : defalutCouponId,
[finCouponName]: finCouponId,
// couponId: id,
haveCoupon: true,
currentCoupon: `${parseFloat(faceAmount/10/10).toFixed(2)} 元`
},() => {
this.reCallPreview();
})
} else if (type == 2) {
// let discounPrice = (faceAmount / 100) * (orderPrice)
// let spread = Math.round(orderPrice - discounPrice)
this.setData({
defalutCoupon: true,
useNotUserCoupon: false,
[finCouponName]: finCouponId,
defalutCouponId: finCouponId ? '' : defalutCouponId,
// couponId: id,
haveCoupon: true,
currentCoupon: `${couponDiscount} 元`
},() => {
this.reCallPreview();
});
}
else if(type == 3){ //定额券
const {
memberId
} = wx.getStorageSync('_baseUserInfo');
const {
trolleySku2Buy,
checkByPremium
} = this.data;
let params = {
checkByPremium,
trolleySku2Buy
};
params.orderType = 4;
params.storeId = this.data.storeInfo.storeId;
this.calPreferentialPrice(params)
},
this.setData({
defalutCoupon: true,
useNotUserCoupon: false,
defalutCouponId: finCouponId ? '' : defalutCouponId,
[finCouponName]: finCouponId,
haveCoupon: true,
currentCoupon: `${couponDiscount} 元`
},() => {
this.reCallPreview();
})
}
//切换tab
onTapChangeType(e) {
let type = e.currentTarget.dataset.type;
this.setData({
currentType: type
});
// 实付款
if (type == 'delivery') {
this.getAddressList()
} else {
this.getLocalStoreInfo();
}
},
//选择门店去
onTapSelectStore() {
wx.navigateTo({
url: '/subPackage/page/pages/chooseStore/chooseStore?isFrom=order',
});
},
//订单备注输入
onBuyerRemarkInput(e) {
this.data.buyerRemark = e.detail.value;
this.setData({
buyerRemark: this.data.buyerRemark
});
},
// select 传过来
updateCoupon(e) {
// faceAmount 抵用多少钱(分) 1 抵用券 2 折扣券 3 定额券
if (!e.detail) {
this.setData({
useNotUserCoupon: true,
defalutCoupon: 0,
couponId: '',
couponSettingId: '',
defalutCouponId: '',
currentCoupon: 0,
}, () => {
this.setPayPrice();
},
setPayPrice() {
const { currentCoupon, orderInitPrice, isSelect, plusMemberPrice, defalutCoupon } = this.data
let newCurrentCoupon = currentCoupon ? currentCoupon : 0
let orderCoupon = parseFloat(newCurrentCoupon) // 优惠券价格
let plusPrice = isSelect ? plusMemberPrice : 0 // plus
let calCouponPrice = orderCoupon ? orderCoupon : defalutCoupon
this.reCallPreview();
});
return
}
const {
faceAmount,
type,
id,
couponDiscount,
sid
} = e.detail
const {
defalutCouponId
} = this.data
const {
orderPrice
} = this.data
// couponId---id couponSettingId --sid
let finCouponId = id ? id : sid
let finCouponName = id ? 'couponId' : 'couponSettingId';
if (type == 1) {
this.setData({
useNotUserCoupon: false,
defalutCoupon: true,
defalutCouponId: finCouponId ? '' : defalutCouponId,
[finCouponName]: finCouponId,
// couponId: id,
haveCoupon: true,
currentCoupon: `${parseFloat(faceAmount/10/10).toFixed(2)} 元`
}, () => {
this.reCallPreview();
})
} else if (type == 2) {
// let discounPrice = (faceAmount / 100) * (orderPrice)
// let spread = Math.round(orderPrice - discounPrice)
this.setData({
defalutCoupon: true,
useNotUserCoupon: false,
[finCouponName]: finCouponId,
defalutCouponId: finCouponId ? '' : defalutCouponId,
// couponId: id,
haveCoupon: true,
currentCoupon: `${couponDiscount} 元`
}, () => {
this.reCallPreview();
});
} else if (type == 3) { //定额券
// 实际价格 - 优惠价 + plus
this.setData({
// orderPrice: Math.round(orderInitPrice - orderCoupon)
// orderPrice: orderInitPrice - orderCoupon + plusPrice
orderPrice: orderInitPrice - calCouponPrice + plusPrice
})
},
//提交按钮
formSubmit(e) {
//判断是不是开卡了
if (this.data.orderingMustOpenCard) {
let baseInfo = wx.getStorageSync('_baseUserInfo');
if (!baseInfo) {
wx.showToast({
title: '你还未登录,请先去登录',
icon: 'none'
});
return;
}
this.setData({
defalutCoupon: true,
useNotUserCoupon: false,
defalutCouponId: finCouponId ? '' : defalutCouponId,
[finCouponName]: finCouponId,
haveCoupon: true,
currentCoupon: `${couponDiscount} 元`
}, () => {
this.reCallPreview();
})
}
let memberActivateStatus = baseInfo.memberActivateStatus;
if (!memberActivateStatus) {
wx.showModal({
title: '下单开卡提示',
content: '对不起,需要您先开卡后才能下单,点击确定去开卡',
showCancel: true,
confirmText: '确定',
confirmColor: '#cb3c3c',
success: function (res) {
if (res.confirm) {
//跳去开卡
wxService.openCard();
}
else if (res.cancel) {
// 实付款
this.setPayPrice();
},
setPayPrice() {
const {
currentCoupon,
orderInitPrice,
isSelect,
plusMemberPrice,
defalutCoupon
} = this.data
let newCurrentCoupon = currentCoupon ? currentCoupon : 0
let orderCoupon = parseFloat(newCurrentCoupon) // 优惠券价格
let plusPrice = isSelect ? plusMemberPrice : 0 // plus
let calCouponPrice = orderCoupon ? orderCoupon : defalutCoupon
//获取计算优惠后的价格
let promotionPrice = (orderInitPrice - calCouponPrice) > 0 ? (orderInitPrice - calCouponPrice) : 0;
// 实际价格 - 优惠价 + plus
this.setData({
// orderPrice: Math.round(orderInitPrice - orderCoupon)
// orderPrice: orderInitPrice - orderCoupon + plusPrice
orderPrice: promotionPrice + plusPrice
})
},
//提交按钮
formSubmit(e) {
//判断是不是开卡了
if (this.data.orderingMustOpenCard) {
let baseInfo = wx.getStorageSync('_baseUserInfo');
if (!baseInfo) {
wx.showToast({
title: '你还未登录,请先去登录',
icon: 'none'
});
return;
}
}
}
})
let memberActivateStatus = baseInfo.memberActivateStatus;
if (!memberActivateStatus) {
wx.showModal({
title: '下单开卡提示',
content: '对不起,需要您先开卡后才能下单,点击确定去开卡',
showCancel: true,
confirmText: '确定',
confirmColor: '#cb3c3c',
success: function(res) {
if (res.confirm) {
//跳去开卡
wxService.openCard();
} else if (res.cancel) {
return;
}
}
})
return;
}
}
//判断是不是快递配送
if (this.data.currentType == 'delivery') {
const {
goodsAddress
} = this.data
// 保存地址 && 支付
if (goodsAddress) {
if (!this.data.uAddress.name) {
wx.showToast({
title: `请输入收货人姓名`,
icon: 'none'
})
return false;
}
if (!this.data.uAddress.phone) {
wx.showToast({
title: `请输入收货人电话`,
icon: 'none'
})
return false;
}
if (!this.data.cityView) {
wx.showToast({
title: `请选择收货地区`,
icon: 'none'
})
return false;
}
if (!this.data.uAddress.address) {
wx.showToast({
title: `请输入收货详细地址`,
icon: 'none'
})
return false;
}
//判断是不是快递配送
if (this.data.currentType == 'delivery') {
const { goodsAddress } = this.data
// 保存地址 && 支付
if (goodsAddress) {
if (!this.data.uAddress.name) {
wx.showToast({
title: `请输入收货人姓名`,
icon: 'none'
})
return false;
}
if (!this.data.uAddress.phone) {
wx.showToast({
title: `请输入收货人电话`,
icon: 'none'
})
return false;
}
if (!this.data.cityView) {
wx.showToast({
title: `请选择收货地区`,
icon: 'none'
})
return false;
}
if (!this.data.uAddress.address) {
wx.showToast({
title: `请输入收货详细地址`,
icon: 'none'
})
return false;
}
const { memberId } = wx.getStorageSync('_baseUserInfo')
this.setData({
params: {
userId: memberId,
name: this.data.uAddress.name,
phone: this.data.uAddress.phone,
province: this.data.params.province,
city: this.data.params.city,
district: this.data.params.district,
address: this.data.uAddress.address,
type: this.data.isSelect ? 1 : 0
}
});
const {
memberId
} = wx.getStorageSync('_baseUserInfo')
this.setData({
params: {
userId: memberId,
name: this.data.uAddress.name,
phone: this.data.uAddress.phone,
province: this.data.params.province,
city: this.data.params.city,
district: this.data.params.district,
address: this.data.uAddress.address,
type: this.data.isSelect ? 1 : 0
}
});
wx.showLoading({
title: '加载中'
});
wx.showLoading({
title: '加载中'
});
wxService.post(`/member/addressManage/save`, this.data.params).then(res => {
const { result } = res.data
if (result == 0) {
wx.hideLoading()
wx.showToast({
title: `保存成功`,
icon: 'none'
});
wxService.post(`/member/addressManage/save`, this.data.params).then(res => {
const {
result
} = res.data
if (result == 0) {
wx.hideLoading()
wx.showToast({
title: `保存成功`,
icon: 'none'
});
this.data.addressId = res.data.data;
this.data.addressId = res.data.data;
this.setData({
addressId: this.data.addressId
});
this.setData({
addressId: this.data.addressId
});
// 调起支付
this.handelGobuy()
}
})
} else {
// 调起支付
this.handelGobuy()
}
}
else {
// 调起支付
this.handelGobuy()
}
},
initCitys() {
let cityData = [];
//热风地址库特殊处理
if (envInfo.brandId == 2010) {
//由于地址框太大了,现在先用热风的一个
cityData = city.default;
}
else {
cityData = city.default;
}
}
})
} else {
// 调起支付
this.handelGobuy()
}
} else {
this.handelGobuy()
}
},
initCitys() {
let cityData = [];
//热风地址库特殊处理
if (envInfo.brandId == 2010) {
//由于地址框太大了,现在先用热风的一个
cityData = city.default;
} else {
cityData = city.default;
}
let province = []
let cityList = []
let district = []
cityData.forEach((item) => {
province.push(item.value)
})
cityData[0].children.forEach((cityItem) => {
cityList.push(cityItem.value)
cityItem.children.forEach((districtItem) => {
district.push(districtItem.value)
})
})
this.setData({
citys: [province, cityList, district]
})
},
bindMultiPickerChange(e) {
const citys = this.data.citys
const multiIndex = e.detail.value
if (citys) {
const cityView = [citys[0][multiIndex[0]], citys[1][multiIndex[1]], citys[2][multiIndex[2]]].join(' ')
let province = []
let cityList = []
let district = []
this.setData({
multiIndex,
cityView,
'params.province': citys[0][multiIndex[0]],
'params.city': citys[1][multiIndex[1]],
'params.district': citys[2][multiIndex[2]]
})
}
},
bindMultiPickerColumnChange(e) {
const detail = e.detail
const index = detail.value
let cityName = ''
let cityData = city.default
let province = []
let cityList = []
let district = []
switch (detail.column) {
case 0:
cityName = this.data.citys[0][index]
this.data.selectCityName[0] = cityName
cityData.forEach((item) => {
province.push(item.value)
})
cityData[0].children.forEach((cityItem) => {
cityList.push(cityItem.value)
cityItem.children.forEach((districtItem) => {
if (item.value == cityName) {
item.children.forEach((cityItem) => {
cityList.push(cityItem.value)
cityItem.children.forEach((districtItem) => {
district.push(districtItem.value)
})
})
}
})
this.setData({
citys: [province, cityList, district]
'citys[1]': cityList,
'citys[2]': district
})
},
bindMultiPickerChange(e) {
const citys = this.data.citys
const multiIndex = e.detail.value
if (citys) {
const cityView = [citys[0][multiIndex[0]], citys[1][multiIndex[1]], citys[2][multiIndex[2]]].join(' ')
break
case 1:
cityName = this.data.citys[1][index]
this.data.selectCityName[1] = cityName
cityData.forEach((item) => {
item.children.forEach((cityItem) => {
if (cityName == cityItem.value) {
cityItem.children.forEach((districtItem) => {
district.push(districtItem.value)
})
}
})
})
this.setData({
'citys[2]': [...district]
})
break
default:
break
}
},
//勾选购买vip时
handelChangeSelectVip() {
this.setData({
isSelect: !this.data.isSelect
}, () => {
const {
isSelect
} = this.data
this.setData({
checkByPremium: isSelect,
defalutCoupon: 0,
couponId: '',
couponSettingId: '',
defalutCouponId: ''
}, () => {
this.reCallPreview();
// 获取默认付费会员设置
this.getPremiumDefault()
})
});
},
// /premium/getDefault
getPremiumDefault() {
wx.showLoading({
title: '加载中'
})
wxService.get(`/sale/premium/getDefault`).then(res => {
if (res) {
const {
result,
data
} = res.data
if (result == 0) {
wx.hideLoading()
this.setData({
plusMemberPrice: data.price,
plusMemberName: data.name
}, () => {
// 实付款
this.setPayPrice()
})
}
}
})
},
// 默认地址
selectAddress() {
wxService.router('/pages/myAddress/myAddress?isFrom=order')
},
//拼接字段重新调用preview
reCallPreview() {
const {
trolleySku2Buy,
checkByPremium,
addressId,
addressInfo
} = this.data
let params = {
checkByPremium,
trolleySku2Buy,
}
// 增加门店自提和快递配送判断
if (this.data.currentType == 'delivery') {
params.addressId = addressId ? addressId : addressInfo.id // 微信地址 or 地址id
params.orderType = 1;
} else {
params.orderType = 4;
params.storeId = this.data.storeInfo.storeId;
}
this.calPreferentialPrice(params) // 重新计算优惠价
// 获取默认付费会员设置
this.getPremiumDefault()
},
// 计算优惠价
calPreferentialPrice(params) {
wx.showLoading({
title: '加载中'
});
//如果有couponId需要在预览接口传过去
if (this.data.couponId) {
params.couponId = this.data.couponId;
}
wxService.post(`/sale/trade/buyer/preview`, params).then(res => {
if (res) {
const {
result,
data
} = res.data
if (result == 0) {
wx.hideLoading()
let skuList = data.tradePreviewSkus;
let sum = 0
skuList.forEach((item, index) => {
// item.price
sum += skuList[index].price * skuList[index].count;
});
this.data.totalGoodsPrice = sum;
// 初始化商品价格
const {
isSelect
} = this.data
if (isSelect) {
this.setData({
multiIndex,
cityView,
'params.province': citys[0][multiIndex[0]],
'params.city': citys[1][multiIndex[1]],
'params.district': citys[2][multiIndex[2]]
selectPrice: sum
})
}
},
bindMultiPickerColumnChange(e) {
const detail = e.detail
const index = detail.value
let cityName = ''
let cityData = city.default
let province = []
let cityList = []
let district = []
switch (detail.column) {
case 0:
cityName = this.data.citys[0][index]
this.data.selectCityName[0] = cityName
cityData.forEach((item) => {
if (item.value == cityName) {
item.children.forEach((cityItem) => {
cityList.push(cityItem.value)
cityItem.children.forEach((districtItem) => {
district.push(districtItem.value)
})
})
}
})
this.setData({
'citys[1]': cityList,
'citys[2]': district
})
break
case 1:
cityName = this.data.citys[1][index]
this.data.selectCityName[1] = cityName
cityData.forEach((item) => {
item.children.forEach((cityItem) => {
if (cityName == cityItem.value) {
cityItem.children.forEach((districtItem) => {
district.push(districtItem.value)
})
}
})
})
this.setData({
'citys[2]': [...district]
})
break
default:
break
}
},
//勾选购买vip时
handelChangeSelectVip() {
this.setData({
isSelect: !this.data.isSelect
}, () => {
const { isSelect } = this.data
} else {
this.setData({
checkByPremium: isSelect,
defalutCoupon: 0,
couponId: '',
couponSettingId: '',
defalutCouponId: ''
}, () => {
this.reCallPreview();
// 获取默认付费会员设置
this.getPremiumDefault()
noSelectPrice: sum
})
});
},
// /premium/getDefault
getPremiumDefault() {
wx.showLoading({
title: '加载中'
})
wxService.get(`/sale/premium/getDefault`).then(res => {
if (res) {
const { result, data } = res.data
if (result == 0) {
wx.hideLoading()
this.setData({
plusMemberPrice: data.price,
plusMemberName: data.name
}, () => {
// 实付款
this.setPayPrice()
})
}
}
//如果没有couponId则认为是第一次进来没有自己选择优惠券
if (!this.data.couponId) {
if (!this.data.useNotUserCoupon) {
//获取优惠券信息
let defalutCoupon = data && data.couponDiscountPreviews.length &&
data.couponDiscountPreviews[0].couponSettingDTO.type == 1 ?
data && data.couponDiscountPreviews.length &&
data.couponDiscountPreviews[0].couponSettingDTO.faceAmount / 100 : data &&
data.couponDiscountPreviews.length && data.couponDiscountPreviews[0] &&
data.couponDiscountPreviews[0].couponDiscount;
let defalutCouponId = data && data.couponDiscountPreviews.length &&
data.couponDiscountPreviews[0] && data.couponDiscountPreviews[0].couponDTOS[0] &&
data.couponDiscountPreviews[0].couponDTOS[0].id || '';
let couponSettingId = data && data.couponDiscountPreviews.length &&
data.couponDiscountPreviews[0] && data.couponDiscountPreviews[0].couponDTOS[0] &&
data.couponDiscountPreviews[0].couponDTOS[0].couponSettingId || '';
data.couponDiscountPreviews = data.couponDiscountPreviews ? data.couponDiscountPreviews : [];
this.data.couponDiscountPreviews = data.couponDiscountPreviews;
// id / couponSettingId
this.setData({
currentOrderList: data,
couponDiscountPreviews: this.data.couponDiscountPreviews,
defalutCoupon: defalutCoupon,
defalutCouponId: defalutCouponId,
couponSettingId: couponSettingId,
orderInitPrice: data.amount,
totalGoodsPrice: this.data.totalGoodsPrice
}, () => {
// 实付款
this.setPayPrice()
})
}
})
},
// 默认地址
selectAddress() {
wxService.router('/pages/myAddress/myAddress?isFrom=order')
},
//拼接字段重新调用preview
reCallPreview() {
const { trolleySku2Buy, checkByPremium, addressId, addressInfo } = this.data
let params = {
checkByPremium,
trolleySku2Buy,
//用户取消使用优惠券
else {
this.setData({
currentOrderList: data,
orderInitPrice: data.amount,
totalGoodsPrice: this.data.totalGoodsPrice
}, () => {
// 实付款
this.setPayPrice()
})
}
} else {
//重新调用之后 不刷新优惠券列表
this.setData({
currentOrderList: data,
defalutCoupon: this.data.defalutCoupon,
defalutCouponId: this.data.defalutCouponId,
couponSettingId: this.data.couponSettingId,
orderInitPrice: data.amount,
totalGoodsPrice: this.data.totalGoodsPrice
}, () => {
// 实付款
this.setPayPrice()
})
}
}
}
});
},
//跳转购买
handelGobuy() {
// 第一项 defalutCouponId couponId/
const {
isSelect,
defalutCoupon,
trolleySku2Buy,
couponId,
couponSettingId,
addressId,
addressInfo,
defalutCouponId,
} = this.data;
// 增加门店自提和快递配送判断
if (this.data.currentType == 'delivery') {
params.addressId = addressId ? addressId : addressInfo.id // 微信地址 or 地址id
params.orderType = 1;
}
else {
params.orderType = 4;
params.storeId = this.data.storeInfo.storeId;
let finCouponName, finCouponId
if (!defalutCoupon) {
finCouponName = 'couponId'
finCouponId = ''
} else {
// 当前选中 哪一个id couponSettingId
// 默认券存在 id settingId
let currentCouponId // couponId / 第一项 id
if (defalutCouponId) {
finCouponId = defalutCouponId
finCouponName = 'couponId'
} else {
currentCouponId = couponId ? couponId : couponSettingId
finCouponName = couponId ? 'couponId' : 'couponSettingId'
finCouponId = currentCouponId
}
}
this.calPreferentialPrice(params) // 重新计算优惠价
// 获取默认付费会员设置
this.getPremiumDefault()
},
// 计算优惠价
calPreferentialPrice(params) {
wx.showLoading({
title: '加载中'
});
//如果有couponId需要在预览接口传过去
if (this.data.couponId){
params.couponId = this.data.couponId;
let params = {
[finCouponName]: finCouponId,
// couponId: couponId? couponId : defalutCouponId,
trolleySku2Buy,
buyerRemark: this.data.buyerRemark,
}
//判断是快递下单还是自提下单
if (this.data.currentType == 'delivery') {
params.orderType = 1;
params.addressId = addressId ? addressId : addressInfo.id // 微信地址 or 地址id
//判断addressId是不是有
if (!params.addressId) {
wx.showToast({
title: '请添加地址或选择地址',
icon: 'none'
})
return;
}
wxService.post(`/sale/trade/buyer/preview`, params).then(res => {
if (res) {
const { result, data } = res.data
if (result == 0) {
wx.hideLoading()
let skuList = data.tradePreviewSkus;
let sum = 0
skuList.forEach((item, index) => {
// item.price
sum += skuList[index].price * skuList[index].count;
});
} else {
params.orderType = 4;
params.storeId = this.data.storeInfo.storeId;
params.storeCode = this.data.storeInfo.storeCode;
params.storeName = this.data.storeInfo.storeName;
if (!params.storeId) {
wx.showToast({
title: '门店自提需要选择门店',
icon: 'none'
})
return;
}
}
this.data.totalGoodsPrice = sum;
// 初始化商品价格
const { isSelect } = this.data
this.getBill(params) // 下单
},
// 下单
getBill(params) {
let _this = this;
wx.showLoading({
title: '正在下单..'
});
if (isSelect) {
this.setData({
selectPrice: sum
})
} else {
this.setData({
noSelectPrice: sum
})
}
//如果没有couponId则认为是第一次进来没有自己选择优惠券
if (!this.data.couponId) {
if(!this.data.useNotUserCoupon){
//获取优惠券信息
let defalutCoupon = data && data.couponDiscountPreviews.length &&
data.couponDiscountPreviews[0].couponSettingDTO.type == 1 ?
data && data.couponDiscountPreviews.length &&
data.couponDiscountPreviews[0].couponSettingDTO.faceAmount / 100 : data &&
data.couponDiscountPreviews.length && data.couponDiscountPreviews[0] &&
data.couponDiscountPreviews[0].couponDiscount;
let defalutCouponId = data && data.couponDiscountPreviews.length &&
data.couponDiscountPreviews[0] && data.couponDiscountPreviews[0].couponDTOS[0] &&
data.couponDiscountPreviews[0].couponDTOS[0].id || '';
let couponSettingId = data && data.couponDiscountPreviews.length &&
data.couponDiscountPreviews[0] && data.couponDiscountPreviews[0].couponDTOS[0] &&
data.couponDiscountPreviews[0].couponDTOS[0].couponSettingId || '';
data.couponDiscountPreviews = data.couponDiscountPreviews ? data.couponDiscountPreviews : [];
this.data.couponDiscountPreviews = data.couponDiscountPreviews;
// id / couponSettingId
this.setData({
currentOrderList: data,
couponDiscountPreviews: this.data.couponDiscountPreviews,
defalutCoupon: defalutCoupon,
defalutCouponId: defalutCouponId,
couponSettingId: couponSettingId,
orderInitPrice: data.amount,
totalGoodsPrice: this.data.totalGoodsPrice
}, () => {
// 实付款
this.setPayPrice()
})
}
//用户取消使用优惠券
else{
this.setData({
currentOrderList: data,
orderInitPrice: data.amount,
totalGoodsPrice: this.data.totalGoodsPrice
}, () => {
// 实付款
this.setPayPrice()
})
}
}
else{
//重新调用之后 不刷新优惠券列表
this.setData({
currentOrderList: data,
defalutCoupon: this.data.defalutCoupon,
defalutCouponId: this.data.defalutCouponId,
couponSettingId: this.data.couponSettingId,
orderInitPrice: data.amount,
totalGoodsPrice: this.data.totalGoodsPrice
}, () => {
// 实付款
this.setPayPrice()
})
}
}
const {
isSelect
} = this.data;
//增加订单备注信息
params.buyerRemark = this.data.buyerRemark;
//下单之前先做校验
this.checkOrder(params).then(result => {
if (result) {
let data = result.data.data ? result.data.data : [];
if (data.length == 0) {
this.order(isSelect, params);
} else {
//有商品限购了,组织提示语
let tips = '根据限购规则以下商品限购:\r\n';
let tempObj = data[0];
//每人限购
if (tempObj.limitType == 1) {
tips = `商品"${tempObj.productName}"每人限购${tempObj.limitNum}件`;
}
//每次限购
else if (tempObj.limitType == 2) {
tips = `商品"${tempObj.productName}"每次限购${tempObj.limitNum}件`;
}
});
},
//跳转购买
handelGobuy() {
// 第一项 defalutCouponId couponId/
const {
isSelect,
defalutCoupon,
trolleySku2Buy,
couponId,
couponSettingId,
addressId,
addressInfo,
defalutCouponId,
} = this.data;
let finCouponName, finCouponId
if (!defalutCoupon) {
finCouponName = 'couponId'
finCouponId = ''
} else {
// 当前选中 哪一个id couponSettingId
// 默认券存在 id settingId
let currentCouponId // couponId / 第一项 id
if (defalutCouponId) {
finCouponId = defalutCouponId
finCouponName = 'couponId'
} else {
currentCouponId = couponId ? couponId : couponSettingId
finCouponName = couponId ? 'couponId' : 'couponSettingId'
finCouponId = currentCouponId
}
wx.showModal({
title: '商品限购提醒',
content: tips,
confirmText: '好的',
confirmColor: '#cb3c3c',
showCancel: false,
success(confirm) {
if (confirm.confirm) {
wx.navigateBack({
delta: 1
});
}
},
})
}
}
});
},
//下单
order(isSelect, params) {
if (this.data.orderStoreInfo) {
if (this.data.orderStoreInfo.storeId) {
params.storeId = this.data.orderStoreInfo.storeId;
}
if (this.data.orderStoreInfo.storeInfo) {
params.storeInfo = this.data.orderStoreInfo.storeInfo;
}
}
let params = {
[finCouponName]: finCouponId,
// couponId: couponId? couponId : defalutCouponId,
trolleySku2Buy,
buyerRemark: this.data.buyerRemark,
}
let _this = this;
let url = isSelect ? '/sale/payment/merged/buyer/bill' : '/sale/trade/buyer/bill'
wxService.post(`${url}`, params).then(res => {
if (res) {
const {
result,
data
} = res.data
let tradeId = data.tradeId;
wx.removeStorageSync('choosedStoreInfo');
wx.removeStorageSync('orderRemark');
if (result == 0) {
delete data.appId
let amount = data.amount || 0;
if (amount > 0) {
wx.requestPayment(Object.assign({
success(res) {
wx.hideLoading()
//消息订阅
let baseUserInfo = wx.getStorageSync('_baseUserInfo');
wxService.post(`${'/merchant/message/wxSubMsgMapping/getListByParams'}`, {
scenarioIds: ['ordersend', 'orderconfirm'],
sourceFrom: 2,
switchType: 3
}).then(res => {
let tempArr = res.data.data ? res.data.data : [];
let currentType = _this.data.currentType;
if (tempArr.length == 0) {
wx.redirectTo({
url: `/subPackage/page/pages/paymentStatus/paymentStatus?status=S&amount=${amount}&type=${currentType}`,
});
return;
}
//判断是快递下单还是自提下单
if (this.data.currentType == 'delivery') {
params.orderType = 1;
params.addressId = addressId ? addressId : addressInfo.id // 微信地址 or 地址id
let tempids = [];
tempArr.map(item => {
tempids.push(item.templateId);
});
//判断addressId是不是有
if (!params.addressId) {
wx.showToast({
title: '请添加地址或选择地址',
icon: 'none'
wx.requestSubscribeMessage({
tmplIds: tempids,
success: (res) => {
for (let i = 0; i < tempArr.length; i++) {
wxService.post(`${'/merchant/message/wxSubMsgSubscride/member/subscribe'}`, {
businessId: tradeId,
memberId: baseUserInfo.memberId,
scenarioId: tempArr[i].scenarioId,
templateId: tempArr[i].templateId
}).then(resp => {});
}
},
complete: (res) => {
wx.redirectTo({
url: `/subPackage/page/pages/paymentStatus/paymentStatus?status=S&amount=${amount}&type=${currentType}`,
});
}
})
}).catch(err => {
let currentType = _this.data.currentType;
wx.redirectTo({
url: `/subPackage/page/pages/paymentStatus/paymentStatus?status=S&amount=${amount}&type=${currentType}`,
});
})
return;
}
}
else {
params.orderType = 4;
params.storeId = this.data.storeInfo.storeId;
params.storeCode = this.data.storeInfo.storeCode;
params.storeName = this.data.storeInfo.storeName;
if (!params.storeId) {
},
fail(res) {
wx.hideLoading();
wx.showToast({
title: '门店自提需要选择门店',
icon: 'none'
})
return;
}
}
this.getBill(params) // 下单
},
// 下单
getBill(params) {
let _this = this;
wx.showLoading({
title: '正在下单..'
});
const { isSelect } = this.data;
//增加订单备注信息
params.buyerRemark = this.data.buyerRemark;
//下单之前先做校验
this.checkOrder(params).then(result => {
if (result) {
let data = result.data.data ? result.data.data : [];
if (data.length == 0) {
this.order(isSelect, params);
}
else {
//有商品限购了,组织提示语
let tips = '根据限购规则以下商品限购:\r\n';
let tempObj = data[0];
//每人限购
if (tempObj.limitType == 1) {
tips = `商品"${tempObj.productName}"每人限购${tempObj.limitNum}件`;
}
//每次限购
else if (tempObj.limitType == 2) {
tips = `商品"${tempObj.productName}"每次限购${tempObj.limitNum}件`;
}
wx.showModal({
title: '商品限购提醒',
content: tips,
confirmText: '好的',
confirmColor: '#cb3c3c',
showCancel: false,
success(confirm) {
if (confirm.confirm) {
wx.navigateBack({
delta: 1
});
}
},
})
title: '支付已取消',
icon: 'none'
});
if (_this.data.currentType == 'delivery') {
wx.redirectTo({
url: '/pages/order/order',
});
} else {
wx.redirectTo({
url: '/subPackage/page/pages/selfPickUpOrderList/selfPickUpOrderList',
});
}
}
}, data.wxParams));
} else {
if (_this.data.currentType == 'delivery') {
wx.redirectTo({
url: '/pages/order/order',
});
} else {
wx.redirectTo({
url: '/subPackage/page/pages/selfPickUpOrderList/selfPickUpOrderList',
});
}
});
},
//下单
order(isSelect, params) {
if (this.data.orderStoreInfo) {
if (this.data.orderStoreInfo.storeId) {
params.storeId = this.data.orderStoreInfo.storeId;
}
if (this.data.orderStoreInfo.storeInfo) {
params.storeInfo = this.data.orderStoreInfo.storeInfo;
}
}
}
}
});
},
//校验订单中商品限购情况
checkOrder(params) {
return wxService.post(`/sale/trade/buyer/bill/before/check`, params);
},
// 获取地址列表
getAddressList() {
const {
memberId
} = wx.getStorageSync('_baseUserInfo');
const {
trolleySku2Buy,
checkByPremium
} = this.data;
let params = {
checkByPremium,
trolleySku2Buy
};
params.orderType = 1;
let _this = this;
let url = isSelect ? '/sale/payment/merged/buyer/bill' : '/sale/trade/buyer/bill'
wxService.post(`${url}`, params).then(res => {
if (res) {
const { result, data } = res.data
let tradeId = data.tradeId;
wx.removeStorageSync('choosedStoreInfo');
wx.removeStorageSync('orderRemark');
if (result == 0) {
delete data.appId
let amount = data.amount || 0;
if(amount > 0){
wx.requestPayment(Object.assign({
success(res) {
wx.hideLoading()
//消息订阅
let baseUserInfo = wx.getStorageSync('_baseUserInfo');
wxService.post(`${'/merchant/message/wxSubMsgMapping/getListByParams'}`, {
scenarioIds: ['ordersend', 'orderconfirm'],
sourceFrom: 2,
switchType: 3
}).then(res => {
let tempArr = res.data.data ? res.data.data : [];
let currentType = _this.data.currentType;
if (tempArr.length == 0){
wx.redirectTo({
url: `/subPackage/page/pages/paymentStatus/paymentStatus?status=S&amount=${amount}&type=${currentType}`,
});
return ;
}
let tempids = [];
tempArr.map(item => {
tempids.push(item.templateId);
});
wx.requestSubscribeMessage({
tmplIds: tempids,
success: (res)=>{
for(let i = 0; i < tempArr.length; i++){
wxService.post(`${'/merchant/message/wxSubMsgSubscride/member/subscribe'}`, {
businessId: tradeId,
memberId: baseUserInfo.memberId,
scenarioId:tempArr[i].scenarioId,
templateId: tempArr[i].templateId
}).then(resp => {});
}
},
complete: (res)=>{
wx.redirectTo({
url: `/subPackage/page/pages/paymentStatus/paymentStatus?status=S&amount=${amount}&type=${currentType}`,
});
}
})
}).catch(err => {
let currentType = _this.data.currentType;
wx.redirectTo({
url: `/subPackage/page/pages/paymentStatus/paymentStatus?status=S&amount=${amount}&type=${currentType}`,
});
})
},
fail(res) {
wx.hideLoading();
wx.showToast({
title: '支付已取消',
icon: 'none'
});
if (_this.data.currentType == 'delivery') {
wx.redirectTo({
url: '/pages/order/order',
});
}
else {
wx.redirectTo({
url: '/subPackage/page/pages/selfPickUpOrderList/selfPickUpOrderList',
});
}
}
}, data.wxParams));
}
else{
if (_this.data.currentType == 'delivery') {
wx.redirectTo({
url: '/pages/order/order',
});
}
else {
wx.redirectTo({
url: '/subPackage/page/pages/selfPickUpOrderList/selfPickUpOrderList',
});
}
}
}
wxService.post(`/member/addressManage/getall`, {
userId: memberId
}).then(res => {
if (!res) return false;
let hasDefalut = wx.getStorageSync('_defalutAddress');
let {
result,
data
} = res.data
if (result == 0) {
//看看本地是不是有已经选择的地址了
if (!hasDefalut) { // 无
//看一下地址列表中是不是有默认地址
let defaultInAddressList = null;
data = data ? data : [];
data.forEach(item => {
item.fullArea = item.province + ' ' + item.city + ' ' + item.district
if (item.type == 1) {
defaultInAddressList = item
}
});
},
//校验订单中商品限购情况
checkOrder(params) {
return wxService.post(`/sale/trade/buyer/bill/before/check`, params);
},
// 获取地址列表
getAddressList() {
const { memberId } = wx.getStorageSync('_baseUserInfo');
const { trolleySku2Buy, checkByPremium } = this.data;
let params = { checkByPremium, trolleySku2Buy };
params.orderType = 1;
wxService.post(`/member/addressManage/getall`, {
userId: memberId
}).then(res => {
if (!res) return false;
let hasDefalut = wx.getStorageSync('_defalutAddress');
let { result, data } = res.data
if (result == 0) {
//看看本地是不是有已经选择的地址了
if (!hasDefalut) { // 无
//看一下地址列表中是不是有默认地址
let defaultInAddressList = null;
data = data ? data : [];
data.forEach(item => {
item.fullArea = item.province + ' ' + item.city + ' ' + item.district
if (item.type == 1) {
defaultInAddressList = item
}
});
});
if (defaultInAddressList) {
this.data.addressId = defaultInAddressList ? defaultInAddressList.id : '';
this.data.addressInfo = defaultInAddressList;
params.addressId = this.data.addressId;
}
if (defaultInAddressList) {
this.data.addressId = defaultInAddressList ? defaultInAddressList.id : '';
this.data.addressInfo = defaultInAddressList;
params.addressId = this.data.addressId;
}
this.setData({
addressInfo: this.data.addressInfo,
addressId: this.data.addressId,
goodsAddress: params.addressId ? false : true,
});
}
else { // 有已经选择的地址了
let defaultInAddressList = null;
//判断地址列表中是不是已经把这个地址删除了
let id = hasDefalut.id;
let filterArr = data.filter(item => item.id == id);
if (filterArr.length > 0) {
defaultInAddressList = hasDefalut
}
else { // 无
//此时已经没有 看看是不是有默认地址 有则默认选中
data = data ? data : [];
data.forEach(item => {
item.fullArea = item.province + ' ' + item.city + ' ' + item.district
if (item.type == 1) {
defaultInAddressList = item
}
});
}
this.setData({
addressInfo: this.data.addressInfo,
addressId: this.data.addressId,
goodsAddress: params.addressId ? false : true,
});
} else { // 有已经选择的地址了
let defaultInAddressList = null;
//判断地址列表中是不是已经把这个地址删除了
let id = hasDefalut.id;
let filterArr = data.filter(item => item.id == id);
if (filterArr.length > 0) {
defaultInAddressList = hasDefalut
} else { // 无
//此时已经没有 看看是不是有默认地址 有则默认选中
data = data ? data : [];
data.forEach(item => {
item.fullArea = item.province + ' ' + item.city + ' ' + item.district
if (item.type == 1) {
defaultInAddressList = item
}
});
}
if (defaultInAddressList) {
this.data.addressId = defaultInAddressList ? defaultInAddressList.id : '';
this.data.addressInfo = defaultInAddressList;
params.addressId = this.data.addressId;
}
if (defaultInAddressList) {
this.data.addressId = defaultInAddressList ? defaultInAddressList.id : '';
this.data.addressInfo = defaultInAddressList;
params.addressId = this.data.addressId;
}
this.setData({
addressInfo: this.data.addressInfo,
addressId: this.data.addressId,
goodsAddress: params.addressId ? false : true,
});
}
this.setData({
addressInfo: this.data.addressInfo,
addressId: this.data.addressId,
goodsAddress: params.addressId ? false : true,
});
}
//校验当前选择的地址是否还有效 (判断是否是老地址,如果是的话 弹出提示,让用户去修改地址)
//校验地址库
this.validateAddress();
//校验当前选择的地址是否还有效 (判断是否是老地址,如果是的话 弹出提示,让用户去修改地址)
//校验地址库
this.validateAddress();
this.calPreferentialPrice(params)
}
}).finally(() => { });
},
//获取微信地址
chooseWxAddress() {
const { memberId } = wx.getStorageSync('_baseUserInfo')
wx.chooseAddress({
success: (res) => {
res.name = res.userName
res.phone = res.telNumber
res.fullArea = res.provinceName + res.cityName + res.countyName
res.address = res.detailInfo;
res.city = res.cityName;
res.district = res.countyName;
res.province = res.provinceName;
this.setData({
goodsAddress: false,
wxAddress: true,
addressInfo: res,
params: {
userId: memberId,
name: res.userName,
phone: res.telNumber,
province: res.provinceName,
city: res.cityName,
district: res.countyName,
address: res.detailInfo,
type: 0
}
});
this.calPreferentialPrice(params)
}
}).finally(() => {});
},
//获取微信地址
chooseWxAddress() {
const {
memberId
} = wx.getStorageSync('_baseUserInfo')
wx.chooseAddress({
success: (res) => {
res.name = res.userName
res.phone = res.telNumber
res.fullArea = res.provinceName + res.cityName + res.countyName
res.address = res.detailInfo;
res.city = res.cityName;
res.district = res.countyName;
res.province = res.provinceName;
this.setData({
goodsAddress: false,
wxAddress: true,
addressInfo: res,
params: {
userId: memberId,
name: res.userName,
phone: res.telNumber,
province: res.provinceName,
city: res.cityName,
district: res.countyName,
address: res.detailInfo,
type: 0
}
});
wxService.post(`/member/addressManage/save`, this.data.params).then(res => {
const { result, data } = res.data
if (result == 0) {
wx.hideLoading();
this.data.addressInfo.fullArea = this.data.addressInfo.provinceName + ' ' +
this.data.addressInfo.cityName + ' ' + this.data.addressInfo.countyName
this.data.addressInfo.id = data;
wx.setStorageSync('_defalutAddress', this.data.addressInfo)
wxService.post(`/member/addressManage/save`, this.data.params).then(res => {
const {
result,
data
} = res.data
if (result == 0) {
wx.hideLoading();
this.data.addressInfo.fullArea = this.data.addressInfo.provinceName + ' ' +
this.data.addressInfo.cityName + ' ' + this.data.addressInfo.countyName
this.data.addressInfo.id = data;
wx.setStorageSync('_defalutAddress', this.data.addressInfo)
this.setData({
addressId: data,
goodsAddress: true,
}, () => {
this.getAddressList();
})
}
}).finally(() => {
wx.hideLoading()
})
},
fail: function (err) {
console.log(err)
}
this.setData({
addressId: data,
goodsAddress: true,
}, () => {
this.getAddressList();
})
}
}).finally(() => {
wx.hideLoading()
})
},
},
fail: function(err) {
console.log(err)
}
})
},
//选择优惠券
selectCoupon() {
this.setData({
showSelectCoupon: true
})
},
//校验地址库 原因是地址库发生过改变 老用户之前维护过地址 但是地址可能对不上影响邮费 若发现地址不对这里强制提示用户去更新
validateAddress(){
if (this.data.addressId){
let province = this.data.addressInfo.province,
cityName = this.data.addressInfo.city,
district = this.data.addressInfo.district;
let defaultCities = city.default;
//先处理省份
let filterProvince = defaultCities.filter(item => item.value == province);
if(filterProvince.length == 0){
//省份地址维护不对 提示用户去改
//选择优惠券
selectCoupon() {
this.setData({
showSelectCoupon: true
})
},
//校验地址库 原因是地址库发生过改变 老用户之前维护过地址 但是地址可能对不上影响邮费 若发现地址不对这里强制提示用户去更新
validateAddress() {
if (this.data.addressId) {
let province = this.data.addressInfo.province,
cityName = this.data.addressInfo.city,
district = this.data.addressInfo.district;
let defaultCities = city.default;
//先处理省份
let filterProvince = defaultCities.filter(item => item.value == province);
if (filterProvince.length == 0) {
//省份地址维护不对 提示用户去改
this.showEditAddressModal(this.data.addressId);
} else {
//檢查市
let filterCity = filterProvince[0].children.filter(item => item.value == cityName);
if (filterCity.length == 0) {
//市维护的地址不对 提示用户去修改
this.showEditAddressModal(this.data.addressId);
}
else{
//檢查市
let filterCity = filterProvince[0].children.filter(item => item.value == cityName);
if (filterCity.length == 0){
//市维护的地址不对 提示用户去修改
} else {
//检查区是否正确
let filterDistinct = filterCity[0].children.filter(item => item.value == district);
if (filterDistinct.length == 0) {
//区维护的地址不对 提示用户去修改
this.showEditAddressModal(this.data.addressId);
}
else{
//检查区是否正确
let filterDistinct = filterCity[0].children.filter(item => item.value == district);
if (filterDistinct.length == 0){
//区维护的地址不对 提示用户去修改
this.showEditAddressModal(this.data.addressId);
}
}
}
}
},
//展示地址修改弹框
showEditAddressModal(addressId){
wx.showModal({
title: '地址更改提示',
content: `您好,因地址库的修改,您当前的收货地址需要重新编辑才可下单,请先编辑此地址。感谢您的配合~`,
showCancel: false,
confirmText: '去更改',
confirmColor: '#cb3c3c',
success(res) {
if (res.confirm) {
wxService.router(`/pages/addAddress/addAddress?id=${addressId}&from=order`)
}
}
},
//展示地址修改弹框
showEditAddressModal(addressId) {
wx.showModal({
title: '地址更改提示',
content: `您好,因地址库的修改,您当前的收货地址需要重新编辑才可下单,请先编辑此地址。感谢您的配合~`,
showCancel: false,
confirmText: '去更改',
confirmColor: '#cb3c3c',
success(res) {
if (res.confirm) {
wxService.router(`/pages/addAddress/addAddress?id=${addressId}&from=order`)
}
})
},
}
})
},
});
\ No newline at end of file
......@@ -4,82 +4,54 @@
<view class="page-confirm-order">
<!-- 选择方式 -->
<view class="deliveryType" wx:if="{{isOpenSelfMention}}">
<view class="de-type-item {{currentType == 'delivery' ? 'active' : ''}}"
data-type="delivery" bindtap="onTapChangeType">快递配送</view>
<view class="de-type-item {{currentType == 'selfPickUp' ? 'active' : ''}}"
data-type="selfPickUp" bindtap="onTapChangeType">门店自提</view>
<view class="de-type-item {{currentType == 'delivery' ? 'active' : ''}}" data-type="delivery" bindtap="onTapChangeType">快递配送</view>
<view class="de-type-item {{currentType == 'selfPickUp' ? 'active' : ''}}" data-type="selfPickUp" bindtap="onTapChangeType">门店自提</view>
</view>
<form>
<form>
<!-- 快递地址 -->
<view class="address-wrap" wx:if="{{currentType == 'delivery'}}">
<block wx:if="{{goodsAddress}}">
<view class="address-section">
<input class="address-input" name="name"
data-name="name" value='{{uAddress.name}}'
bindinput='onInput'
placeholder="请输入收货人姓名" />
<input class="address-input" name="phone"
data-name="phone"
bindinput='onInput'
value='{{uAddress.phone}}'
placeholder="请输入手机号码" />
</view>
<view class="address-section">
<picker
class="address-input address-picker"
mode="multiSelector"
bindchange="bindMultiPickerChange"
bindcolumnchange="bindMultiPickerColumnChange"
value="{{multiIndex}}"
range="{{citys}}"
>
<view class="form-picker" style="padding-top: 8rpx;" wx:if="{{cityView}}">
{{cityView}}
</view>
<view wx:if="{{!cityView}}">
<input
class='form-input'
placeholder-class="placeholder-picker"
style="padding-top: 8rpx;"
type="text"
disabled
placeholder="所在区域"
/>
</view>
</picker>
</view>
<view class="address-section">
<input class="address-input address-detail"
name="address"
bindinput='onInput'
data-name="address"
value='{{uAddress.address}}'
placeholder="请输入路名门牌号" />
</view>
</block>
<block wx:if="{{!goodsAddress}}">
<view class="address-list" bindtap="selectAddress">
<view class="address-info">
<view>
<image class="defalut-add-img"
src="{{addressInfo.type == 1 ? 'https://img3.bigaka.com/prd/3001/202003/20200309/3001f7a6186d-6882-422c-a77c-61b8291c091a.png' : 'https://img3.bigaka.com/prd/3001/202003/20200309/300129705d0a-bf5c-4b2f-aedd-0c3fc9f78ba1.png'}}" />
<text class="user-name">{{addressInfo.name}}</text>
<text class="phone-number">{{addressInfo.phone}}</text>
</view>
<view class="address-list-detail">
{{addressInfo.fullArea}} {{addressInfo.address}}
</view>
<view class="arrow-right-wrap">
<image class="arrow-right" src="/assets/imgs/7_1_0/arrow-right.png" />
</view>
</view>
</view>
</block>
<view class="wx-address" bindtap="chooseWxAddress" wx:if="{{canUseWechatAddress}}">
+ 使用微信地址
</view>
</view>
<view class="address-wrap" wx:if="{{currentType == 'delivery'}}">
<block wx:if="{{goodsAddress}}">
<view class="address-section">
<input class="address-input" name="name" data-name="name" value='{{uAddress.name}}' bindinput='onInput' placeholder="请输入收货人姓名" />
<input class="address-input" name="phone" data-name="phone" bindinput='onInput' value='{{uAddress.phone}}' placeholder="请输入手机号码" />
</view>
<view class="address-section">
<picker class="address-input address-picker" mode="multiSelector" bindchange="bindMultiPickerChange" bindcolumnchange="bindMultiPickerColumnChange" value="{{multiIndex}}" range="{{citys}}">
<view class="form-picker" style="padding-top: 8rpx;" wx:if="{{cityView}}">
{{cityView}}
</view>
<view wx:if="{{!cityView}}">
<input class='form-input' placeholder-class="placeholder-picker" style="padding-top: 8rpx;" type="text" disabled placeholder="所在区域" />
</view>
</picker>
</view>
<view class="address-section">
<input class="address-input address-detail" name="address" bindinput='onInput' data-name="address" value='{{uAddress.address}}' placeholder="请输入路名门牌号" />
</view>
</block>
<block wx:if="{{!goodsAddress}}">
<view class="address-list" bindtap="selectAddress">
<view class="address-info">
<view>
<image class="defalut-add-img" src="{{addressInfo.type == 1 ? 'https://img3.bigaka.com/prd/3001/202003/20200309/3001f7a6186d-6882-422c-a77c-61b8291c091a.png' : 'https://img3.bigaka.com/prd/3001/202003/20200309/300129705d0a-bf5c-4b2f-aedd-0c3fc9f78ba1.png'}}"
/>
<text class="user-name">{{addressInfo.name}}</text>
<text class="phone-number">{{addressInfo.phone}}</text>
</view>
<view class="address-list-detail">
{{addressInfo.fullArea}} {{addressInfo.address}}
</view>
<view class="arrow-right-wrap">
<image class="arrow-right" src="/assets/imgs/7_1_0/arrow-right.png" />
</view>
</view>
</view>
</block>
<view class="wx-address" bindtap="chooseWxAddress" wx:if="{{canUseWechatAddress}}">
+ 使用微信地址
</view>
</view>
<!-- 自提门店地址 -->
<view class="pick-up" wx:if="{{currentType == 'selfPickUp'}}">
<!-- <view class="address-title">提货地址</view> -->
......@@ -102,104 +74,104 @@
</view>
</view>
<view class="address-line">
<image src="/assets/imgs/7_1_0/address-line.png" />
</view>
<!-- 分割线 -->
<view class="gray-line" />
<!-- 商品列表 -->
<view class="pro-wrap">
<block wx:for="{{currentOrderList.tradePreviewSkus}}" wx:key="*this">
<view class="pro-list">
<image class="pro-img" src="{{item.skuImgUrl}}" />
<view class="pro-info">
<view class="pro-name">{{item.productName}}</view>
<view class="pro-desc">
规格 {{item.skuSpec}}
</view>
<view class="pro-price">
<text class="price">¥{{item.price}}</text>
<text class="number">x {{item.count}}</text>
</view>
</view>
</view>
</block>
</view>
<!-- 分割线 -->
<view class="gray-line" />
<view class="address-line">
<image src="/assets/imgs/7_1_0/address-line.png" />
</view>
<!-- 分割线 -->
<view class="gray-line" />
<!-- 商品列表 -->
<view class="pro-wrap">
<block wx:for="{{currentOrderList.tradePreviewSkus}}" wx:key="*this">
<view class="pro-list">
<image class="pro-img" src="{{item.skuImgUrl}}" />
<view class="pro-info">
<view class="pro-name">{{item.productName}}</view>
<view class="pro-desc">
规格 {{item.skuSpec}}
</view>
<view class="pro-price">
<text class="price">¥{{item.price}}</text>
<text class="number">x {{item.count}}</text>
</view>
</view>
</view>
</block>
</view>
<!-- 分割线 -->
<view class="gray-line" />
<!-- 商品合计 -->
<view class="pro-sum">
<view class="vip-info" wx:if="{{!isVip && plusIsOpen}}">
<view class="vip-left">
<view class="left-top">
<image class="top-image"
src="https://img3.bigaka.com/prd/3001/202003/20200309/3001a3933408-de10-4029-861f-f8fb5de26092.png" />
<text>现在勾选成为vip,享受更多优惠</text>
</view>
<view class="left-bottom">
<text>vip可尊享更多权益</text>
<!-- <image class="bottom-image" src="/assets/imgs/7_1_0/explain.png" /> -->
</view>
</view>
<view class="vip-right df" bindtap="handelChangeSelectVip">
<view class="right-check-status">
<image class="check-status-img" src="{{isSelect ? '/assets/imgs/7_1_0/08_22/trade-success.png' : '/assets/imgs/7_1_0/08_22/trade-unsel.png'}}" />
</view>
<view class="right-check-tips {{isSelect? 'tip-check' : 'tip-un-check'}}">
<image class="select-check-open {{isSelect? 'tip-check' : 'tip-un-check'}}" src="{{isSelect ? 'https://img3.bigaka.com/prd/3001/202003/20200309/3001ab6df057-e550-446c-a641-c5dcd8dbb51e.png' : 'https://img3.bigaka.com/prd/3001/202003/20200309/3001e6e3414a-3f8e-4100-b9da-7f852d842235.png'}}" />
</view>
</view>
</view>
<view class="order-sum">
<view class="order-price">
<view class="pro-total-price">
<text class="price-label">商品合计</text>
<text class="total-price">¥{{utils.numberFormat(totalGoodsPrice)}}</text>
</view>
<view class="plus-price" wx:if="{{isSelect}}">
<view class="plus-info">
<text class="price-label">plus会员价</text>
<text class="member-price">-¥{{utils.numberFormat(noSelectPrice - selectPrice)}}</text>
</view>
<text class="plus-member-price total-price">¥{{plusMemberPrice}}</text>
</view>
</view>
<view class="coupon">
<view>
<text class="price-label">活动折扣</text>
<text class="total-price">¥{{utils.numberFormat(currentOrderList.promotionDiscount)}}</text>
</view>
</view>
<view class="coupon">
<!-- class='coupon-items' -->
<view bindtap="selectCoupon">
<text class="price-label">优惠券</text>
<view class="select-coupon" >
<text class="{{defalutCoupon ? 'coupon-price' : 'no-coupon'}}">{{defalutCoupon ? (currentCoupon ? '-' + currentCoupon : '-' + defalutCoupon): (currentOrderList.couponDiscountPreviews.length == 0 ? '无可使用优惠券' : '选择优惠券')}}</text>
<image class="arrow-right" src="/assets/imgs/7_1_0/arrow-right.png" />
</view>
</view>
</view>
<!-- 商品合计 -->
<view class="pro-sum">
<view class="vip-info" wx:if="{{!isVip && plusIsOpen}}">
<view class="vip-left">
<view class="left-top">
<image class="top-image" src="https://img3.bigaka.com/prd/3001/202003/20200309/3001a3933408-de10-4029-861f-f8fb5de26092.png" />
<text>现在勾选成为vip,享受更多优惠</text>
</view>
<view class="left-bottom">
<text>vip可尊享更多权益</text>
<!-- <image class="bottom-image" src="/assets/imgs/7_1_0/explain.png" /> -->
</view>
</view>
<view class="vip-right df" bindtap="handelChangeSelectVip">
<view class="right-check-status">
<image class="check-status-img" src="{{isSelect ? '/assets/imgs/7_1_0/08_22/trade-success.png' : '/assets/imgs/7_1_0/08_22/trade-unsel.png'}}" />
</view>
<view class="right-check-tips {{isSelect? 'tip-check' : 'tip-un-check'}}">
<image class="select-check-open {{isSelect? 'tip-check' : 'tip-un-check'}}" src="{{isSelect ? 'https://img3.bigaka.com/prd/3001/202003/20200309/3001ab6df057-e550-446c-a641-c5dcd8dbb51e.png' : 'https://img3.bigaka.com/prd/3001/202003/20200309/3001e6e3414a-3f8e-4100-b9da-7f852d842235.png'}}"
/>
</view>
</view>
</view>
<view class="order-sum">
<view class="order-price">
<view class="pro-total-price">
<text class="price-label">商品合计</text>
<text class="total-price">¥{{utils.numberFormat(totalGoodsPrice)}}</text>
</view>
<view class="plus-price" wx:if="{{isSelect}}">
<view class="plus-info">
<text class="price-label">plus会员价</text>
<text class="member-price">-¥{{utils.numberFormat(noSelectPrice - selectPrice)}}</text>
</view>
<text class="plus-member-price total-price">¥{{plusMemberPrice}}</text>
</view>
</view>
<view class="coupon">
<view>
<text class="price-label">活动折扣</text>
<text class="total-price">¥{{utils.numberFormat(currentOrderList.promotionDiscount)}}</text>
</view>
</view>
<view class="coupon">
<!-- class='coupon-items' -->
<view bindtap="selectCoupon">
<text class="price-label">优惠券</text>
<view class="select-coupon">
<text class="{{defalutCoupon ? 'coupon-price' : 'no-coupon'}}">{{defalutCoupon ? (currentCoupon ? '-' + currentCoupon : '-' + defalutCoupon): (currentOrderList.couponDiscountPreviews.length == 0 ? '无可使用优惠券' : '选择优惠券')}}</text>
<image class="arrow-right" src="/assets/imgs/7_1_0/arrow-right.png" />
</view>
</view>
</view>
<view class="coupon">
<view>
<text class="price-label">运费</text>
<view class="select-coupon" bindtap="selectCoupon">
<text class="no-coupon">¥{{currentOrderList.freight}}</text>
</view>
</view>
</view>
<view class="coupon" wx:if="{{isSelect}}">
<view>
<text class="price-label">{{plusMemberName}}</text>
<text class="vip-desc"> (不可使用任何优惠或积分)</text>
<view class="select-coupon">
<text class="coupon-price">+¥{{plusMemberPrice}}</text>
<!--<image class="arrow-right" src="/assets/imgs/7_1_0/arrow-right.png" />-->
</view>
</view>
</view>
<view class="coupon">
<view>
<text class="price-label">运费</text>
<view class="select-coupon" bindtap="selectCoupon">
<text class="no-coupon">¥{{currentOrderList.freight}}</text>
</view>
</view>
</view>
<view class="coupon" wx:if="{{isSelect}}">
<view>
<text class="price-label">{{plusMemberName}}</text>
<text class="vip-desc"> (不可使用任何优惠或积分)</text>
<view class="select-coupon">
<text class="coupon-price">+¥{{plusMemberPrice}}</text>
<!--<image class="arrow-right" src="/assets/imgs/7_1_0/arrow-right.png" />-->
</view>
</view>
</view>
<!-- 配送方式 -->
<!-- <view class="deliveryType">
<view class="de-title">配送方式</view>
......@@ -239,10 +211,10 @@
</view>
</view>
</view>
</view>
</view>
</view>
<!-- <view class="pro-footer">
<!-- <view class="pro-footer">
<view class="cost">
<text class="cost-label">实付款:</text>
<text class="cost-price">¥{{utils.numberFormat(orderPrice)}}</text>
......@@ -254,17 +226,13 @@
<view class="footer-btns">
<view class="order-price-info">
<text class="cost-label">实付款:</text>
<text class="cost-price">¥{{utils.numberFormat(orderPrice)}}</text>
<text class="cost-price">¥{{utils.numberFormat(orderPrice)}}</text>
</view>
<button bind:tap="formSubmit" class="theme-color">立即购买</button>
</view>
</form>
</form>
</view>
<!--goHome-->
<go-home/>
<floatNav bind:getAuth="_getUserInfo" bind:updatePage="updatePage"/>
<select-coupon
show="{{showSelectCoupon}}"
bind:updateCoupon="updateCoupon"
coupon-list="{{couponDiscountPreviews}}"/>
<floatNav bind:getAuth="_getUserInfo" bind:updatePage="updatePage" />
<select-coupon show="{{showSelectCoupon}}" bind:updateCoupon="updateCoupon" coupon-list="{{couponDiscountPreviews}}" />
\ No newline at end of file
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