【订单详情】

1. 梳理分销、分享相关的逻辑,把方法放到一起
pull/1/MERGE
YunaiV 2023-06-09 00:18:44 +08:00
parent 83a6955778
commit 6320bb3453
2 changed files with 319 additions and 329 deletions

View File

@ -1,5 +1,5 @@
<template>
<view class='sharing-packets' :class='sharePacket.isState==true?"on":""'>
<view class='sharing-packets' :class='sharePacket.isState ? "on":""'>
<view class='iconfont icon-guanbi' @click="closeShare"></view>
<view class='line'></view>
<view class='sharing-con' @click='goShare'>
@ -10,34 +10,35 @@
<view class='tip'>下单即返佣金</view>
<view class='shareBut'>立即分享</view>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
props: {
sharePacket: {
type: Object,
default: function(){
return {isState: true,priceName:''}
}
}
sharePacket: {
type: Object,
default: function() {
return {
isState: true,
priceName:'' //
}
}
}
},
data() {
return {
};
},
methods: {
closeShare:function(){
this.$emit('closeChange');
},
goShare:function(){
this.$emit('listenerActionSheet');
}
this.$emit('closeChange');
},
goShare:function(){
this.$emit('listenerActionSheet');
}
}
}
</script>

View File

@ -218,8 +218,12 @@
</view>
</block>
</view>
<shareRedPackets :sharePacket="sharePacket" @listenerActionSheet="listenerActionSheet"
@closeChange="closeChange"></shareRedPackets>
<!-- 左侧的分销提示 -->
<shareRedPackets
:sharePacket="sharePacket"
@listenerActionSheet="listenerActionSheet"
@closeChange="closeChange"
/>
<!-- SKU 弹窗 -->
<productWindow
:attr="attr"
@ -234,7 +238,7 @@
<!-- 优惠劵弹窗 TODO 芋艿待实现 -->
<couponListWindow :coupon='coupon' @ChangCouponsClone="ChangCouponsClone" @ChangCoupons="ChangCoupons"
@ChangCouponsUseState="ChangCouponsUseState" @tabCouponType="tabCouponType"></couponListWindow>
<!-- 分享按钮 TODO 芋艿待实现 -->
<!-- 分享按钮 -->
<view class="generate-posters acea-row row-middle" :class="posters ? 'on' : ''">
<!-- #ifndef MP -->
<button class="item" hover-class='none' v-if="weixinStatus === true" @click="H5ShareBox = true">
@ -243,7 +247,7 @@
</button>
<!-- #endif -->
<!-- #ifdef MP -->
<button class="item" open-type="share" hover-class='none' @click="goFriend">
<button class="item" open-type="share" hover-class='none' @click="closePosters">
<view class="iconfont icon-weixin3"></view>
<view class="">发送给朋友</view>
</button>
@ -253,13 +257,13 @@
<view class="">生成海报</view>
</button>
</view>
<!-- TODO 芋艿不知道啥东西 -->
<!-- 海报展示 -->
<view class="mask" v-if="posters" @click="closePosters"></view>
<view class="mask" v-if="canvasStatus"></view>
<!-- #ifdef MP -->
<!-- <authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize> -->
<!-- #endif -->
<!-- 海报展示 TODO 芋艿待实现 -->
<!-- 海报展示操作 -->
<view class='poster-pop' v-if="canvasStatus">
<image src='../../static/images/poster-close.png' class='close' @click="posterImageClose"></image>
<image :src='imagePath'></image>
@ -294,15 +298,9 @@
import {
getCoupons
} from '@/api/api.js';
import {
toLogin
} from '@/libs/login.js';
import {
mapGetters
} from "vuex";
import {
imageBase64
} from "@/api/public";
import { toLogin } from '@/libs/login.js';
import { mapGetters } from "vuex";
import { imageBase64 } from "@/api/public";
import productConSwiper from '@/components/productConSwiper';
import couponListWindow from '@/components/couponListWindow';
import productWindow from '@/components/productWindow';
@ -315,15 +313,11 @@
import * as Util from '@/utils/util.js';
import * as ProductUtil from '@/utils/product.js';
// #ifdef MP
import {
base64src
} from '@/utils/base64src.js'
import { base64src } from '@/utils/base64src.js'
import authorize from '@/components/Authorize';
import {
getQrcode
} from '@/api/api.js';
import { getQrcode } from '@/api/api.js';
// #endif
let app = getApp();
const app = getApp();
export default {
components: {
productConSwiper,
@ -339,14 +333,8 @@
},
data() {
return {
// TODO
coupon: {
coupon: false,
type: 1,
list: [],
count: []
},
id: 0, // id
type: "", // normal - video -
productInfo: {}, // TODO
spu: {}, // SPU
skuMap: [], // SKU Map
@ -359,7 +347,13 @@
},
cartCount: 0, //
cartAnimated: false, //
replyCount: 0, // TODO
tagStyle: { //
img: 'width:100%;display:block;',
table: 'width:100%',
video: 'width:100%'
},
replyCount: 0, // TODO
reply: [], //
replyChance: 0, // TODO
userCollect: false,
@ -367,35 +361,37 @@
cart_num: 1, // TODO
isAuto: false, // TODO
isShowAuth: false, // TODO
actionSheetHidden: true, // TODO
storeImage: '', // // TODO
PromotionCode: '', // // TODO
posterbackgd: '/static/images/posterbackgd.png', // TODO
sharePacket: { //
isState: true, // // TODO
},
circular: false, // TODO
autoplay: false, // TODO
interval: 3000, // TODO
duration: 500, // TODO
systemStore: {}, // TODO
good_list: [], // TODO
isDown: true, // TODO
posters: false, // TODO
weixinStatus: false, // TODO
H5ShareBox: false, // TODO
activityH5: [], // TODO
tagStyle: { //
img: 'width:100%;display:block;',
table: 'width:100%',
video: 'width:100%'
},
qrcodeSize: 600, // TODO
canvasStatus: false, // TODO
imagePath: '', // TODO
imgTop: '', // TODO
errT: '', // TODO
type: "", // TODO
// TODO
coupon: {
coupon: false,
type: 1,
list: [],
count: []
},
// ========== ==========
qrcodeSize: 600, //
promotionCode: '', //
imgTop: '', // base64
errT: '', //
posters: false, //
weixinStatus: false, // TODO
canvasStatus: false, //
imagePath: '', //
H5ShareBox: false, // TODO
posterbackgd: '/static/images/posterbackgd.png', //
storeImage: '', //
sharePacket: { //
isState: true, // // TODO
},
actionSheetHidden: true, //
// ========== nav + scroll ==========
returnShow: true, // []
@ -417,6 +413,7 @@
computed: mapGetters(['isLogin', 'uid', 'chatUrl']),
watch: {
isLogin: {
// TODO
handler: function(newV, oldV) {
let that = this;
if (newV === true) {
@ -504,18 +501,16 @@
// #endif
});
},
// TODO
/**
* 用户点击右上角分享
* 微信小程序的用户点击右上角分享会回调该方法
*/
// #ifdef MP
onShareAppMessage: function() {
let that = this;
that.$set(that, 'actionSheetHidden', !that.actionSheetHidden);
this.$set(this, 'actionSheetHidden', !this.actionSheetHidden);
return {
title: that.productInfo.storeName || '',
imageUrl: that.productInfo.image || '',
path: '/pages/goods_details/index?id=' + that.id + '&spread=' + that.uid,
title: this.spu.name || '',
imageUrl: this.spu.picUrl || '',
path: '/pages/goods_details/index?id=' + this.id + '&spread=' + this.uid,
}
},
// #endif
@ -534,22 +529,24 @@
this.$set(this, 'userCollect', res.data.userCollect); // TODO
this.$set(this.attr, 'properties', ProductUtil.convertProductPropertyList(skus));
this.$set(this, 'skuMap', ProductUtil.convertProductSkuMap(skus));
this.$set(this.sharePacket, 'priceName', res.data.priceName); // TODO share packet
// // TODO
this.$set(this.sharePacket, 'priceName', res.data.priceName);
this.$set(this.sharePacket, 'isState', Math.floor(res.data.priceName) === 0);
//
this.$set(this, 'activityH5', res.data.activityAllH5 ? res.data.activityAllH5 : []);
//
uni.setNavigationBarTitle({
title: productInfo.name.substring(0, 7) + "..."
title: spu.name.substring(0, 7) + "..."
})
// TODO
//
if (this.isLogin) {
this.getCartCount();
//#ifdef H5
this.make(this.uid);
// #ifdef H5
this.make();
this.ShareInfo();
this.getImageBase64(this.productInfo.image);
this.getImageBase64();
// #endif
// #ifdef MP
this.getQrcode();
@ -561,6 +558,7 @@
this.infoScroll();
}, 500);
//
// #ifdef MP
this.imgTop = spu.picUrl
// #endif
@ -778,9 +776,6 @@
kefuClick() {
location.href = this.chatUrl;
},
closeChange: function() {
this.$set(this.sharePacket, 'isState', true);
},
goActivity: function(e) {
let item = e;
if (item.type === "1") {
@ -917,8 +912,6 @@
success: function() {},
});
},
/**
* 获取优惠券
*/
@ -985,251 +978,247 @@
authColse: function(e) {
this.isShowAuth = e
},
/**
* 分享打开
*/
listenerActionSheet: function() {
if (this.isLogin === false) {
toLogin();
} else {
// #ifdef H5
if (this.$wechat.isWeixin() === true) {
this.weixinStatus = true;
}
// #endif
this.posters = true;
}
},
closePosters: function() {
this.posters = false;
},
//
posterImageClose: function() {
this.canvasStatus = false
},
//
setDomain: function(url) {
url = url ? url.toString() : '';
//,
if (url.indexOf("https://") > -1) return url;
else return url.replace('http://', 'https://');
},
//
downloadFilestoreImage: function() {
let that = this;
uni.downloadFile({
url: that.setDomain(that.productInfo.image),
success: function(res) {
that.storeImage = res.tempFilePath;
},
fail: function() {
return that.$util.Tips({
title: ''
});
that.storeImage = '';
},
});
},
//
goFriend: function() {
this.posters = false;
},
//
getQrcode() {
let that = this;
let data = {
pid: that.uid,
id: that.id,
path: 'pages/goods_details/index'
}
getQrcode(data).then(res => {
base64src(res.data.code, res => {
that.PromotionCode = res;
});
}).catch(err => {
that.errT = err;
});
},
//
make(uid) {
let href = location.href.split('?')[0] + "?id="+ this.id + "&spread=" + this.uid;
uQRCode.make({
canvasId: 'qrcode',
text: href,
size: this.qrcodeSize,
margin: 10,
success: res => {
this.PromotionCode = res;
},
complete: () => {},
fail: res => {
this.$util.Tips({
title: '海报二维码生成失败!'
});
}
})
},
getImageBase64: function(images) {
let that = this;
imageBase64({
url: images
}).then(res => {
that.imgTop = res.data.code;
})
},
/**
* 获取产品分销二维码
* @param function successFn 下载完成回调
*
*/
downloadFilePromotionCode: function(successFn) {
let that = this;
getProductCode(that.id)
.then(res => {
uni.downloadFile({
url: that.setDomain(res.data.code),
success: function(res) {
that.$set(that, 'isDown', false);
if (typeof successFn == 'function') successFn && successFn(res
.tempFilePath);
else that.$set(that, 'PromotionCode', res.tempFilePath);
},
fail: function() {
that.$set(that, 'isDown', false);
that.$set(that, 'PromotionCode', '');
}
});
})
.catch(err => {
that.$set(that, 'isDown', false);
that.$set(that, 'PromotionCode', '');
});
},
/**
* 生成海报
*/
goPoster: function() {
let that = this;
uni.showLoading({
title: '海报生成中',
mask: true
});
that.posters = false;
let arrImagesUrl = '';
let arrImagesUrlTop = '';
if (!that.PromotionCode) {
uni.hideLoading();
that.$util.Tips({
title: that.errT
});
return
}
setTimeout(() => {
if (!that.imgTop) {
uni.hideLoading();
that.$util.Tips({
title: '无法生成商品海报!'
});
return
}
}, 1000);
uni.downloadFile({
url: that.imgTop, //
success: (res) => {
arrImagesUrlTop = res.tempFilePath;
let arrImages = [that.posterbackgd, arrImagesUrlTop, that.PromotionCode];
let storeName = that.productInfo.storeName;
let price = that.productInfo.price;
setTimeout(() => {
that.$util.PosterCanvas(arrImages, storeName, price, that.productInfo
.otPrice,
function(tempFilePath) {
that.imagePath = tempFilePath;
that.canvasStatus = true;
uni.hideLoading();
});
}, 500);
}
});
},
/*
* 保存到手机相册
*/
// #ifdef MP
savePosterPath: function() {
let that = this;
uni.getSetting({
success(res) {
if (!res.authSetting['scope.writePhotosAlbum']) {
uni.authorize({
scope: 'scope.writePhotosAlbum',
success() {
uni.saveImageToPhotosAlbum({
filePath: that.imagePath,
success: function(res) {
that.posterImageClose();
that.$util.Tips({
title: '保存成功',
icon: 'success'
});
},
fail: function(res) {
that.$util.Tips({
title: '保存失败'
});
}
})
}
})
} else {
uni.saveImageToPhotosAlbum({
filePath: that.imagePath,
success: function(res) {
that.posterImageClose();
that.$util.Tips({
title: '保存成功',
icon: 'success'
});
},
fail: function(res) {
that.$util.Tips({
title: '保存失败'
});
},
})
}
}
})
},
// #endif
ShareInfo() {
let data = this.productInfo;
let href = location.href;
if (this.$wechat.isWeixin()) {
href =
href.indexOf("?") === -1 ?
href + "?spread=" + this.uid :
href + "&spread=" + this.uid;
// ========== ==========
/**
* 生成二维码设置到 promotionCode 变量
*/
make() {
let href = location.href.split('?')[0] + "?id="+ this.id + "&spread=" + this.uid;
uQRCode.make({
canvasId: 'qrcode',
text: href,
size: this.qrcodeSize,
margin: 10,
success: res => {
this.promotionCode = res;
},
complete: () => {},
fail: res => {
this.$util.Tips({
title: '海报二维码生成失败!'
});
}
})
},
/**
* 设置微信公众号的分享标题内容等信息
*/
ShareInfo() {
//
if (!this.$wechat.isWeixin()) {
return
}
let spu = this.spu;
let href = location.href;
href = href.indexOf("?") === -1 ? href + "?spread=" + this.uid : href + "&spread=" + this.uid;
let configAppMessage = {
desc: spu.description,
title: spu.name,
link: href,
imgUrl: spu.picUrl
};
this.$wechat.wechatEvevt([
"updateAppMessageShareData",
"updateTimelineShareData",
"onMenuShareAppMessage",
"onMenuShareTimeline"
], configAppMessage).then(res => {
console.log(res);
}).catch(err => {
console.log(err);
})
},
/**
* 获得商品的封面 base64
*/
getImageBase64: function() {
imageBase64({
url: this.spu.picUrl
}).then(res => {
this.imgTop = res.data.code;
})
},
/**
* 获得小程序的二维码
*/
getQrcode() {
let data = {
pid: this.uid,
id: this.id,
path: 'pages/goods_details/index'
}
getQrcode(data).then(res => {
base64src(res.data.code, res => {
this.promotionCode = res;
});
}).catch(err => {
this.errT = err;
});
},
/**
* 生成海报并进行展示
*/
goPoster: function() {
//
uni.showLoading({
title: '海报生成中',
mask: true
});
this.posters = false;
//
if (!this.promotionCode) {
uni.hideLoading();
this.$util.Tips({
title: this.errT
});
return
}
//
setTimeout(() => {
if (!this.imgTop) {
uni.hideLoading();
this.$util.Tips({
title: '无法生成商品海报!'
});
}
}, 1000);
let configAppMessage = {
desc: data.storeInfo,
title: data.storeName,
link: href,
imgUrl: data.image
};
this.$wechat.wechatEvevt([
"updateAppMessageShareData",
"updateTimelineShareData",
"onMenuShareAppMessage",
"onMenuShareTimeline"
], configAppMessage).then(res => {
console.log(res);
}).catch(err => {
console.log(err);
})
}
},
//
const that = this;
let arrImagesUrlTop = '';
uni.downloadFile({
url: that.imgTop, //
success: (res) => {
debugger
arrImagesUrlTop = res.tempFilePath;
const arrImages = [that.posterbackgd, arrImagesUrlTop, that.promotionCode];
const name = that.spu.name;
const price = that.fen2yuan(this.spu.price);
const marketPrice = that.fen2yuan(this.spu.marketPrice);
setTimeout(() => {
that.$util.PosterCanvas(arrImages, name, price, marketPrice,
function(tempFilePath) {
that.imagePath = tempFilePath;
that.canvasStatus = true;
uni.hideLoading();
});
}, 500);
}
});
},
/**
* 隐藏海报
*/
posterImageClose: function() {
this.canvasStatus = false
},
/**
* 关闭分享弹窗
*/
closePosters: function() {
this.posters = false;
},
/**
* 获取海报产品图解决跨域问题只适用于小程序
*/
downloadFilestoreImage: function() {
let that = this;
uni.downloadFile({
url: that.setDomain(that.spu.picUrl),
success: function(res) {
that.storeImage = res.tempFilePath;
},
fail: function() {
that.storeImage = '';
return that.$util.Tips({
title: ''
});
},
});
},
/**
* 替换安全域名
*/
setDomain: function(url) {
url = url ? url.toString() : '';
// ,
if (url.indexOf("https://") > -1) {
return url;
}
return url.replace('http://', 'https://');
},
/**
* 分享打开
*/
listenerActionSheet: function() {
if (!this.isLogin) {
toLogin();
return
}
// #ifdef H5
if (this.$wechat.isWeixin() === true) {
this.weixinStatus = true;
}
// #endif
this.posters = true;
},
/**
* 微信小程序的保存图片到本机
*/
// #ifdef MP
savePosterPath: function() {
let that = this;
uni.getSetting({
success(res) {
if (!res.authSetting['scope.writePhotosAlbum']) {
uni.authorize({
scope: 'scope.writePhotosAlbum',
success() {
uni.saveImageToPhotosAlbum({
filePath: that.imagePath,
success: function(res) {
that.posterImageClose();
that.$util.Tips({
title: '保存成功',
icon: 'success'
});
},
fail: function(res) {
that.$util.Tips({
title: '保存失败'
});
}
})
}
})
} else {
uni.saveImageToPhotosAlbum({
filePath: that.imagePath,
success: function(res) {
that.posterImageClose();
that.$util.Tips({
title: '保存成功',
icon: 'success'
});
},
fail: function(res) {
that.$util.Tips({
title: '保存失败'
});
},
})
}
}
})
},
// #endif
/**
* 关闭分销的弹窗
*/
closeChange: function() {
this.$set(this.sharePacket, 'isState', true);
},
// ========== nav ==========
/**