shouye.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. // pages/shouye/shouye.js
  2. const util = require('../../utils/util.js')
  3. const app = getApp()
  4. const link = app.globalData.url
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. placement: 'left',
  11. placementArr: ['top', 'left', 'right', 'bottom'],
  12. scrollAbleTabs: [],
  13. iconTabs: [{
  14. tab: '购物车',
  15. key: 'cart',
  16. icon: 'cart',
  17. picPlacement: 'left'
  18. }, {
  19. tab: '历史记录',
  20. key: 'history',
  21. icon: 'history',
  22. picPlacement: 'left'
  23. }, {
  24. tab: '我的',
  25. key: 'mine',
  26. icon: 'user',
  27. picPlacement: 'left'
  28. }],
  29. imagesTabs: [{
  30. tab: '客厅',
  31. key: 'dining',
  32. picPlacement: 'top',
  33. image: {
  34. activeImage: '/pages/components/nav/images/tab-icon/dining-active.png',
  35. defaultImage: '/pages/components/nav/images/tab-icon/dining.png',
  36. }
  37. },
  38. {
  39. tab: '卧室',
  40. key: 'badroom',
  41. picPlacement: 'top',
  42. image: {
  43. activeImage: '/pages/components/nav/images/tab-icon/badroom-active.png',
  44. defaultImage: '/pages/components/nav/images/tab-icon/badroom.png',
  45. }
  46. }, {
  47. tab: '厨房',
  48. key: 'kichten',
  49. picPlacement: 'top',
  50. image: {
  51. activeImage: '/pages/components/nav/images/tab-icon/kichten-active.png',
  52. defaultImage: '/pages/components/nav/images/tab-icon/kichten.png',
  53. }
  54. },
  55. {
  56. tab: '浴室',
  57. key: 'bathroom',
  58. picPlacement: 'top',
  59. image: {
  60. activeImage: '/pages/components/nav/images/tab-icon/bathroom-active.png',
  61. defaultImage: '/pages/components/nav/images/tab-icon/bathroom.png',
  62. }
  63. }
  64. ],
  65. goodsList:[],
  66. listId:"",
  67. page:1,
  68. pageSize:10,
  69. currentPage:0,
  70. totalCount:0,
  71. listId:"",
  72. show:true,
  73. lType:"loading",
  74. activity_tags:"",
  75. // pid:"9112489_209622235",
  76. pid:"9112489_212035116",
  77. keyword:""
  78. },
  79. _asyncData() {
  80. this.setData({
  81. scrollAbleTabs: [
  82. {
  83. tab: '精选',
  84. key: '0'
  85. },
  86. {
  87. tab: '秒杀',
  88. key: '4'
  89. }, {
  90. tab: '百亿补贴',
  91. key: '7'
  92. }, {
  93. tab: '千万补贴',
  94. key: '10851'
  95. }, {
  96. tab: '品牌',
  97. key: '31'
  98. },{
  99. tab:'官方爆品',
  100. key:'10564'
  101. },
  102. {
  103. tab:'大牌',
  104. key:'24'
  105. }],
  106. });
  107. },
  108. /**
  109. * 生命周期函数--监听页面加载
  110. */
  111. onLoad: function (options) {
  112. // this._asyncData
  113. var that = this;
  114. that.page = 1
  115. that.pageSize = 18
  116. wx.request( {
  117. url: link + "/v1/set",
  118. header: {
  119. "Content-Type": "application/json"
  120. },
  121. method: "POST",
  122. data: { version: "1.0.2" },
  123. complete: function( res ) {
  124. console.log(res)
  125. if( res == null || res.data == null ) {
  126. console.error( '网络请求失败' );
  127. return;
  128. }
  129. if (res.data.data.type == "false"){
  130. // wx.reLanch({
  131. // url: 'pages/search/search'
  132. // })
  133. wx.redirectTo({
  134. url: '../search/search'
  135. })
  136. }else{
  137. //获取数据
  138. setTimeout(that._asyncData, 0);
  139. wx.request( {
  140. url: link + "/v1/pdd/ddk/search",
  141. header: {
  142. "Content-Type": "application/json"
  143. },
  144. method: "POST",
  145. data: { page: that.page.toString(), page_size: that.pageSize.toString()},
  146. complete: function( res ) {
  147. wx.hideLoading();
  148. console.log(res)
  149. that.totalCount = res.data.data.goods_search_response.total_count
  150. for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) {
  151. that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]);
  152. }
  153. that.setData({
  154. goodsList: that.data.goodsList,
  155. })
  156. console.log(res.data.data.goods_search_response)
  157. if( res == null || res.data == null ) {
  158. console.error( '网络请求失败' );
  159. return;
  160. }
  161. }
  162. })
  163. }
  164. }
  165. })
  166. },
  167. search:function(e){
  168. var that = this
  169. console.log(e)
  170. that.keyword = e.detail.value
  171. that.activity_tags = ""
  172. that.pid = "9112489_209622235"
  173. console.log(that.keyword)
  174. console.log(that.pid)
  175. that.page = 1
  176. that.pageSize = 18
  177. wx.request( {
  178. url: link + "/v1/pdd/ddk/search",
  179. header: {
  180. "Content-Type": "application/json"
  181. },
  182. method: "POST",
  183. data: { page: that.page.toString(), page_size: that.pageSize.toString(), activity_tags: that.activity_tags, pid:that.pid, keyword: that.keyword},
  184. complete: function( res ) {
  185. wx.hideLoading();
  186. console.log(res)
  187. that.totalCount = res.data.data.goods_search_response.total_count
  188. that.data.goodsList = res.data.data.goods_search_response.goods_list
  189. // for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) {
  190. // that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]);
  191. // }
  192. that.setData({
  193. goodsList: that.data.goodsList,
  194. })
  195. console.log(res.data.data.goods_search_response)
  196. if( res == null || res.data == null ) {
  197. console.error( '网络请求失败' );
  198. return;
  199. }
  200. }
  201. })
  202. // wx.navigateTo({
  203. // url: '../search/search'
  204. // })
  205. },
  206. keyData:function(e){
  207. var that = this
  208. that.keyword = ""
  209. if (e.detail.activeKey == "0"){
  210. that.activity_tags = ""
  211. } else{
  212. that.activity_tags = "["+e.detail.activeKey + "]"
  213. }
  214. console.log(e)
  215. that.page = 1
  216. that.pageSize = 18
  217. wx.request( {
  218. url: link + "/v1/pdd/ddk/search",
  219. header: {
  220. "Content-Type": "application/json"
  221. },
  222. method: "POST",
  223. data: { page: that.page.toString(), page_size: that.pageSize.toString(), activity_tags: that.activity_tags},
  224. complete: function( res ) {
  225. wx.hideLoading();
  226. console.log(res)
  227. that.totalCount = res.data.data.goods_search_response.total_count
  228. that.data.goodsList = res.data.data.goods_search_response.goods_list
  229. // for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) {
  230. // that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]);
  231. // }
  232. that.setData({
  233. goodsList: that.data.goodsList,
  234. })
  235. console.log(res.data.data.goods_search_response)
  236. if( res == null || res.data == null ) {
  237. console.error( '网络请求失败' );
  238. return;
  239. }
  240. }
  241. })
  242. },
  243. goodsCollection: function(e){
  244. var that=this
  245. var currentPage=that.data.page+1;
  246. wx.request({
  247. url: link + '/v1/pdd/ddk/search',
  248. data: {
  249. listId:that.data.listId,
  250. pageSize:10,
  251. page: that.data.page+1,
  252. },
  253. method:'GET',
  254. header:{
  255. 'Accept': 'application/json'
  256. },
  257. success (res) {
  258. wx.hideLoading();
  259. for (var i = 0; i < res.data.goodsSearchInfo.goodsSearchResponse.goodsList.length; i++) {
  260. that.data.goodsList.push( res.data.goodsSearchInfo.goodsSearchResponse.goodsList[i]);
  261. }
  262. that.setData({
  263. goodsList: that.data.goodsList,//res.data.goodsSearchInfo.goodsSearchResponse.goodsList,
  264. listId:res.data.goodsSearchInfo.goodsSearchResponse.listId,
  265. currentPage:currentPage
  266. })
  267. }
  268. })
  269. },
  270. /**
  271. * 生命周期函数--监听页面初次渲染完成
  272. */
  273. onReady: function () {
  274. },
  275. /**
  276. * 生命周期函数--监听页面显示
  277. */
  278. onShow: function () {
  279. var that = this
  280. wx.getClipboardData({
  281. success (res){
  282. console.log(res.data)
  283. var da = res.data
  284. if (res.data != 0){
  285. console.log('不为0')
  286. wx.showModal({
  287. title: '搜索产品',
  288. content: res.data,
  289. success: function(res) {
  290. if (res.confirm) {
  291. console.log('用户点击确认')
  292. //搜索数据
  293. that.page = 1
  294. that.pageSize = 18
  295. that.pid = "9112489_209622235"
  296. that.keyword = da
  297. that.activity_tags = ""
  298. wx.request( {
  299. url: link + "/v1/pdd/ddk/search",
  300. header: {
  301. "Content-Type": "application/json"
  302. },
  303. method: "POST",
  304. // data: { page: that.page.toString(), page_size: that.pageSize.toString(),with_coupon:"true", activity_tags: that.activity_tags},
  305. data: { page: that.page.toString(), page_size: that.pageSize.toString(), pid:that.pid, activity_tags: that.activity_tags,keyword: that.keyword},
  306. complete: function( res ) {
  307. wx.hideLoading();
  308. console.log(res)
  309. that.totalCount = res.data.data.goods_search_response.total_count
  310. that.data.goodsList = res.data.data.goods_search_response.goods_list
  311. that.setData({
  312. goodsList: that.data.goodsList,
  313. })
  314. console.log(res.data.data.goods_search_response)
  315. if( res == null || res.data == null ) {
  316. console.error( '网络请求失败' );
  317. return;
  318. }
  319. }
  320. })
  321. } else if (res.cancel) {
  322. console.log('用户点击取消')
  323. }
  324. }
  325. })
  326. }
  327. }
  328. })
  329. },
  330. /**
  331. * 生命周期函数--监听页面隐藏
  332. */
  333. onHide: function () {
  334. },
  335. /**
  336. * 生命周期函数--监听页面卸载
  337. */
  338. onUnload: function () {
  339. },
  340. /**
  341. * 页面相关事件处理函数--监听用户下拉动作
  342. */
  343. onPullDownRefresh: function () {
  344. },
  345. /**
  346. * 页面上拉触底事件的处理函数
  347. */
  348. onReachBottom: function () {
  349. //获取数据
  350. var that = this;
  351. if ((that.totalCount+that.pageSize-1)/that.pageSize <= that.page){ //提示页码到了
  352. that.setData({
  353. lType:"end"
  354. })
  355. return
  356. }
  357. that.page +=1
  358. wx.request( {
  359. url: link + "/v1/pdd/ddk/search",
  360. // url: "http://127.0.0.1:8081/v1/pdd/ddk/search",
  361. header: {
  362. "Content-Type": "application/json"
  363. },
  364. method: "POST",
  365. //data: { cityname: "上海", key: "1430ec127e097e1113259c5e1be1ba70" },
  366. data: { page: that.page.toString(), page_size: that.pageSize.toString(), activity_tags: that.activity_tags,keyword:that.keyword,pid:that.pid},
  367. complete: function( res ) {
  368. wx.hideLoading();
  369. console.log(res)
  370. that.totalCount = res.data.data.goods_search_response.total_count
  371. for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) {
  372. that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]);
  373. }
  374. that.setData({
  375. goodsList: that.data.goodsList,
  376. })
  377. console.log(res.data.data.goods_search_response)
  378. if( res == null || res.data == null ) {
  379. console.error( '网络请求失败' );
  380. return;
  381. }
  382. }
  383. })
  384. },
  385. goodsDetail:function(e){
  386. const goodsSign=e.currentTarget.dataset.sign;
  387. const searchId=e.currentTarget.dataset.searchid;
  388. wx.navigateTo({
  389. url: `/pages/details/details?goodsSign=${goodsSign}&searchId=${searchId}`,
  390. // url: `/pages/goods-detail/index`,
  391. })
  392. },
  393. /**
  394. * 用户点击右上角分享
  395. */
  396. onShareAppMessage: function () {
  397. }
  398. })