perry-mall/pagesB/personalPoster/personalPoster.vue

224 lines
7.3 KiB
Vue

<template>
<view>
<!-- 状态栏 -->
<status-nav :titleVal="'二维码海报'" :statusTitle="true"></status-nav>
<!-- 自定义二级分类 -->
<!-- 列表 -->
<view :style="{paddingTop: statusHNH+'px'}" class="pad-zy20 pad-x180">
<view class="tc mar-s20 col6 fon28">请选择海报背景后分享</view>
<view v-if="imgList.length!=0">
<view class="mar-s20 disjbac fw">
<image @tap="chooseImg(index)" v-for="(item,index) in imgList" :key="index" class="width100 radius20 mar-x20" :src="item" style="width: 48.5%;max-height: 474rpx" mode="aspectFill" lazy-load></image>
</view>
</view>
<view v-else class="disjcac fc" style="margin-top: 50%;">
<image class="zanw-img mar-x50" src="/static/public/zanwn.png" mode="aspectFill"></image>
<view class="fon24 col3 mar-s50" style="margin-top: 30%;">暂无内容</view>
</view>
<!-- 预览弹框 -->
<view v-if="showBtn" @tap.stop="showBtn=false" class="posAll disjcac fc pad-zy50" style="z-index: 3;">
<image :src="imgSrc" @tap.stop="showBtn=true" class="radius20" style="width: 80%;" mode="widthFix"></image>
<!-- 分享按钮 -->
<view v-if="haved" @tap.stop="shareEv" class="disjcac radius20 posixzy" style="height: 90rpx;margin: 20rpx 80rpx;background-color: #38CE51;line-height: 90rpx;bottom: 40rpx;">
<view class="disac">
<image src="/static/public/sharef.png" style="width: 54rpx;height: 54rpx;" mode=""></image>
<view class="fon40 bold colf mar-z10">分享给好友</view>
</view>
</view>
</view>
</view>
<!-- 弹框 -->
<pu-po :isShowT="imgList.length==0 && isHaib" :contentVal="'立即生成创意海报'" :clearVal="'暂不生成'" :comfrimVal="'立即生成'" @comfirmev="comfirmev" @cancleev="cancleev"></pu-po>
<!-- 底部客服 -->
<!-- <public-customer :nbottom="100"></public-customer> -->
<!-- 弹框授权 -->
<empower @buttonH="buttonH" :vision="vision" :isWhere="2"></empower>
<!-- -->
<auth-phone v-if="isShowP"></auth-phone>
<!-- 底部tab -->
<foot-tab :titleList="titleList" :imgList="tabimgList" :newcurrent='-1'></foot-tab>
</view>
</template>
<script>
import {base64ToPath} from '@/jsFile/base64-src.js';
export default {
data() {
return {
statusHNH:uni.getStorageSync('statusHNH'),
publicColor:uni.getStorageSync('publicColor'),//主题颜色
isShowT:true,
imgList:uni.getStorageSync('imgSrcList'),
imgSrc:'',
showBtn:false,
isHaib:false,
haved:true,
vision:false,
isShowP:false,
titleList:[],//tab标题
tabimgList:[],//tab图标
}
},
onShareAppMessage() {
var shareObj = {
path: `/pagesB/personalPoster/personalPoster?invite_code=${uni.getStorageSync('invite_code')}`, // 默认是当前页面,必须是以‘/’开头的完整路径
};
return shareObj;
},
onLoad(options) {
if(uni.getStorageSync('is_active')!=1){this.vision = true;} else {this.$toolAll.tools.isLogin() ;this.haved = true;}
if(options.invite_code!='' && options.invite_code!=undefined){
this.loginEv(options.invite_code);
} else if(options.source_code!='' && options.source_code!=undefined){
this.loginEv('',options.source_code,options.channel);
}
// uni.removeStorageSync('imgSrcList')
//如果还没有生成海报
if(uni.getStorageSync('imgSrcList')!='') this.imgSrcList = uni.getStorageSync('imgSrcList')//弹框关闭
else this.imgList = []
this.checkPoster();
this.$requst.post('index/mini-program-setting').then(res=>{
// log('数据:',res);
if(res.code==0){
if(res.data.length!=0){
if(res.data.footBar.length!=0){//底部导航
res.data.footBar.forEach(item=>{
let newName = item.name
let newObj = {
iconPath:this.$http + item.icon[0],
selectedIconPath:this.$http + item.icon[1],
}
if(item.key=="home"){
this.tabimgList[0] = newObj
this.titleList[0] = newName
}
if(item.key=="category"){
this.tabimgList[1] = newObj
this.titleList[1] = newName
}
if(item.key=="service"){
this.tabimgList[2] = newObj
this.titleList[2] = newName
}
if(item.key=="shop"){
this.tabimgList[3] = newObj
this.titleList[3] = newName
}
if(item.key=="my"){
this.tabimgList[4] = newObj
this.titleList[4] = newName
}
})
uni.setStorageSync('footTitle',this.titleList)
uni.setStorageSync('footimg',this.tabimgList)
this.titleList = uni.getStorageSync('footTitle')
this.tabimgList = uni.getStorageSync('footimg')
}
}
}
},error=>{})
},
methods: {
loginEv(invite_code='',source='',channel=''){
uni.login({
provider: 'weixin',
success: (res)=> {
var params = {
code:res.code,
invite_code:invite_code,//用户邀请码
source_code:source,
channel:channel
}
this.$requst.post('user/login',params).then(res => {
if(res.data.token!=''){
if(res.data.is_active==0) {
this.haveImg = false;
this.vision = true;
}
}
},error => {})
},
});
},
buttonH(e){//授权成功
this.haveImg = e
if(e) {
this.vision = false
this.isShowP = true
}
},
checkPoster(){//查询海报模板
this.$requst.get('user/poster').then(res=>{
if(res.code==0){
if(res.data.list.length!=0){
res.data.list.forEach(item=>{
this.imgList.push(this.$http + item);
})
}
}
},error=>{})
},
chooseImg(index){//选择海报模板,并生成海报
this.imgSrc = '';
this.haved = this.showBtn = true;
this.$toolAll.tools.showToast('正在生成海报...','loading',10000);
this.$requst.post('user/poster-info',{poster_src:this.imgList[index]}).then(res=>{
if(res.code==0){
base64ToPath(res.data.poster).then(path => {
this.imgSrc = path;
}).catch(error => {})
this.$toolAll.tools.showToast('海报生成成功','none',1500);
} else {
this.$toolAll.tools.showToast('海报生成失败','none',1500);
this.haved = this.showBtn = false;
}
})
},
shareEv(){
this.haved = false;
wx.showShareImageMenu({
path: this.imgSrc,
success:(res=>{
this.$requst.post('user/record',{type:'other',action:'share',id:''}).then(res=>{console.log('分享成功:',res);},error=>{})
let maiOjb = {
e:4,//内容分享
t:new Date().getTime()//当前时间戳
}
this.$toolAll.tools.maiDian(maiOjb);
}),
fail:(res=>{//取消分享
this.haved = true
})
})
},
comfirmev(){//立即生成事件
this.$toolAll.tools.showToast('生成中...')
this.isShowT = false
// 单张海报
this.$requst.get('user/personal-poster').then(res=>{
// console.log('生成个人海报成功:',res);
if(res.code==0){
let newArr = [];
newArr.push(res.data.poster)
uni.hideToast()
newArr.forEach(item=>{
base64ToPath(item).then(path => {
this.imgList.push(path)
uni.setStorageSync('imgSrcList',this.imgList)
}).catch(error => {})
})
this.$toolAll.tools.showToast('生成海报成功');
this.isHaib = false
}
},error=>{})
},
cancleev(){//暂不生成事件
uni.navigateBack({delta:1})
}
}
}
</script>
<style>
</style>