// package_A/pages/goods-page/index.js
import {getUserData} from '../../../api/login.js'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        list: [],
        // 列表数据筛选条件
        params: {
            goodsName: ''
        },
        goodsName: '',
        current: "/goods/index",
        // 用户信息
        userInfo: {}
    },
    onShow() {
        this.getUserInfo()
    },

    // 获取
    getUserInfo() {
        const params = {}
        params.tenantId = wx.getStorageSync('tenant').tenantId
        params.openid = wx.getStorageSync('openid')
        getUserData(params).then(success=> {
            const userInfo = success.data
            wx.setStorage({
                key: 'userInfo',
                data:userInfo
            })
            this.setData({userInfo})
        })
    },

     /* 输入商品名称搜索 */
     search(e) {
        let params = this.data.params
        params.goodsName = this.data.goodsName
        this.setData({ params })
    },
    /* 更新数据 */
    updateList(e) {
        let list = this.data.list.concat(e.detail || [])
        this.setData({ list })
    },
    /* 重置数据 */
    resetList() {
        this.setData({ list: [] })
    },
      /* 跳转至详情页 */
      showDetail(e) {
        let data = e.currentTarget.dataset.item
        wx.navigateTo({
          url: '/package_A/pages/goods-detail/index?data='+ encodeURIComponent(JSON.stringify(data)),
        })
    }
})