Browse Source

修改小程序砍价逻辑

master
Gao xiaosong 5 years ago
parent
commit
2e55f39775
  1. 4
      config/index.js
  2. 2
      libs/wechat.js
  3. 5
      main.js
  4. 4
      pages/Loading/index.vue
  5. 409
      pages/activity/DargainDetails/index.vue
  6. 4
      pages/shop/GoodsCon/index.vue
  7. 12
      utils/index.js

4
config/index.js

@ -1,8 +1,8 @@
// export const VUE_APP_API_URL = 'http://natapp.xinxintuan.co/api';
// export const VUE_APP_API_URL = 'https://wxapi.yixiang.co/api';
export const VUE_APP_API_URL = 'https://wxapi.yixiang.co/api';
// export const VUE_APP_API_URL = 'http://192.168.31.223:8008/api';
export const VUE_APP_API_URL = 'https://h5api.xinxintuan.co/api';
// export const VUE_APP_API_URL = 'https://h5api.xinxintuan.co/api';
// export const VUE_APP_API_URL = 'https://h5api.xinxintuan.co/api';
export const VUE_APP_RESOURCES_URL = 'https://wx.yixiang.co/static';

2
libs/wechat.js

@ -153,6 +153,8 @@ export async function auth(code) {
return new Promise((resolve, reject) => {
let loginType = cookie.get(LOGINTYPE);
let spread = cookie.get('spread');
alert(spread)
debugger
wechatAuth(code, spread, loginType)
.then(({ data }) => {
console.log(data)

5
main.js

@ -125,7 +125,10 @@ if (!cookie.has(CACHE_KEY)) {
}
var urlSpread = parseQuery()["spread"];
cookie.set("spread", urlSpread || 0);
if (urlSpread) {
cookie.set("spread", urlSpread);
}
// #endif

4
pages/Loading/index.vue

@ -43,7 +43,9 @@
//
if (url) {
let urlSpread = parseInt(url.spread);
cookie.set("spread", urlSpread || 0);
if (urlSpread) {
cookie.set("spread", urlSpread);
}
}
// if (this.$deviceType == "app" || this.$deviceType == "weixinh5") {
// this.$yrouter.switchTab({

409
pages/activity/DargainDetails/index.vue

@ -1,9 +1,11 @@
<template>
<view class="bargain on">
<!-- 在header上加 on 为请求支援 -->
<view :class="[bargainPartake != userInfo.uid ? 'wrapper bargain-box on user' : 'wrapper bargain-box user']"
v-if="bargainUserInfo && bargainPartake != userInfo.uid">
<!-- <view class="people">{{ lookCount }}人查看 {{ shareCount }}人分享 {{ userCount }}人参与</view> -->
<!-- 当前登录的用户和url上携带的用户id不一致视为被邀请砍价 -->
<view class="wrapper bargain-box on user" v-if="bargainUserInfo && bargainUid != userInfo.uid">
<!-- <view class="people">
{{ bargainShare.lookCount }}人查看 {{ bargainShare.shareCount }}人分享 {{ bargainShare.userCount }}人参与
</view> -->
<!-- 帮助砍价帮砍成功-->
<view class="pictxt acea-row row-center-wrapper ">
<div class="bargain-header">
@ -20,79 +22,70 @@
<view class="wrapper bargain-box time on">
<div class="pictxt ">
<count-down :isDay="true" :tipText="'倒计时 '" :dayText="' 天 '" :hourText="' 时 '" :minuteText="' 分 '"
:secondText="' 秒'" :datatime="datatime"></count-down>
:secondText="' 秒'" :datatime="goodsDetail.stopTime"></count-down>
</div>
</view>
<view class="wrapper bargain-box bargain-product">
<view class="pictxt acea-row row-between-wrapper" @click="openAlone">
<view class="pictrue">
<image :src="bargain.image" />
<image :src="goodsDetail.image" />
<view class="bargain_view">
查看商品
<view class="iconfont icon-jiantou iconfonts"></view>
</view>
</view>
<view class="text acea-row row-column-around">
<view class="line2" v-text="bargain.title"></view>
<view class="line2" v-text="goodsDetail.title"></view>
<view class="money font-color-red">
已砍至:
<text class="num" v-text="price"></text>
<text class="num" v-text="bargainHelpCount.remainingPrice"></text>
</view>
<view class="acea-row row-middle">
<view class="successNum" v-text="'原价' + bargain.price"></view>
<view class="successNum" v-text="'原价' + goodsDetail.price"></view>
<view class="successNum" v-text="'已有' + bargainSumCount + '人砍价成功'"></view>
</view>
</view>
</view>
<!-- 砍价进度条 -->
<view class="cu-progress acea-row row-middle round margin-top">
<view class="acea-row row-middle bg-red" :style="{ width: loading ? pricePercent + '%' : '' }"></view>
<view class="acea-row row-middle bg-red" :style="{ width: bargainHelpCount.pricePercent + '%' }"></view>
</view>
<!-- 砍价进度条下的金额 -->
<view class="balance acea-row row-between-wrapper">
<view v-text="'已砍' + alreadyPrice + '元'"></view>
<view v-if="surplusPrice === 0">砍价成功</view>
<view v-else v-text="'还剩' + surplusPrice + '元'"></view>
<view v-text="'已砍' + bargainHelpCount.alreadyPrice + '元'"></view>
<view v-if="bargainHelpCount.remainingPrice === 0">砍价成功</view>
<view v-else v-text="'还剩' + bargainHelpCount.remainingPrice + '元'"></view>
</view>
<!-- 帮助砍价帮砍成功-->
<!-- <view class="bargainSuccess" v-if="bargainPartake != userInfo.uid && !statusUser && !helpListLoading">
<span class="iconfont icon-xiaolian"></span>已成功帮助好友砍价
</view> -->
<!-- 砍价成功-->
<view class="bargainSuccess" v-if="
surplusPrice === 0 &&
bargainPartake === userInfo.uid &&
userBargainStatus === 1 &&
!helpListLoading
">
<!--
surplusPrice 砍价剩余金额为0
bargainUid 砍价人为发起砍价用户
userBargainStatus 砍价状态为
-->
<view class="bargainSuccess" v-if="pay">
<span class="iconfont icon-xiaolian"></span>恭喜您砍价成功快去支付吧~
</view>
<view v-if="userBargainStatus == 0 && bargainPartake === userInfo.uid" class="bargainBnt" @click="goParticipate">
立即参与砍价</view>
<view class="bargainBnt" @click="goPoster" v-if="
surplusPrice > 0 &&
bargainPartake === userInfo.uid &&
userBargainStatus === 1 &&
!helpListLoading
">邀请好友帮砍价</view>
<view class="bargainBnt" @click="getBargainHelp" v-else-if="
bargainPartake != userInfo.uid &&
userBargainStatus == 1 &&
statusUser &&
!helpListLoading
">帮好友砍一刀</view>
<view class="bargainBnt" @click="getBargainStart"
v-if="bargainPartake != userInfo.uid && !statusUser && !helpListLoading">我也要参与</view>
<view class="bargainBnt" @click="goPay" v-if="
surplusPrice === 0 &&
bargainPartake === userInfo.uid &&
userBargainStatus === 1
">立即支付</view>
<!-- 参与砍价按钮 同一人-->
<view v-if="participate" class="bargainBnt" @click="goParticipate">立即参与砍价</view>
<!-- 邀请好友按钮 -->
<view v-if="inviteFriends" class="bargainBnt" @click="goPoster">邀请好友帮砍价</view>
<!-- 帮砍好友砍按钮 -->
<view v-if="helpFriendsBargain" class="bargainBnt" @click="getBargainHelp">帮好友砍一刀</view>
<!-- 发起砍价按钮 非同一人-->
<view v-if="bargain" class="bargainBnt" @click="getBargainStart">我也要参与</view>
<!-- 支付按钮 -->
<view class="bargainBnt" @click="goPay" v-if="pay">立即支付</view>
<view class="bargainBnt on" @click="goList">抢更多商品</view>
<view class="tip">
已有
<span class="font-color-red" v-text="helpCount"></span>
位好友成功帮您砍价
</view>
<view class="tip">已有<span class="font-color-red" v-text="bargainHelpCount.count"></span>位好友成功帮您砍价</view>
<view class="lock"></view>
</view>
<view class="bargainGang bargain-box">
@ -123,7 +116,7 @@
</view>
</view>
</view>
<view class="load font-color-red" v-if="!helpListStatus && !helpListLoading" @click="getBargainHelpList">点击加载更多
<view class="load font-color-red" v-if="!helpListStatus " @click="getBargainHelpList">点击加载更多
</view>
<view class="lock"></view>
</view>
@ -137,7 +130,7 @@
<image src="@/static/images/left.png" />
</view>
</view>
<view class="conter" v-html="bargain.description"></view>
<view class="conter" v-html="goodsDetail.description"></view>
<view class="lock"></view>
</view>
<view class="goodsDetails bargain-box">
@ -150,21 +143,17 @@
<image src="@/static/images/left.png" />
</view>
</view>
<view class="conter" v-html="bargain.rule"></view>
<view class="conter" v-html="goodsDetail.rule"></view>
</view>
<view class="bargainTip" :class="active === true ? 'on' : ''">
<!-- <view class="pictrue">
<image src="@/static/images/bargainBg.jpg" />
<view class="iconfont icon-guanbi" @click="close"></view>
</view>-->
<view class="cutOff" v-if="bargainPartake === userInfo.uid">
<view class="cutOff" v-if="bargainUid === userInfo.uid">
您已砍掉
<text class="font-color-red" v-text="bargainHelpPrice"></text>听说分享次数越多砍价成功的机会越大哦
</view>
<view class="cutOff on" v-else>
<view class="help font-color-red" v-text="'成功帮砍' + bargainHelpPrice + '元'"></view>您也可以砍价低价拿哦快去挑选心仪的商品吧~
</view>
<view class="tipBnt" @click="goPoster" v-if="bargainPartake === userInfo.uid">邀请好友帮砍价</view>
<view class="tipBnt" @click="goPoster" v-if="bargainUid === userInfo.uid">邀请好友帮砍价</view>
<view class="tipBnt" @click="getBargainStart" v-else>我也要参与</view>
</view>
<view class="mask" @touchmove.prevent :hidden="active === false" @click="close"></view>
@ -207,88 +196,50 @@
return {
price: 0,
bargainId: 0, //
bargainPartake: 0, //
bargain: [], //
partake: null,
bargainSumCount: 0, //
activeMsg: "",
// ssssss
active: false,
loading: false,
datatime: 0,
lookCount: 0, //
shareCount: 0, //
userCount: 0, //
bargainHelpPrice: 0, //
bargainHelpList: [],
helpListStatus: false, // false true
helpListLoading: false, // false true
page: 1, //
limit: 2, //
helpCount: 0, //
surplusPrice: 0, //
alreadyPrice: 0, //
pricePercent: 0, //
bargainUserInfo: [], //
userBargainStatus: 2, //
statusUser: false // ,truefalse
bargainShare: {}, //
bargainHelpCount: {}, //
goodsDetail: {}, //
bargainUserInfo: [], //
bargainUid: 0, //
pay: false, //
bargain: false, //
participate: false, //
inviteFriends: false, //
helpFriendsBargain: false, //
bargainSuccess: false, //
mainBargainSuccess: false, //
};
},
computed: mapGetters(["userInfo", "isLogin"]),
// watch: {
// $yroute: function(n) {
// var that = this;
// if (n.name === NAME) {
// that.mountedStart();
// }
// }
// },
mounted: function () {
var that = this;
that.mountedStart();
setTimeout(function () {
that.loading = true;
}, 500);
this.mountedStart();
},
methods: {
onShareAppMessage: function () {
return {
title: this.storeInfo.title,
imageUrl: this.storeInfo.image,
path: "pages/activity/DargainDetails/index?id=" + this.storeInfo.id + "&spread=" + uni.getStorageSync(
"uid"),
success(res) {
uni.showToast({
title: '分享成功'
})
},
fail(res) {
uni.showToast({
title: '分享失败',
icon: 'none'
})
}
}
},
//
goParticipate() {
if (this.bargainPartake === this.userInfo.uid) this.getBargainStart();
else this.getBargainStartUser();
this.getBargainHelpCount();
},
openAlone: function () {
this.$yrouter.push({
path: "/detail/" + this.bargain.productId
});
},
//
mountedStart: function () {
var that = this;
console.log(this)
let url = handleQrCode();
console.log(url)
if (url) {
//
that.bargainId = url.bargainId;
that.partake = url.uid;
that.partake = url.partake;
} else {
that.bargainId = that.$yroute.query.id;
that.partake = parseInt(that.$yroute.query.partake);
@ -298,25 +249,43 @@
this.partake <= 0 ||
isNaN(this.partake)
) {
that.bargainPartake = that.userInfo.uid;
// that.$yrouter.push({
// path: "/pages/activity/DargainDetails/index",
// query: { id: that.bargainId, partake: that.bargainPartake }
// });
// urluiduid
that.bargainUid = that.userInfo.uid;
that.$yrouter.push({
path: "/pages/activity/DargainDetails/index",
query: {
id: that.bargainId,
partake: that.bargainUid
}
});
return
} else {
that.bargainPartake = parseInt(this.partake);
that.bargainUid = this.partake;
}
that.getBargainHelpCountStart();
//
that.getBargainDetail();
//
that.getBargainShare(0);
// if (that.bargainPartake !== that.userInfo.uid) that.getBargainStartUser();
if (that.bargainPartake === that.userInfo.uid) {
// that.getBargainStart();
} else {
if (that.bargainUid !== that.userInfo.uid) {
that.getBargainStartUser();
}
},
//
goParticipate() {
if (this.bargainUid === this.userInfo.uid) {
this.getBargainStart()
} else {
this.getBargainStartUser();
}
this.getBargainHelpCount();
},
//
openAlone: function () {
this.$yrouter.push({
path: "/detail/" + this.bargain.productId
});
},
//
goPay: function () {
var data = {};
var that = this;
@ -342,6 +311,7 @@
});
});
},
//
goPoster: function () {
var that = this;
that.getBargainShare(that.bargainId);
@ -353,6 +323,7 @@
}
});
},
//
goList: function () {
this.$yrouter.push({
path: "/pages/activity/GoodsBargain/index"
@ -366,9 +337,7 @@
getBargainShare({
bargainId: bargainId
}).then(res => {
that.lookCount = res.data.lookCount;
that.shareCount = res.data.shareCount;
that.userCount = res.data.userCount;
that.bargainShare = res.data
});
},
//
@ -376,19 +345,17 @@
var that = this;
getBargainDetail(that.bargainId)
.then(res => {
that.bargain = res.data.bargain;
that.bargain.description = that.bargain.description.replace(
that.goodsDetail = res.data.bargain;
that.goodsDetail.description = that.goodsDetail.description.replace(
/\<img/gi,
'<img style="max-width:100%;height:auto;"'
);
that.bargain.rule = that.bargain.rule.replace(
that.goodsDetail.rule = that.goodsDetail.rule.replace(
/\<img/gi,
'<img style="max-width:100%;height:auto;"'
);
that.datatime = that.bargain.stopTime / 1000;
that.goodsDetail.stopTime = that.goodsDetail.stopTime / 1000
that.getBargainHelpCount();
// that.setOpenShare();
that.getBargainHelpList();
})
.catch(res => {
uni.showToast({
@ -398,14 +365,14 @@
});
});
},
//
//
getBargainStart: function () {
var that = this;
getBargainStart({
bargainId: that.bargainId
})
.then(() => {
that.bargainPartake = that.userInfo.uid;
that.bargainUid = that.userInfo.uid;
that.getBargainHelp();
})
.catch(res => {
@ -416,12 +383,12 @@
});
});
},
//
//
getBargainHelp: function () {
var that = this;
if (
that.surplusPrice === 0 &&
that.bargainPartake !== that.userInfo.uid
this.bargainHelpCount.remainingPrice === 0 &&
that.bargainUid !== that.userInfo.uid
) {
return uni.showToast({
title: "好友已经砍价成功",
@ -431,15 +398,12 @@
}
var data = {
bargainId: that.bargainId,
bargainUserUid: that.bargainPartake
bargainUserUid: that.bargainUid
};
getBargainHelp(data)
.then(res => {
that.activeMsg = res.data.status;
if (
res.data.status === "SUCCESSFUL" &&
that.bargainPartake !== that.userInfo.uid
) {
if (res.data.status === "SUCCESSFUL" && that.bargainUid !== that.userInfo.uid) {
uni.showToast({
title: "您已经砍过了",
icon: "none",
@ -463,15 +427,12 @@
//
getBargainHelpPrice: function () {
var that = this;
that.helpListLoading = true;
getBargainHelpPrice({
bargainId: that.bargainId,
bargainUserUid: that.bargainPartake
bargainUserUid: that.bargainUid
})
.then(res => {
that.bargainHelpPrice = res.data.price;
that.helpListLoading = false;
that.getBargainHelpCount();
that.getBargainHelpList();
switch (that.activeMsg) {
@ -490,29 +451,25 @@
});
});
},
//
//
getBargainHelpList: function () {
var that = this;
if (that.helpListLoading === true) return;
if (that.helpListStatus === true) return;
that.helpListLoading = true;
getBargainHelpList({
bargainId: that.bargainId,
bargainUserUid: that.bargainPartake,
bargainUserUid: that.bargainUid,
page: that.page,
limit: that.limit
})
.then(res => {
that.helpListStatus = res.data.length < that.limit;
that.helpListLoading = false;
that.page++;
if (res.data) {
that.bargainHelpList.push.apply(that.bargainHelpList, res.data);
}
})
.catch(err => {
console.log(err)
if(!err.msg){
if (!err.msg) {
return
}
uni.showToast({
@ -522,53 +479,100 @@
});
});
},
getBargainHelpCountStart: function () {
var that = this;
getBargainHelpCount({
bargainId: that.bargainId,
bargainUserUid: that.bargainPartake
})
.then(() => {
})
.catch(() => {
// this.$yrouter.push({
// path: "/pages/activity/DargainDetails/index",
// query: {
// id: that.bargainId,
// partake: that.userInfo.uid
// }
// });
});
},
//
getBargainHelpCount: function () {
var that = this;
getBargainHelpCount({
bargainId: that.bargainId,
bargainUserUid: that.bargainPartake
bargainId: this.bargainId,
bargainUserUid: this.bargainUid
})
.then(res => {
that.userBargainStatus = res.data.status;
that.helpCount = res.data.count;
that.surplusPrice = res.data.price;
that.alreadyPrice = res.data.alreadyPrice;
that.pricePercent = res.data.pricePercent;
that.price = (that.bargain.price - that.alreadyPrice).toFixed(2);
console.log(that);
// = -
let remainingPrice = (this.goodsDetail.price - res.data.alreadyPrice).toFixed(2)
this.bargainHelpCount = {
...res.data,
remainingPrice
}
this.handleButtonStatus()
})
.catch(() => {
that.bargainPartake = that.userInfo.uid;
// that.$yrouter.push({
// path: "/pages/activity/DargainDetails/index",
// query: { id: that.bargainId, partake: that.userInfo.uid }
// });
.catch(err => {
if (!err.msg) {
return
}
uni.showToast({
title: err.msg || err.response.data.msg || err.response.data.message,
icon: "none",
duration: 2000
});
});
},
//
handleButtonStatus() {
//
// 1. ==> &&
if (
this.bargainUid === this.userInfo.uid &&
this.bargainHelpCount.status == 0
) {
this.participate = true
} else {
this.participate = false
}
// 2. ==> && && >0
if (
this.bargainUid === this.userInfo.uid &&
this.bargainHelpCount.status == 1 &&
this.bargainHelpCount.remainingPrice > 0
) {
this.inviteFriends = true
} else {
this.inviteFriends = false
}
// 3. ==> && && >0 &&
if (
this.bargainUid != this.userInfo.uid &&
this.bargainHelpCount.status == 1 &&
// this.bargainHelpCount.userBargainStatus &&
this.bargainHelpCount.remainingPrice > 0
) {
this.helpFriendsBargain = true
} else {
this.helpFriendsBargain = false
}
// 4. ==> && && <=0
if (
this.bargainUid === this.userInfo.uid &&
this.bargainHelpCount.status == 1 &&
this.bargainHelpCount.remainingPrice <= 0
) {
this.pay = true
} else {
this.pay = false
}
// 5. ==> &&
if (
this.bargainUid != this.userInfo.uid
) {
this.bargain = true
}else{
this.bargain = false
}
//
// 1. ==> &&
// 2. ==> &&
// 3. ==> && true
},
//
getBargainStartUser: function () {
var that = this;
getBargainStartUser({
bargainId: that.bargainId,
bargainUserUid: that.bargainPartake
bargainUserUid: that.bargainUid
})
.then(res => {
that.bargainUserInfo = res.data;
@ -582,9 +586,30 @@
});
});
},
//
close: function () {
this.active = false;
}
},
//
onShareAppMessage: function () {
return {
title: this.storeInfo.title,
imageUrl: this.storeInfo.image,
path: "pages/activity/DargainDetails/index?id=" + this.storeInfo.id + "&spread=" + uni.getStorageSync(
"uid"),
success(res) {
uni.showToast({
title: '分享成功'
})
},
fail(res) {
uni.showToast({
title: '分享失败',
icon: 'none'
})
}
}
},
},
onShareAppMessage() {
return {

4
pages/shop/GoodsCon/index.vue

@ -311,7 +311,9 @@
if (url && url.id) {
this.id = url.id;
let urlSpread = parseInt(url.spread);
cookie.set("spread", urlSpread || 0);
if (urlSpread) {
cookie.set("spread", urlSpread);
}
} else {
this.id = this._route.query.id;
}

12
utils/index.js

@ -889,7 +889,9 @@ export const handleLoginFailure = () => {
id: qrCode.pinkId,
}
})
cookie.set("spread", qrCode.spread || 0);
if (qrCode.spread) {
cookie.set("spread", qrCode.spread || 0);
}
} else {
console.log('————————')
console.log('是拼团进来的,但是没有获取到参数')
@ -912,7 +914,9 @@ export const handleLoginFailure = () => {
partake: qrCode.uid
}
})
cookie.set("spread", qrCode.spread || 0);
if (qrCode.spread) {
cookie.set("spread", qrCode.spread || 0);
}
} else {
handleNoParameters()
console.log('————————')
@ -933,7 +937,9 @@ export const handleLoginFailure = () => {
id: qrCode.productId,
}
})
cookie.set("spread", qrCode.spread || 0);
if (qrCode.spread) {
cookie.set("spread", qrCode.spread || 0);
}
} else {
handleNoParameters()
console.log('————————')

Loading…
Cancel
Save