outique.js 7.6 KB

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