var Api = require('../../../utils/common.js');
var re = require('../../../utils/request.js');
var wxCharts = require('../../../utils/wxcharts.js');
var app = getApp();
var daylineChart = null;
var yuelineChart = null;
Page({ 

  /**
   * 页面的初始数据
   */
  data: {
    detail:{views:'1223',share:'2444',join:'344',cancel:'23',all:'22222'},
    switchChecked: true,
    switchCheckedbao:true
  },
  toedit:function(){
    wx.navigateTo({
      url: '../addactive/addactive?id=1'
    })
  },
  tosign:function(){
    wx.navigateTo({
      url: '../signIndex/signIndex'
    })
  },
  switchChange: function(e) {
    this.setData({
      switchChecked:e.detail.value
    })
  },
  switchbaoChange: function(e) {
    this.setData({
      switchCheckedbao:e.detail.value
    })
  },
  getMothElectro:function(){
    var windowWidth = 320;
    try {
      var res = wx.getSystemInfoSync();
      windowWidth = res.windowWidth;
    } catch (e) {
      console.error('getSystemInfoSync failed!');
    }
    yuelineChart = new wxCharts({ //X轴
      canvasId: 'yueEle',
      type: 'line',
      categories: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31'], //categories X轴
      animation: true,
      // background: '#f5f5f5',
      series: [{
        name: '浏览次数',
        //data: yuesimulationData.data,
        data: [1, 6, 9, 1, 0, 2, 9, 2, 8, 6, 0, 9, 8, 0, 3, 7, 3, 9, 3, 8, 9, 5, 4, 1, 5, 8, 2, 4, 9, 8, 7],
      }, {
        name: '报名人数',
        data: [0, 6, 2, 2, 7, 6, 2, 5, 8, 1, 8, 4, 0, 9, 7, 2, 5, 2, 8, 2, 5, 2, 9, 4, 4, 9, 8, 5, 5, 5, 6],
      }],
      xAxis: {
        disableGrid: true
      },
      yAxis: {
        title: '近30天(人)',
        max: 20,
        min: 0
      },
      width: windowWidth,
      height: 200,
      dataLabel: false,
      dataPointShape: true,
      extra: {
        lineStyle: 'curve'
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getMothElectro();
    this.setData({
      id:options.id
    })
    this.manageIndex(options.id);
    this.lastviews(options.id);
  },
  manageIndex:function(id){
    var that = this;
    const imgUrl = wx.getStorageSync('imgUrl')
    var header = {
      token:wx.getStorageSync('token'),
      "Content-Type": "application/x-www-form-urlencoded"
    };
    var postData={
      activityId:id
    };
    re.request(Api.manageIndex(), postData, header).then((res) => {
      console.log(res.data)
      // let datas = res.data.rows;
      // for(let i=0;i<datas.length;i++){
      //   if(datas[i].activityLogo){
      //     datas[i].activityLogo = imgUrl + datas[i].activityLogo
      //   }
      // }
      // that.setData({
      //   otheractive:datas
      // })
    })
  },
  lastviews:function(id){
    var that = this;
    var postData = {
      activityId:id,
    };
    var header = {
      token:wx.getStorageSync('token'),
      "Content-Type": "application/x-www-form-urlencoded"
    };
    re.request(Api.lastviews(), postData, header).then((res) => {
      let datas = res.data.data;
      console.log(datas);
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})