Browse Source

产品下单接入补贴

产品下单接入补贴
master
xuetaotao 4 years ago
parent
commit
bd2f995e80
  1. 18
      pages/info/postProductInfo/index.js
  2. 6
      pages/info/postProductInfo/index.wxml
  3. 27
      pages/info/postProductInfo/index.wxss
  4. 242
      pages/order/postOrder/index.js
  5. 14
      pages/order/postOrder/index.wxml
  6. 48
      pages/order/postOrder/index.wxss
  7. 156
      utils/https.js

18
pages/info/postProductInfo/index.js

@ -68,15 +68,15 @@ Page({
}) })
// 获取补贴 // 获取补贴
// commonApi.user_post("product/getProductAllowancePrice", { commonApi.user_post("product/getProductAllowancePrice", {
// product_code: res.data.product_code product_code: res.data.product_code
// }).then(resTwo => { }).then(resTwo => {
// if (resTwo) { if (resTwo && resTwo.code == 1) {
// this.setData({ this.setData({
// allowance_data: resTwo.data allowance_data: resTwo.data
// }) })
// } }
// }) })
this.BroswerRecord() this.BroswerRecord()
}) })
// 获取评价列表 // 获取评价列表

6
pages/info/postProductInfo/index.wxml

@ -20,7 +20,7 @@
</swiper> </swiper>
<view class="allowance-box" wx:if="{{allowance_data}}"> <view class="allowance-box" wx:if="{{allowance_data}}">
补贴价 补贴价
<view class="com-price two">{{ allowance_data.mini_price / 100 }}</view> <view class="com-price two">{{ allowance_data.mini_price / 100 }}</view>
<view class="yellow">单品最高补贴{{ allowance_data.max_price / 100 }}元</view> <view class="yellow">单品最高补贴{{ allowance_data.max_price / 100 }}元</view>
</view> </view>
<view class="top-info" wx:if="{{info}}"> <view class="top-info" wx:if="{{info}}">
@ -107,7 +107,9 @@
<view class="sku-info-box"> <view class="sku-info-box">
<image id="skuImg" src="{{info.sku[skuIndex].headimg}}" mode="aspectFill"></image> <image id="skuImg" src="{{info.sku[skuIndex].headimg}}" mode="aspectFill"></image>
<view class="sku-info"> <view class="sku-info">
<view class="sku-price">{{info.sku[skuIndex].price/100}}</view> <view class="sku-price">{{info.sku[skuIndex].price/100}}
<view class="allowance" wx:if="{{allowance_data}}">补贴价:¥{{ (1 - allowance_data.discount_rate / 100) * info.sku[skuIndex].price / 100 }}</view>
</view>
<view class="sku-name">已选择:{{info.sku[skuIndex].sku_name}}</view> <view class="sku-name">已选择:{{info.sku[skuIndex].sku_name}}</view>
</view> </view>
</view> </view>

27
pages/info/postProductInfo/index.wxss

