You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
3.9 KiB

2 years ago
// pages/category/category.js
2 years ago
var app = getApp();
var WxSearch = require('../../wxSearch/wxSearch.js')
var WXAPI = require('../../utils/server.js');
2 years ago
Page({
data: {
color:'',
// 左侧点击类样式
listHeight: '',
cont: 1,
remind: '加载中',
curNav: 1,
curIndex: 0,
isFocus:false,
},
onPullDownRefresh: function () {
wx.showNavigationBarLoading() //在标题栏中显示加载
this.search();
wx.hideNavigationBarLoading() //完成停止加载
wx.stopPullDownRefresh() //停止下拉刷新
},
search: function (e) {
var that = this;
WXAPI.searchIndex({
2 years ago
accessId: app.globalData.accessId,
storeId: 239,
}).then(res => {
2 years ago
if (res.code == 200) {
var data = res.data;
2 years ago
that.setData({
2 years ago
cateItems: data,
hotwords: data.hot,
2 years ago
curNav: data[0].cate_id
2 years ago
});
that.onReady();
that.setData({
remind: ''
});
2 years ago
} else {
wx.showToast({
title: res.message,
duration: 2000
});
2 years ago
}
});
},
onShow: function () {
},
onLoad: function (options) {
var that = this;
that.setData({
color:app.d.bgcolor,
})
this.search();
},
//事件处理函数
switchRightTab: function (e) {
// 获取item项的id,和数组的下标值
let id = e.target.dataset.id,
index = parseInt(e.target.dataset.index);
// 把点击到的某一项,设为当前index
this.setData({
curNav: id,
curIndex: index
})
},
search_confirmType: function (e) {
var that = this, value = e.detail.value;
this.setData({
value: e.detail.value,
});
if (value != '') {
WxSearch.wxSearchAddHisKey(that);
wx.navigateTo({
url: "../listdetail/listdetail?keyword=" + value
})
}
},
wxSearchFn: function (e) {
console.log(e)
var that = this
WxSearch.wxSearchAddHisKey(that);
var value = that.data.wxSearchData.value;
if (value){
wx.navigateTo({
url: "../listdetail/listdetail?keyword=" + value
})
}
},
wxSearchInput: function (e) {
console.log(e)
var that = this
console.log(that)
WxSearch.wxSearchInput(e, that);
},
wxSerchFocus: function (e) {
var that = this;
that.setData({
isFocus: false
});
WxSearch.wxSearchFocus(that);
},
wxSearchBlur: function (e) {
var that = this
WxSearch.wxSearchBlur(e, that);
},
wxSearchKeyTap: function (e) {
var that = this
WxSearch.wxSearchKeyTap(e, that);
},
wxSearchDeleteKey: function (e) {
var that = this
WxSearch.wxSearchDeleteKey(e, that);
},
wxSearchDeleteAll: function (e) {
var that = this;
WxSearch.wxSearchDeleteAll(that);
},
wxSearchTap: function (e) {
var that = this
WxSearch.wxSearchHiddenPancel(that);
},
// 生命周期函数--监听页面初次渲染完成
onReady: function () {
var that = this;
//初始化的时候渲染wxSearchdata
WxSearch.init(that, 43, this.data.hotwords);
WxSearch.initMindKeys(['laiketui.com', '微信小程序开发', '微信开发', '微信小程序']);
// 定义右侧标题的 rpx 高度 和 px 高度
var right_titleRpxHeight = 60;
var right_titleHeight;
// 定义右侧单个商品的 rpx 高度 和 px 高度
var right_contentRpxHeight = 200;
var right_contentHeight;
// 定义左侧单个tab的 rpx 高度 和 px 高度
var left_titleRpxHeight = 140;
var left_titleHeight;
// 获取可视区屏幕高度
wx.getSystemInfo({
success: function (res) {
// percent 为当前设备1rpx对应的px值
var percent = res.windowWidth / 1200;
that.setData({
right_titleHeight: Number(right_titleRpxHeight * percent),
right_contentHeight: Number(right_contentRpxHeight * percent),
left_titleHeight: Number(left_titleRpxHeight * percent)
})
}
})
},
})