outique.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. // pages/boutique/outique.js
  2. const app = getApp()
  3. const link = app.globalData.url
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. offset:0,
  10. limit:20,
  11. channel_type:"4",
  12. pid:"9112489_209622235",
  13. totalCount:0,
  14. goodsList:[],
  15. cat_id:"20100"
  16. },
  17. _asyncData() {
  18. this.setData({
  19. scrollAbleTabs: [
  20. {
  21. tab: '精选',
  22. key: '4'
  23. },
  24. {
  25. tab: '今日热销',
  26. key: '1'
  27. }, {
  28. tab: '高佣商品',
  29. key: '6'
  30. }, {
  31. tab: '百货',
  32. key: '20100'
  33. }, {
  34. tab: '母婴',
  35. key: '20200'
  36. },{
  37. tab:'食品',
  38. key:'20300'
  39. },
  40. {
  41. tab:'女装',
  42. key:'20400'
  43. },
  44. {
  45. tab:'电器',
  46. key:'20500'
  47. },
  48. {
  49. tab:'鞋包',
  50. key:'20600'
  51. },{
  52. tab:'内衣',
  53. key:'20700'
  54. },
  55. {
  56. tab:'美妆',
  57. key:'20800'
  58. },
  59. {
  60. tab:'男装',
  61. key:'20900'
  62. },
  63. {
  64. tab:'水果',
  65. key:'21000'
  66. },{
  67. tab:'家纺',
  68. key:'21100'
  69. },{
  70. tab:'文具',
  71. key:'21200'
  72. }
  73. ,{
  74. tab:'运动',
  75. key:'21300'
  76. },{
  77. tab:'虚拟',
  78. key:'21400'
  79. },{
  80. tab:'汽车',
  81. key:'21500'
  82. },{
  83. tab:'家装',
  84. key:'21600'
  85. },{
  86. tab:'家具',
  87. key:'21700'
  88. },{
  89. tab:'医药',
  90. key:'21800'
  91. }
  92. ],
  93. });
  94. },
  95. //20100-百货,20200-母婴,20300-食品,20400-女装,20500-电器,20600-鞋包,20700-内衣,20800-美妆,20900-男装,21000-水果,21100-家纺,21200-文具,21300-运动,21400-虚拟,21500-汽车,21600-家装,21700-家具,21800-医药
  96. /**
  97. * 生命周期函数--监听页面加载
  98. */
  99. onLoad: function (options) {
  100. var that = this
  101. that.offset = 0
  102. that.limit = 20
  103. that.channel_type = "4"
  104. that.pid = "9112489_209622235"
  105. that.cat_id = ""
  106. wx.request( {
  107. url: link + "/v1/set",
  108. header: {
  109. "Content-Type": "application/json"
  110. },
  111. method: "POST",
  112. data: { version: "1.0.3" },
  113. complete: function( res ) {
  114. console.log(res)
  115. if( res == null || res.data == null ) {
  116. console.error( '网络请求失败' );
  117. return;
  118. }
  119. if (res.data.data.type == "false"){
  120. wx.redirectTo({
  121. url: '../search/search'
  122. })
  123. }else{
  124. //获取数据
  125. setTimeout(that._asyncData, 0);
  126. wx.request( {
  127. url: link + "/v1/pdd/recommend/get",
  128. header: {
  129. "Content-Type": "application/json"
  130. },
  131. method: "POST",
  132. data: { offset: that.offset.toString(), limit: that.limit.toString(),channel_type:that.channel_type,pid:that.pid,cat_id:that.cat_id},
  133. complete: function( res ) {
  134. wx.hideLoading();
  135. if( res == null || res.data == null ) {
  136. console.error( '网络请求失败' );
  137. return;
  138. }
  139. console.log(res)
  140. that.totalCount = res.data.data.goods_basic_detail_response.total
  141. that.data.goodsList = res.data.data.goods_basic_detail_response.list
  142. // for (var i = 0; i < res.data.data.goods_basic_detail_response.list.length; i++) {
  143. // that.data.goodsList.push( res.data.data.goods_basic_detail_response.list[i]);
  144. // }
  145. that.setData({
  146. goodsList: that.data.goodsList,
  147. })
  148. }
  149. })
  150. }
  151. }
  152. })
  153. },
  154. search: function(options){
  155. wx.navigateTo({
  156. url: '../shouye/shouye'
  157. })
  158. },
  159. keyData:function(e){
  160. var that = this
  161. if (e.detail.activeKey == "4" || e.detail.activeKey == "1" || e.detail.activeKey == "6"){
  162. that.channel_type = e.detail.activeKey
  163. that.cat_id = ""
  164. } else{
  165. that.channel_type = "4"
  166. that.cat_id = e.detail.activeKey
  167. }
  168. console.log(e)
  169. that.offset = 0
  170. that.limit = 20
  171. wx.request( {
  172. url: link + "/v1/pdd/recommend/get",
  173. header: {
  174. "Content-Type": "application/json"
  175. },
  176. method: "POST",
  177. data: { offset: that.offset.toString(), limit: that.limit.toString(),channel_type:that.channel_type,pid:that.pid,cat_id:that.cat_id},
  178. complete: function( res ) {
  179. wx.hideLoading();
  180. console.log(res)
  181. that.totalCount = res.data.data.goods_basic_detail_response.total
  182. that.data.goodsList = res.data.data.goods_basic_detail_response.list
  183. // for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) {
  184. // that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]);
  185. // }
  186. that.setData({
  187. goodsList: that.data.goodsList,
  188. })
  189. console.log(res.data.data.goods_search_response)
  190. if( res == null || res.data == null ) {
  191. console.error( '网络请求失败' );
  192. return;
  193. }
  194. }
  195. })
  196. },
  197. /**
  198. * 生命周期函数--监听页面初次渲染完成
  199. */
  200. onReady: function () {
  201. },
  202. /**
  203. * 生命周期函数--监听页面显示
  204. */
  205. onShow: function () {
  206. },
  207. /**
  208. * 生命周期函数--监听页面隐藏
  209. */
  210. onHide: function () {
  211. },
  212. /**
  213. * 生命周期函数--监听页面卸载
  214. */
  215. onUnload: function () {
  216. },
  217. /**
  218. * 页面相关事件处理函数--监听用户下拉动作
  219. */
  220. onPullDownRefresh: function () {
  221. },
  222. /**
  223. * 页面上拉触底事件的处理函数
  224. */
  225. onReachBottom: function () {
  226. //获取数据
  227. var that = this;
  228. if (that.totalCount <= that.offset + 20){ //提示页码到了
  229. that.setData({
  230. lType:"end"
  231. })
  232. return
  233. }
  234. that.offset +=20
  235. wx.request( {
  236. url: link + "/v1/pdd/recommend/get",
  237. header: {
  238. "Content-Type": "application/json"
  239. },
  240. method: "POST",
  241. data: { offset: that.offset.toString(), limit: that.limit.toString(),channel_type:that.channel_type,pid:that.pid,cat_id:that.cat_id},
  242. complete: function( res ) {
  243. wx.hideLoading();
  244. console.log(res)
  245. that.totalCount = res.data.data.goods_basic_detail_response.total_count
  246. for (var i = 0; i < res.data.data.goods_basic_detail_response.list.length; i++) {
  247. that.data.goodsList.push( res.data.data.goods_basic_detail_response.list[i]);
  248. }
  249. console.log(res.data.data.goods_search_response)
  250. if( res == null || res.data == null ) {
  251. console.error( '网络请求失败' );
  252. return;
  253. }
  254. that.setData({
  255. goodsList: that.data.goodsList,
  256. })
  257. }
  258. })
  259. },
  260. goodsDetail:function(e){
  261. const goodsSign=e.currentTarget.dataset.sign;
  262. const searchId=e.currentTarget.dataset.searchid;
  263. wx.navigateTo({
  264. url: `/pages/details/details?goodsSign=${goodsSign}&searchId=${searchId}`,
  265. // url: `/pages/goods-detail/index`,
  266. })
  267. },
  268. /**
  269. * 用户点击右上角分享
  270. */
  271. onShareAppMessage: function () {
  272. }
  273. })