Commit cacf36db by 程南

订阅消息

parent 3f732f13
......@@ -6,899 +6,927 @@ 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,
citys: null,
cityView: '',
multiIndex: [0, 0, 0],
selectCityName: ['', ''],
wxAddress: false,
currentCoupon: '',
orderPrice: null, // 订单金额
orderInitPrice: 0,
plusMemberPrice: 0, // plus 默认价
plusMemberName: '',
defalutCoupon: '',
defalutCouponId: '', // 默认第一项
addressId: '', // 收货地址id
totalGoodsPrice : 0,
buyerRemark : '',//备注信息
currentType: 'delivery',//delivery 快递 selfPickUp 门店自提
storeInfo : {
storeName : '',
storeId : '',
storeAddress : '',
storeCode : ''
/**
* 页面的初始数据
*/
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,
citys: null,
cityView: '',
multiIndex: [0, 0, 0],
selectCityName: ['', ''],
wxAddress: false,
currentCoupon: '',
orderPrice: null, // 订单金额
orderInitPrice: 0,
plusMemberPrice: 0, // plus 默认价
plusMemberName: '',
defalutCoupon: '',
defalutCouponId: '', // 默认第一项
addressId: '', // 收货地址id
totalGoodsPrice: 0,
buyerRemark: '',//备注信息
currentType: 'delivery',//delivery 快递 selfPickUp 门店自提
storeInfo: {
storeName: '',
storeId: '',
storeAddress: '',
storeCode: ''
},
orderStoreInfo: null,
},
orderStoreInfo : null,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.hideShareMenu();
this.getMyLocationInfo();
console.log(this.data)
},
////获取位置信息并获取附近门店信息
getMyLocationInfo(cb) {
let _this = this;
if (!envInfo.isNeedGetLocation) {
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);
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.hideShareMenu();
this.getMyLocationInfo();
},
////获取位置信息并获取附近门店信息
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);
}
});
return;
}
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
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)
}
}
});
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
let pages = getCurrentPages();
let currPage = pages[pages.length - 1];
const { trolleySku2Buy } = this.options;
let tradeDto = {
trolleySku2Buy: JSON.parse(trolleySku2Buy)
}
// 下单 && 计算优惠价
this.setData({
trolleySku2Buy: tradeDto.trolleySku2Buy
}, () => {
this.initCitys()
// 地址列表
if (this.data.currentType == 'delivery'){
this.getAddressList()
}
else{
// 获取本地选择的门店信息
this.getLocalStoreInfo();
}
});
// 下单 && 计算优惠价
this.setData({
trolleySku2Buy: tradeDto.trolleySku2Buy
}, () => {
this.initCitys()
// 地址列表
if (this.data.currentType == 'delivery') {
this.getAddressList()
}
else {
// 获取本地选择的门店信息
this.getLocalStoreInfo();
}
});
//获取备注信息
this.getLocalRemarkInfo();
},
//获取备注信息
this.getLocalRemarkInfo();
},
//获取备注信息
getLocalRemarkInfo(){
this.data.buyerRemark = wx.getStorageSync('orderRemark');
this.setData({
buyerRemark: this.data.buyerRemark
})
},
//输入备注
onTapInputRemark(){
wx.navigateTo({
url: '/pages/remark/remark',
});
},
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 : '',
}
}
getLocalRemarkInfo() {
this.data.buyerRemark = wx.getStorageSync('orderRemark');
this.setData({
buyerRemark: this.data.buyerRemark
})
},
this.setData({
storeInfo: this.data.storeInfo
});
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)
},
//切换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 折扣券
if(!e.detail) {
this.setData({
defalutCoupon: 0,
couponId: '',
couponSettingId: '',
defalutCouponId: '',
currentCoupon : 0,
},() => {
this.setPayPrice();
});
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({
defalutCoupon: true,
defalutCouponId: finCouponId ? '' : defalutCouponId,
[finCouponName] : finCouponId,
// couponId: id,
haveCoupon: true,
currentCoupon: `${faceAmount / 100} 元`
})
} else if (type == 2) {
// let discounPrice = (faceAmount / 100) * (orderPrice)
// let spread = Math.round(orderPrice - discounPrice)
this.setData({
defalutCoupon: true,
[finCouponName] : finCouponId,
defalutCouponId: finCouponId ? '' : defalutCouponId,
// couponId: id,
haveCoupon: true,
currentCoupon: `${couponDiscount} 元`
});
}
// 实付款
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
// 实际价格 - 优惠价 + 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'
//输入备注
onTapInputRemark() {
wx.navigateTo({
url: '/pages/remark/remark',
});
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){
},
}
}
})
onUnload() {
wx.removeStorageSync('orderRemark');
wx.removeStorageSync('choosedStoreInfo');
},
return;
}
}
//判断是不是快递配送
if (this.data.currentType == 'delivery'){
const { goodsAddress } = this.data
// 保存地址 && 支付
if (goodsAddress) {
if (!e.detail.value.name) {
wx.showToast({
title: `请输入姓名`,
icon: 'none'
})
return false;
}
if (!e.detail.value.phone) {
wx.showToast({
title: `请输入电话`,
icon: 'none'
})
return false;
//获取本地选择的门店信息
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;
}
if (!this.data.cityView) {
wx.showToast({
title: `请选择地区`,
icon: 'none'
})
return false;
}
if (!e.detail.value.address) {
wx.showToast({
title: `请输入详细地址`,
icon: 'none'
})
return false;
else {
this.data.storeInfo = {
storeName: '',
storeId: '',
storeAddress: '',
storeCode: '',
}
}
const { memberId } = wx.getStorageSync('_baseUserInfo')
this.setData({
params: {
userId: memberId,
name: e.detail.value.name,
phone: e.detail.value.phone,
province: this.data.params.province,
city: this.data.params.city,
district: this.data.params.district,
address: e.detail.value.address,
type: this.data.isSelect ? 1 : 0
}
storeInfo: this.data.storeInfo
});
wx.showLoading({
title: '加载中'
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)
},
//切换tab
onTapChangeType(e) {
let type = e.currentTarget.dataset.type;
this.setData({
currentType: type
});
wxService.post(`/member/addressManage/save`, this.data.params).then(res => {
const { result } = res.data
if (result == 0) {
wx.hideLoading()
wx.showToast({
title: `保存成功`,
icon: 'none'
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 折扣券
if (!e.detail) {
this.setData({
defalutCoupon: 0,
couponId: '',
couponSettingId: '',
defalutCouponId: '',
currentCoupon: 0,
}, () => {
this.setPayPrice();
});
this.data.addressId = res.data.data;
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({
addressId: this.data.addressId
defalutCoupon: true,
defalutCouponId: finCouponId ? '' : defalutCouponId,
[finCouponName]: finCouponId,
// couponId: id,
haveCoupon: true,
currentCoupon: `${faceAmount / 100} 元`
})
} else if (type == 2) {
// let discounPrice = (faceAmount / 100) * (orderPrice)
// let spread = Math.round(orderPrice - discounPrice)
this.setData({
defalutCoupon: true,
[finCouponName]: finCouponId,
defalutCouponId: finCouponId ? '' : defalutCouponId,
// couponId: id,
haveCoupon: true,
currentCoupon: `${couponDiscount} 元`
});
}
// 调起支付
this.handelGobuy()
}
})
} 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(' ')
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) => {
if (item.value == cityName) {
item.children.forEach((cityItem) => {
cityList.push(cityItem.value)
cityItem.children.forEach((districtItem) => {
district.push(districtItem.value)
})
})
}
})
// 实付款
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
// 实际价格 - 优惠价 + plus
this.setData({
'citys[1]': cityList,
'citys[2]': district
// orderPrice: Math.round(orderInitPrice - orderCoupon)
// orderPrice: orderInitPrice - orderCoupon + plusPrice
orderPrice: orderInitPrice - calCouponPrice + plusPrice
})
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)
})
},
//提交按钮
formSubmit(e) {
//判断是不是开卡了
if (this.data.orderingMustOpenCard) {
let baseInfo = wx.getStorageSync('_baseUserInfo');
if (!baseInfo) {
wx.showToast({
title: '你还未登录,请先去登录',
icon: 'none'
});
return;
}
})
})
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: ''
}, () => {
const { trolleySku2Buy, checkByPremium, addressId, addressInfo } = this.data
let params = {
checkByPremium,
trolleySku2Buy,
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;
}
}
// 增加门店自提和快递配送判断
//判断是不是快递配送
if (this.data.currentType == 'delivery') {
params.addressId = addressId ? addressId : addressInfo.id // 微信地址 or 地址id
params.orderType = 1;
const { goodsAddress } = this.data
// 保存地址 && 支付
if (goodsAddress) {
if (!e.detail.value.name) {
wx.showToast({
title: `请输入姓名`,
icon: 'none'
})
return false;
}
if (!e.detail.value.phone) {
wx.showToast({
title: `请输入电话`,
icon: 'none'
})
return false;
}
if (!this.data.cityView) {
wx.showToast({
title: `请选择地区`,
icon: 'none'
})
return false;
}
if (!e.detail.value.address) {
wx.showToast({
title: `请输入详细地址`,
icon: 'none'
})
return false;
}
const { memberId } = wx.getStorageSync('_baseUserInfo')
this.setData({
params: {
userId: memberId,
name: e.detail.value.name,
phone: e.detail.value.phone,
province: this.data.params.province,
city: this.data.params.city,
district: this.data.params.district,
address: e.detail.value.address,
type: this.data.isSelect ? 1 : 0
}
});
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'
});
this.data.addressId = res.data.data;
this.setData({
addressId: this.data.addressId
});
// 调起支付
this.handelGobuy()
}
})
} else {
// 调起支付
this.handelGobuy()
}
}
else{
params.orderType = 4;
params.storeId = this.data.storeInfo.storeId;
else {
this.handelGobuy()
}
this.calPreferentialPrice(params) // 重新计算优惠价
// 获取默认付费会员设置
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()
})
},
initCitys() {
let cityData = [];
//热风地址库特殊处理
if (envInfo.brandId == 2010) {
//由于地址框太大了,现在先用热风的一个
cityData = city.default;
}
}
})
},
// 默认地址
selectAddress() {
wxService.router('/pages/myAddress/myAddress?isFrom=order')
},
// 计算优惠价
calPreferentialPrice(params) {
wx.showLoading({
title: '加载中'
});
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({
selectPrice: sum
})
} else {
this.setData({
noSelectPrice: sum
})
}
//获取优惠券信息
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 :[];
// id / couponSettingId
this.setData({
currentOrderList: data,
defalutCoupon: defalutCoupon,
defalutCouponId: defalutCouponId,
couponSettingId: couponSettingId,
orderInitPrice: data.amount,
totalGoodsPrice: this.data.totalGoodsPrice
}, () => {
// 实付款
this.setPayPrice()
})
else {
cityData = city.default;
}
}
})
},
//跳转购买
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
}
}
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
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)
})
})
//判断addressId是不是有
if (!params.addressId) {
wx.showToast({
title: '请添加地址或选择地址',
icon: 'none'
this.setData({
citys: [province, cityList, district]
})
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){
wx.showToast({
title: '门店自提需要选择门店',
icon: 'none'
},
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(' ')
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) => {
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
this.setData({
checkByPremium: isSelect,
defalutCoupon: 0,
couponId: '',
couponSettingId: '',
defalutCouponId: ''
}, () => {
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()
})
});
},
// /premium/getDefault
getPremiumDefault() {
wx.showLoading({
title: '加载中'
})
return;
}
}
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')
},
// 计算优惠价
calPreferentialPrice(params) {
wx.showLoading({
title: '加载中'
});
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);
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({
selectPrice: sum
})
} else {
this.setData({
noSelectPrice: sum
})
}
//获取优惠券信息
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 : [];
// id / couponSettingId
this.setData({
currentOrderList: data,
defalutCoupon: defalutCoupon,
defalutCouponId: defalutCouponId,
couponSettingId: couponSettingId,
orderInitPrice: data.amount,
totalGoodsPrice: this.data.totalGoodsPrice
}, () => {
// 实付款
this.setPayPrice()
})
}
}
})
},
//跳转购买
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
}
}
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
});
}
},
})
let params = {
[finCouponName]: finCouponId,
// couponId: couponId? couponId : defalutCouponId,
trolleySku2Buy,
buyerRemark: this.data.buyerRemark,
}
}
});
},
//下单
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 _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
wx.removeStorageSync('choosedStoreInfo');
wx.removeStorageSync('orderRemark');
if (result == 0) {
delete data.appId
let amount = data.amount || 0
wx.requestPayment(Object.assign({
success(res) {
wx.hideLoading()
// 支付成功页面
wx.redirectTo({
url: `/subPackage/page/pages/paymentStatus/paymentStatus?status=S&amount=${amount}&type=${_this.data.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',
});
}
//判断是快递下单还是自提下单
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;
}
}, data.wxParams));
}
}
});
},
//校验订单中商品限购情况
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
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;
}
});
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
}
});
}
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.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
});
}
},
})
}
}
});
},
//下单
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;
}
}
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
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
}
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
wx.requestPayment(Object.assign({
success(res) {
wx.hideLoading()
// 支付成功页面
let baseUserInfo = wx.getStorageSync('_baseUserInfo');
wxService.post(`${'/merchant/message/wxSubMsgMapping/getListByParams'}`, {
scenarioIds: ['ordersend', 'ordersign'],
sourceFrom: 2,
switchType: 3
}).then(res => {
let tempArr = res.data.data;
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=${_this.data.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));
}
}
});
},
//校验订单中商品限购情况
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;
}
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;
}
this.setData({
addressInfo: this.data.addressInfo,
addressId: this.data.addressId,
goodsAddress: params.addressId ? false : true,
});
}
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
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)
this.setData({
addressId: data,
goodsAddress: true,
},() => {
this.getAddressList();
})
}
}).finally(() => {
wx.hideLoading()
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)
}
})
},
},
fail: function (err) {
console.log(err)
}
})
},
//选择优惠券
selectCoupon() {
this.setData({
showSelectCoupon: true
})
}
//选择优惠券
selectCoupon() {
this.setData({
showSelectCoupon: true
})
}
});
\ No newline at end of file
......@@ -10,7 +10,7 @@
data-type="selfPickUp" bindtap="onTapChangeType">门店自提</view>
</view>
<form bindsubmit="formSubmit">
<form>
<!-- 快递地址 -->
<view class="address-wrap" wx:if="{{currentType == 'delivery'}}">
<block wx:if="{{goodsAddress}}">
......@@ -244,7 +244,7 @@
<text class="cost-label">实付款:</text>
<text class="cost-price">¥{{utils.numberFormat(orderPrice)}}</text>
</view>
<button form-type="submit" class="theme-color">立即购买</button>
<button bind:tap="formSubmit" class="theme-color">立即购买</button>
</view>
</form>
</view>
......
......@@ -6,318 +6,350 @@ const envInfo = require('../../config/index').envInfo
wxService.page({
/**
* 页面的初始数据
*/
data: {
imageDomain: '',
refundCreateDto: {
reason: "", // 原因
skuList: [],
tradeId: 0,
proofImgUrls: [] //凭证
data: {
imageDomain: '',
refundCreateDto: {
reason: "", // 原因
skuList: [],
tradeId: 0,
proofImgUrls: [] //凭证
},
refundMark: '',
cartList: [],
curType: { // 当前选择原因
value: 0,
name: '请选择'
},
// 所有退货原因
resonType: [],
refundAmount: 0,
checkedColor: 'rgb(203, 60, 60)',
pics: [],
id: '',
returnOrder: 0
},
refundMark: '',
cartList: [],
curType: { // 当前选择原因
value: 0,
name: '请选择'
submitRefund() {
var selectGoods = this.data.cartList.filter(item => item.checked)
if (selectGoods.length == 0) {
wx.showToast({
title: '请选择退款商品',
icon: 'none'
})
return false
}
if (this.data.curType.value == 0) {
wx.showToast({
title: '请选择退款原因',
icon: 'none'
})
return false
}
let skulist = [];
selectGoods.forEach(item => {
const { skuId, count } = item;
skulist.push({
skuId,
count
})
});
this.reFundPreview({
tradeId: this.data.id,
skuList: skulist
})
var refundCreateDto = this.data.refundCreateDto
refundCreateDto.reason = this.data.curType.name // 退款原因
refundCreateDto.remark = this.data.refundMark// 说明备注
refundCreateDto.skuList = selectGoods.map(function (item) {
return {
amount: item.amount,
count: item.count,
skuId: item.skuId
}
})
this.handelRequestRefund(refundCreateDto)
},
// 所有退货原因
resonType: [],
refundAmount: 0,
checkedColor: 'rgb(203, 60, 60)',
pics: [],
id: '',
returnOrder: 0
},
submitRefund() {
var selectGoods = this.data.cartList.filter(item => item.checked)
if (selectGoods.length == 0) {
wx.showToast({
title: '请选择退款商品',
icon: 'none'
})
return false
}
if (this.data.curType.value == 0) {
wx.showToast({
title: '请选择退款原因',
icon: 'none'
})
return false
}
//创建退款
handelRequestRefund(params) {
let _self = this;
wx.showLoading({
title: '加载中',
mask: true
})
wxService.post('/sale/refund/buyer/create', params).then(res => {
if (res) {
const { result, data } = res.data
if (result == 0) {
wx.hideLoading()
let skulist = [];
selectGoods.forEach(item=>{
const {skuId,count} = item;
skulist.push({
skuId,
count
})
});
let baseUserInfo = wx.getStorageSync('_baseUserInfo');
wxService.post(`${'/merchant/message/wxSubMsgMapping/getListByParams'}`, {
scenarioIds: ['orderrefundfinsh', 'orderrefundcheck'],
sourceFrom: 2,
switchType: 3
}).then(res => {
let tempArr = res.data.data;
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: _self.data.id,
memberId: baseUserInfo.memberId,
scenarioId:tempArr[i].scenarioId,
templateId: tempArr[i].templateId
}).then(resp => { })
}
},
complete: (res)=>{
wx.showToast({
title: '申请退款成功',
});
// 订单列表
setTimeout(() => {
// wxService.router(`/pages/order/order`).search({params})
wx.navigateBack({
delta: 1
});
}, 2000)
}
})
})
this.reFundPreview({
tradeId: this.data.id,
skuList:skulist
})
var refundCreateDto = this.data.refundCreateDto
refundCreateDto.reason = this.data.curType.name // 退款原因
refundCreateDto.remark = this.data.refundMark// 说明备注
refundCreateDto.skuList = selectGoods.map(function (item) {
return {
amount: item.amount,
count: item.count,
skuId: item.skuId
}
})
this.handelRequestRefund(refundCreateDto)
},
//创建退款
handelRequestRefund(params) {
wx.showLoading({
title: '加载中',
mask: true
})
wxService.post('/sale/refund/buyer/create', params).then(res => {
if (res) {
const { result, data } = res.data
if (result == 0) {
wx.hideLoading()
wx.showToast({
title: '申请退款成功',
});
// 订单列表
setTimeout(() => {
// wxService.router(`/pages/order/order`).search({params})
wx.navigateBack({
delta : 1
});
}, 2000)
}
}
})
},
//获取退款原因列表
getReasonList() {
wx.showLoading({
title: '加载中',
mask: true
})
const refundReason = {}
wxService.post('/sale/refund/reason/buyer/sortAll', refundReason).then(res => {
if (res) {
const { result, data } = res.data
if (result == 0) {
wx.hideLoading()
let newReasonList = [];
data.forEach((item, index) => {
const { reason } = item;
newReasonList.push({
name: reason,
value: index + 1
})
});
this.setData({
resonType: newReasonList
})
}
}
})
},
// 上传图片
_uploadImg(e) {
if (e.detail) {
this.data.refundCreateDto.proofImgUrls.push(e.detail)
this.setData({
'refundCreateDto.proofImgUrls': this.data.refundCreateDto.proofImgUrls
})
}
}
})
},
},
//获取退款原因列表
getReasonList() {
wx.showLoading({
title: '加载中',
mask: true
})
const refundReason = {}
wxService.post('/sale/refund/reason/buyer/sortAll', refundReason).then(res => {
if (res) {
const { result, data } = res.data
if (result == 0) {
wx.hideLoading()
checkPro(e) {
var index = e.currentTarget.dataset.index
const { cartList } = this.data
if (cartList[index].checked) {
cartList[index].checked = false
} else {
cartList[index].checked = true
}
this.setData({
cartList
}, () => {
this.getReturnPrice()
})
},
changeRemark(event) { // 备注
this.setData({
refundMark: event.detail.value
})
},
selectType: function (event) { // 选择退货类型
this.setData({
curType: this.data.resonType[event.detail.value]
})
},
minusNum: function (e) { // 减少数量
var cartList = this.data.cartList
var index = e.currentTarget.dataset.index
let proNum = cartList[index].count
let newReasonList = [];
data.forEach((item,index)=>{
const {reason} = item;
newReasonList.push({
name: reason,
value: index + 1
if (proNum > 1) {
proNum--
} else {
wx.showToast({
title: '数量不能为0',
icon: 'none'
})
});
this.setData({
resonType: newReasonList
})
return false
}
cartList[index].count = proNum
this.setData({
cartList: cartList
}, () => {
this.getReturnPrice()
this.editOk(cartList[index]) //调用完成
})
},
//新增数量
addNum: function (e) { // 增加数量
var index = e.currentTarget.dataset.index
var cartList = this.data.cartList
var proNum = cartList[index].count;
if (proNum < cartList[index].canRefundNum) {
proNum++
}
else {
wx.showToast({
title: '退单数量不能大于当前商品购买数量',
icon: 'none'
});
return;
}
}
})
},
// 上传图片
_uploadImg(e) {
if (e.detail) {
this.data.refundCreateDto.proofImgUrls.push(e.detail)
this.setData({
'refundCreateDto.proofImgUrls': this.data.refundCreateDto.proofImgUrls
})
}
},
checkPro(e) {
var index = e.currentTarget.dataset.index
const { cartList } = this.data
if (cartList[index].checked) {
cartList[index].checked = false
} else {
cartList[index].checked = true
}
this.setData({
cartList
},()=>{
this.getReturnPrice()
})
},
changeRemark(event) { // 备注
this.setData({
refundMark: event.detail.value
})
},
selectType: function (event) { // 选择退货类型
this.setData({
curType: this.data.resonType[event.detail.value]
})
},
minusNum: function (e) { // 减少数量
var cartList = this.data.cartList
var index = e.currentTarget.dataset.index
let proNum = cartList[index].count
cartList[index].count = proNum
this.setData({
cartList: cartList
}, () => {
this.getReturnPrice()
this.editOk(cartList[index]) //调用完成
})
if (proNum > 1) {
proNum--
} else {
wx.showToast({
title: '数量不能为0',
icon: 'none'
})
return false
}
cartList[index].count = proNum
this.setData({
cartList: cartList
}, () => {
this.getReturnPrice()
this.editOk(cartList[index]) //调用完成
})
},
//新增数量
addNum: function (e) { // 增加数量
var index = e.currentTarget.dataset.index
var cartList = this.data.cartList
var proNum = cartList[index].count;
if (proNum < cartList[index].canRefundNum){
proNum++
}
else{
wx.showToast({
title: '退单数量不能大于当前商品购买数量',
icon : 'none'
});
return ;
}
},
blurNum: function (e) { // 输入数量
var newNum = e.detail.value
var cartList = this.data.cartList
var index = e.currentTarget.dataset.index
var refundNum = cartList[index].count
cartList[index].count = proNum
this.setData({
cartList: cartList
}, () => {
this.getReturnPrice()
this.editOk(cartList[index]) //调用完成
})
if (newNum === '' || newNum === '0') {
newNum = 1
} else {
newNum = parseInt(newNum)
if (newNum > refundNum) {
newNum = refundNum
} else {
newNum = newNum
}
}
cartList[index].count = newNum
},
blurNum: function (e) { // 输入数量
var newNum = e.detail.value
var cartList = this.data.cartList
var index = e.currentTarget.dataset.index
var refundNum = cartList[index].count
this.setData({
cartList: cartList
}, () => {
this.getReturnPrice()
this.editOk(cartList[index]) //调用完成
})
},
editOk(cartPro) {
let skulist = [];
const { skuId, count } = cartPro;
skulist.push({
skuId,
count
})
if (newNum === '' || newNum === '0') {
newNum = 1
} else {
newNum = parseInt(newNum)
if (newNum > refundNum) {
newNum = refundNum
} else {
newNum = newNum
}
}
cartList[index].count = newNum
this.reFundPreview({
tradeId: this.data.id,
skuList: skulist
}) // 退款预览
},
getReturnPrice() {
var cartList = this.data.cartList
var returnPrice = 0
this.setData({
cartList: cartList
}, () => {
this.getReturnPrice()
this.editOk(cartList[index]) //调用完成
})
},
editOk(cartPro){
let skulist = [];
const {skuId,count} = cartPro;
skulist.push({
skuId,
count
})
this.reFundPreview({
tradeId: this.data.id,
skuList:skulist}) // 退款预览
},
getReturnPrice() {
var cartList = this.data.cartList
var returnPrice = 0
for (let i = 0; i < cartList.length; i++) {
if (cartList[i].checked) {
returnPrice += cartList[i].paySkuPrice * (cartList[i].count ? cartList[i].count : 1)
}
}
for (let i = 0; i < cartList.length; i++) {
if (cartList[i].checked) {
returnPrice += cartList[i].paySkuPrice * (cartList[i].count ? cartList[i].count : 1)
}
}
let tempPrice = parseInt(returnPrice * 100);
let tempPrice = parseInt(returnPrice * 100);
this.setData({
returnOrder: parseFloat(tempPrice / 100).toFixed(2)
})
},
this.setData({
returnOrder: parseFloat(tempPrice/100).toFixed(2)
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.hideShareMenu();
const { params } = options;
let detail = JSON.parse(params)
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.hideShareMenu();
const { params } = options;
let detail = JSON.parse(params)
// item.checked
detail.skuVOList.forEach(item => {
item.checked = false;
let paySkuPrice = parseInt(item.amount * 100 / item.totalCount);
item.paySkuPrice = (paySkuPrice/100).toFixed(2);
});
// item.checked
detail.skuVOList.forEach(item => {
item.checked = false;
let paySkuPrice = parseInt(item.amount * 100 / item.totalCount);
item.paySkuPrice = (paySkuPrice / 100).toFixed(2);
});
this.setData({
id: detail.id,
cartList: detail.skuVOList,
refundAmount: detail.payAmount,
'refundCreateDto.tradeId': detail.id
}, () => {
// 退款原因列表 /refund/reason/buyer/sortAll
this.getReasonList()
})
},
this.setData({
id: detail.id,
cartList: detail.skuVOList,
refundAmount: detail.payAmount,
'refundCreateDto.tradeId': detail.id
}, () => {
// 退款原因列表 /refund/reason/buyer/sortAll
this.getReasonList()
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
//退款prever
reFundPreview(cartPro = {}) {
const params = { ...cartPro }
wx.showLoading({
title: '加载中',
mask: true
})
wxService.post(`/sale/refund/buyer/preview`, params).then(res => {
if (res) {
const { result, data } = res.data
if (result == 0) {
wx.hideLoading()
}
}
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
//退款prever
reFundPreview(cartPro={}) {
const params = {...cartPro}
wx.showLoading({
title: '加载中',
mask: true
})
wxService.post(`/sale/refund/buyer/preview`,params).then(res => {
if (res) {
const { result, data } = res.data
if (result == 0) {
wx.hideLoading()
}
}
})
},
});
\ No newline at end of file
......@@ -43,7 +43,7 @@
"list": []
},
"miniprogram": {
"current": 80,
"current": -1,
"list": [
{
"id": -1,
......@@ -149,7 +149,7 @@
"id": 16,
"name": "商品详情页",
"pathName": "pages/productDetail/productDetail",
"query": "id=686861371018723328",
"query": "id=647096699302580224",
"scene": null
},
{
......
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