var app = getApp();
var $ = require('../../../js/util.js');
Page({
  data: {
    is_show:0,
    goods_id:0,
    list:[],
    matter_img_id:0,
    big_pic:'',
    tj_code:'',
    xz_img:'',
    is_xz:0,
    goods_name:'',
    shop_price:'0.00',
    market_price:'0.00'
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var self = this;
    if (options.goods_id){
      self.setData({
        goods_id: options.goods_id
      })
      self.getIndex(options.goods_id);
    }
  },
  getIndex: function (goods_id) {
    var self = this;
    var action = 'c=ExtensionMatter&a=posters';
    var data = new Object;
    data.goods_id = goods_id;
    app.showLoading('加载中...');
    app.ajaxRequest(action, 'POST', data, function (ret) {
      // console.log(ret);
      if (ret.status == 1) {
        self.setData({
          list: ret.list,
          big_pic: ret.big_pic,
          tj_code: ret.tj_code,
          matter_img_id: ret.matter_img_id,
          goods_name: ret.goods_name,
          shop_price: ret.shop_price,
          market_price: ret.market_price,
          is_show: 1
        })
        app.HCsetStorage('current_list', ret.list);
      }else{
        self.setData({
          is_show: 2
        })
      }
    }, true);
  },
  click_pic:function(e){
    var self = this;
    var matter_img = e.currentTarget.dataset.item;
    if (matter_img){
      self.setData({
        big_pic: matter_img.matter_img,
        matter_img_id: matter_img.id
      })
    }
  },
  down_pic: function (e) {
    return;
  },
  down_xcx_pic: function (e) {
    var self = this;
    self.setData({
      is_xz: 1
    })
    var param = e.currentTarget.dataset;
    var action = 'c=ExtensionMatter&a=save_xcx_matter';
    var data = new Object;
    data.goods_id = param.goods_id;
    data.matter_img_id = param.matter_img_id;
    app.showLoading('加载中...');
    app.ajaxRequest(action, 'POST', data, function (ret) {
      if (ret.status == 1) {
        self.setData({
          xz_img: ret.bc_url
        })
        wx.getImageInfo({
          src: ret.bc_url,
          success: function (sres) {
            wx.saveImageToPhotosAlbum({
              filePath: sres.path,
              success: function (fres) {
                if (fres.errMsg == 'saveImageToPhotosAlbum:ok') {
                  app.HCtoast('保存成功', 1000);
                } else {
                  self.setData({
                    is_xz: 0
                  })
                  app.HCtoast('保存失败,请重新保存', 1000);
                }
              }
            })
          }
        })
      } else {
        self.setData({
          is_xz: 0
        })
        app.HCtoast('保存失败,请重新保存', 1000);
      }
    }, true);
  },
  matter_mask: function () {
    var self = this;
    self.setData({
      is_xz: 0
    })
  },
  onShareAppMessage: function () {
    return {
      title: this.data.goods_name,
      desc: '选择您心仪的宝贝!',
      path: '/pages/takeout/cont/cont?invite_key=' + app.globalData.init_invite_key + '&id=' + this.data.goods_id//' + $.getCurrentPageUrl() + '
    }
  },
})