Commit e7098dec authored by 刘文虎's avatar 刘文虎

生成海报

parent 1ab2b027
Pipeline #3963 canceled with stages
<template> <template>
<u-popup v-model="show" :animation="false" ref="uniPopup" border-radius="24" type="center" mode="center"> <uni-popup v-model="show" ref="uniPopup" :animation="false" border-radius="24" type="center" mode="center">
<view class="custom-popup"> <view class="custom-popup">
<view class="apply-refuse"> <view class="apply-refuse">
<view class="title">本次服务收费金额</view> <view class="user">
<view class="user-avatar">
<image :src="userInfo.avatar" mode="" v-if="userInfo.avatar"></image>
<image :src="avatar" v-else></image>
</view>
<text>{{ userInfo.nickname || '微信用户' }}</text>
</view>
<view class="content-view"> <view class="content-view">
<view class="qrcode-view"><image :src="qrcode"></image></view>
</view>
</view> </view>
<view class="btn"> <view class="btn">
<view class="confirm" hover-class="u-hover-class" @click="$u.throttle(handleClickSure, 500)">确定</view> <view class="confirm" @click="$u.throttle(handleClickSure, 500)">
<view class="image-view"><image :src="saveImage"></image></view>
<text hover-class="u-hover-class">保存至相册</text>
</view> </view>
</view> </view>
<u-toast ref="uToast" />
</view> </view>
</u-popup> </uni-popup>
</template> </template>
<script> <script>
import UniPopup from '@/uni_modules/uni-popup/uni-popup.vue';
import { mineBaseUrl } from '@/utils/config.js';
import { mapGetters } from 'vuex';
export default { export default {
props:['qrcode'], props: ['qrcode'],
components: {
UniPopup
},
data() { data() {
return { return {
show: false, show: false,
saveImage: mineBaseUrl + 'haibaobaocunxiangce@3x.png',
avatar: mineBaseUrl + 'toxuiang@3x.png',
backgroundImage: mineBaseUrl + 'min-share-haibao.jpg'
}; };
}, },
computed: {
...mapGetters(['userInfo']),
},
methods: { methods: {
open() { open() {
this.show = true; this.show = true;
this.$refs.uniPopup.open();
}, },
close() { close() {
this.show = false; this.show = false;
this.$refs.uniPopup.close();
}, },
handleClickSure() { handleClickSure() {
this.close(); this.$emit('save');
this.$emit('confirm', this.text); }
},
} }
}; };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.custom-popup { .custom-popup {
position: relative;
.apply-refuse { .apply-refuse {
background: linear-gradient(180deg, #f4fffc 0%, #ffffff 50%) #fff; background-color: $default-color;
width: 622rpx; background: url('https://static-book.kaying.cc/icon/mine/min-share-haibao.jpg') no-repeat;
background-position: center top;
background-size: 100%;
width: 620rpx;
height: 1010rpx;
border-radius: 12rpx; border-radius: 12rpx;
padding: 0 24rpx 32rpx; padding: 52rpx 36rpx;
position: relative;
.user {
display: flex;
align-items: center;
color: #FFFFFF;
.title { .user-avatar {
padding: 48rpx 0 40rpx; width: 44rpx;
text-align: center; height: 44rpx;
font-size: 32rpx; border-radius: 50%;
color: #333333; background: #FFFFFF;
padding: 4rpx;
display: flex;
margin-right: 12rpx;
} }
.content-view {
width: 100%;
} }
.content-view {
position: absolute;
top: 550rpx;
left: 50%;
transform: translateX(-50%);
width: 192rpx;
height: 192rpx;
background: #FFFFFF;
border-radius: 16rpx;
display: flex;
align-items: center;
justify-content: center;
.qrcode-view {
width: 160rpx;
height: 160rpx;
display: flex;
}
}
}
.btn { .btn {
margin-top: 68rpx; position: absolute;
bottom: -146rpx;
left: 50%;
transform: translateX(-50%);
font-size: 32rpx; font-size: 32rpx;
width: 480rpx;
.confirm { .confirm {
height: 96rpx; width: 100%;
height: 104rpx;
font-weight: bold; font-weight: bold;
background: $default-color; background: #ffffff;
border-radius: 16rpx; border-radius: 16rpx;
line-height: 96rpx; line-height: 104rpx;
text-align: center; text-align: center;
margin-left: 30rpx; color: $default-color;
color: #ffffff; display: flex;
align-items: center;
justify-content: center;
.image-view {
width: 32rpx;
height: 32rpx;
margin-right: 16rpx;
display: flex;
} }
} }
} }
......
...@@ -15,10 +15,10 @@ ...@@ -15,10 +15,10 @@
</view> </view>
</view> </view>
<view class="bottom-view"> <view class="bottom-view">
<u-button type="success" open-type="share" :custom-style="customSave" @click="handleClickSave"> <u-button type="success" :custom-style="customSave" @click="handleSave">
<view class="bottom-content"> <view class="bottom-content save-content">
<view class="icon-view"><image :src="shareIcon"></image></view> <view class="icon-view"><image :src="saveIcon"></image></view>
<view class="share-view">生成海报</view> <view class="share-view save-view">生成海报</view>
</view> </view>
</u-button> </u-button>
<u-button type="success" open-type="share" :custom-style="customShare" @click="handleClickShare"> <u-button type="success" open-type="share" :custom-style="customShare" @click="handleClickShare">
...@@ -28,30 +28,41 @@ ...@@ -28,30 +28,41 @@
</view> </view>
</u-button> </u-button>
</view> </view>
<save-poster-popup ref="save-poster-popup" :qrcode="qrcode"></save-poster-popup> <u-toast ref="uToast" />
<QRCodeView :url="shareUrl" @canvas="handleCanvas" />
<SavePosterPopup ref="save-poster-popup" :qrcode="qrcode" @save="handleClickSave"></SavePosterPopup>
<l-painter :board="poster" isCanvasToTempFilePath @success="handleCanvasSuccess" @fail="handleCanvasFail" custom-style="position: fixed; left: 400%" />
</view> </view>
</template> </template>
<script> <script>
import NavbarRight from '@/components/navbar-right'; import NavbarRight from '@/components/navbar-right';
import QRCodeView from '@/components/qr-code-view';
import SavePosterPopup from './components/save-poster-popup.vue'; import SavePosterPopup from './components/save-poster-popup.vue';
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import { wxMiniId, webUrl } from '@/utils/config.js'; import { index_share_url, wxMiniId, webUrl, mineBaseUrl } from '@/utils/config.js';
import { shareInvited } from '@/api/mine/share.js'; import { shareInvited } from '@/api/mine/share.js';
import { getSetting } from '@/utils/common.js';
export default { export default {
components: { components: {
NavbarRight, NavbarRight,
SavePosterPopup SavePosterPopup,
QRCodeView
}, },
data() { data() {
return { return {
qrcode:'', avatar: mineBaseUrl + 'toxuiang@3x.png',
saveIcon: mineBaseUrl + 'shengcehnghaibaoanniu@3x.png',
qrcode: '',
poster: {},
currentBlock: () => {},
billImageUrl: '',
customerId: ''
}; };
}, },
computed: { computed: {
...mapGetters(['userInfo']), ...mapGetters(['userInfo']),
baseUrl() { baseUrl() {
return process.uniEnv.qn_base_url; return process.uniEnv.qn_base_url;
}, },
...@@ -84,13 +95,189 @@ export default { ...@@ -84,13 +95,189 @@ export default {
padding: '0rpx' padding: '0rpx'
}; };
}, },
shareTitle() {
return '请客户微信扫码领取账单';
},
shareParams() {
return `?shareUserId=${this.userInfo.id}`;
},
shareUrl() {
return index_share_url + this.shareParams;
},
receive() {
return this.customerId != this.userInfo.id;
}
}, },
onLoad(options) {}, onLoad(options) {},
onUnload() {}, onUnload() {},
onReady() {
setTimeout(() => {
console.log('handleCanvas-qrcode---onReady', this.qrcode);
}, 1500);
},
methods: { methods: {
handleClickSave(){ handleCanvas(url) {
this.$refs['save-poster-popup'].open() console.log('handleCanvas-qrcode---', url);
this.qrcode = url;
},
handleSave() {
this.$refs['save-poster-popup'].open();
},
handleCanvasSuccess(url) {
console.log('---------handleCanvasSuccess--------', url);
this.billImageUrl = url;
this.currentBlock(url);
},
handleCanvasFail(err) {
console.log('---------handleCanvasFail--------', err);
uni.hideLoading();
this.$refs.uToast.show({
title: '保存失败',
type: 'error',
duration: 1500,
callback: () => {}
});
},
handleClickSave() {
this.currentBlock = url => {
uni.saveImageToPhotosAlbum({
filePath: url,
success: () => {
this.$refs.uToast.show({
title: '保存成功',
type: 'success',
duration: 1500,
callback: () => {}
});
},
fail: err => {
// #ifdef APP-PLUS
if (err.errCode == 2) {
uni.hideLoading();
getSetting('photoLibrary', '检测到您没打开保存到相册功能权限,是否去设置打开?', res => {
this.handleClickSave();
});
return;
}
// #endif
var str = err && err.errMsg;
if (str && str.indexOf('cancel') != -1) {
str = '取消保存';
}
this.$refs.uToast.show({
title: str,
type: 'error',
duration: 1500,
callback: () => {}
});
},
complete: res => {
uni.hideLoading();
}
});
};
// #ifdef APP-PLUS
if (this.isIOS) {
this.saveBillImage();
} else {
getSetting('android.permission.WRITE_EXTERNAL_STORAGE', '检测到您没打开保存到相册功能权限,是否去设置打开?', res => {
this.saveBillImage();
});
}
// #endif
// #ifdef MP-WEIXIN
getSetting('scope.writePhotosAlbum', '检测到您没打开保存到相册功能权限,是否去设置打开?', res => {
this.saveBillImage();
});
// #endif
// #ifdef MP-TOUTIAO
getSetting('scope.album', '检测到您没打开保存到相册功能权限,是否去设置打开?', res => {
this.saveBillImage();
});
// #endif
}, },
saveBillImage(tip = '保存中') {
uni.showLoading({
title: tip
});
if (this.billImageUrl) {
this.currentBlock(this.billImageUrl);
} else {
this.saveReceipt();
}
},
saveReceipt() {
console.log('saveReceipt');
this.poster = {
css: {
width: '750rpx',
height: '1220rpx',
backgroundImage: 'url(https://static-book.kaying.cc/icon/mine/min-share-haibao.jpg)',
'object-fit': 'fill'
},
views: [
{
type: 'view',
css: {
marginTop: '60rpx',
marginLeft: '38rpx',
display: 'flex',
'align-items': 'center',
fontSize: '24rpx',
color: '#ffffff',
'line-height': '44rpx'
},
views: [
{
type: 'image',
src: this.userInfo.avatar ? this.userInfo.avatar : this.avatar,
css: {
width: '44rpx',
height: '44rpx',
'border-radius': '50%',
background: '#FFFFFF',
display: 'flex',
'margin-right': '12rpx',
boxSize: 'border-box'
}
},
{
type: 'text',
text: this.userInfo.nickname || '微信用户',
css: {}
}
]
},
{
type: 'view',
css: {
margin: '600rpx auto 0 auto',
width: '192rpx',
height: '192rpx',
background: '#FFFFFF',
'border-radius': '16rpx',
display: 'flex',
'align-items': 'center',
'justify-content': 'center'
},
views: [
{
type: 'image',
src: this.qrcode,
css: {
width: '160rpx',
height: '160rpx',
textAlign: 'center'
}
}
]
}
]
};
},
shareInvited() { shareInvited() {
shareInvited({}) shareInvited({})
.then(res => { .then(res => {
...@@ -191,7 +378,7 @@ export default { ...@@ -191,7 +378,7 @@ export default {
margin: 16rpx 24rpx 36rpx 24rpx; margin: 16rpx 24rpx 36rpx 24rpx;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: space-between;
// background-color: #ffffff; // background-color: #ffffff;
.bottom-content { .bottom-content {
...@@ -200,7 +387,7 @@ export default { ...@@ -200,7 +387,7 @@ export default {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
background-image: linear-gradient(to bottom, #ff8a20 0%, #eb172c 100%); background: linear-gradient(to bottom, #ff8a20 0%, #eb172c 100%);
overflow: hidden; overflow: hidden;
border-radius: 52rpx; border-radius: 52rpx;
...@@ -222,6 +409,14 @@ export default { ...@@ -222,6 +409,14 @@ export default {
height: 100%; height: 100%;
line-height: 104rpx; line-height: 104rpx;
} }
.save-view {
color: #eb172c;
background-color: #ffffff;
}
}
.save-content{
border: 2rpx solid #eb172c;
background: #ffffff;
} }
} }
} }
......
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