@ -20,7 +20,7 @@ page {
background: white; background: white;
position: relative; position: relative;
z-index: 1; z-index: 1;
margin-top: -20rpx; margin-top: -60rpx;
padding: 20rpx 40rpx; padding: 20rpx 40rpx;
} }
@ -483,12 +483,26 @@ page {
font-weight: 500; font-weight: 500;
color: #D62828; color: #D62828;
margin: 20rpx 0; margin: 20rpx 0;
display: flex;
justify-content: flex-start;
align-items: center;
} }
.sku-price::before { .sku-price::before {
content: "¥"; content: "¥";
font-weight: 400; font-weight: 400;
font-size: 27rpx; font-size: 27rpx;
vertical-align: baseline;
}
.sku-price view {
font-size: 24rpx;
color: #FFFFFF;
background-color: #D62828;
border-radius: 22rpx;
line-height: 44rpx;
margin-left: 7rpx;
padding: 0 20rpx;
} }
.sku-name { .sku-name {
@ -743,15 +757,18 @@ page {
} }
.allowance-box { .allowance-box {
height: 114rpx; height: 113rpx;
background-image: url("/static/images/detail/allowanceBacTwo.png"); background: url("https://sz-qd.oss-cn-hangzhou.aliyuncs.com/uploads/20220602/7762b9c4be5adac1f3d0ab5228569821.png");
padding: 20rpx 10rpx; background-size: 100% auto;
font-size: 18rpx; background-repeat: no-repeat;
padding: 30rpx 30rpx 10rpx;
font-size: 24rpx;
color: #FFFFFF; color: #FFFFFF;
margin-top: -60rpx; margin-top: -60rpx;
position: relative; position: relative;
display: flex; display: flex;
justify-content: start; justify-content: start;
align-items: baseline;
} }
.allowance-box .com-price { .allowance-box .com-price {

242
pages/order/postOrder/index.js

@ -7,16 +7,19 @@ Page({
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
product:[], product: [],
showPrice:0, showPrice: 0,
from:null, from: null,
address:null, address: null,
postFee:0, postFee: 0,
coupon:null, coupon: null,
sku_id:'', sku_id: '',
kjId:null, kjId: null,
gp_id:null, gp_id: null,
prizeId:null prizeId: null,
select_allowance: false,
allowance_data: null,
allowance_price: 0,
}, },
/** /**
@ -24,196 +27,210 @@ Page({
*/ */
onLoad: function (options) { onLoad: function (options) {
this.setData({ this.setData({
from:options.from, from: options.from,
kjId:app.globalData.kjId, kjId: app.globalData.kjId,
gp_id:app.globalData.gp_id || app.globalData.team_id, gp_id: app.globalData.gp_id || app.globalData.team_id,
prizeId:wx.getStorageSync('prizeId') prizeId: wx.getStorageSync('prizeId')
}) })
let price = 0,sku_id=[]; let price = 0, sku_id = [];
app.globalData.postProduct.map(item=>{ app.globalData.postProduct.map(item => {
if(!app.globalData.kjId && !this.data.gp_id){ if (!app.globalData.kjId && !this.data.gp_id) {
price = price + item.sku.price * item.productNum; price = price + item.sku.price * item.productNum;
} }
else if(this.data.gp_id){ else if (this.data.gp_id) {
price = price + item.sku.event_price * item.productNum; price = price + item.sku.event_price * item.productNum;
} }
sku_id.push(item.sku.id) sku_id.push(item.sku.id)
}) })
this.setData({ this.setData({
product:app.globalData.postProduct, product: app.globalData.postProduct,
showPrice:app.globalData.kjId?0:price, showPrice: app.globalData.kjId ? 0 : price,
sku_id:sku_id.join(",") sku_id: sku_id.join(",")
}) })
if(!this.data.kjId && !this.data.gp_id){ if (!this.data.kjId && !this.data.gp_id) {
this.couponCom = this.selectAllComponents("#coupon")[0]; this.couponCom = this.selectAllComponents("#coupon")[0];
} }
}, },
inputRemark:function(e){ inputRemark: function (e) {
let index = e.currentTarget.dataset.index,product = this.data.product; let index = e.currentTarget.dataset.index, product = this.data.product;
product[index].remark = e.detail.value; product[index].remark = e.detail.value;
this.setData({ this.setData({
product:product product: product
}) })
}, },
setAddress:function(e){ setAddress: function (e) {
this.setData({ this.setData({
address:e.detail address: e.detail
}) })
this.getPostFee() this.getPostFee()
}, },
minus:function(e){ minus: function (e) {
let index = e.currentTarget.dataset.index,product = this.data.product; let index = e.currentTarget.dataset.index, product = this.data.product;
let productNum = product[index].productNum; let productNum = product[index].productNum;
if(productNum<=1) return; if (productNum <= 1) return;
product[index].productNum--; product[index].productNum--;
this.setData({ this.setData({
product:product, product: product,
coupon:null coupon: null
}) })
this.getPostFee() this.getPostFee()
this.changePrice() this.changePrice()
}, },
add:function(e){ add: function (e) {
let index = e.currentTarget.dataset.index,product = this.data.product; let index = e.currentTarget.dataset.index, product = this.data.product;
product[index].productNum = product[index].productNum+1; product[index].productNum = product[index].productNum + 1;
this.setData({ this.setData({
product:product, product: product,
coupon:null coupon: null
}) })
this.getPostFee() this.getPostFee()
this.changePrice() this.changePrice()
}, },
changePrice:function(){ changePrice: function () {
let product = this.data.product,price=0; let product = this.data.product, price = 0;
product.map(item=>{ product.map(item => {
price = price + item.sku.price * item.productNum; price = price + item.sku.price * item.productNum;
if (this.data.allowance_data && this.data.select_allowance && this.data.allowance_price) {
let spread_price = Number(this.data.allowance_data.discount_limit_price - this.data.allowance_data.user_used_price);
price -= this.data.allowance_price * item.productNum < spread_price ? this.data.allowance_price * item.productNum : spread_price
}
}) })
if(this.data.coupon && this.data.showPrice!=price){ if (this.data.coupon && this.data.showPrice != price) {
wx.showToast({ wx.showToast({
title: '订单价格发生变化,请重新选择优惠券', title: '订单价格发生变化,请重新选择优惠券',
icon: 'none' icon: 'none'
}) })
app.globalData.couponInfo = null; app.globalData.couponInfo = null;
if(!this.data.kjId && !this.data.gp_id){ if (!this.data.kjId && !this.data.gp_id) {
this.couponCom.setNullCoupon() this.couponCom.setNullCoupon()
} }
this.setData({ this.setData({
coupon:null coupon: null
}) })
} }
this.setData({ this.setData({
showPrice:app.globalData.kjId?0:price showPrice: app.globalData.kjId ? 0 : price
}) })
}, },
order:function(){ order: function () {
if(!this.data.address){ if (!this.data.address) {
wx.showToast({ wx.showToast({
title: '请选择收货地址!', title: '请选择收货地址!',
icon:'none' icon: 'none'
}) })
return; return;
} }
let product = this.data.product,product_list=[]; let product = this.data.product, product_list = [];
product.map(item=>{ product.map(item => {
let productItem = { let productItem = {
type:item.product.type, type: item.product.type,
product_id:item.product.id, product_id: item.product.id,
sku_id:item.sku.id, sku_id: item.sku.id,
post:this.data.address.id, post: this.data.address.id,
product_num:item.productNum, product_num: item.productNum,
remark:item.remark remark: item.remark
} }
product_list.push(productItem) product_list.push(productItem)
}) })
let data = { let data = {
source:"WECHATXCX", source: "WECHATXCX",
product_list:product_list, product_list: product_list,
coupon:this.data.coupon?this.data.coupon.id:null, coupon: this.data.coupon ? this.data.coupon.id : null,
originate_order_id:this.data.kjId, originate_order_id: this.data.kjId,
gp_id:app.globalData.gp_id, gp_id: app.globalData.gp_id,
team_id:app.globalData.team_id team_id: app.globalData.team_id
}; };
if(app.globalData.from){ if (this.data.select_allowance) data.is_allowance = 1
if (app.globalData.from) {
data.system_name = app.globalData.from; data.system_name = app.globalData.from;
} }
if(app.globalData.retailId){ if (app.globalData.retailId) {
data.commission_code = app.globalData.retailId; data.commission_code = app.globalData.retailId;
app.globalData.retailId = null; app.globalData.retailId = null;
} }
if(this.data.prizeId){ if (this.data.prizeId) {
data.lottery_id = this.data.prizeId data.lottery_id = this.data.prizeId
} }
if(app.globalData.category_id){ if (app.globalData.category_id) {
data.category_id = app.globalData.category_id; data.category_id = app.globalData.category_id;
} }
commonApi.user_post("order/create",{ commonApi.user_post("order/create", {
data:JSON.stringify(data) data: JSON.stringify(data)
}).then(res=>{ }).then(res => {
if(app.globalData.kjId){ if (app.globalData.kjId) {
app.globalData.kjId = null; app.globalData.kjId = null;
this.setData({ this.setData({
kjId:null kjId: null
}) })
this.onLoad({}) this.onLoad({})
} }
app.globalData.gp_id = null; app.globalData.gp_id = null;
app.globalData.team_id = null; app.globalData.team_id = null;
this.setData({ this.setData({
gp_id:null gp_id: null
}) })
this.onLoad({}); this.onLoad({});
}) })
}, },
getPostFee:function(){ getPostFee: function () {
if(!this.data.address) return; if (!this.data.address) return;
let product = this.data.product,list=[],that = this; let product = this.data.product, list = [], that = this;
product.map(item=>{ product.map(item => {
list.push(commonApi.user_post("order/get_post_price",{ list.push(commonApi.user_post("order/get_post_price", {
sku_id:item.sku.id, sku_id: item.sku.id,
num:item.productNum, num: item.productNum,
consignee_id:that.data.address.id consignee_id: that.data.address.id
})) }))
}) })
// 获取邮费 // 获取邮费
Promise.all(list).then(res=>{ Promise.all(list).then(res => {
let postFee = 0,flag = true; let postFee = 0, flag = true;
res.map((item,index)=>{ res.map((item, index) => {
if(item.data.price<0) flag = false; if (item.data.price < 0) flag = false;
postFee = postFee+Number(item.data.price); postFee = postFee + Number(item.data.price);
product[index].postFee = item.data.price; product[index].postFee = item.data.price;
}) })
if(!flag){ if (!flag) {
wx.showToast({ wx.showToast({
title: '该地区不发货', title: '该地区不发货',
icon:'none' icon: 'none'
}) })
product.map(item=>{ product.map(item => {
item.postFee = 0; item.postFee = 0;
}) })
postFee = 0; postFee = 0;
} }
if(this.data.coupon && this.data.postFee!=postFee){ if (this.data.coupon && this.data.postFee != postFee) {
wx.showToast({ wx.showToast({
title: '订单价格发生变化,请重新选择优惠券', title: '订单价格发生变化,请重新选择优惠券',
icon: 'none' icon: 'none'
}) })
app.globalData.couponInfo = null; app.globalData.couponInfo = null;
if(!this.data.kjId && !this.data.gp_id){ if (!this.data.kjId && !this.data.gp_id) {
this.couponCom.setNullCoupon() this.couponCom.setNullCoupon()
} }
this.setData({ this.setData({
coupon:null coupon: null
}) })
} }
this.setData({ this.setData({
postFee:postFee, postFee: postFee,
product:product product: product
}) })
}) })
}, },
/**
* 选择补贴
*/
selectAllowance: function () {
this.setData({
select_allowance: !this.data.select_allowance
})
this.changePrice()
},
/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
*/ */
@ -226,8 +243,41 @@ Page({
*/ */
onShow: function () { onShow: function () {
this.setData({ this.setData({
coupon:app.globalData.couponInfo coupon: app.globalData.couponInfo
})
// 获取补贴
if (this.data.product.length == 1) {
commonApi.user_post("product/getProductAllowancePrice", {
product_code: this.data.product[0].product.product_code
}).then(resTwo => {
console.log(resTwo)
if (resTwo && resTwo.code == 1) {
this.setData({
allowance_data: resTwo.data
}) })
let spread_price = Number(this.data.allowance_data.discount_limit_price - this.data.allowance_data.user_used_price)
let sInfo = this.data.product[0].sku
console.log(9999, this.data.allowance_data.discount_rate / 100 * sInfo.price)
console.log(9999, spread_price)
if (spread_price > 0) {
if (spread_price < this.data.allowance_data.discount_rate / 100 * sInfo.price) {
this.setData({
allowance_price: spread_price
})
} else {
this.setData({
allowance_price: this.data.allowance_data.discount_rate / 100 * sInfo.price
})
}
this.changePrice()
} else {
this.setData({
allowance_price: 0
})
}
}
})
}
}, },
/** /**
@ -242,8 +292,8 @@ Page({
*/ */
onUnload: function () { onUnload: function () {
this.setData({ this.setData({
kjId:null, kjId: null,
gp_id:null gp_id: null
}); });
app.globalData.kjId = null; app.globalData.kjId = null;
app.globalData.gp_id = null; app.globalData.gp_id = null;

14
pages/order/postOrder/index.wxml

@ -36,11 +36,23 @@
<view class="all-money-box" wx:if="{{from=='cart'}}"> <view class="all-money-box" wx:if="{{from=='cart'}}">
小计:<text class="unit">¥</text><text class="s-price">{{item.sku.price * item.productNum /100}}</text> 小计:<text class="unit">¥</text><text class="s-price">{{item.sku.price * item.productNum /100}}</text>
</view> </view>
<!-- 补贴 -->
<view class="box-title allowance" wx:if="{{allowance_price}}">
<view>惠民补贴</view>
<view class="com-flex-tao" bindtap="selectAllowance">
-¥{{allowance_price / 100}}
<image src="https://sz-qd.oss-cn-hangzhou.aliyuncs.com/uploads/20220602/6ecdbc41527c0c603608686967d4493b.png"
alt="" wx:if="{{select_allowance}}"></image>
<view class="border" wx:else></view>
</view>
</view>
</view> </view>
<coupon id="coupon" wx:if="{{!kjId && !gp_id}}" money="{{showPrice + postFee}}" sku="{{sku_id}}"></coupon> <coupon id="coupon" wx:if="{{!kjId && !gp_id}}" money="{{showPrice + postFee}}" sku="{{sku_id}}"></coupon>
<view style="height:113rpx"></view> <view style="height:113rpx"></view>
<view class="fixed-bottom" wx:if="{{product}}"> <view class="fixed-bottom" wx:if="{{product}}">
<view class="fixed-price-box" wx:if="{{!prizeId}}"><text>合计:</text><text class="price">¥{{((showPrice + postFee - (coupon?coupon.activity.money:0))>0?(showPrice + postFee - (coupon?coupon.activity.money:0)):0)/100}}</text></view> <view class="fixed-price-box" wx:if="{{!prizeId}}"><text>合计:</text><text
class="price">¥{{((showPrice + postFee - (coupon?coupon.activity.money:0))>0?(showPrice + postFee - (coupon?coupon.activity.money:0)):0)/100}}</text>
</view>
<view class="fixed-price-box" wx:else><text>合计:</text><text class="price">¥{{postFee?(0+postFee)/100:0}}</text></view> <view class="fixed-price-box" wx:else><text>合计:</text><text class="price">¥{{postFee?(0+postFee)/100:0}}</text></view>
<view class="fixed-btn" bindtap="order">提交订单</view> <view class="fixed-btn" bindtap="order">提交订单</view>
</view> </view>

48
pages/order/postOrder/index.wxss

@ -2,11 +2,13 @@
page { page {
background: #f6f6f6; background: #f6f6f6;
} }
.box { .box {
margin: 30rpx 25rpx; margin: 30rpx 25rpx;
background: white; background: white;
border-radius: 9rpx; border-radius: 9rpx;
} }
.box-title { .box-title {
height: 113rpx; height: 113rpx;
margin: 0 20rpx; margin: 0 20rpx;
@ -16,6 +18,30 @@ page {
display: flex; display: flex;
align-items: center; align-items: center;
} }
.allowance {
justify-content: space-between;
}
.allowance>view:nth-child(2) {
display: flex;
align-items: center;
}
.allowance image {
width: 40rpx;
height: 40rpx;
margin-left: 10rpx;
}
.allowance .border {
width: 30rpx;
height: 30rpx;
border-radius: 50%;
border: 4rpx solid #0B98BE;
margin-left: 10rpx;
}
.coupon-btn { .coupon-btn {
width: 138rpx; width: 138rpx;
line-height: 56rpx; line-height: 56rpx;
@ -25,12 +51,14 @@ page {
font-size: 28rpx; font-size: 28rpx;
color: #000; color: #000;
} }
.skuinfo { .skuinfo {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
padding: 30rpx 20rpx; padding: 30rpx 20rpx;
margin-bottom: 30rpx; margin-bottom: 30rpx;
} }
.skuinfo image { .skuinfo image {
flex-shrink: 0; flex-shrink: 0;
width: 174rpx; width: 174rpx;
@ -38,10 +66,12 @@ page {
border-radius: 7rpx; border-radius: 7rpx;
margin-right: 23rpx; margin-right: 23rpx;
} }
.right-info { .right-info {
flex: 1; flex: 1;
width: 400rpx; width: 400rpx;
} }
.sku-name { .sku-name {
font-size: 32rpx; font-size: 32rpx;
line-height: 47rpx; line-height: 47rpx;
@ -51,6 +81,7 @@ page {
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
} }
.info-tips { .info-tips {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
@ -58,22 +89,27 @@ page {
font-size: 27rpx; font-size: 27rpx;
color: #666; color: #666;
} }
.info-tips .price { .info-tips .price {
font-size: 33rpx; font-size: 33rpx;
color: #000; color: #000;
flex: 1; flex: 1;
margin-left: 10rpx; margin-left: 10rpx;
} }
.info-tips .price text { .info-tips .price text {
font-size: 24rpx; font-size: 24rpx;
} }
.info-tips .iconfont { .info-tips .iconfont {
font-size: 26rpx; font-size: 26rpx;
} }
.box-title .iconfont { .box-title .iconfont {
font-size: 28rpx; font-size: 28rpx;
flex-shrink: 0; flex-shrink: 0;
} }
.number-box { .number-box {
font-size: 29rpx; font-size: 29rpx;
font-weight: 500; font-weight: 500;
@ -86,14 +122,17 @@ page {
text-align: center; text-align: center;
margin: 0 20rpx; margin: 0 20rpx;
} }
.line { .line {
margin: 0 20rpx; margin: 0 20rpx;
background: #ccc; background: #ccc;
height: 1rpx; height: 1rpx;
} }
.topbox .box-title { .topbox .box-title {
border-top: 1rpx solid #ccc; border-top: 1rpx solid #ccc;
} }
.box-title input { .box-title input {
flex: 1; flex: 1;
display: block; display: block;
@ -102,6 +141,7 @@ page {
margin-left: 15rpx; margin-left: 15rpx;
font-weight: 400; font-weight: 400;
} }
.fixed-bottom { .fixed-bottom {
position: fixed; position: fixed;
left: 0; left: 0;
@ -115,6 +155,7 @@ page {
z-index: 2; z-index: 2;
box-shadow: 0px 0px 16rpx 0px rgba(6, 0, 1, 0.1); box-shadow: 0px 0px 16rpx 0px rgba(6, 0, 1, 0.1);
} }
.fixed-btn { .fixed-btn {
width: 320rpx; width: 320rpx;
line-height: 113rpx; line-height: 113rpx;
@ -124,6 +165,7 @@ page {
font-size: 36rpx; font-size: 36rpx;
font-weight: 500; font-weight: 500;
} }
.fixed-price-box { .fixed-price-box {
margin-left: 25rpx; margin-left: 25rpx;
flex-shrink: 0; flex-shrink: 0;
@ -131,11 +173,13 @@ page {
color: #333; color: #333;
font-weight: 500; font-weight: 500;
} }
.fixed-price-box .price { .fixed-price-box .price {
color: #D62828; color: #D62828;
font-size: 36rpx; font-size: 36rpx;
margin-left: 10rpx; margin-left: 10rpx;
} }
.all-money-box { .all-money-box {
margin: 0 20rpx; margin: 0 20rpx;
display: flex; display: flex;
@ -146,15 +190,19 @@ page {
border-top: 1rpx solid #ccc; border-top: 1rpx solid #ccc;
color: #000; color: #000;
} }
.all-money-box text { .all-money-box text {
color: #D62828; color: #D62828;
} }
.all-money-box .unit { .all-money-box .unit {
font-size: 24rpx; font-size: 24rpx;
} }
.all-money-box .s-price { .all-money-box .s-price {
font-size: 33rpx; font-size: 33rpx;
} }
.header-title { .header-title {
font-size: 31rpx; font-size: 31rpx;
font-weight: 500; font-weight: 500;

156
utils/https.js

@ -1,14 +1,14 @@
var app = getApp(); var app = getApp();
import util from "../utils/util" import util from "../utils/util"
// import userApi from "../utils/https/user.js"; // import userApi from "../utils/https/user.js";
const baseUrl = "https://test.api.cloud.sz-trip.com/api/"; // const baseUrl = "https://test.api.cloud.sz-trip.com/api/";
// const baseUrl = "https://api.cloud.sz-trip.com/api/"; const baseUrl = "https://api.cloud.sz-trip.com/api/";
const orders = ['','weight','distance','sale_number','sale_price','price']; const orders = ['', 'weight', 'distance', 'sale_number', 'sale_price', 'price'];
//封装GET请求 //封装GET请求
function _get(url,data) { function _get(url, data) {
//为了用户体验,加一个loading效果 //为了用户体验,加一个loading效果
wx.showLoading({ title: '加载中', mask: true }); wx.showLoading({ title: '加载中', mask: true });
url = baseUrl+url; url = baseUrl + url;
// 如果有order // 如果有order
// if(data && data.order){ // if(data && data.order){
// data.order = orders[data.order]; // data.order = orders[data.order];
@ -27,7 +27,7 @@ function _get(url,data) {
wx.showToast({ wx.showToast({
title: res.data.msg, title: res.data.msg,
icon: "none", icon: "none",
duration:2000 duration: 2000
}) })
} }
resolved(res.data); resolved(res.data);
@ -42,7 +42,7 @@ function _get(url,data) {
wx.request(obj) wx.request(obj)
}) })
} }
function back(){ function back() {
const pages = getCurrentPages(); const pages = getCurrentPages();
if (pages.length <= 1) { if (pages.length <= 1) {
wx.switchTab({ wx.switchTab({
@ -56,7 +56,7 @@ function back(){
} }
} }
//封装POST请求 //封装POST请求
function _post(url,data={}) { function _post(url, data = {}) {
//为了用户体验,加一个loading效果 //为了用户体验,加一个loading效果
wx.showLoading({ title: '加载中', mask: true }); wx.showLoading({ title: '加载中', mask: true });
url = baseUrl + url; url = baseUrl + url;
@ -81,21 +81,21 @@ function _post(url,data={}) {
// icon: "none", // icon: "none",
// }) // })
// } // }
if(url.indexOf('product/get_product_detail')!=-1){ if (url.indexOf('product/get_product_detail') != -1) {
// 如果是产品详情的话 需要加埋点 // 如果是产品详情的话 需要加埋点
_post('browse/ProductStatistics',{ _post('browse/ProductStatistics', {
uuid:wx.getStorageSync('uuid'), uuid: wx.getStorageSync('uuid'),
product_id:res.data.data.id, product_id: res.data.data.id,
product_name:res.data.data.title, product_name: res.data.data.title,
type:res.data.data.type type: res.data.data.type
}) })
util.pagePoint({ util.pagePoint({
event:'product_view', event: 'product_view',
param:{ param: {
type:res.data.data.type, type: res.data.data.type,
id:res.data.data.id id: res.data.data.id
} }
},1) }, 1)
} }
resolved(res.data); resolved(res.data);
} }
@ -103,35 +103,35 @@ function _post(url,data={}) {
rejected(res.data); rejected(res.data);
} }
}, },
fail: (err) => {wx.hideLoading();rejected(err)} fail: (err) => { wx.hideLoading(); rejected(err) }
} }
wx.request(obj) wx.request(obj)
}) })
} }
function user_post(url,data={},type){ function user_post(url, data = {}, type) {
if(wx.getStorageSync('authCode')){ if (wx.getStorageSync('authCode')) {
// 如果有授权码的话 用授权码去获取下用户信息 // 如果有授权码的话 用授权码去获取下用户信息
return new Promise((resolved,rejected)=>{ return new Promise((resolved, rejected) => {
_post("/uservice/user/loginWithUserCenterAuthCode",{ _post("/uservice/user/loginWithUserCenterAuthCode", {
auth_code:wx.getStorageSync('authCode') auth_code: wx.getStorageSync('authCode')
}).then(res=>{ }).then(res => {
wx.removeStorageSync('authCode') wx.removeStorageSync('authCode')
if(res && res.data){ if (res && res.data) {
wx.setStorageSync('jstrip_userid', res.data.id) wx.setStorageSync('jstrip_userid', res.data.id)
wx.setStorageSync('jstrip_token', res.data.token) wx.setStorageSync('jstrip_token', res.data.token)
wx.setStorageSync('jstrip_userInfo', res.data) wx.setStorageSync('jstrip_userInfo', res.data)
} }
user_post_new(url,data,type).then(res=>{ user_post_new(url, data, type).then(res => {
resolved(res) resolved(res)
}).catch(err=>{ }).catch(err => {
rejected(err) rejected(err)
}) })
}).catch(err=>{ }).catch(err => {
wx.removeStorageSync('authCode') wx.removeStorageSync('authCode')
user_post_new(url,data,type).then(res=>{ user_post_new(url, data, type).then(res => {
resolved(res) resolved(res)
}).catch(err=>{ }).catch(err => {
rejected(err) rejected(err)
}) })
}) })
@ -139,19 +139,19 @@ function user_post(url,data={},type){
} }
else { else {
return user_post_new(url,data,type) return user_post_new(url, data, type)
} }
} }
function user_post_new(url,data={},type){ function user_post_new(url, data = {}, type) {
console.log(type) console.log(type)
var token = wx.getStorageSync("jstrip_token"),userId = wx.getStorageSync("jstrip_userid"); var token = wx.getStorageSync("jstrip_token"), userId = wx.getStorageSync("jstrip_userid");
//为了用户体验,加一个loading效果 //为了用户体验,加一个loading效果
wx.showLoading({ title: '加载中', mask: true }); wx.showLoading({ title: '加载中', mask: true });
url = baseUrl + url; url = baseUrl + url;
var header = Object.assign({ var header = Object.assign({
token:token, token: token,
userId:userId userId: userId
},{ }, {
'context-type': 'application/json' 'context-type': 'application/json'
}) })
// 如果有order // 如果有order
@ -165,7 +165,7 @@ function user_post_new(url,data={},type){
return new Promise((resolved, rejected) => { return new Promise((resolved, rejected) => {
// 判断是否登录 // 判断是否登录
// 没有登录就跳转到登录页面 // 没有登录就跳转到登录页面
if (!token || !userId){ if (!token || !userId) {
wx.hideLoading(); wx.hideLoading();
// 去登陆 // 去登陆
console.log("去登陆去登陆去登陆去登陆去登陆去登陆去登陆") console.log("去登陆去登陆去登陆去登陆去登陆去登陆去登陆")
@ -177,12 +177,12 @@ function user_post_new(url,data={},type){
const obj = { const obj = {
url, url,
data, data,
method: type?type:'POST', method: type ? type : 'POST',
header: header, header: header,
success: (res) => { success: (res) => {
wx.hideLoading(); wx.hideLoading();
console.log(url,url.indexOf('team_order/apply_post')!=-1) console.log(url, url.indexOf('team_order/apply_post') != -1)
if(url.indexOf('user/getJumpThirdAppCode')!=-1){ if (url.indexOf('user/getJumpThirdAppCode') != -1) {
} }
else if (res.data.code == 401) { else if (res.data.code == 401) {
@ -192,7 +192,7 @@ function user_post_new(url,data={},type){
wx.removeStorageSync("jstrip_userInfo"); wx.removeStorageSync("jstrip_userInfo");
checkLogin(); checkLogin();
} }
else if(res.data.code==4005){ else if (res.data.code == 4005) {
wx.navigateTo({ wx.navigateTo({
url: '/pages/user/verify/index', url: '/pages/user/verify/index',
}) })
@ -200,33 +200,37 @@ function user_post_new(url,data={},type){
} }
else if (res.data.code != 1 && res.data.msg) { else if (res.data.code != 1 && res.data.msg) {
// 不出现提示语 // 不出现提示语
if(url.indexOf('actonline/video_act/getRaffle')!=-1 || url.indexOf('team_order/apply_post')!=-1 && type=='get'){ const noToast = [
'actonline/video_act/getRaffle',
'getProductAllowancePrice'
]
if (noToast.indexOf(url) || url.indexOf('team_order/apply_post') != -1 && type == 'get') {
} }
else if(url.indexOf('actonline/act_online/vote')!=-1 && res.data.code==0){ else if (url.indexOf('actonline/act_online/vote') != -1 && res.data.code == 0) {
wx.showToast({ wx.showToast({
title: res.data.msg, title: res.data.msg,
icon: "none", icon: "none",
duration:2000 duration: 2000
}) })
} }
else if(url.indexOf('actonline/act_online/vote')==-1){ else if (url.indexOf('actonline/act_online/vote') == -1) {
wx.showToast({ wx.showToast({
title: res.data.msg==='身份证号码错误'?'身份证和姓名不匹配':res.data.msg, title: res.data.msg === '身份证号码错误' ? '身份证和姓名不匹配' : res.data.msg,
icon: "none", icon: "none",
duration:2000 duration: 2000
}) })
} }
} }
if(res.statusCode == 200){ if (res.statusCode == 200) {
if(url.indexOf('/order/create')!=-1 && res.data.code==1 && res.data.data){ if (url.indexOf('/order/create') != -1 && res.data.code == 1 && res.data.data) {
// 下单成功 // 下单成功
wx.removeStorageSync('prizeId') wx.removeStorageSync('prizeId')
if(res.data.data.pay_status==1){ if (res.data.data.pay_status == 1) {
// 0元直接付款成功 // 0元直接付款成功
wx.navigateTo({ wx.navigateTo({
url:"/pages/order/payresult/index?tid="+res.data.data.order_id url: "/pages/order/payresult/index?tid=" + res.data.data.order_id
}) })
// util.gotoOrder(res.data.data) // util.gotoOrder(res.data.data)
// // wx.navigateTo({ // // wx.navigateTo({
@ -235,38 +239,38 @@ function user_post_new(url,data={},type){
} }
else { else {
wx.navigateTo({ wx.navigateTo({
url: '/pages/order/pay/index?id='+res.data.data.order_id, url: '/pages/order/pay/index?id=' + res.data.data.order_id,
}) })
} }
if(wx.getStorageSync('order_from')){ if (wx.getStorageSync('order_from')) {
util.pagePoint({ util.pagePoint({
event:wx.getStorageSync('order_from') event: wx.getStorageSync('order_from')
},1) }, 1)
} }
wx.removeStorageSync('order_from') wx.removeStorageSync('order_from')
} }
else if(url.indexOf('/order/create')!=-1 && res.data.msg=='您有正在进行中或待支付的拼团,请查看拼团订单'){ else if (url.indexOf('/order/create') != -1 && res.data.msg == '您有正在进行中或待支付的拼团,请查看拼团订单') {
setTimeout(() => { setTimeout(() => {
wx.navigateTo({ wx.navigateTo({
url: '/pages/user/order/list', url: '/pages/user/order/list',
}) })
}, 1000); }, 1000);
} }
if(url.indexOf('product/get_product_detail')!=-1){ if (url.indexOf('product/get_product_detail') != -1) {
// 如果是产品详情的话 需要加埋点 // 如果是产品详情的话 需要加埋点
_post('browse/ProductStatistics',{ _post('browse/ProductStatistics', {
uuid:wx.getStorageSync('uuid'), uuid: wx.getStorageSync('uuid'),
product_id:res.data.data.id, product_id: res.data.data.id,
product_name:res.data.data.title, product_name: res.data.data.title,
type:res.data.data.type type: res.data.data.type
}) })
util.pagePoint({ util.pagePoint({
event:'product_view', event: 'product_view',
param:{ param: {
type:res.data.data.type, type: res.data.data.type,
id:res.data.data.id id: res.data.data.id
} }
},1) }, 1)
} }
resolved(res.data); resolved(res.data);
} }
@ -292,11 +296,11 @@ const set_logininfo = r => {
if (getCurrentPages().length != 0) { if (getCurrentPages().length != 0) {
//刷新当前页面的数据 //刷新当前页面的数据
let item = getCurrentPages()[getCurrentPages().length - 1]; let item = getCurrentPages()[getCurrentPages().length - 1];
if(item.route.indexOf('login')!=-1){ if (item.route.indexOf('login') != -1) {
item = getCurrentPages()[getCurrentPages().length - 2]; item = getCurrentPages()[getCurrentPages().length - 2];
item.onLoad(item.__displayReporter.query) item.onLoad(item.__displayReporter.query)
} }
else if(item.route=='pages/index/index'){ else if (item.route == 'pages/index/index') {
// 首页只可能去获取苏康码 // 首页只可能去获取苏康码
item.gotoSkm(); item.gotoSkm();
} }
@ -309,7 +313,7 @@ const set_logininfo = r => {
const checkLogin = () => { const checkLogin = () => {
// 判断是否已经授权过 // 判断是否已经授权过
let page = getCurrentPages(); let page = getCurrentPages();
if(page[page.length-1].route!='pages/login/index') { if (page[page.length - 1].route != 'pages/login/index') {
wx.navigateTo({ wx.navigateTo({
url: '/pages/login/index', url: '/pages/login/index',
}) })
@ -333,7 +337,7 @@ const checkLogin = () => {
} }
// r.data.isBind是false的时候去绑定手机号 该用户没有注册过 // r.data.isBind是false的时候去绑定手机号 该用户没有注册过
// 已经注册的用户返回userinfo // 已经注册的用户返回userinfo
else if (r.data.isBindMobile === 0 && page[page.length-1].route!='pages/user/bindtel/index') { else if (r.data.isBindMobile === 0 && page[page.length - 1].route != 'pages/user/bindtel/index') {
wx.navigateTo({ wx.navigateTo({
url: '/pages/user/bindtel/index?regToken=' + encodeURIComponent(r.data.openid), url: '/pages/user/bindtel/index?regToken=' + encodeURIComponent(r.data.openid),
}) })
@ -343,7 +347,7 @@ const checkLogin = () => {
title: '网络请求失败', title: '网络请求失败',
icon: 'none' icon: 'none'
}) })
console.log(err,"666666") console.log(err, "666666")
back() back()
}) })
} }
@ -352,14 +356,14 @@ const checkLogin = () => {
}) })
} }
else { else {
if(page[page.length-1].route!='pages/login/index') { if (page[page.length - 1].route != 'pages/login/index') {
wx.navigateTo({ wx.navigateTo({
url: '/pages/login/index', url: '/pages/login/index',
}) })
} }
} }
}, },
fail:err=>{ fail: err => {
} }
}) })

Loading…
Cancel
Save