<template>
  <view class="app-content">
    <view class="img_box" style="margin-top:30upx;">
      <image :src="gatherUrl" mode="heightFix" class="img_url"></image>
    </view>
    <view style="font-size:30upx;text-align: center;margin:30upx 0 5upx 0;">支持信用卡和花呗，打印尺寸100mmx150mm</view>
    <view class="confirm-btn">
      <button class="admin-button-com big blue" style="width:60vw;" @click="downloadImg(gatherUrl)">下载收款码</button>
    </view>

    <view class="confirm-btn">
      <button class="admin-button-com big blue" style="width:60vw;">购买音响</button>
    </view>

    <view style="margin-top:30upx;text-align:center;margin-bottom:30upx;">
      <image :src="laba" mode="widthFix" style="width:640upx;margin:0 auto;border-radius: 10upx;"></image>
    </view>

  </view>
</template>
<script>
import { miniGatheringCode } from '@/api/shop'
export default {
  data() {
    return {
      gatherUrl:'',
      laba: `${this.$constant.hostUrl}/image/horn.jpg`
    }
  },
  methods: {
    init() {
      this.getImg()
    },
    downloadImg(url){
            // #ifdef APP-PLUS
            let platformType = uni.getSystemInfoSync().platform
            if(platformType == 'android'){
                let store = plus.navigator.checkPermission('android.permission.READ_EXTERNAL_STORAGE')
                if(store != 'authorized'){
                    this.$util.confirmModal({content:'将申请您的存储权限，用于保存小程序码'},() => {
                        this.downloadImg2(url)
            })
                }else{
                    this.downloadImg2(url)
                }
            }else{
                this.downloadImg2(url)
            }
            // #endif
            // #ifdef MP-WEIXIN
            this.downloadImg2(url)
            // #endif
    },
    downloadImg2(url){
      uni.downloadFile({
        url: url,
        success: (res) => {
          if (res.statusCode === 200) {
            uni.saveImageToPhotosAlbum({
              filePath: res.tempFilePath,
              success: function (data) {
                uni.showToast({title:'下载成功!'})
              }
            });
          }
        }
      });
    },
    getImg() {
      miniGatheringCode().then(res => {
        this.gatherUrl = res.data.imgUrl
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.app-content{
  overflow: hidden;
}
.img_box{
  height:900upx;
  box-sizing: border-box;
  &>.img_url{
    height:900upx;
    width: auto;
    margin: 20upx auto;
  }
}
// 按钮
.confirm-btn {
  width: calc(100% - 60upx);
  margin: 30upx 30upx 20upx;
  text-align:center;
  .admin-button-com {
    width: 100%;
  }
}
// 按钮
.confirm-btn1 {
  width: calc(100% - 60upx);
  margin: 30upx 30upx 20upx;
  text-align:center;
  .admin-button-com {
    width: 100%;
  }
}
</style>