// subPackage/page/pages/myValueCard/myValueCard.js
const wxService = require('../../../../utils/wxService')
const utils = require('../../../../utils/util')
var wxbarcode = require('../../../../codeUtils/index.js');
wxService.page({

  /**
   * 页面的初始数据
   */
  data: {
    no : '1212345645645782',
    myCardsList : [
      { id: 1, isOpen: false, no: '12314545654545' },
      { id: 1, isOpen: false, no: '45456456456456' },
      { id: 1, isOpen: false, no: '85858582544585' },
      { id: 1, isOpen: false, no: '96335525252525' },
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.hideShareMenu();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  //barcode 失败回调
  canvasIdErrorCallback(e){

  },
  //生成条形码
  generatorBarCode(canvasId){
    if (this.data.no){
      wxbarcode.barcode(canvasId, this.data.no, 500, 100);
      setTimeout(() => {
        wxbarcode.barcode(canvasId, this.data.no, 500, 100);
      }, 200);
    }
  },
  //展开
  onTapShowMoreInfo(e){
    let item = e.currentTarget.dataset.item;
    let index = e.currentTarget.dataset.index;
    if (item.isOpen){
      return ;
    }

    this.data.myCardsList.forEach(item => {
      item.isOpen = false;
    });

    this.data.myCardsList[index].isOpen = true;
    this.data.no = this.data.myCardsList[index].no;
    let canvasId = 'barcode' + index;
    this.setData({
      myCardsList: this.data.myCardsList,
      no: this.data.no
    }, () => {
      this.generatorBarCode(canvasId);
    });
    
  },

  //关闭
  onTapCloseExtro(e){
    let index = e.currentTarget.dataset.index;
    this.data.myCardsList[index].isOpen = false;
    this.data.no = '';
    this.setData({
      myCardsList: this.data.myCardsList,
      no: this.data.no
    });
  },

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

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

})