shouye.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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. activity_tags:"",
  73. pid:"9112489_209622235",
  74. keyword:""
  75. },
  76. _asyncData() {
  77. this.setData({
  78. scrollAbleTabs: [
  79. {
  80. tab: '精选',
  81. key: '0'
  82. },
  83. {
  84. tab: '秒杀',
  85. key: '4'
  86. }, {
  87. tab: '百亿补贴',
  88. key: '7'
  89. }, {
  90. tab: '千万补贴',
  91. key: '10851'
  92. }, {
  93. tab: '品牌',
  94. key: '31'
  95. },{
  96. tab:'官方爆品',
  97. key:'10564'
  98. },
  99. {
  100. tab:'大牌',
  101. key:'24'
  102. }],
  103. });
  104. },
  105. /**
  106. * 生命周期函数--监听页面加载
  107. */
  108. onLoad: function (options) {
  109. // this._asyncData
  110. var that = this;
  111. that.page = 1
  112. that.pageSize = 18
  113. wx.request( {
  114. url: "http://127.0.0.1:8081/v1/set",
  115. header: {
  116. "Content-Type": "application/json"
  117. },
  118. method: "POST",
  119. data: { version: "1.0.1" },
  120. complete: function( res ) {
  121. console.log(res)
  122. if( res == null || res.data == null ) {
  123. console.error( '网络请求失败' );
  124. return;
  125. }
  126. if (res.data.data.type == "true"){
  127. wx.navigateTo({
  128. url: '../search/search'
  129. })
  130. }else{
  131. //获取数据
  132. setTimeout(that._asyncData, 0);
  133. wx.request( {
  134. url: "http://49.234.19.130:8081/v1/pdd/ddk/search",
  135. header: {
  136. "Content-Type": "application/json"
  137. },
  138. method: "POST",
  139. data: { page: that.page.toString(), page_size: that.pageSize.toString(),with_coupon:"true" },
  140. complete: function( res ) {
  141. wx.hideLoading();
  142. console.log(res)
  143. that.totalCount = res.data.data.goods_search_response.total_count
  144. for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) {
  145. that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]);
  146. }
  147. that.setData({
  148. goodsList: that.data.goodsList,
  149. })
  150. console.log(res.data.data.goods_search_response)
  151. if( res == null || res.data == null ) {
  152. console.error( '网络请求失败' );
  153. return;
  154. }
  155. }
  156. })
  157. }
  158. }
  159. })
  160. },
  161. search:function(e){
  162. var that = this
  163. console.log(e)
  164. that.keyword = e.detail.value
  165. that.activity_tags = ""
  166. that.pid = "9112489_209622235"
  167. console.log(that.keyword)
  168. console.log(that.pid)
  169. that.page = 1
  170. that.pageSize = 18
  171. wx.request( {
  172. url: "http://49.234.19.130:8081/v1/pdd/ddk/search",
  173. header: {
  174. "Content-Type": "application/json"
  175. },
  176. method: "POST",
  177. data: { page: that.page.toString(), page_size: that.pageSize.toString(),with_coupon:"true", activity_tags: that.activity_tags, pid:that.pid, keyword: that.keyword},
  178. complete: function( res ) {
  179. wx.hideLoading();
  180. console.log(res)
  181. that.totalCount = res.data.data.goods_search_response.total_count
  182. that.data.goodsList = res.data.data.goods_search_response.goods_list
  183. // for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) {
  184. // that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]);
  185. // }
  186. that.setData({
  187. goodsList: that.data.goodsList,
  188. })
  189. console.log(res.data.data.goods_search_response)
  190. if( res == null || res.data == null ) {
  191. console.error( '网络请求失败' );
  192. return;
  193. }
  194. }
  195. })
  196. // wx.navigateTo({
  197. // url: '../search/search'
  198. // })
  199. },
  200. keyData:function(e){
  201. var that = this
  202. that.keyword = ""
  203. if (e.detail.activeKey == "0"){
  204. that.activity_tags = ""
  205. } else{
  206. that.activity_tags = "["+e.detail.activeKey + "]"
  207. }
  208. console.log(e)
  209. that.page = 1
  210. that.pageSize = 18
  211. wx.request( {
  212. url: "http://49.234.19.130:8081/v1/pdd/ddk/search",
  213. header: {
  214. "Content-Type": "application/json"
  215. },
  216. method: "POST",
  217. data: { page: that.page.toString(), page_size: that.pageSize.toString(),with_coupon:"true", activity_tags: that.activity_tags},
  218. complete: function( res ) {
  219. wx.hideLoading();
  220. console.log(res)
  221. that.totalCount = res.data.data.goods_search_response.total_count
  222. that.data.goodsList = res.data.data.goods_search_response.goods_list
  223. // for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) {
  224. // that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]);
  225. // }
  226. that.setData({
  227. goodsList: that.data.goodsList,
  228. })
  229. console.log(res.data.data.goods_search_response)
  230. if( res == null || res.data == null ) {
  231. console.error( '网络请求失败' );
  232. return;
  233. }
  234. }
  235. })
  236. },
  237. goodsCollection: function(e){
  238. var that=this
  239. var currentPage=that.data.page+1;
  240. wx.request({
  241. url: 'http://49.234.19.130:8081/v1/pdd/ddk/search',
  242. data: {
  243. listId:that.data.listId,
  244. pageSize:10,
  245. page: that.data.page+1,
  246. },
  247. method:'GET',
  248. header:{
  249. 'Accept': 'application/json'
  250. },
  251. success (res) {
  252. wx.hideLoading();
  253. for (var i = 0; i < res.data.goodsSearchInfo.goodsSearchResponse.goodsList.length; i++) {
  254. that.data.goodsList.push( res.data.goodsSearchInfo.goodsSearchResponse.goodsList[i]);
  255. }
  256. that.setData({
  257. goodsList: that.data.goodsList,//res.data.goodsSearchInfo.goodsSearchResponse.goodsList,
  258. listId:res.data.goodsSearchInfo.goodsSearchResponse.listId,
  259. currentPage:currentPage
  260. })
  261. }
  262. })
  263. },
  264. /**
  265. * 生命周期函数--监听页面初次渲染完成
  266. */
  267. onReady: function () {
  268. },
  269. /**
  270. * 生命周期函数--监听页面显示
  271. */
  272. onShow: function () {
  273. },
  274. /**
  275. * 生命周期函数--监听页面隐藏
  276. */
  277. onHide: function () {
  278. },
  279. /**
  280. * 生命周期函数--监听页面卸载
  281. */
  282. onUnload: function () {
  283. },
  284. /**
  285. * 页面相关事件处理函数--监听用户下拉动作
  286. */
  287. onPullDownRefresh: function () {
  288. },
  289. /**
  290. * 页面上拉触底事件的处理函数
  291. */
  292. onReachBottom: function () {
  293. //获取数据
  294. var that = this;
  295. if ((that.totalCount+that.pageSize-1)/that.pageSize <= that.page){ //提示页码到了
  296. that.setData({
  297. lType:"end"
  298. })
  299. return
  300. }
  301. that.page +=1
  302. wx.request( {
  303. url: "http://49.234.19.130:8081/v1/pdd/ddk/search",
  304. // url: "http://127.0.0.1:8081/v1/pdd/ddk/search",
  305. header: {
  306. "Content-Type": "application/json"
  307. },
  308. method: "POST",
  309. //data: { cityname: "上海", key: "1430ec127e097e1113259c5e1be1ba70" },
  310. data: { page: that.page.toString(), page_size: that.pageSize.toString(),with_coupon:"true", activity_tags: that.activity_tags,keyword:that.keyword,pid:that.pid},
  311. complete: function( res ) {
  312. wx.hideLoading();
  313. console.log(res)
  314. that.totalCount = res.data.data.goods_search_response.total_count
  315. for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) {
  316. that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]);
  317. }
  318. that.setData({
  319. goodsList: that.data.goodsList,
  320. })
  321. console.log(res.data.data.goods_search_response)
  322. if( res == null || res.data == null ) {
  323. console.error( '网络请求失败' );
  324. return;
  325. }
  326. }
  327. })
  328. },
  329. goodsDetail:function(e){
  330. const goodsSign=e.currentTarget.dataset.sign;
  331. const searchId=e.currentTarget.dataset.searchid;
  332. wx.navigateTo({
  333. url: `/pages/details/details?goodsSign=${goodsSign}&searchId=${searchId}`,
  334. // url: `/pages/goods-detail/index`,
  335. })
  336. },
  337. /**
  338. * 用户点击右上角分享
  339. */
  340. onShareAppMessage: function () {
  341. }
  342. })