// pages/shouye/shouye.js const util = require('../../utils/util.js') const app = getApp() const link = app.globalData.url Page({ /** * 页面的初始数据 */ data: { placement: 'left', placementArr: ['top', 'left', 'right', 'bottom'], scrollAbleTabs: [], iconTabs: [{ tab: '购物车', key: 'cart', icon: 'cart', picPlacement: 'left' }, { tab: '历史记录', key: 'history', icon: 'history', picPlacement: 'left' }, { tab: '我的', key: 'mine', icon: 'user', picPlacement: 'left' }], imagesTabs: [{ tab: '客厅', key: 'dining', picPlacement: 'top', image: { activeImage: '/pages/components/nav/images/tab-icon/dining-active.png', defaultImage: '/pages/components/nav/images/tab-icon/dining.png', } }, { tab: '卧室', key: 'badroom', picPlacement: 'top', image: { activeImage: '/pages/components/nav/images/tab-icon/badroom-active.png', defaultImage: '/pages/components/nav/images/tab-icon/badroom.png', } }, { tab: '厨房', key: 'kichten', picPlacement: 'top', image: { activeImage: '/pages/components/nav/images/tab-icon/kichten-active.png', defaultImage: '/pages/components/nav/images/tab-icon/kichten.png', } }, { tab: '浴室', key: 'bathroom', picPlacement: 'top', image: { activeImage: '/pages/components/nav/images/tab-icon/bathroom-active.png', defaultImage: '/pages/components/nav/images/tab-icon/bathroom.png', } } ], goodsList:[], listId:"", page:1, pageSize:10, currentPage:0, totalCount:0, listId:"", show:true, lType:"loading", activity_tags:"", // pid:"9112489_209622235", pid:"9112489_212035116", keyword:"" }, _asyncData() { this.setData({ scrollAbleTabs: [ { tab: '精选', key: '0' }, { tab: '秒杀', key: '4' }, { tab: '百亿补贴', key: '7' }, { tab: '千万补贴', key: '10851' }, { tab: '品牌', key: '31' },{ tab:'官方爆品', key:'10564' }, { tab:'大牌', key:'24' }], }); }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // this._asyncData var that = this; that.page = 1 that.pageSize = 18 //获取数据 setTimeout(that._asyncData, 0); wx.request( { url: link + "/v1/forward/lhf", header: { "Content-Type": "application/json", "function":"/v1/pdd/ddk/search" }, method: "POST", data: { page: that.page.toString(), page_size: that.pageSize.toString()}, complete: function( res ) { wx.hideLoading(); console.log(res) that.totalCount = res.data.data.goods_search_response.total_count for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) { that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]); } that.setData({ goodsList: that.data.goodsList, }) console.log(res.data.data.goods_search_response) if( res == null || res.data == null ) { console.error( '网络请求失败' ); return; } } }) }, search:function(e){ var that = this console.log(e) that.keyword = e.detail.value that.activity_tags = "" that.pid = "9112489_209622235" console.log(that.keyword) console.log(that.pid) that.page = 1 that.pageSize = 18 wx.request( { url: link + "/v1/forward/lhf", header: { "Content-Type": "application/json", "function":"/v1/pdd/ddk/search" }, method: "POST", data: { page: that.page.toString(), page_size: that.pageSize.toString(), activity_tags: that.activity_tags, pid:that.pid, keyword: that.keyword}, complete: function( res ) { wx.hideLoading(); console.log(res) that.totalCount = res.data.data.goods_search_response.total_count that.data.goodsList = res.data.data.goods_search_response.goods_list // for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) { // that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]); // } that.setData({ goodsList: that.data.goodsList, }) console.log(res.data.data.goods_search_response) if( res == null || res.data == null ) { console.error( '网络请求失败' ); return; } } }) // wx.navigateTo({ // url: '../search/search' // }) }, keyData:function(e){ var that = this that.keyword = "" if (e.detail.activeKey == "0"){ that.activity_tags = "" } else{ that.activity_tags = "["+e.detail.activeKey + "]" } console.log(e) that.page = 1 that.pageSize = 18 wx.request( { url: link + "/v1/forward/lhf", header: { "Content-Type": "application/json", "function":"/v1/pdd/ddk/search" }, method: "POST", data: { page: that.page.toString(), page_size: that.pageSize.toString(), activity_tags: that.activity_tags}, complete: function( res ) { wx.hideLoading(); console.log(res) that.totalCount = res.data.data.goods_search_response.total_count that.data.goodsList = res.data.data.goods_search_response.goods_list // for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) { // that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]); // } that.setData({ goodsList: that.data.goodsList, }) console.log(res.data.data.goods_search_response) if( res == null || res.data == null ) { console.error( '网络请求失败' ); return; } } }) }, goodsCollection: function(e){ var that=this var currentPage=that.data.page+1; wx.request({ url: link + '/v1/pdd/ddk/search', data: { listId:that.data.listId, pageSize:10, page: that.data.page+1, }, method:'GET', header:{ 'Accept': 'application/json' }, success (res) { wx.hideLoading(); for (var i = 0; i < res.data.goodsSearchInfo.goodsSearchResponse.goodsList.length; i++) { that.data.goodsList.push( res.data.goodsSearchInfo.goodsSearchResponse.goodsList[i]); } that.setData({ goodsList: that.data.goodsList,//res.data.goodsSearchInfo.goodsSearchResponse.goodsList, listId:res.data.goodsSearchInfo.goodsSearchResponse.listId, currentPage:currentPage }) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { var that = this wx.getClipboardData({ success (res){ console.log(res.data) var da = res.data if (res.data != 0){ console.log('不为0') wx.setClipboardData({ data: '0', success (res) { } }) wx.showModal({ title: '搜索产品', content: res.data, success: function(res) { if (res.confirm) { console.log('用户点击确认') //搜索数据 that.page = 1 that.pageSize = 18 that.pid = "9112489_209622235" that.keyword = da that.activity_tags = "" wx.request( { url: link + "/v1/forward/lhf", header: { "Content-Type": "application/json", "function":"/v1/pdd/ddk/search" }, method: "POST", // data: { page: that.page.toString(), page_size: that.pageSize.toString(),with_coupon:"true", activity_tags: that.activity_tags}, data: { page: that.page.toString(), page_size: that.pageSize.toString(), pid:that.pid, activity_tags: that.activity_tags,keyword: that.keyword}, complete: function( res ) { wx.hideLoading(); console.log(res) that.totalCount = res.data.data.goods_search_response.total_count that.data.goodsList = res.data.data.goods_search_response.goods_list that.setData({ goodsList: that.data.goodsList, }) console.log(res.data.data.goods_search_response) if( res == null || res.data == null ) { console.error( '网络请求失败' ); return; } } }) } else if (res.cancel) { console.log('用户点击取消') } } }) } } }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { //获取数据 var that = this; if ((that.totalCount+that.pageSize-1)/that.pageSize <= that.page){ //提示页码到了 that.setData({ lType:"end" }) return } that.page +=1 wx.request( { url: link + "/v1/forward/lhf", // url: "http://127.0.0.1:8081/v1/pdd/ddk/search", header: { "Content-Type": "application/json", "function":"/v1/pdd/ddk/search" }, method: "POST", //data: { cityname: "上海", key: "1430ec127e097e1113259c5e1be1ba70" }, data: { page: that.page.toString(), page_size: that.pageSize.toString(), activity_tags: that.activity_tags,keyword:that.keyword,pid:that.pid}, complete: function( res ) { wx.hideLoading(); console.log(res) that.totalCount = res.data.data.goods_search_response.total_count for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) { that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]); } that.setData({ goodsList: that.data.goodsList, }) console.log(res.data.data.goods_search_response) if( res == null || res.data == null ) { console.error( '网络请求失败' ); return; } } }) }, goodsDetail:function(e){ const goodsSign=e.currentTarget.dataset.sign; const searchId=e.currentTarget.dataset.searchid; wx.navigateTo({ url: `/pages/details/details?goodsSign=${goodsSign}&searchId=${searchId}`, // url: `/pages/goods-detail/index`, }) }, /** * 用户点击右上角分享 */ // onShareAppMessage: function () { // } })