shouye.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. // pages/shouye/shouye.js
  2. const util = require('../../utils/util.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. placement: 'left',
  9. placementArr: ['top', 'left', 'right', 'bottom'],
  10. scrollAbleTabs: [],
  11. iconTabs: [{
  12. tab: '购物车',
  13. key: 'cart',
  14. icon: 'cart',
  15. picPlacement: 'left'
  16. }, {
  17. tab: '历史记录',
  18. key: 'history',
  19. icon: 'history',
  20. picPlacement: 'left'
  21. }, {
  22. tab: '我的',
  23. key: 'mine',
  24. icon: 'user',
  25. picPlacement: 'left'
  26. }],
  27. imagesTabs: [{
  28. tab: '客厅',
  29. key: 'dining',
  30. picPlacement: 'top',
  31. image: {
  32. activeImage: '/pages/components/nav/images/tab-icon/dining-active.png',
  33. defaultImage: '/pages/components/nav/images/tab-icon/dining.png',
  34. }
  35. },
  36. {
  37. tab: '卧室',
  38. key: 'badroom',
  39. picPlacement: 'top',
  40. image: {
  41. activeImage: '/pages/components/nav/images/tab-icon/badroom-active.png',
  42. defaultImage: '/pages/components/nav/images/tab-icon/badroom.png',
  43. }
  44. }, {
  45. tab: '厨房',
  46. key: 'kichten',
  47. picPlacement: 'top',
  48. image: {
  49. activeImage: '/pages/components/nav/images/tab-icon/kichten-active.png',
  50. defaultImage: '/pages/components/nav/images/tab-icon/kichten.png',
  51. }
  52. },
  53. {
  54. tab: '浴室',
  55. key: 'bathroom',
  56. picPlacement: 'top',
  57. image: {
  58. activeImage: '/pages/components/nav/images/tab-icon/bathroom-active.png',
  59. defaultImage: '/pages/components/nav/images/tab-icon/bathroom.png',
  60. }
  61. }
  62. ],
  63. goodsList:[],
  64. listId:"",
  65. page:1,
  66. pageSize:10,
  67. currentPage:0,
  68. totalCount:0,
  69. listId:"",
  70. show:true,
  71. lType:"loading"
  72. },
  73. _asyncData() {
  74. this.setData({
  75. scrollAbleTabs: [{
  76. tab: '精选',
  77. key: 'treasure'
  78. }, {
  79. tab: '居家生活',
  80. key: 'life'
  81. }, {
  82. tab: '美食厨房',
  83. key: 'food'
  84. }, {
  85. tab: '服饰珠宝',
  86. key: 'cloth'
  87. }, {
  88. tab: '美妆洗护',
  89. key: 'cosmetics'
  90. },{
  91. tab:'家用电器',
  92. key:'one'
  93. },
  94. {
  95. tab:'运动女装',
  96. key:'sport'
  97. }],
  98. });
  99. },
  100. /**
  101. * 生命周期函数--监听页面加载
  102. */
  103. onLoad: function (options) {
  104. // this._asyncData
  105. setTimeout(this._asyncData, 0);
  106. //获取数据
  107. var that = this;
  108. that.page = 1
  109. that.pageSize = 18
  110. wx.request( {
  111. url: "http://49.234.19.130:8081/v1/pdd/ddk/search",
  112. //url: "http://127.0.0.1:8081/v1/pdd/ddk/search",
  113. header: {
  114. "Content-Type": "application/json"
  115. },
  116. method: "POST",
  117. //data: { cityname: "上海", key: "1430ec127e097e1113259c5e1be1ba70" },
  118. data: { page: that.page.toString(), page_size: that.pageSize.toString() },
  119. complete: function( res ) {
  120. wx.hideLoading();
  121. console.log(res)
  122. that.totalCount = res.data.data.goods_search_response.total_count
  123. for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) {
  124. that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]);
  125. }
  126. that.setData({
  127. goodsList: that.data.goodsList,
  128. })
  129. console.log(res.data.data.goods_search_response)
  130. if( res == null || res.data == null ) {
  131. console.error( '网络请求失败' );
  132. return;
  133. }
  134. }
  135. })
  136. },
  137. search(){
  138. wx.navigateTo({
  139. url: '../search/search'
  140. })
  141. },
  142. goodsCollection: function(e){
  143. var that=this
  144. var currentPage=that.data.page+1;
  145. wx.request({
  146. url: 'http://49.234.19.130:8081/v1/pdd/ddk/search',
  147. data: {
  148. listId:that.data.listId,
  149. pageSize:10,
  150. page: that.data.page+1,
  151. },
  152. method:'GET',
  153. header:{
  154. 'Accept': 'application/json'
  155. },
  156. success (res) {
  157. wx.hideLoading();
  158. for (var i = 0; i < res.data.goodsSearchInfo.goodsSearchResponse.goodsList.length; i++) {
  159. that.data.goodsList.push( res.data.goodsSearchInfo.goodsSearchResponse.goodsList[i]);
  160. }
  161. that.setData({
  162. goodsList: that.data.goodsList,//res.data.goodsSearchInfo.goodsSearchResponse.goodsList,
  163. listId:res.data.goodsSearchInfo.goodsSearchResponse.listId,
  164. currentPage:currentPage
  165. })
  166. }
  167. })
  168. },
  169. /**
  170. * 生命周期函数--监听页面初次渲染完成
  171. */
  172. onReady: function () {
  173. },
  174. /**
  175. * 生命周期函数--监听页面显示
  176. */
  177. onShow: function () {
  178. },
  179. /**
  180. * 生命周期函数--监听页面隐藏
  181. */
  182. onHide: function () {
  183. },
  184. /**
  185. * 生命周期函数--监听页面卸载
  186. */
  187. onUnload: function () {
  188. },
  189. /**
  190. * 页面相关事件处理函数--监听用户下拉动作
  191. */
  192. onPullDownRefresh: function () {
  193. },
  194. /**
  195. * 页面上拉触底事件的处理函数
  196. */
  197. onReachBottom: function () {
  198. //获取数据
  199. var that = this;
  200. if ((that.totalCount+that.pageSize-1)/that.pageSize <= that.page){ //提示页码到了
  201. that.setData({
  202. lType:"end"
  203. })
  204. return
  205. }
  206. that.page +=1
  207. wx.request( {
  208. url: "http://49.234.19.130:8081/v1/pdd/ddk/search",
  209. // url: "http://127.0.0.1:8081/v1/pdd/ddk/search",
  210. header: {
  211. "Content-Type": "application/json"
  212. },
  213. method: "POST",
  214. //data: { cityname: "上海", key: "1430ec127e097e1113259c5e1be1ba70" },
  215. data: { page: that.page.toString(), page_size: that.pageSize.toString() },
  216. complete: function( res ) {
  217. wx.hideLoading();
  218. console.log(res)
  219. that.totalCount = res.data.data.goods_search_response.total_count
  220. for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) {
  221. that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]);
  222. }
  223. that.setData({
  224. goodsList: that.data.goodsList,
  225. })
  226. console.log(res.data.data.goods_search_response)
  227. if( res == null || res.data == null ) {
  228. console.error( '网络请求失败' );
  229. return;
  230. }
  231. }
  232. })
  233. },
  234. goodsDetail:function(e){
  235. const goodsSign=e.currentTarget.dataset.sign;
  236. const searchId=e.currentTarget.dataset.searchid;
  237. wx.navigateTo({
  238. url: `/pages/details/details?goodsSign=${goodsSign}&searchId=${searchId}`,
  239. // url: `/pages/goods-detail/index`,
  240. })
  241. },
  242. /**
  243. * 用户点击右上角分享
  244. */
  245. onShareAppMessage: function () {
  246. }
  247. })