var app = getApp();

Page({
  data: {
    language: '',
    // goodsData:[],
    goodsData:[],
    dataState:0,
    showEdit:false,
    // 是否显示面板指示点
    indicatorDots: true,
    // 方向
    vertical: false, 
    // 是否自动切换 
    autoplay: true,
    // 自动切换时间间隔
    interval: 4000,
    // 滑动动画时长
    duration: 300
  },
  // 清空收藏收藏(没接口)
  claerData:function(){
    var that= this;
    var url = app.getNetAddresss("favorite/Remove");
    url += "&id="+e.currentTarget.dataset.id;
    wx.showModal({
      title: '提示',
      content: '确定要删除么？此操作不可逆！',
      success: function(res) {
        if (res.confirm) {
          console.log('用户点击确定');


          app._getNetWork(
            {
              url:url,
              success:function(res){
                var _data = res.data;
                console.log("收货地址列表",_data);
                if(_data.result==1){
                  that._getData();
                  wx.showToast({
                    title: _data.msg,
                    icon: 'success',
                    duration: 2000,
                    success:function(){},
                    fail:function(){}
                  });
                }
                else{
                  wx.showToast({
                    title: '数据错误',
                    icon: 'success',
                    duration: 2000,
                    success:function(){},
                    fail:function(){}
                  });
                }
                
              },
              fail:function(res){}
            } 
          );
        }
      }
    });
  },
  // 打开编辑(没接口)
  openEdit:function(){
    wx.showToast({title: '加载中..',icon: 'loading',duration: 1000,mask:true});
    var that = this;
    that.setData({
      showEdit:true
    });
  },
  // 关闭编辑(没接口)
  closeEdit:function(){
    wx.showToast({title: '加载中..',icon: 'loading',duration: 1000,mask:true});
    var that = this;
    that.setData({
      showEdit:false
    });
  },
  // 单条删除
  delData:function(e){
    var that= this;
    //todo, 无接口
    var url = app.getNetAddresss("member.member-favorite.destroy");
    url += "&goods_id="+e.currentTarget.dataset.goodsid;
    wx.showModal({
      title: '提示',
      content: '确定要取消收藏么？此操作不可逆！',
      success: function(res) {
        if (res.confirm) {
          console.log('用户点击确定');
          app._getNetWork(
            {
              url:url,
              success:function(res){
                var _data = res.data;
                console.log("_data",_data);
                if(_data.result==1){
                  that._getData();
                  wx.showToast({
                    title: _data.msg,
                    icon: 'success',
                    duration: 2000,
                    success:function(){},
                    fail:function(){}
                  });
                }
                else{
                  wx.showToast({
                    title: '数据错误',
                    icon: 'success',
                    duration: 2000,
                    success:function(){},
                    fail:function(){}
                  });
                }
                
              },
              fail:function(res){}
            } 
          );
        }
      }
    });
  },
  goDetail:function(e){
    wx.navigateTo({
      url: '/packageA/detail_v2/detail_v2?id='+e.currentTarget.dataset.goodsid
    });
  },
  // 获取数据
  _getData:function(){
    var that = this;
    let urlStr = app.getNetAddresss("member.member-favorite.index");
    if(app.globalData.store_alone_temp == 1) {
      // 开启门店独立模块
      urlStr = app.getNetAddresss("plugin.store-alone-temp.frontend.member.favorite-list");
    }
    app._getNetWork(
      {
        url:urlStr,
        showToastIn:false,
        success:function(res){
          var _data = res.data;
          console.log("收藏data", _data);
          if(_data.result==1){
            var _dataState;
            if(_data.data.length>0){
              _dataState=2;
            }
            else{
              _dataState=1;
            }
            that.setData({
              goodsData:_data.data,
              dataState:_dataState,
            });
          }
          else{
            wx.showToast({title: '数据错误',icon: 'success',duration: 2000});
          }
        },
        fail:function(res){}
      } 
    );
  },
  onLoad:function(options){
    this._getData();
  },
  onReady:function() {
    let language = wx.getStorageSync('langIndex');
    this.setData({ 'language': language.en});
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
});





