// page/newpro/newpro.js
const app = getApp();
var a = require("../../wxParse/wxParse.js");
var api = require("../../api.js");
var amapFile = require('../../amap-wx.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goods:[],
    news:[],
    takeup: true,
    more: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that =this
    app.request1({
      url: api.goods_list,
      success: function (e) {
        console.log(e)
        var good = e.data.data
        var l = good.length
        var goods = []
        for(var i =0;i<l;i++){
          var t = good[i]
          goods[i] = t.img
        }
        console.log(goods)
        that.setData({
          goods: e.data.data,
        })
      }
    });
    app.request1({
      url: api.newgoods_list,
      success: function (e) {
        console.log(e)
        that.setData({
          next_page_url: e.data.next_page_url,
          newsgoods: e.data.data,
        })
      }
    })
  },
  takeup: function () {
    var that = this
    that.setData({
      takeup: false,
      more: true
    })
  },
  more: function () {
    var that = this
    that.setData({
      takeup: true,
      more: false
    })
  },
  togdetail: function (e) {
    console.log(e.currentTarget.dataset.id)
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../homePage/detail/detail?id=' + id + '&way=' + 'xp',
    })
  },
  onReachBottom: function () {
    var that = this
    if (that.data.next_page_url) {
      app.request1({
        url: that.data.next_page_url,
        success: function (e) {
          that.setData({
            next_page_url: e.data.next_page_url,
            newsgoods: [...that.data.news.concat(e.data.data)],
          })
        }
      })
    } else {
      console.log('no more news')
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})