// packageH/deposit_group/component/sharePoster/sharePoster.js
var posterBehavior = require("../../../../poster/poster.js");
var app = getApp();

Component({
  behaviors: [posterBehavior],
  properties: {
    activityid: {
      type: Number,
    },
  },

  data: {},
  ready() {
    // this.getPosterPic();
  },


  /**
   * 组件的方法列表
   */
  methods: {
    async getPosterPic() {
      console.log(this.data.activityid);
      var urlStr = app.getNetAddresss("plugin.deposit-ladder.frontend.index.poster");
      wx.showLoading({
        title: '加载中',
      });
      app._getNetWork({
        url: urlStr,
        // 需要修改参数
        data: {
          id: this.data.activityid,
        },
        success: (resdata) => {
          wx.hideLoading();
          let res = resdata.data;
          if (res.result != 1) {
            wx.showToast({
              title: res.msg,
            });
            return;
          }
          this.setData({
            poster: res.data.poster,
          });
        },
        fail () {
          wx.hideLoading();
        }
      });
    },
    saveImg() {
      var imgSrc = this.data.poster;
      var imgPath =
        wx.env.USER_DATA_PATH + "/solitaire_qrcode" + "haibao" + ".png";
      var imageData = imgSrc.replace(/^data:image\/\w+;base64,/, "");
      var fs = wx.getFileSystemManager();
      fs.writeFileSync(imgPath, imageData, "base64");
      wx.saveImageToPhotosAlbum({
        filePath: imgPath,
        success: (data) => {
          fs.unlinkSync(imgPath);
          wx.showToast({
            title: "保存成功",
            icon: "none",
            duration: 2000,
          });
        },
        fail: function (err) {
          console.log(err);
        },
      });
    },
  },
});
