123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- // pages/boutique/outique.js
- const app = getApp()
- const link = app.globalData.url
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- offset:0,
- limit:20,
- channel_type:"4",
- pid:"9112489_209622235",
- totalCount:0,
- goodsList:[],
- cat_id:"20100"
- },
- _asyncData() {
- this.setData({
- scrollAbleTabs: [
- {
- tab: '精选',
- key: '4'
- },
- {
- tab: '今日热销',
- key: '1'
- }, {
- tab: '高佣商品',
- key: '6'
- }, {
- tab: '百货',
- key: '20100'
- }, {
- tab: '母婴',
- key: '20200'
- },{
- tab:'食品',
- key:'20300'
- },
- {
- tab:'女装',
- key:'20400'
- },
- {
- tab:'电器',
- key:'20500'
- },
- {
- tab:'鞋包',
- key:'20600'
- },{
- tab:'内衣',
- key:'20700'
- },
- {
- tab:'美妆',
- key:'20800'
- },
- {
- tab:'男装',
- key:'20900'
- },
- {
- tab:'水果',
- key:'21000'
- },{
- tab:'家纺',
- key:'21100'
- },{
- tab:'文具',
- key:'21200'
- }
- ,{
- tab:'运动',
- key:'21300'
- },{
- tab:'虚拟',
- key:'21400'
- },{
- tab:'汽车',
- key:'21500'
- },{
- tab:'家装',
- key:'21600'
- },{
- tab:'家具',
- key:'21700'
- },{
- tab:'医药',
- key:'21800'
- }
- ],
- });
- },
- //20100-百货,20200-母婴,20300-食品,20400-女装,20500-电器,20600-鞋包,20700-内衣,20800-美妆,20900-男装,21000-水果,21100-家纺,21200-文具,21300-运动,21400-虚拟,21500-汽车,21600-家装,21700-家具,21800-医药
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- var that = this
- that.offset = 0
- that.limit = 20
- that.channel_type = "4"
- that.pid = "9112489_209622235"
- that.cat_id = ""
- console.log(options)
- //var openId = options.openId
-
- wx.request( {
- url: link + "/v1/forward/lhf",
- header: {
- "Content-Type": "application/json",
- "function":"/v1/set"
- },
- method: "POST",
- data: { version: "1.0.4" },
- complete: function( res ) {
- console.log(res)
- if( res == null || res.data == null ) {
- console.error( '网络请求失败' );
- return;
- }
- if (res.data.data.type == "true"){
- wx.redirectTo({
- url: '../search/search'
- })
- }else{
-
- //获取数据
- setTimeout(that._asyncData, 0);
- wx.request( {
- url: link + "/v1/forward/lhf",
- header: {
- "Content-Type": "application/json",
- "function":"/v1/pdd/recommend/get"
- },
- method: "POST",
- data: { offset: that.offset.toString(), limit: that.limit.toString(),channel_type:that.channel_type,pid:that.pid,cat_id:that.cat_id},
- complete: function( res ) {
- wx.hideLoading();
- if( res == null || res.data == null ) {
- console.error( '网络请求失败' );
- return;
- }
- console.log(res)
- that.totalCount = res.data.data.goods_basic_detail_response.total
- that.data.goodsList = res.data.data.goods_basic_detail_response.list
- // for (var i = 0; i < res.data.data.goods_basic_detail_response.list.length; i++) {
- // that.data.goodsList.push( res.data.data.goods_basic_detail_response.list[i]);
- // }
-
- that.setData({
- goodsList: that.data.goodsList,
- })
-
-
- }
- })
- }
- }
- })
- wx.login({
- success: res => {
- // 发送 res.code 到后台换取 openId, sessionKey, unionId
- console.log(res)
- wx.request( {
- url: link + "/v1/forward/lhf",
- header: {
- "Content-Type": "application/json",
- "function":"/v1/user/open.id/set"
- },
- method: "POST",
- //
- data: { code: res.code,openId: options.openId },
- complete: function( res ) {
- console.log(res)
- console.log('openid='+ options.openId )
- if (res.data.code == 200){
- wx.setStorageSync('openId', res.data.data.openid)
- }
-
- }
- })
- }
- })
- },
- search: function(options){
- wx.navigateTo({
- url: '../shouye/shouye'
- })
- },
- keyData:function(e){
- var that = this
-
- if (e.detail.activeKey == "4" || e.detail.activeKey == "1" || e.detail.activeKey == "6"){
- that.channel_type = e.detail.activeKey
- that.cat_id = ""
- } else{
- that.channel_type = "4"
- that.cat_id = e.detail.activeKey
- }
-
- console.log(e)
- that.offset = 0
- that.limit = 20
- wx.request( {
- url: link + "/v1/forward/lhf",
- header: {
- "Content-Type": "application/json",
- "function":"/v1/pdd/recommend/get"
- },
- method: "POST",
- data: { offset: that.offset.toString(), limit: that.limit.toString(),channel_type:that.channel_type,pid:that.pid,cat_id:that.cat_id},
- complete: function( res ) {
- wx.hideLoading();
- console.log(res)
- that.totalCount = res.data.data.goods_basic_detail_response.total
- that.data.goodsList = res.data.data.goods_basic_detail_response.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;
- }
- }
- })
- },
-
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- //获取数据
- var that = this;
- if (that.totalCount <= that.offset + 20){ //提示页码到了
- that.setData({
- lType:"end"
- })
- return
- }
-
- that.offset +=20
- wx.request( {
- url: link + "/v1/forward/lhf",
- header: {
- "Content-Type": "application/json",
- "function":"/v1/pdd/recommend/get"
- },
- method: "POST",
- data: { offset: that.offset.toString(), limit: that.limit.toString(),channel_type:that.channel_type,pid:that.pid,cat_id:that.cat_id},
- complete: function( res ) {
- wx.hideLoading();
- console.log(res)
- that.totalCount = res.data.data.goods_basic_detail_response.total_count
- for (var i = 0; i < res.data.data.goods_basic_detail_response.list.length; i++) {
- that.data.goodsList.push( res.data.data.goods_basic_detail_response.list[i]);
- }
- console.log(res.data.data.goods_search_response)
- if( res == null || res.data == null ) {
- console.error( '网络请求失败' );
- return;
- }
-
- that.setData({
- goodsList: that.data.goodsList,
- })
-
- }
- })
- },
- 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 () {
- // }
- })
|