outique.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. console.log(options)
  107. //var openId = options.openId
  108. wx.request( {
  109. url: link + "/v1/forward/lhf",
  110. header: {
  111. "Content-Type": "application/json",
  112. "function":"/v1/set"
  113. },
  114. method: "POST",
  115. data: { version: "1.0.4" },
  116. complete: function( res ) {
  117. console.log(res)
  118. if( res == null || res.data == null ) {
  119. console.error( '网络请求失败' );
  120. return;
  121. }
  122. if (res.data.data.type == "true"){
  123. wx.redirectTo({
  124. url: '../search/search'
  125. })
  126. }else{
  127. //获取数据
  128. setTimeout(that._asyncData, 0);
  129. wx.request( {
  130. url: link + "/v1/forward/lhf",
  131. header: {
  132. "Content-Type": "application/json",
  133. "function":"/v1/pdd/recommend/get"
  134. },
  135. method: "POST",
  136. data: { offset: that.offset.toString(), limit: that.limit.toString(),channel_type:that.channel_type,pid:that.pid,cat_id:that.cat_id},
  137. complete: function( res ) {
  138. wx.hideLoading();
  139. if( res == null || res.data == null ) {
  140. console.error( '网络请求失败' );
  141. return;
  142. }
  143. console.log(res)
  144. that.totalCount = res.data.data.goods_basic_detail_response.total
  145. that.data.goodsList = res.data.data.goods_basic_detail_response.list
  146. // for (var i = 0; i < res.data.data.goods_basic_detail_response.list.length; i++) {
  147. // that.data.goodsList.push( res.data.data.goods_basic_detail_response.list[i]);
  148. // }
  149. that.setData({
  150. goodsList: that.data.goodsList,
  151. })
  152. }
  153. })
  154. }
  155. }
  156. })
  157. wx.login({
  158. success: res => {
  159. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  160. console.log(res)
  161. wx.request( {
  162. url: link + "/v1/forward/lhf",
  163. header: {
  164. "Content-Type": "application/json",
  165. "function":"/v1/user/open.id/set"
  166. },
  167. method: "POST",
  168. //
  169. data: { code: res.code,openId: options.openId },
  170. complete: function( res ) {
  171. console.log(res)
  172. console.log('openid='+ options.openId )
  173. if (res.data.code == 200){
  174. wx.setStorageSync('openId', res.data.data.openid)
  175. }
  176. }
  177. })
  178. }
  179. })
  180. },
  181. search: function(options){
  182. wx.navigateTo({
  183. url: '../shouye/shouye'
  184. })
  185. },
  186. keyData:function(e){
  187. var that = this
  188. if (e.detail.activeKey == "4" || e.detail.activeKey == "1" || e.detail.activeKey == "6"){
  189. that.channel_type = e.detail.activeKey
  190. that.cat_id = ""
  191. } else{
  192. that.channel_type = "4"
  193. that.cat_id = e.detail.activeKey
  194. }
  195. console.log(e)
  196. that.offset = 0
  197. that.limit = 20
  198. wx.request( {
  199. url: link + "/v1/forward/lhf",
  200. header: {
  201. "Content-Type": "application/json",
  202. "function":"/v1/pdd/recommend/get"
  203. },
  204. method: "POST",
  205. data: { offset: that.offset.toString(), limit: that.limit.toString(),channel_type:that.channel_type,pid:that.pid,cat_id:that.cat_id},
  206. complete: function( res ) {
  207. wx.hideLoading();
  208. console.log(res)
  209. that.totalCount = res.data.data.goods_basic_detail_response.total
  210. that.data.goodsList = res.data.data.goods_basic_detail_response.list
  211. // for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) {
  212. // that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]);
  213. // }
  214. that.setData({
  215. goodsList: that.data.goodsList,
  216. })
  217. console.log(res.data.data.goods_search_response)
  218. if( res == null || res.data == null ) {
  219. console.error( '网络请求失败' );
  220. return;
  221. }
  222. }
  223. })
  224. },
  225. /**
  226. * 生命周期函数--监听页面初次渲染完成
  227. */
  228. onReady: function () {
  229. },
  230. /**
  231. * 生命周期函数--监听页面显示
  232. */
  233. onShow: function () {
  234. },
  235. /**
  236. * 生命周期函数--监听页面隐藏
  237. */
  238. onHide: function () {
  239. },
  240. /**
  241. * 生命周期函数--监听页面卸载
  242. */
  243. onUnload: function () {
  244. },
  245. /**
  246. * 页面相关事件处理函数--监听用户下拉动作
  247. */
  248. onPullDownRefresh: function () {
  249. },
  250. /**
  251. * 页面上拉触底事件的处理函数
  252. */
  253. onReachBottom: function () {
  254. //获取数据
  255. var that = this;
  256. if (that.totalCount <= that.offset + 20){ //提示页码到了
  257. that.setData({
  258. lType:"end"
  259. })
  260. return
  261. }
  262. that.offset +=20
  263. wx.request( {
  264. url: link + "/v1/forward/lhf",
  265. header: {
  266. "Content-Type": "application/json",
  267. "function":"/v1/pdd/recommend/get"
  268. },
  269. method: "POST",
  270. data: { offset: that.offset.toString(), limit: that.limit.toString(),channel_type:that.channel_type,pid:that.pid,cat_id:that.cat_id},
  271. complete: function( res ) {
  272. wx.hideLoading();
  273. console.log(res)
  274. that.totalCount = res.data.data.goods_basic_detail_response.total_count
  275. for (var i = 0; i < res.data.data.goods_basic_detail_response.list.length; i++) {
  276. that.data.goodsList.push( res.data.data.goods_basic_detail_response.list[i]);
  277. }
  278. console.log(res.data.data.goods_search_response)
  279. if( res == null || res.data == null ) {
  280. console.error( '网络请求失败' );
  281. return;
  282. }
  283. that.setData({
  284. goodsList: that.data.goodsList,
  285. })
  286. }
  287. })
  288. },
  289. goodsDetail:function(e){
  290. const goodsSign=e.currentTarget.dataset.sign;
  291. const searchId=e.currentTarget.dataset.searchid;
  292. wx.navigateTo({
  293. url: `/pages/details/details?goodsSign=${goodsSign}&searchId=${searchId}`,
  294. // url: `/pages/goods-detail/index`,
  295. })
  296. },
  297. /**
  298. * 用户点击右上角分享
  299. */
  300. // onShareAppMessage: function () {
  301. // }
  302. })