shop-applet/pages/payment/qrcode.vue

156 lines
3.4 KiB
Vue
Raw Normal View History

2024-02-29 14:13:50 +08:00
<template>
<view class="container">
<view class="v-navbar">
2024-03-19 18:10:33 +08:00
<u-navbar title="商户收款" :autoBack="true" :fixed="false" bgColor="transparent" leftIconColor="#fff"
2024-03-01 10:16:23 +08:00
:titleStyle="{color:'#fff',fontWeight:'bold',fontSize:'32rpx'}">
2024-02-29 14:13:50 +08:00
</u-navbar>
</view>
2024-03-18 16:36:42 +08:00
<view style="display:flex;justify-content:center;flex-direction:column;align-items:center;">
<image src="https://lihai001.oss-cn-chengdu.aliyuncs.com/def/82347202403181619505958.png"
style="width:350rpx;height:118rpx;" mode="widthFix" />
<text class="shop_name">店铺:{{userInfo.mer_info.mer_name || '-'}}</text>
</view>
2024-02-29 14:13:50 +08:00
<view class="v-qrcode">
2024-03-18 16:36:42 +08:00
<u-image width="490rpx" height="490rpx" :showLoading="true" :src="img" class="v-qrcode-img"></u-image>
2024-02-29 14:13:50 +08:00
</view>
<view class="v-btn" @click="handleSavePic">
<text>保存二维码</text>
</view>
</view>
</template>
<script>
2024-02-29 20:35:06 +08:00
import {
qrcode
} from "@/api/payment.js";
2024-02-29 14:13:50 +08:00
export default {
2024-02-29 20:35:06 +08:00
data() {
return {
2024-03-04 11:05:04 +08:00
img: '',
2024-03-18 16:36:42 +08:00
userInfo: {}
2024-02-29 20:35:06 +08:00
}
},
onLoad(opt) {
2024-03-18 16:36:42 +08:00
let user = this.$store.state.app.userInfo;
if (typeof user == 'string') user = JSON.parse(user);
this.userInfo = user;
this.getQrcode(user.service.mer_id)
2024-02-29 20:35:06 +08:00
},
2024-02-29 14:13:50 +08:00
methods: {
2024-02-29 20:35:06 +08:00
// 获取二维码
getQrcode(merid) {
qrcode({
2024-03-18 16:36:42 +08:00
mer_id: merid
2024-02-29 20:35:06 +08:00
}).then(res => {
2024-03-20 17:32:43 +08:00
if (!res.data.count || res.data.count == 0) {
this.$util.Tips({
title: "您还没有添加商品,请添加!"
}, () => {
uni.redirectTo({
url: "/pages/product/addGood/addGood?mer_id=" + merid
})
})
} else {
this.img = res.data.url;
}
2024-02-29 20:35:06 +08:00
})
},
2024-02-29 14:13:50 +08:00
handleSavePic() {
// 获取要保存的图片路径或URL
2024-02-29 20:35:06 +08:00
let imageUrl = this.img; // 这里使用了网络上的图片作为示例
2024-02-29 14:13:50 +08:00
// #ifdef H5
var a = document.createElement("a");
a.download = imageUrl;
a.href = imageUrl;
document.body.appendChild(a);
a.click();
a.remove();
2024-02-29 20:35:06 +08:00
this.$util.Tips({
title: '二维码保存成功!'
})
2024-02-29 14:13:50 +08:00
// #endif
// #ifndef H5
let that = this;
uni.downloadFile({
url: imageUrl,
success(res) {
if (res.statusCode === 200) {
let tempFilePath = res.tempFilePath; // 临时文件路径
uni.saveImageToPhotosAlbum({
filePath: tempFilePath,
success() {
return that.$util.Tips({
title: '图片已保存至相册!'
});
},
fail(err) {
console.error('保存失败', err);
}
});
} else {
console.error('下载失败', res.statusCode);
}
},
fail(err) {
console.error('下载失败', err);
}
});
// #endif
}
}
}
2024-03-18 16:36:42 +08:00
</script>
2024-03-19 18:10:33 +08:00
<style lang="scss">
2024-03-18 16:36:42 +08:00
page {
background-color: #40AE36;
}
.container {
position: relative;
height: 100vh;
background-size: 100% auto;
background-repeat: no-repeat;
padding-top: var(--status-bar-height);
.v-navbar {
margin-bottom: 54rpx;
}
.v-qrcode {
width: 650rpx;
height: 650rpx;
2024-03-20 17:32:43 +08:00
margin-top: 100rpx;
margin: 100rpx auto 0;
2024-03-18 16:36:42 +08:00
background-color: #fff;
display: flex;
justify-content: center;
align-items: center;
}
.shop_name {
margin-top: 30rpx;
font-size: 30rpx;
color: #FFFFFF;
}
.v-btn {
display: flex;
align-items: center;
justify-content: center;
width: 690rpx;
height: 100rpx;
2024-03-20 17:32:43 +08:00
margin: 70rpx auto 0;
2024-03-18 16:36:42 +08:00
text {
font-weight: 400;
font-size: 32rpx;
color: #fff;
}
}
}
</style>