outique.js 7.9 KB

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