xuxueyang
2024-08-03 f8ed6c9b46800105789afccc444c46c2aeb956dd
sub_pages/partner/partner-info/partner-code.vue
@@ -2,9 +2,17 @@
   <!-- 联系我们 -->
   <!--  -->
   <view class="contact-container">
      <view class="container" @click="saveCode">
      <view class="container" @click="saveCode" v-if="!codeUrl">
         <canvas type="2d" id="myQrcode" class="code"></canvas>
         <view class="info">
            <view class="desc">
               <p>{{name||'-'}}的推广二维码</p>
               <p style="font-size: 600;color: #000;">点击保存二维码</p>
            </view>
         </view>
      </view>
      <view v-if="codeUrl" @click="saveImg">
         <image :src="codeUrl" class="code-img"></image>
         <view class="info">
            <view class="desc">
               <p>{{name||'-'}}的推广二维码</p>
@@ -23,6 +31,7 @@
         return {
            name: '',
            userId: '',
            codeUrl: '',
            canvas: undefined,
         }
      },
@@ -45,15 +54,67 @@
            this.$message.showToast('请先完善合伙人信息')
            return
         }
         //有定制二维码,显示定制二维码
         this.codeUrl = this.currentInfo.partnerDTO.codeUrl || ''
         this.name = this.currentInfo.partnerDTO.name || '佚名'
         // this.userId = this.currentInfo.userId
         this.initcode()
         if (!this.codeUrl)
            this.initcode()
      },
      methods: {
         async saveImg() {
            await this.$message.confirm('确定保存此文件吗')
            let _this = this
            _this.$message.showLoading()
            uni.downloadFile({
               url: _this.codeUrl, //下载地址接口返回
               success: (data) => {
                  _this.$message.hideLoading()
                  console.log('success', data)
                  if (data.statusCode === 200) {
                     //文件保存到本地
                     uni.saveImageToPhotosAlbum({
                        filePath: data.tempFilePath,
                        success: function() {
                           console.log('save success');
                           uni.showToast({
                              title: '保存成功'
                           })
                        },
                        fail(res) {
                           console.error(res)
                           uni.showToast({
                              title: '保存失败。',
                              icon: 'error'
                           })
                        }
                     })
                  }else{
                     uni.showToast({
                        title: '保存失败。.',
                        icon: 'error'
                     })
                  }
               },
               fail: (err) => {
                  _this.$message.hideLoading()
                  console.log(err);
                  uni.showToast({
                     icon: 'none',
                     mask: true,
                     title: '失败请重新下载',
                  });
               },
            });
         },
         initcode() {
            let that = this
            const query = uni.createSelectorQuery()
            var qrUrl =
               `https://scan.hmyxianhua.com/wx/?partnerUserId=${this.currentInfo.id||'-'}&partnerUserName=${this.name||'-'}`
            query.select('#myQrcode')
               .fields({
                  node: true,
@@ -74,12 +135,12 @@
                     padding: 30,
                     background: '#ffffff',
                     foreground: '#000000',
                     text: JSON.stringify({
                        'name': that.name,
                        'userId': that.currentInfo.id,
                        // 'userId': that.currentInfo.partnerDTO.id,
                        'version': '1.1.0'
                     }),
                     // text: JSON.stringify({
                     //    'name': that.name,
                     //    'userId': that.currentInfo.id,
                     //    'version': '1.1.0'
                     // }),
                     text: qrUrl
                     // text: `https://www.hmyxianhua.com/wx-c-jump/sub_pages/customer/customer-info/customer-info?name=${that.name}&userId=${that.currentInfo.id}`
                     // JSON.stringify({
                     //    'name': that.name,
@@ -138,6 +199,14 @@
   .contact-container {
      position: relative;
      .code-img {
         width: 600rpx;
         min-height: 600rpx;
         display: inline-block;
         margin: 0 auto;
         margin-top: 100rpx;
      }
      .container {
         position: absolute;
         top: 148rpx;