12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- var Util = require('../../utils/util.js');
- var host = getApp().globalData.servsers;
- // 热销新品
- Page({
- data: {
- contentList: [],
- commodity_name: '',
- page: 0, // 默认第一页
- limit: 10, // 每页请求最多数据
- requestState:true, //表示还可以请求
- loginStatic: false, //登陆状态,默认为false
- },
-
- onShow(){
- let that = this;
- if (wx.getStorageSync('channelIdObj').channelId) {
- that.setData({
- loginStatic: true,
- })
- }
- },
- //滚动到底部触发事件
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- let that = this;
- if (that.data.requestState){
- that.setData({
- page:that.data.page + 1
- })
- that.getSearchList(that)
- }
- },
- searResult(e){
- console.log(e,"dd")
- let that = this;
- that.setData({
- commodity_name: e.detail.value,
- contentList: [],//数据初始化
- requestState:true, //数据初始化
- page: 0,//数据初始化
- })
- that.getSearchList(that)
- },
- getSearchList(that){
- if (that.data.commodity_name){
- let data = {
- commodity_name: that.data.commodity_name,
- offset: that.data.page,
- limit: that.data.limit,
- channelId: wx.getStorageSync('channelIdObj').channelId ? wx.getStorageSync('channelIdObj').channelId : ""
- }
- wx.request({
- url: host + "commodityapi/findAllforseach",
- data: data,
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- let contentList = that.data.contentList;
- contentList.push(...res.data.rows)
- that.setData({
- contentList: contentList ,
- commodity_name: that.data.commodity_name,
- requestState: res.data.rows.length == that.data.limit
- });
- if (res == null || res.data == null) {
- console.error('网络请求失败');
- return;
- }
- }
- });
- } else {
- wx.showToast({
- title: "没有搜索关键词",
- icon:'none'
- })
- }
-
- },
- toGoodsDetail(e) { // 进入商品详情页
- let that = this, id = e.currentTarget.dataset.id;
- wx.navigateTo({
- url: '/pages/buy/buy?com_id=' + id,
- })
- },
- })
|