outique.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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.6" },
  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 == "false"){
  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. if (options.goodsSign != undefined){
  181. var goodsSign = options.goodsSign
  182. var searchId = options.searchId
  183. wx.navigateTo({
  184. url: `/pages/details/details?goodsSign=${goodsSign}&searchId=${searchId}`,
  185. // url: `/pages/goods-detail/index`,
  186. })
  187. }
  188. },
  189. search: function(options){
  190. wx.navigateTo({
  191. url: '../shouye/shouye'
  192. })
  193. },
  194. keyData:function(e){
  195. var that = this
  196. if (e.detail.activeKey == "4" || e.detail.activeKey == "1" || e.detail.activeKey == "6"){
  197. that.channel_type = e.detail.activeKey
  198. that.cat_id = ""
  199. } else{
  200. that.channel_type = "4"
  201. that.cat_id = e.detail.activeKey
  202. }
  203. console.log(e)
  204. that.offset = 0
  205. that.limit = 20
  206. wx.request( {
  207. url: link + "/v1/forward/lhf",
  208. header: {
  209. "Content-Type": "application/json",
  210. "function":"/v1/pdd/recommend/get"
  211. },
  212. method: "POST",
  213. data: { offset: that.offset.toString(), limit: that.limit.toString(),channel_type:that.channel_type,pid:that.pid,cat_id:that.cat_id},
  214. complete: function( res ) {
  215. wx.hideLoading();
  216. console.log(res)
  217. that.totalCount = res.data.data.goods_basic_detail_response.total
  218. that.data.goodsList = res.data.data.goods_basic_detail_response.list
  219. // for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) {
  220. // that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]);
  221. // }
  222. that.setData({
  223. goodsList: that.data.goodsList,
  224. })
  225. console.log(res.data.data.goods_search_response)
  226. if( res == null || res.data == null ) {
  227. console.error( '网络请求失败' );
  228. return;
  229. }
  230. }
  231. })
  232. },
  233. /**
  234. * 生命周期函数--监听页面初次渲染完成
  235. */
  236. onReady: function () {
  237. },
  238. /**
  239. * 生命周期函数--监听页面显示
  240. */
  241. onShow: function () {
  242. },
  243. /**
  244. * 生命周期函数--监听页面隐藏
  245. */
  246. onHide: function () {
  247. },
  248. /**
  249. * 生命周期函数--监听页面卸载
  250. */
  251. onUnload: function () {
  252. },
  253. /**
  254. * 页面相关事件处理函数--监听用户下拉动作
  255. */
  256. onPullDownRefresh: function () {
  257. },
  258. /**
  259. * 页面上拉触底事件的处理函数
  260. */
  261. onReachBottom: function () {
  262. //获取数据
  263. var that = this;
  264. if (that.totalCount <= that.offset + 20){ //提示页码到了
  265. that.setData({
  266. lType:"end"
  267. })
  268. return
  269. }
  270. that.offset +=20
  271. wx.request( {
  272. url: link + "/v1/forward/lhf",
  273. header: {
  274. "Content-Type": "application/json",
  275. "function":"/v1/pdd/recommend/get"
  276. },
  277. method: "POST",
  278. data: { offset: that.offset.toString(), limit: that.limit.toString(),channel_type:that.channel_type,pid:that.pid,cat_id:that.cat_id},
  279. complete: function( res ) {
  280. wx.hideLoading();
  281. console.log(res)
  282. that.totalCount = res.data.data.goods_basic_detail_response.total_count
  283. for (var i = 0; i < res.data.data.goods_basic_detail_response.list.length; i++) {
  284. that.data.goodsList.push( res.data.data.goods_basic_detail_response.list[i]);
  285. }
  286. console.log(res.data.data.goods_search_response)
  287. if( res == null || res.data == null ) {
  288. console.error( '网络请求失败' );
  289. return;
  290. }
  291. that.setData({
  292. goodsList: that.data.goodsList,
  293. })
  294. }
  295. })
  296. },
  297. goodsDetail:function(e){
  298. const goodsSign=e.currentTarget.dataset.sign;
  299. const searchId=e.currentTarget.dataset.searchid;
  300. console.log(e)
  301. wx.navigateTo({
  302. url: `/pages/details/details?goodsSign=${goodsSign}&searchId=${searchId}`,
  303. // url: `/pages/goods-detail/index`,
  304. })
  305. },
  306. /**
  307. * 用户点击右上角分享
  308. */
  309. // onShareAppMessage: function () {
  310. // }
  311. })