145 lines
3.3 KiB
JavaScript
145 lines
3.3 KiB
JavaScript
/*
|
|
* 手太欠
|
|
* 愿这世界都如故事里一样 美好而动人~
|
|
*/
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
name : '', // 搜索名字
|
|
sortStaus : false, // 分类弹出
|
|
ordertype : '', // 排序类型 price为价格 sales为销量
|
|
orderasc : '', // 排序方式 asc为正序 desc为倒序
|
|
goodsArr : [], // 商品列表
|
|
goodsId : '', // 分类id
|
|
categorieArr : [], // 分类列表
|
|
categorieindex : 0 // 第一分类下标
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
this.setData({
|
|
goodsId: options.id,
|
|
name: options.title
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
// 获取商品列表
|
|
this.goodsInfo();
|
|
},
|
|
|
|
/**
|
|
* 商品列表信息
|
|
*/
|
|
goodsInfo(page) {
|
|
wx.$api.mall.Goods({
|
|
name : this.data.name || '',
|
|
category_id: this.data.goodsId || '',
|
|
page : page || 1,
|
|
order_by : this.data.ordertype,
|
|
order_by_type: this.data.orderasc
|
|
}).then(res => {
|
|
let listArr = this.data.goodsArr,
|
|
newData = []
|
|
if(page == 1 || page == undefined) listArr = []
|
|
newData = listArr.concat(res.data.data)
|
|
this.setData({
|
|
goodsArr : newData,
|
|
page : res.data.page,
|
|
lodingStats : false
|
|
})
|
|
wx.stopPullDownRefresh()
|
|
}).catch(err =>{
|
|
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 销量排序
|
|
*/
|
|
orderTap (e) {
|
|
let type = e.currentTarget.dataset.type
|
|
this.setData({
|
|
ordertype : type,
|
|
})
|
|
if(type == 'price') {
|
|
if (this.data.orderasc == 'asc') {
|
|
this.setData({
|
|
orderasc : 'desc',
|
|
})
|
|
} else {
|
|
this.setData({
|
|
orderasc : 'asc',
|
|
})
|
|
}
|
|
} else {
|
|
this.setData({
|
|
orderasc: '',
|
|
})
|
|
}
|
|
// 拉取商品列表数据
|
|
this.goodsInfo();
|
|
},
|
|
|
|
/**
|
|
* 跳转商品详情
|
|
*/
|
|
detailsGo(e) {
|
|
wx.navigateTo({
|
|
url: '/pages/mall/details/details?id=' + e.currentTarget.dataset.id
|
|
})
|
|
this.setData({
|
|
name: ''
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 搜索
|
|
*/
|
|
searchForm(e) {
|
|
this.setData({
|
|
name: e.detail.value.search
|
|
})
|
|
|
|
// 拉取商品列表数据
|
|
this.goodsInfo();
|
|
},
|
|
|
|
/**
|
|
* 商品分类展示
|
|
*/
|
|
sortShow() {
|
|
this.setData({
|
|
sortStaus : !this.data.sortStaus
|
|
})
|
|
|
|
// 获取商品分类
|
|
this.categorieInfo()
|
|
},
|
|
|
|
/**
|
|
* 商品分类信息
|
|
*/
|
|
categorieInfo() {
|
|
wx.$api.mall.Categorie().then(res => {
|
|
this.setData({
|
|
categorieArr: res.data
|
|
})
|
|
}).catch(err =>{})
|
|
},
|
|
|
|
// 一级分类
|
|
categorieTap(e) {
|
|
this.setData({
|
|
categorieindex: e.currentTarget.dataset.index
|
|
})
|
|
}
|
|
}) |