Initial Commit
This commit is contained in:
357
pages/search_details/search_details.js
Normal file
357
pages/search_details/search_details.js
Normal file
@ -0,0 +1,357 @@
|
||||
|
||||
const app = getApp();
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
statusBarHeight: app.globalData.statusBarHeight,
|
||||
type: ['默认精选', '销量', '最新', '会员折扣', '价格', '分销比例'],
|
||||
goods: [],
|
||||
typeIndex: 0,
|
||||
searchCont: '',
|
||||
bigOrSmall: true, //上ture 下false
|
||||
bigprice: 0, //由大到小 1选择 0不选
|
||||
goodsSales: 0, //销量
|
||||
news: 0, //最新时间
|
||||
smallprice: 0, //由小到大
|
||||
|
||||
isDiscount: 0,//1会员折扣 不选0
|
||||
|
||||
goodsName: '',//搜索名
|
||||
hot: [],
|
||||
|
||||
inputShowed: true,//获取焦点
|
||||
|
||||
page:1,
|
||||
multiIndex: [0, 0],
|
||||
multiArray: [['不限', '0%-5%', '5%-10%', '10%-15%', '15%-20%'], ['不限', '0%-5%', '5%-10%', '10%-15%', '15%-20%']]
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad: function (options) {
|
||||
//三级id
|
||||
if (options.threeTypeId) {
|
||||
console.log(options.threeTypeId)
|
||||
console.log(options.name)
|
||||
this.setData({
|
||||
threeTypeId: options.threeTypeId,
|
||||
searchCont: options.name,
|
||||
goodsName: ''
|
||||
})
|
||||
this.dataList()
|
||||
} else {
|
||||
this.setData({
|
||||
threeTypeId: 0,
|
||||
})
|
||||
}
|
||||
//搜索进入
|
||||
if (options.search) {
|
||||
this.setData({
|
||||
search: true,//搜索
|
||||
inputShowed: true//获取焦点
|
||||
})
|
||||
} else {
|
||||
this.setData({
|
||||
search: false,//搜索
|
||||
inputShowed: false//获取焦点
|
||||
})
|
||||
}
|
||||
|
||||
//获取热门推荐
|
||||
wx.request({
|
||||
url: app.globalData.ip + '/wisdommining/api/goods/getHotGoodsType',
|
||||
method: 'GET',
|
||||
header: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
data: {},
|
||||
success: res => {
|
||||
console.log(res)
|
||||
wx.hideLoading()
|
||||
if (res.data.code == 1) {
|
||||
this.setData({
|
||||
hot: res.data.value
|
||||
})
|
||||
} else {
|
||||
wx.showModal({
|
||||
title: '获取数据失败!',
|
||||
content: res.data.message,
|
||||
showCancel: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
//失去焦点
|
||||
bindblurFn() {
|
||||
this.setData({
|
||||
delCont: false,
|
||||
})
|
||||
},
|
||||
//聚焦
|
||||
bindfocusFn() {
|
||||
this.setData({
|
||||
delCont: true,
|
||||
search: true,
|
||||
inputShowed: true,
|
||||
searchCont: '',
|
||||
})
|
||||
},
|
||||
//搜索
|
||||
sear() {
|
||||
if (!this.data.delCont&&this.data.searchCont!='') {
|
||||
this.setData({
|
||||
delCont: true,
|
||||
search: true,
|
||||
inputShowed: true,
|
||||
searchCont: '',
|
||||
})
|
||||
return
|
||||
}
|
||||
if (this.data.goodsName == '') {
|
||||
wx.showToast({
|
||||
title: '请先输入搜索内容~',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
search: false,
|
||||
// searchCont:this.data.goodsName,
|
||||
threeTypeId: 0,
|
||||
goods:[],
|
||||
page:1
|
||||
})
|
||||
this.dataList()
|
||||
},
|
||||
//搜索名
|
||||
search_input(e) {
|
||||
this.setData({
|
||||
goodsName: e.detail.value
|
||||
})
|
||||
},
|
||||
//删除搜索名
|
||||
delCont(e) {
|
||||
console.log('delCont')
|
||||
this.setData({
|
||||
goodsName: ''
|
||||
})
|
||||
},
|
||||
//热门推荐
|
||||
hot(e) {
|
||||
let id = e.currentTarget.dataset.id;
|
||||
let name = e.currentTarget.dataset.name;
|
||||
this.setData({
|
||||
search: false,
|
||||
threeTypeId: id,
|
||||
searchCont: name,
|
||||
goodsName: '',
|
||||
goods:[],
|
||||
page:1
|
||||
})
|
||||
this.dataList()
|
||||
},
|
||||
|
||||
bindMultiPickerChange: function (e) {
|
||||
console.log('picker发送选择改变,携带值为', e.detail.value)
|
||||
this.setData({
|
||||
multiIndex: e.detail.value,
|
||||
typeIndex: 5,
|
||||
goods:[],
|
||||
page:1
|
||||
})
|
||||
this.dataList()
|
||||
},
|
||||
|
||||
//类型选择
|
||||
type(e) {
|
||||
let index = e.currentTarget.dataset.index;
|
||||
|
||||
if (index == 5) {
|
||||
//分销比例
|
||||
|
||||
} else {
|
||||
this.setData({
|
||||
goods:[],
|
||||
page:1
|
||||
})
|
||||
if (this.data.typeIndex == 4 && index == 4) {
|
||||
this.setData({
|
||||
bigOrSmall: !this.data.bigOrSmall
|
||||
})
|
||||
}
|
||||
this.setData({
|
||||
typeIndex: index
|
||||
})
|
||||
this.dataList()
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
//数据
|
||||
dataList: function (e) {
|
||||
let typeIndex = this.data.typeIndex
|
||||
let oneProfitsS = 0;
|
||||
let oneProfitsE = 0;
|
||||
let twoProfitsS = 0;
|
||||
let twoProfitsE = 0;
|
||||
//默认
|
||||
if (typeIndex == 0) {
|
||||
this.setData({
|
||||
bigprice: 0, //由大到小 1选择 0不选
|
||||
goodsSales: 0, //销量
|
||||
news: 0, //最新时间
|
||||
smallprice: 0, //由小到大
|
||||
isDiscount: 0,
|
||||
fx: 0,//分销比例
|
||||
})
|
||||
}
|
||||
//销量
|
||||
if (typeIndex == 1) {
|
||||
this.setData({
|
||||
bigprice: 0, //由大到小 1选择 0不选
|
||||
goodsSales: 1, //销量
|
||||
news: 0, //最新时间
|
||||
smallprice: 0, //由小到大
|
||||
isDiscount: 0,
|
||||
fx: 0,//分销比例
|
||||
})
|
||||
}
|
||||
//价格
|
||||
if (typeIndex == 4) {
|
||||
let smallprice = 0;
|
||||
let bigprice = 0;
|
||||
if (this.data.bigOrSmall) {
|
||||
smallprice = 1
|
||||
} else {
|
||||
bigprice = 1
|
||||
}
|
||||
this.setData({
|
||||
bigprice: bigprice, //由大到小 1选择 0不选
|
||||
goodsSales: 0, //销量
|
||||
news: 0, //最新时间
|
||||
smallprice: smallprice, //由小到大
|
||||
isDiscount: 0,
|
||||
fx: 0,//分销比例
|
||||
})
|
||||
}
|
||||
//最新
|
||||
if (typeIndex == 2) {
|
||||
this.setData({
|
||||
bigprice: 0, //由大到小 1选择 0不选
|
||||
goodsSales: 0, //销量
|
||||
news: 1, //最新时间
|
||||
smallprice: 0, //由小到大
|
||||
isDiscount: 0,
|
||||
fx: 0,//分销比例
|
||||
})
|
||||
}
|
||||
//会员折扣
|
||||
if (typeIndex == 3) {
|
||||
this.setData({
|
||||
bigprice: 0, //由大到小 1选择 0不选
|
||||
goodsSales: 0, //销量
|
||||
news: 0, //最新时间
|
||||
smallprice: 0, //由小到大
|
||||
isDiscount: 1,
|
||||
fx: 0,//分销比例
|
||||
})
|
||||
}
|
||||
//fx
|
||||
if (typeIndex == 5) {
|
||||
let multiIndex = this.data.multiIndex
|
||||
this.setData({
|
||||
bigprice: 0, //由大到小 1选择 0不选
|
||||
goodsSales: 0, //销量
|
||||
news: 0, //最新时间
|
||||
smallprice: 0, //由小到大
|
||||
isDiscount: 0,
|
||||
fx: 1,
|
||||
})
|
||||
oneProfitsS = multiIndex[0] == 1 ? 0 : multiIndex[0] == 2 ? 5 : multiIndex[0] == 3 ? 10 : multiIndex[0] == 4 ? 15 : 0;
|
||||
oneProfitsE = multiIndex[0] == 1 ? 5 : multiIndex[0] == 2 ? 10 : multiIndex[0] == 3 ? 15 : multiIndex[0] == 4 ? 20 : 0;
|
||||
twoProfitsS = multiIndex[1] == 1 ? 0 : multiIndex[1] == 2 ? 5 : multiIndex[1] == 3 ? 10 : multiIndex[1] == 4 ? 15 : 0;
|
||||
twoProfitsE = multiIndex[1] == 1 ? 5 : multiIndex[1] == 2 ? 10 : multiIndex[1] == 3 ? 15 : multiIndex[1] == 4 ? 20 : 0;
|
||||
}
|
||||
wx.showLoading({
|
||||
title: '加载中',
|
||||
mask: true,
|
||||
})
|
||||
wx.request({
|
||||
url: app.globalData.ip + '/wisdommining/api/goods/getGoodsByThreeType',
|
||||
method: 'GET',
|
||||
header: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
data: {
|
||||
threeTypeId: this.data.threeTypeId,
|
||||
userId: app.globalData.userId,
|
||||
bigprice: this.data.bigprice, //由大到小
|
||||
goodsSales: this.data.goodsSales, //销量
|
||||
news: this.data.news, //最新时间
|
||||
smallprice: this.data.smallprice, //由小到大
|
||||
goodsName: this.data.goodsName,//搜索名
|
||||
isDiscount: this.data.isDiscount,//会员折扣,
|
||||
|
||||
oneProfitsS: oneProfitsS,
|
||||
oneProfitsE: oneProfitsE,
|
||||
twoProfitsS: twoProfitsS,
|
||||
twoProfitsE: twoProfitsE,
|
||||
page: this.data.page,
|
||||
num: 10
|
||||
},
|
||||
success: res => {
|
||||
console.log(res)
|
||||
wx.hideLoading()
|
||||
if (res.data.code == 1) {
|
||||
let dataList = res.data.value.records;
|
||||
if (dataList.length == 0) {
|
||||
wx.showToast({
|
||||
title: '暂无更多~',
|
||||
icon:'none'
|
||||
})
|
||||
} else {
|
||||
let goods = this.data.goods;
|
||||
for (let i = 0; i < dataList.length; i++) {
|
||||
goods.push(dataList[i])
|
||||
}
|
||||
this.setData({
|
||||
goods: goods,
|
||||
page: this.data.page + 1,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
wx.showModal({
|
||||
title: '获取数据失败!',
|
||||
content: res.data.message,
|
||||
showCancel: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
//返回
|
||||
back() {
|
||||
wx.navigateBack()
|
||||
},
|
||||
//商品详情
|
||||
goodsDetails(e) {
|
||||
let id = e.currentTarget.dataset.id;
|
||||
wx.navigateTo({
|
||||
url: '/pages/goodsDetails/goodsDetails?goodsId=' + id,
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function () {
|
||||
this.dataList()
|
||||
},
|
||||
})
|
Reference in New Issue
Block a user