
<template>
<div class="container"
style="background-image:url('https://qiniu.zyb16.cn/work/image/static/myPages/promote/bg.png')">
<u-gap height="968rpx"></u-gap>
<div class="buttons">
<u-button :customStyle="submitCustomStyle" openType="share" type="primary" @click="miniProgramShare()">
<u--image height="88rpx" src='https://qiniu.zyb16.cn/work/image/static/myPages/promote/wx.png'
width="312rpx"></u--image>
</u-button>
<u--image height="88rpx" src='https://qiniu.zyb16.cn/work/image/static/myPages/promote/album.png'
width="312rpx" @click="saveImages"></u--image>
</div>
<u-gap height="32rpx"></u-gap>
<div class="card"
style="background-image:url('https://qiniu.zyb16.cn/work/image/static/myPages/promote/card.png')">
<div class="invite-code">
<div class="code-line"></div>
<div class="code-text">邀请码</div>
<div class="code-line"></div>
</div>
<div class="code-number">
{{ invite_code }}
</div>
<u-button :customStyle="copyCustomStyle" text="复制邀请码" type="primary" @click="copyCode()">
</u-button>
</div>
<u-gap height="32rpx"></u-gap>
<div class="my-promote">
<u-gap height="48rpx"></u-gap>
<div class="promote-title">
<u--image height="20rpx" src='https://qiniu.zyb16.cn/work/image/static/myPages/promote/pr-left.png'
width="48rpx"></u--image>
<div class="title-text">我的推广</div>
<u--image height="20rpx" src='https://qiniu.zyb16.cn/work/image/static/myPages/promote/pr-right.png'
width="48rpx"></u--image>
</div>
<u-gap height="36rpx"></u-gap>
<div class="promote-info">
<div class="promote-info-item">
<div class="promote-info-number">
{{ promote.people }}
</div>
<div class="promote-info-desc">
推广人数
</div>
</div>
<div class="promote-info-line"></div>
<div class="promote-info-item">
<div class="promote-info-number">
¥{{ promote.money }}
</div>
<div class="promote-info-desc">
累计佣金
</div>
</div>
</div>
<u-gap height="36rpx"></u-gap>
<div class="list">
<u-list height="420rpx" @scrolltolower="scrolltolower">
<u-list-item v-for="(item, index) in list" :key="index">
<div class="list-item">
<div class="list-item-left">
<u--image :src="item.avatar" height="64rpx" shape="circle" width="64rpx"></u--image>
<div class="list-left-info">
<div class="list-left-info-header">
<div class="list-left-info-header-name">{{ item.name }}</div>
<div :class="item.verify_project === 1 ? 'success' : 'fail'"
class="list-left-info-header-status">
{{ item.verify_project | statusFilter }}
</div>
</div>
<div class="list-left-info-phone">
{{ item.mobile }}
</div>
</div>
</div>
<div class="list-item-right">¥{{ item.amount }}</div>
</div>
</u-list-item>
</u-list>
</div>
</div>
<u-overlay :show="showOverlay">
<view class="warp-overlay">
<view class="rect" @tap.stop>
<u--image height="290rpx" src='https://qiniu.zyb16.cn/work/image/static/myPages/promote/rocket.png'
width="290rpx"></u--image>
<view class="rect-text-thanks">
感谢您的助力
</view>
<view class="rect-text-desc">
当被推荐人购买会员,您将获赠佣金!
</view>
<u-button :customStyle="rocketCustomStyle" text="好的" type="primary" @click="showOverlay = false">
</u-button>
</view>
</view>
</u-overlay>
<canvas id="canvas" canvas-id="canvas" class="canvas" style="width:750rpx;height:1532rpx;" />
</div>
</template>
<script>
import {
mapState,
mapGetters
} from 'vuex'
export default {
name: 'Promote',
filters: {
statusFilter(value) {
if (value === 1) return '已认证项目'
return '未认证项目'
}
},
data() {
return {
showOverlay: false,
rawBg: 'https://img1.clozhome.com/new-clozhome/app/register_poster.png',
rawQrCode: 'https://qa-img.clozhome.com/oms/house/210521/21052111340001.jpg',
bg: 'https://qa-img.clozhome.com/oms/house/210528/21052817710016.png',
qrCode: 'https://qa-img.clozhome.com/oms/house/210521/21052111340001.jpg',
name: '用户',
rpxIndex: '',
canvasDesc: '海外租房新选择,走遍世界都是家!一起来选房吧!',
canvasDesc2: '#英国#美国#加拿大#澳洲#中国香港#新加坡#',
list: [{
avatar: 'https://cdn.uviewui.com/uview/album/1.jpg',
name: '周海波',
phone: '15689097653',
status: 1,
money: 2334
},
{
avatar: 'https://cdn.uviewui.com/uview/album/2.jpg',
name: '周海波2',
phone: '15689097653',
status: 2,
money: 2334
},
{
avatar: 'https://cdn.uviewui.com/uview/album/3.jpg',
name: '周海波3',
phone: '15689097653',
status: 1,
money: 2334
},
{
avatar: 'https://cdn.uviewui.com/uview/album/4.jpg',
name: '周海波4',
phone: '15689097653',
status: 1,
money: 2334
},
{
avatar: 'https://cdn.uviewui.com/uview/album/4.jpg',
name: '周海波4',
phone: '15689097653',
status: 1,
money: 2334
},
{
avatar: 'https://cdn.uviewui.com/uview/album/4.jpg',
name: '周海波4',
phone: '15689097653',
status: 1,
money: 2334
},
{
avatar: 'https://cdn.uviewui.com/uview/album/4.jpg',
name: '周海波4',
phone: '15689097653',
status: 1,
money: 2334
},
],
invite_code: '56789',
promote: {
people: 4,
money: 2345
},
submitCustomStyle: {
'width': '312rpx',
'height': '88rpx',
'border': 'none',
'border-radius': '240rpx',
'color': '#FFFFFF',
'font-size': "30rpx",
'font-weight': '500'
},
copyCustomStyle: {
'width': '436rpx',
'height': '74rpx',
'background': 'linear-gradient(98deg, #ff5b27 0%, #ff0f00 100%)',
'border': 'none',
'border-radius': '320rpx',
'color': '#FFFFFF',
'font-size': "30rpx",
'font-weight': '500'
},
rocketCustomStyle: {
'width': '436rpx',
'height': '74rpx',
'background': 'linear-gradient(98deg, #ff5b27 0%, #ff0f00 100%)',
'border': 'none',
'border-radius': '320rpx',
'color': '#FFFFFF',
'font-size': "30rpx",
'font-weight': '500'
}
};
},
mounted() {
this.init()
},
computed: {
...mapState({
token: (state) => state.user.token
}),
canvasW() {
return 750 * this.rpxIndex
},
canvasH() {
return 1530 * this.rpxIndex
},
ewmW() {
return 312 * this.rpxIndex
},
ewmH() {
return 88 * this.rpxIndex
}
},
onShow() {
const _this = this
uni.getSystemInfo({
success: function(res) {
_this.rpxIndex = res.windowWidth / 750
}
});
},
methods: {
init() {
this.$request.post('/user/invite_info').then(({
data,
code,
msg
}) => {
this.invite_code = data.invite_code
this.promote.people = data.count
this.promote.money = data.commission
this.list = data.list
})
},
miniProgramShare() {
console.log('ssss😊===>');
uni.share({
provider: "weixin",
scene: "WXSceneSession",
type: 1,
summary: "我正在使用HBuilderX开发uni-app,赶紧跟我一起来体验!",
openCustomerServiceChat: true,
corpid: 'xx',
customerUrl: 'https://work.weixin.qq.com/kf/kfcbf8f8d07ac7215f?enc_scene=ENCGFSDF567DF',
success: function(res) {
console.log("success:" + JSON.stringify(res));
},
fail: function(err) {
console.log("fail:" + JSON.stringify(err));
}
});
},
copyCode() {
this.showOverlay = true
const data = this.invite_code
uni.setClipboardData({
data: data,
success: function() {
uni.$u.toast('已复制')
console.log('success');
}
});
},
async saveImage(e) {
var _this = this
uni.showLoading({
title: '加载中'
})
this.bg = await this.getLocalImage('https://qiniu.zyb16.cn/work/image/static/myPages/promote/bg.png')
this.qrCode = await this.getLocalImage(
'https://qiniu.zyb16.cn/work/image/static/myPages/promote/album.png')
await this.makeCanvas()
return new Promise((resolve, reject) => {
setTimeout(() => {
uni.canvasToTempFilePath({
canvasId: 'canvas',
quality: 1,
complete: function(res) {
uni.hideLoading()
console.log('保存canvas为图片===>', res)
_this.posterUrl = res.tempFilePath
resolve(res.tempFilePath)
},
})
}, 200)
})
},
async saveImages() {
const url = await this.saveImage()
let _this = this;
this.saveImageLocal(url);
uni.authorize({
scope: "scope.writePhotosAlbum",
success() {
console.log("success=====");
_this.saveImageLocal(url);
},
fail() {
wx.showModal({
title: "提示",
content: "请前往授权",
success(res) {
if (res.confirm) {
wx.openSetting({
success(res) {
console.log(res.authSetting);
},
});
console.log("用户点击确定");
} else if (res.cancel) {
console.log("用户点击取消");
}
},
});
console.log("fail=====");
},
});
},
saveImageLocal(url) {
let _this = this;
console.log("保存图片到本地");
uni.saveImageToPhotosAlbum({
filePath: url,
success(res) {
uni.$u.toast("已保存到相册");
},
fail(r) {
console.log("saveImageToPhotosAlbum fail结果😀😀😀===>", r);
},
});
},
getLocalImage(url) {
console.log('把网络图片转换为本地图片开始', url);
var _this = this
return new Promise((resolve, reject) => {
console.log('把网络图片转换为本地图片执行', url);
uni.downloadFile({
url: url,
success: (res) => {
if (res.statusCode === 200) {
console.log('把网络图片转换为本地图片结束');
resolve(res.tempFilePath)
}
}
});
})
},
makeCanvas() {
var _this = this
return new Promise((resolve, reject) => {
var ctx = uni.createCanvasContext('canvas', this);
ctx.setFillStyle('#fff');
ctx.fillRect(0, 0, this.canvasW, this.canvasH)
ctx.drawImage(this.bg, 0, 0, this.canvasW, this.canvasH)
ctx.drawImage(this.qrCode, this.canvasW / 2 - this.ewmW / 2, this.canvasH - this.ewmH -
100 * _this.rpxIndex,
this.ewmW, this.ewmH)
const text = this.name;
ctx.fillStyle = "red";
ctx.setFontSize(42 * _this.rpxIndex)
const {
width
} = ctx.measureText(text);
function roundRectColor(context, x, y, w, h, r, color) {
context.setFillStyle(color);
context.setStrokeStyle(color)
context.setLineJoin('round');
context.setLineWidth(r);
context.strokeRect(x + r / 2 + 2, y + r / 2 + 2, w - r - 3, h - r - 3);
context.fillRect(x + r, y + r, w - r * 2, h - r * 2);
context.stroke();
context.closePath();
}
function findBreakPoint(text, width, context) {
var min = 0;
var max = text.length - 1;
while (min <= max) {
var middle = Math.floor((min + max) / 2);
var middleWidth = context.measureText(text.substr(0, middle)).width;
var oneCharWiderThanMiddleWidth = context.measureText(text.substr(0, middle + 1))
.width;
if (middleWidth <= width && oneCharWiderThanMiddleWidth > width) {
return middle;
}
if (middleWidth < width) {
min = middle + 1;
} else {
max = middle - 1;
}
}
return -1;
}
function breakLinesForCanvas(context, text, width, font) {
var result = [];
var breakPoint = 0;
if (font) {
context.font = font;
}
while ((breakPoint = findBreakPoint(text, width, context)) !== -1) {
result.push(text.substr(0, breakPoint));
text = text.substr(breakPoint);
}
if (text) {
result.push(text);
}
return result;
}
const tempfontSize = 24 * this.rpxIndex
const fontSizeDesc = `12px 微软雅黑`
console.log('fontSizeDesc', fontSizeDesc)
ctx.setFontSize(42 * _this.rpxIndex)
ctx.setFillStyle('#EF584A')
const scanbonus = '扫一扫 赢奖励'
ctx.setFontSize(28 * _this.rpxIndex)
ctx.setFillStyle('#333333')
const rentmiddlelength = (this.canvasW - ctx.measureText(scanbonus).width) / 2
ctx.shadowColor = '#C33222';
ctx.shadowOffsetX = -3;
ctx.shadowOffsetY = 3;
ctx.shadowBlur = 3;
ctx.setFontSize(32 * _this.rpxIndex)
ctx.setFillStyle('#FFF')
ctx.draw(false, (ret) => {
console.log('把以上内容画到 canvas 中===>', ret)
setTimeout(() => {
resolve(ret)
}, 150)
});
})
},
},
};
</script>
<style lang="scss" scoped>
.warp-overlay {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
background: rgba(18, 18, 18, 0.86);
backdrop-filter: blur(12rpx);
.rect {
width: 688rpx;
height: 696rpx;
background: #ffffff;
border-radius: 24rpx;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
padding: 64rpx 0;
box-sizing: border-box;
.rect-text {
font-size: 30rpx;
font-family: PingFang SC, PingFang SC-Regular;
font-weight: 400;
text-align: CENTER;
color: #121212;
}
}
}
.container {
width: 100%;
min-height: 1532rpx;
background-size: 100% 1532rpx;
background-repeat: no-repeat;
background-position: 0 0;
padding: 0 0 50rpx;
// padding: 60rpx 30rpx;
// box-sizing: border-box
background-color: #ff2a14;
.buttons {
padding: 0 48rpx;
box-sizing: border-box;
display: flex;
justify-content: space-between;
align-items: center;
}
.card {
width: 688rpx;
height: 352rpx;
margin: 0 30rpx;
padding: 48rpx 0;
box-sizing: border-box;
// min-height: 1532rpx;
background-size: 100%;
background-repeat: no-repeat;
background-position: 0 0;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
.invite-code {
display: flex;
justify-content: center;
align-items: center;
.code-line {
width: 100rpx;
height: 4rpx;
background-color: #f5f5f5;
// border: 2rpx solid #666666;
}
.code-text {
padding: 0 30rpx;
font-size: 32rpx;
font-family: PingFang SC, PingFang SC-Medium;
font-weight: 500;
color: #666666;
}
}
.code-number {
font-size: 64rpx;
font-family: PingFang SC, PingFang SC-Medium;
font-weight: 500;
text-align: CENTER;
color: #222222;
line-height: 64rpx;
letter-spacing: 1.28rpx
}
}
.my-promote {
margin: 0 30rpx;
box-sizing: border-box;
// width: 612rpx;
// height: 150rpx;
background: #fff;
border-radius: 24rpx;
.promote-title {
display: flex;
justify-content: center;
align-items: center;
.title-text {
font-size: 32rpx;
font-family: PingFang SC, PingFang SC-Bold;
font-weight: 700;
text-align: CENTER;
color: #ff2a14;
margin: 0 20rpx;
}
}
.promote-info {
// width: 612rpx;
height: 150rpx;
background: #ffeae0;
border-radius: 24rpx;
display: flex;
justify-content: space-between;
align-items: center;
margin: 0 30rpx;
padding: 0 60rpx;
box-sizing: border-box;
.promote-info-line {
width: 0rpx;
height: 64rpx;
border: 2rpx solid rgba(255, 66, 45, 0.20);
}
.promote-info-item {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
.promote-info-number {
font-size: 36rpx;
font-family: PingFang SC, PingFang SC-Medium;
font-weight: 500;
text-align: CENTER;
color: #ff2a14;
}
.promote-info-desc {
font-size: 28rpx;
font-family: PingFang SC, PingFang SC-Regular;
font-weight: 400;
text-align: CENTER;
color: #222222;
}
}
}
}
.list {
padding: 0 30rpx;
box-sizing: border-box;
.list-item {
margin-bottom: 40rpx;
display: flex;
justify-content: space-between;
align-items: center;
.list-item-left {
display: flex;
justify-content: space-between;
align-items: center;
.list-left-info {
margin-left: 8rpx;
display: flex;
flex-direction: column;
justify-content: space-between;
// align-items: center;
.list-left-info-header {
display: flex;
align-items: center;
.list-left-info-header-name {
font-size: 28rpx;
font-family: PingFang SC, PingFang SC-Medium;
font-weight: 500;
color: #222222;
margin-right: 8rpx;
}
.list-left-info-header-status {
font-size: 24rpx;
font-family: PingFang SC, PingFang SC-Medium;
font-weight: 500;
border-radius: 4rpx;
font-weight: bold;
padding: 2rpx 5rpx;
}
.success {
background: linear-gradient(180deg, rgba(255, 145, 44, 0.2), rgba(255, 122, 0, 0.5) 100%);
color: #ff8d24;
}
.fail {
background: linear-gradient(180deg, rgba(191, 191, 191, .1) 0%, rgba(132, 132, 132, .5) 100%);
color: #919191;
}
}
.list-left-info-phone {
font-size: 26rpx;
font-family: PingFang SC, PingFang SC-Regular;
font-weight: 400;
color: #666666;
}
}
}
.list-item-right {
font-size: 32rpx;
font-family: PingFang SC, PingFang SC-Medium;
font-weight: 500;
color: #ff4242;
}
}
}
}
.canvas {
position: fixed;
// left: 999px
top: 150rpx;
left: 300%;
}
</style>