// pages/member/rankingListSecond/rankingListSecond.js
var app = getApp();
const aloneData = 'plugin.store-alone-temp.frontend.businessCard.card.sendCardByRoleId';
const aloneWsq = 'plugin.store-alone-temp.frontend.businessCard.paging.tricks';
const aloneDsp ='plugin.store-alone-temp.frontend.businessCard.paging.videos';
const aloneGood = 'plugin.store-alone-temp.frontend.businessCard.card.getStoreGoods';
let path;
let iconFrom = {};
// var colOneHeight = 0;
// var colTwoHeight = 0;
Page({
  /**
	 * 页面的初始数据
	 */
  data: {
    language: '',
    show1: false,
    award: null,
    voice: '',
    playAudio: false,
    custom_name: {
      love_name: '',
      point_name: ''
    },
    card_id: '',
    visit_id: '',
    cardData: {
      picture: []
    },
    areas: '',
    clickStatus: {},
    nums: {
      visit_statistics: {}
    },
    goods: [],
    cardType: '',
    shop_owner: {},

    level_name: '',
    store_name: '',
    actives: 0,
    // 供应商
    supplier: null,

    // 门店
    good_page: 1,
    store_good: [],
    coupon_list: [],

    // 招商员
    cardUrl: '',
    cardList_page: 1,
    cardList: [],
    showMore: true,
    member: {},
    // 导航
    toolbar: false,
    visit: 0,
    collection: 0,
    reliable: 0,
    // 本地存储的数据
    visits: '/image/card_img_a.png',
    card_mobile: '/image/card_img_b.png',
    card_wechat: '/image/card_img_c.png',
    area_nameIcon: '/image/card_img_d.png',
    // 我的贴子
    newClassification: {},
    isVideo: {},
    isArticle: {},
    area_name: '',
    //导航
    active: 0,
    istapBtn: 'intro',
    tapTitle: 'intro',
    activitys1:[],
    activitys2:[],
    imgCount:0,
    page:0,
    aloneStyle:false,
    openTemplate: 0,//门店列表样式
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function(options) {
    console.log('详情参数', options);

    if (options.card_id) {
      this.setData({
        card_id: options.card_id
      });
    }
    if (options.scene) {
      let scene = decodeURIComponent(options.scene);
      // card_id=7,mark=card,mark_id=7,mid=7 => 7,card,7,7
      if (scene) {
        var info_arr = [];
        info_arr = scene.split(',');
        console.log(info_arr, '切除');
        this.setData({
          card_id: info_arr[0]
        });
        this.setData({
          mark: info_arr[1]
        });
        this.setData({
          mark_id: info_arr[2]
        });
        if(info_arr[3]) {
          app._setMid(info_arr[3]);
        }
        // 				for (let i = 0; i < info_arr.length; i++) {
        // 					let chil_arr = []
        // 					chil_arr = info_arr[i].split('=')
        //
        // 					if (chil_arr[0] == 'card_id') {
        // 						this.setData({
        // 							card_id: chil_arr[1]
        // 						})
        // 					} else if (chil_arr[0] == 'mark') {
        // 						this.setData({
        // 							mark: chil_arr[1]
        // 						})
        // 					} else if (chil_arr[0] == 'mark_id') {
        // 						this.setData({
        // 							mark_id: chil_arr[1]
        // 						})
        // 					}
        // 				}
      }
    } else {
      this.setData({
        card_id: options.card_id,
        mark: options.mark,
        mark_id: options.mark_id
      });
    }
    if(app.globalData.store_alone_temp == 1){
      this.setData({
        aloneStyle:true
      });
      this.getCardDate();
      this.getCardVideo();
      this.getStoreCommunities();
    }else{
      this.getCardDate();
      this.getCardVideo();
      this.getStoreCommunities();
      this.getCardArticle();
      this.getCardRoom();
    }

    // this.innerAudioContext = wx.createInnerAudioContext()
    // this.innerAudioContext.onError((res) => {
    // 	this.tip('播放录音失败！')
    // })
  },
  toPages(val){
    let url = val.target.dataset.url || val.currentTarget.dataset.url;
    let type = val.target.dataset.type || val.currentTarget.dataset.type;
    console.log(val);
    wx.getStorage({
      key: 'iconFrom',
      success: res => {
        if (res.data) {
          wx.navigateTo({
            url: '/packageB/member/business_card/' + url + '/' + url + '?card_id=' + this.data.card_id + '&type=' + type
          });
          console.log('/packageB/member/business_card/' + url + '/' + url + '?card_id=' + this.data.card_id + '&type=' + type);
        }
      }
    });
    this.setData({
      showcode: false
    });
  },
  //直播间跳转
  gopage(e) {
    let status = e.currentTarget.dataset.status;
    let id = e.currentTarget.dataset.id;
    let backid = e.currentTarget.dataset.backid;
    if (status == 1) {
      wx.navigateTo({
        url: '/packageD/directSeeding/livePage/livePage?id=' + id + '&playerType=live'
      });
    } else if (status == 2) {
      wx.navigateTo({
        url: '/packageD/directSeeding/livePage/livePage?id=' + id + '&playerType=video' + '&backid=' + backid
      });
    } else if (status == 3) {
      wx.navigateTo({
        url: '/packageD/directSeeding/foreshow/foreshow?id=' + id
      });
    }
  },
  /**
	 * 生命周期函数--监听页面初次渲染完成
	 */
  onReady: function() {
    let language = wx.getStorageSync('langIndex');
    this.setData({ 'language': language.en});
  },

  /**
	 * 生命周期函数--监听页面显示
	 */
  onShow: function() {
    wx.showShareMenu({
      withShareTicket: false,
      menus: ['shareAppMessage', 'shareTimeline']
    });
    // this.getCardDate()
  },

  /**
	 * 生命周期函数--监听页面隐藏
	 */
  onHide: function() {},

  /**
	 * 生命周期函数--监听页面卸载
	 */
  onUnload: function() {},

  /**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
  onPullDownRefresh: function() {},

  /**
	 * 页面上拉触底事件的处理函数
	 */
  onReachBottom: function() {
    console.log(this.data.active);
    var that = this;
    console.log(this.data.page);
    if(this.data.active == '0'){
      return;
    }
    console.log(that.data.current_page,that.data.last_page);
    console.log(that.data.current_page >= that.data.last_page);
    if(that.data.current_page >= that.data.last_page){
      wx.hideLoading({});
      wx.showToast({
        title: '没有更多了',
        icon:'none'
      });
    }else{
      let pages = that.data.page + 1;
      that.setData({
        page : pages
      });
      that.loadMorein();
      console.log(this.data.isVideo);
    }
  },
  loadMorein(){
    var that = this;
    var urlStr;
    if(this.data.active == '2'){
      // 视频
      urlStr = app.getNetAddresss(app.globalData.store_alone_temp == 1?aloneDsp:"plugin.business-card.frontend.controllers.card.paging.videos");
    }else if(this.data.active == '1'){
      // 帖子
      urlStr = app.getNetAddresss(app.globalData.store_alone_temp == 1?aloneWsq:"plugin.business-card.frontend.controllers.card.paging.tricks");
    }else if(this.data.active == '3'){
      // 文章
      urlStr = app.getNetAddresss("plugin.business-card.frontend.controllers.card.paging.articles");
    }else if(this.data.active == '0'){
      return;
    }else if(this.data.active == '4'){
      // 直播
      urlStr = app.getNetAddresss("plugin.business-card.frontend.controllers.card.paging.rooms");
    }
    wx.showLoading({
      title: '加载中',
      icon:'none',
    });
    app._postNetWork({
      url: urlStr,
      data:{
        card_id: this.data.card_id,
        page : this.data.page
      },
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          console.log(res);
          if(that.data.active == 1){
            that.setData({
              newClassification:that.data.newClassification.concat(res.data.data),
              current_page:res.data.current_page,
              last_page:res.data.last_page
            });
          }else if(that.data.active == 2){
            that.setData({
              isVideo:that.data.isVideo.concat(res.data.data),
              current_page:res.data.current_page,
              last_page:res.data.last_page
            });
          }else if(that.data.active == 3){
            that.setData({
              isArticle:that.data.isArticle.concat(res.data.data),
              current_page:res.data.current_page,
              last_page:res.data.last_page
            });
          }
          else if(that.data.active == 4){
            console.log(res);
            that.setData({
              room:that.data.room.concat(res.data.data),
              current_page:res.data.current_page,
              last_page:res.data.last_page
            });
          }
          wx.hideLoading({});
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none'
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  // 视频
  getCardVideo(){
    var that = this;
    let urlStr = app.getNetAddresss(app.globalData.store_alone_temp == 1?aloneDsp:"plugin.business-card.frontend.controllers.card.paging.videos");
    app._postNetWork({
      url: urlStr,
      data:{
        card_id: this.data.card_id,
        page : this.data.page
      },
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          console.log(res);
          that.setData({
            isVideo:res.data.data,
            current_page:res.data.current_page,
            last_page:res.data.last_page
          });
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none'
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  // 帖子
  getStoreCommunities(){
    var that = this;
    let urlStr = app.getNetAddresss(app.globalData.store_alone_temp == 1?aloneWsq:"plugin.business-card.frontend.controllers.card.paging.tricks");
    app._postNetWork({
      url: urlStr,
      data:{
        card_id: this.data.card_id,
        page : this.data.page
      },
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          console.log(res);
          that.setData({
            newClassification:res.data.data,
            current_page:res.data.current_page,
            last_page:res.data.last_page
          });
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none'
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  getCardArticle(){
    var that = this;
    let urlStr = app.getNetAddresss("plugin.business-card.frontend.controllers.card.paging.articles");
    app._postNetWork({
      url: urlStr,
      data:{
        card_id: this.data.card_id,
        page : this.data.page
      },
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          console.log(res);
          that.setData({
            isArticle:res.data.data,
            current_page:res.data.current_page,
            last_page:res.data.last_page
          });
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none'
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  getCardRoom(){
    var that = this;
    let urlStr = app.getNetAddresss("plugin.business-card.frontend.controllers.card.paging.rooms");
    app._postNetWork({
      url: urlStr,
      data:{
        card_id: this.data.card_id,
        page : this.data.page
      },
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          console.log(res);
          that.setData({
            room:res.data.data,
            current_page:res.data.current_page,
            last_page:res.data.last_page
          });
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none'
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  /**
	 * 用户点击右上角分享
	 */
  onShareTimeline(){
    return{
      title:`${this.data.cardData.card_name}发给你名片`,
      query:`card_id=${this.data.card_id}&mark=${this.data.mark}&mark_id=${this.data.mark_id}`
    };
  },
  onShareAppMessage: function() {
    path = '/packageB/member/business_card/BusinessCard/BusinessCard?card_id=' + this.data.card_id + '&mark=' + this.data.mark + '&mark_id=' + this.data.mark_id;
    return {
      title: this.data.cardData.card_name + '发给你名片',
      path: path,
      success: (res) => {
        wx.showToast({
          title: '转发成功'
        });
      },
      fail: (error) => {
        // 转发失败
        wx.showToast({
          title: '转发失败',
          icon: 'none'
        });
      }
    };
  },
  /**
	 * 提示
	 */
  tip: function(msg) {
    wx.showModal({
      title: '提示',
      content: msg,
      showCancel: false
    });
  },
  // 初始化数据
  toCardVisit() {
    this.triggerAction('3');
    wx.navigateTo({
      url: '/packageB/member/business_card/CardVisit/CardVisit' + '?card_id=' + this.data.card_id
    });
  },
  toPage(val) {
    let url = val.target.dataset.url || val.currentTarget.dataset.url;
    if (url == 'hotelApply') {
      wx.navigateTo({
        url: '/packageA/member/storeApply/storeApply' + '?name=' + 'hotelApply'
      });
      return;
    }
    wx.navigateTo({
      url: '/packageA/member/' + url + '/' + url
    });
    // this.$router.push(this.fun.getUrl(url))
  },
  toGood(val) {
    let item = val.target.dataset.item || val.currentTarget.dataset.item;
    wx.navigateTo({
      url: '/packageA/detail_v2/detail_v2' + '?id=' + item.id + '&mark=' + 'card' + '&mark_id=' + this.options.card_id
    });
  },
  toShop(val) {
    let id = val.target.dataset.id || val.currentTarget.dataset.id;
    let str = val.target.dataset.url || val.currentTarget.dataset.url;
    if (str === 'hotel') {
      wx.navigateTo({
        url: '/packageC/hotel/HotelHome/HotelHome' + '?id=' + id
      });
    } else if (str === 'store') {
      wx.navigateTo({
        url: '/packageC/o2o/HomeSeller/HomeSeller' + '?store_id=' + id
      });
    } else if (str === 'supplier') {
      wx.navigateTo({
        url: '/packageA/member/supplier/SupplierShop/SupplierShop' + '?id=' + id
      });
    }
  },
  toBuy(val) {
    let id = val.target.dataset.id || val.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/packageC/cashier/cashier_pay/cashier_pay' + '?store_id=' + id
    });
  },
  getGoods() {
    let url = ''; // 供应商
    if (this.data.cardType === 'supplier') {
      url = 'plugin.business-card.frontend.controllers.card.card.getSupplierGoods'; // 供应商
    } else if (this.data.cardType === 'shop_owner' || this.data.cardType === 'clerk') {
      url = 'plugin.business-card.frontend.controllers.card.card.getStoreGoods'; // 门店
    } else {
      return;
    }
    let urlStr = app.getNetAddresss(app.globalData.store_alone_temp == 1?aloneGood:url);
    urlStr = urlStr + '&page=' + this.data.good_page + '&card_id=' + this.data.card_id;
    app._getNetWork({
      url: urlStr,
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          let goodArr = this.data.store_good.concat(res.data.data);
          this.setData({
            store_good: goodArr
          });
          if (res.data.current_page >= res.data.last_page) {
            this.setData({
              showMore: false
            });
          } else {
            this.setData({
              showMore: true
            });
          }
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none'
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  getList() {
    let urlStr = app.getNetAddresss(this.data.cardUrl);
    urlStr += '&page=' + this.data.cardList_page;
    urlStr += '&card_id=' + this.data.card_id;
    app._getNetWork({
      url: urlStr,
      success: (resdata) => {
        var res = resdata.data;

        if (res.result == 1) {
          let cardArr = this.data.cardList.concat(res.data.data);
          this.setData({
            cardList: cardArr
          });

          if (res.data.current_page >= res.data.last_page) {
            this.setData({
              showMore: false
            });
          } else {
            this.setData({
              showMore: true
            });
          }

          if (res.data.hasOwnProperty("store_list_style")) {
            this.setData({
              openTemplate: res.data.store_list_style || 0
            });
          }
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none'
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  playAmr() {
    console.log(this.data.voice, '路径');
    if (app._isTextEmpty(this.data.voice)) {
      wx.showToast({
        title: '请先去录音',
        icon: 'none'
      });
      return;
    }
    this.innerAudioContext.src = this.data.voice;
    this.innerAudioContext.play();
  },
  loadMore(val) {
    let str = val.target.dataset.item || val.currentTarget.dataset.item;
    if (str === 'good') {
      let page = this.data.good_page;
      page++;
      this.setData({
        good_page: page
      });
      this.getGoods();
    } else if (str === 'list') {
      let pages = this.data.cardList_page;
      pages++;
      this.setData({
        cardList_page: pages
      });
      this.getList();
    }
  },
  triggerAction(type) {
    let urlStr = app.getNetAddresss('plugin.business-card.frontend.controllers.action.card-pre-action.index');
    urlStr += '&card_type=' + type + '&card_id=' + this.data.card_id;
    app._getNetWork({
      url: urlStr,
      success: function(resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          let cardArr = this.cardList.concat(res.data.data);
          this.setData({
            cardList: cardArr
          });
          if (res.data.current_page >= res.data.last_page) {
            this.setData({
              showMore: false
            });
          } else {
            this.setData({
              showMore: true
            });
          }
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none'
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  copyText(e) {
    let str = e.currentTarget.dataset.text;
    wx.setClipboardData({
      data: str,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            wx.showToast({
              title: '复制成功'
            });
          }
        });
      }
    });
  },
  // 保存通讯录
  onCopy() {
    if (this.data.cardData.card_name != '') {
      wx.getStorage({
        key: 'iconFrom',
        success: res => {
          wx.addPhoneContact({
            firstName: this.data.cardData.card_name,
            mobilePhoneNumber: this.data.cardData.card_mobile,
            weChatNumber: this.data.cardData.card_wechat,
            photoFilePath: res.data.card_avatar,
            addressState: this.data.addressState,
            addressCity: this.data.addressCity,
            addressStreet: this.data.addressStreet,

            success: res => {
              wx.showToast({
                title: '保存成功'
              });
            }
          });
        }
      });
    } else {
      wx.showToast({
        title: '请去编辑姓名',
        icon: 'none'
      });
    }
  },
  changeLike(e) {
    let type = e.target.dataset.index || e.currentTarget.dataset.index;
    let urlStr = app.getNetAddresss('plugin.business-card.frontend.controllers.action.card-action.index');
    urlStr += '&card_id=' + this.data.card_id + '&card_type=' + type;
    app._getNetWork({
      url: urlStr,
      success: (resdata) => {
        var response = resdata.data;
        if (response.result == 1) {
          if (type === '1') {
            this.setData({
              'clickStatus.collected': response.data
            });
          } else {
            this.setData({
              'clickStatus.reliabled': response.data
            });
          }
        } else {
          // wx.showToast({
          // 	title: response.msg,
          // 	icon: 'none'
          // })
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  // 加载更多
  loadNext(e) {
    console.log(e.currentTarget.dataset.tap);
    let name = e.currentTarget.dataset.tap;
    if (name == 'intro') {
      this.setData({
        isintro: true
      });
      console.log(this.data.cardData.picture.length);
    }
  },
  // 我的导航变化事件
  tabChange(e) {
    console.log(e.detail);
    // let name = e.detail.title;
    this.setData({
      isintro: false,
      active:e.detail.index,
      page:1,
      current_page:1,
    });

  },
  // tab改变
  chooseTabchange(e) {
    this.chooseTab(e.detail.title);
  },
  chooseTab(title) {
    if (this.data.cardType == 'staff') {
      // 招商员
      if (title == '供应商') {
        this.setData({
          cardUrl: 'plugin.business-card.frontend.controllers.card.card.getStaffSupplier'
        });
      } else if (title == '门店') {
        this.setData({
          cardUrl: 'plugin.business-card.frontend.controllers.card.card.getStaffStore'
        });
      } else if (title == '酒店') {
        this.setData({
          cardUrl: 'plugin.business-card.frontend.controllers.card.card.getStaffHotel'
        });
      }
    } else if (this.data.cardType == 'center') {
      // 招商中心
      if (title == '供应商') {
        this.setData({
          cardUrl: 'plugin.business-card.frontend.controllers.card.card.getCenterSupplier'
        });
      } else if (title == '门店') {
        this.setData({
          cardUrl: 'plugin.business-card.frontend.controllers.card.card.getCenterStore'
        });
      } else if (title == '酒店') {
        this.setData({
          cardUrl: 'plugin.business-card.frontend.controllers.card.card.getCenterHotel'
        });
      }
    } else {
      return;
    }
    this.setData({
      cardList_page: 1,
      showMore: true,
      cardList: []
    });
    this.getList();
  },
  getCardDate() {
    let urlStr = app.getNetAddresss(app.globalData.store_alone_temp == 1?aloneData:'plugin.business-card.frontend.controllers.card.card.sendCardByRoleId');
    urlStr += '&card_id=' + this.data.card_id + '&visit_id=' + this.data.visit_id + '&mark=' + this.data.mark +
			'&mark_id=' + this.data.mark_id;
    app._getNetWork({
      url: urlStr,
      success: (resdata) => {
        var response = resdata.data;
        if (response.result == 1) {
          this.setData({
            allData: response.data,
            cardData: response.data.card,
            award: response.data.award,
            member: response.data.result.member,
            voice: response.data.card.voice,
            banner: response.data.banner,
            shop_name: response.data.shop_name,
            // newClassification: response.data.tricks,
            // isVideo: response.data.videos,
            // isArticle: response.data.articles,
            is_trick: response.data.is_trick,
            is_video: response.data.is_video,
            is_article: response.data.is_article,
            is_room: response.data.is_room,
            // room: response.data.room?response.data.room:[]
          });
          let backgroundImg = wx.getStorageSync('iconFrom').background;
          this.saveImg(backgroundImg);
          if (this.data.cardData.picture.length < 2) {
            this.setData({
              isintro: true
            });
          }
          if (app._isTextEmpty(response.data.card.voice)) {
            this.setData({
              voiceShow: false
            });
          } else if (response.data.card.voice.indexOf('amr') != '-1') {
            this.setData({
              voiceShow: false
            });
          } else {
            this.setData({
              voiceShow: true
            });
          }

          if (this.data.voice) {
            // this.loadDemoBtn(this.data.voice)
          }
          if (!this.data.member.member && this.data.member.name) {
            let name = this.data.member.name.level_name;
            this.setData({
              level_name: name
            });
          } else {
            let names = this.data.cardData.level_name;
            this.setData({
              level_name: names
            });
          }
          if (this.data.award) {
            this.setData({
              show1: true,
              custom_name: response.data.result.member.custom_name
            });
          }
          if (response.data.card.address == null) {
            response.data.card.address = '';
          }
          if (this.data.cardData.areas[0]) {
            if (this.data.cardData.areas[3] == null) {
              this.data.cardData.areas[3] = '';
            }
            let areas =
							this.data.cardData.areas[0] +
							this.data.cardData.areas[1] +
							this.data.cardData.areas[2] +
							this.data.cardData.areas[3] + response.data.card.address;
            this.setData({
              areas
            });
            this.setData({
              addressState: this.data.cardData.areas[0],
              addressCity: this.data.cardData.areas[1] +
								this.data.cardData.areas[2],
              addressStreet: this.data.cardData.areas[3] + response.data.card.address
            });
          }
          this.setData({
            visit: response.data.result.member?.achievement?.visit_statistics?.visit,
            collection: response.data?.card?.card_statistics?.collection,
            reliable: response.data?.card?.card_statistics?.reliable
          });
          this.setDatas(response.data.result.member);
          if (response.data.result.member.is_supplier == 1) {
            this.chooseTab('供应商');
          } else if (response.data.result.member.is_store == 1) {
            this.chooseTab('门店');
          } else if (response.data.result.member.is_hotel == 1) {
            this.chooseTab('酒店');
          }
          this.getGoods();

          this.setData({
            visit_id: response.data.result.member.self,
            clickStatus: response.data.result.member.status,
            nums: response.data.result.member.achievement,
            goods: response.data.result.member.goods
          });
          let info = {};
          if (app._isTextEmpty(response.data.card.level_name)) {
            response.data.card.level_name = '';
          }
          info.card_name = response.data.card.card_name;
          info.card_mobile = response.data.card.card_mobile;
          info.card_wechat = response.data.card.card_wechat;
          info.area_name = this.data.areas;
          info.visit = '人气' + (response.data.card.card_statistics.visit + 1);
          info.card_name = response.data.card.card_name + '名片码';
          info.shop_name = `名片由【${response.data.shop_name}】生成`;
          info.role_name = response.data.card.role_name + '|' + response.data.card.level_name;
          wx.setStorage({
            key: 'info',
            data: info
          });
        } else {
          wx.showToast({
            title: response.msg,
            icon: 'none'
          });
          setTimeout(() => {
            wx.reLaunch({
              url: '/packageG/index/index'
            });
          }, 2000);
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  setDatas(data) {
    if (data.member) {
      this.setData({
        cardType: 'member'
      });
    } else if (data.team_dividend) {
      this.setData({
        cardType: 'team_dividend'
      });
    } else if (data.commission) {
      this.setData({
        cardType: 'commission'
      });
    } else if (data.staff) {
      this.setData({
        cardType: 'staff'
      });
    } else if (data.center) {
      this.setData({
        cardType: 'center'
      });
    } else if (data.area_dividend) {
      this.setData({
        cardType: 'area_dividend'
      });
      if (data.name) {
        this.setData({
          level_name: data.name.level_name
        });
      } else {
        this.setData({
          level_name: data.area_dividend.level_name
        });
      }
    } else if (data.supplier) {
      this.setData({
        cardType: 'supplier',
        supplier: data.supplier
      });
      if (data.name) {
        this.setData({
          level_name: data.name.level_name
        });
      } else {
        this.setData({
          level_name: data.supplier.store_name
        });
      }
    } else if (data.shop_owner) {
      this.setData({
        cardType: 'shop_owner',
        store_name: data.shop_owner.store_name,
        shop_owner: data.shop_owner,
        coupon_list: data.coupon
      });
    } else if (data.clerk) {
      this.setData({
        cardType: 'clerk',
        store_name: data.clerk.store_name,
        coupon_list: data.coupon
      });
    }
  },
  closeCneter() {
    this.setData({
      show1: false
    });
  },
  showToolbar(e) {
    this.setData({
      toolbar: !this.data.toolbar
    });
  },
  toxiangq(e) {
    console.log(e);
    if (e.currentTarget.dataset.name == 'postMy') {
      let stick_id = e.currentTarget.dataset.item.id;
      wx.navigateTo({
        url: '/packageC/micro_communities/microCommentDetails/microCommentDetails?stickId=' + stick_id
      });
    }
    if (e.currentTarget.dataset.name == 'video') {
      let stick_id = e.currentTarget.dataset.item.id;
      wx.navigateTo({
        url: '/packageC/video_goods/VideoDetail/VideoDetail?vid=' + stick_id + '&page=1'
      });
    }
    if (e.currentTarget.dataset.name == 'text') {
      let stick_id = e.currentTarget.dataset.item.id;
      wx.navigateTo({
        url: '/packageA/member/article/articleContent/articleContent?article_id=' + stick_id
      });
    }
  },
  // 去首页
  goTohome(e) {
    wx.reLaunch({
      url: '/packageG/index/index'
    });
  },

  toolCard() {
    wx.navigateTo({
      url: '/packageB/member/business_card/CardCenter/CardCenter'
    });
  },
  callMobile() {
    wx.makePhoneCall({
      phoneNumber: this.data.cardData.card_mobile, // 仅为示例，并非真实的电话号码
      success: res => {
        console.log(res, '成功');
      },
      fail: error => {
        console.log(error, '失败');
      }
    });
  },
  // 存储图片
  // 网络图标存本地
  saveImg(bimg) {
    wx.getImageInfo({
      src: this.data.visits,
      success: (res) => {
        this.setData({
          visits: res.path
        });
        iconFrom.visit = this.data.visits;
        wx.setStorage({
          key: 'iconFrom',
          data: iconFrom
        });
      },
      fail: function(res) {
        // 失败回调
        console.log(res, '错误的回调1');
      }
    });
    wx.getImageInfo({
      src: this.data.card_mobile,
      success: (res) => {
        this.setData({
          card_mobile: res.path
        });
        iconFrom.card_mobile = this.data.card_mobile;
        wx.setStorage({
          key: 'iconFrom',
          data: iconFrom
        });
      },
      fail: function(res) {
        // 失败回调
        console.log(res, '错误的回调2');
      }
    });
    wx.getImageInfo({
      src: this.data.card_wechat,
      success: (res) => {
        this.setData({
          card_wechat: res.path
        });
        iconFrom.card_wechat = this.data.card_wechat;
        wx.setStorage({
          key: 'iconFrom',
          data: iconFrom
        });
      },
      fail: function(res) {
        // 失败回调
        console.log(res, '错误的回调3');
      }
    });
    wx.getImageInfo({
      src: this.data.area_nameIcon,
      success: (res) => {
        this.setData({
          area_nameIcon: res.path
        });
        iconFrom.area_nameIcon = this.data.area_nameIcon;
        wx.setStorage({
          key: 'iconFrom',
          data: iconFrom
        });
      },
      fail: function(res) {
        // 失败回调
        console.log(res, '错误的回调4');
      }
    });
    if (!app._isTextEmpty(this.data.cardData.card_avatar)) {
      wx.downloadFile({
        url: this.data.cardData.card_avatar, // 服务器返回的图片地址
        success: (res) => {
          // res.tempFilePath是网络图片的本地地址
          this.setData({
            'cardData.card_avatar': res.tempFilePath
          });
          iconFrom.card_avatar = res.tempFilePath;
        },
        fail: function(res) {
          // 失败回调
        }
      });
    }
    if (!app._isTextEmpty(this.data.banner)) {
      wx.downloadFile({
        url: this.data.banner, // 服务器返回的图片地址
        success: (res) => {
          // res.tempFilePath是网络图片的本地地址
          this.setData({
            banner: res.tempFilePath
          });
          iconFrom.background = bimg?bimg:res.tempFilePath;
          wx.setStorage({
            key: 'iconFrom',
            data: iconFrom
          });
        },
        fail: function(res) {
          // 失败回调
        }
      });
    }
    wx.downloadFile({
      url: this.data.cardData.min_code, // 服务器返回的图片地址
      success: (res) => {
        // res.tempFilePath是网络图片的本地地址
        this.setData({
          'cardData.min_code': res.tempFilePath
        });
        console.log(res.tempFilePath);
        iconFrom.min_code = res.tempFilePath;
        wx.setStorage({
          key: 'iconFrom',
          data: iconFrom
        });
      },
      fail: function(res) {
        // 失败回调
        console.log(res, '错误的回调');
      }
    });
  }
});
