// pages/goodslist/goodslist.js
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        id: ""
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            id: options.id,
            page: 1,
            rows: 10,
            keywords: "",
            goodsList: [],
            imgUrl: app.shopImgUrl,
            hidePageLoading: false
        })
        this.getGoodsList();
    },
    inputKeywords(event) {
        this.setData({
            keywords: event.detail.value
        })
    },
    doSearch() {
        wx.startPullDownRefresh()
    },
    getGoodsList() {
        var _self = this
        var info = {
            'page': _self.data.page,
            'rows': _self.data.rows,
            'categoryId': _self.data.id,
            'keywords': _self.data.keywords
        };
        app.restAjax.get(app.restAjax.path('{shopUrl}/app/shopgoods/solrrelease', [app.shopUrl]), info, null, function (code, data) {
            if (data.rows.length == 0) {
                app.dialog.msg('暂无数据');
                return;
            }
            _self.setData({
                goodsList: _self.data.goodsList.concat(data.rows),
                hidePageLoading: true
            })
            console.log(_self.data.goodsList)
            wx.stopPullDownRefresh()
        }, function (code, data) {
            app.dialog.msg(data.msg);
            wx.stopPullDownRefresh()
            _self.setData({
                hidePageLoading: true
            })
        }, function () {
            wx.hideLoading();
            wx.stopPullDownRefresh()
        })
    },
    //下拉刷新
    onPullDownRefresh() {
        this.setData({
            page: 1,
            goodsList: []
        })
        this.getGoodsList()
    },
    //加载更多
    onReachBottom() {
        var _self = this;
        _self.setData({
            page: _self.data.page += 1
        })
        _self.getGoodsList()
    },
    goDetail(e) {
        wx.navigateTo({
            url: '/subpages/goodsdetail/goodsdetail?id=' + e.currentTarget.dataset.id,
        })
    }
})