const util = require("../../../../utils/util");
const app = getApp();
Component({
  properties: {
    show: {
      type: Boolean,
      observer: function (newVal) {
        this.setData({ showCode: newVal });
      }
    },
    headImg: {
      type: String,
      observer: function (newVal) {
        this.setData({ headImg: newVal });
      }
    },
    methodView:{
      type: Number,
      observer: function (newVal) {
        this.setData({ methodView: newVal });
      }
    }
  },
  data: {
    height:'80%',
    showCode:false,
    headImg:'',
    methodView:0
  },
  methods: {
    // 弹窗关闭
    closeCode(e){
      this.triggerEvent("close", e.detail);
    },
    saveImage(e){
      let self = this;
      wx.downloadFile({
        url:e.currentTarget.dataset.img,
        success(res) {
          wx.saveImageToPhotosAlbum({
            filePath:res.tempFilePath,
            success:(res)=>{
              util.showTips('已保存至相册！')
              setTimeout(() => {
                self.triggerEvent("close", false)
              }, 500);
            }
          })
        },
        fail(res){
          util.showTips('保存失败！')
        }
      })
    }
  }
})