shouye.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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://49.234.19.130: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. var that = this
  274. wx.getClipboardData({
  275. success (res){
  276. console.log(res.data)
  277. var da = res.data
  278. if (res.data != 0){
  279. console.log('不为0')
  280. wx.showModal({
  281. title: '搜索产品',
  282. content: res.data,
  283. success: function(res) {
  284. if (res.confirm) {
  285. console.log('用户点击确认')
  286. //搜索数据
  287. that.page = 1
  288. that.pageSize = 18
  289. that.pid = "9112489_209622235"
  290. that.keyword = da
  291. that.activity_tags = ""
  292. wx.request( {
  293. url: "http://49.234.19.130:8081/v1/pdd/ddk/search",
  294. header: {
  295. "Content-Type": "application/json"
  296. },
  297. method: "POST",
  298. // data: { page: that.page.toString(), page_size: that.pageSize.toString(),with_coupon:"true", activity_tags: that.activity_tags},
  299. data: { page: that.page.toString(), page_size: that.pageSize.toString(),with_coupon:"true", pid:that.pid, activity_tags: that.activity_tags,keyword: that.keyword},
  300. complete: function( res ) {
  301. wx.hideLoading();
  302. console.log(res)
  303. that.totalCount = res.data.data.goods_search_response.total_count
  304. that.data.goodsList = res.data.data.goods_search_response.goods_list
  305. that.setData({
  306. goodsList: that.data.goodsList,
  307. })
  308. console.log(res.data.data.goods_search_response)
  309. if( res == null || res.data == null ) {
  310. console.error( '网络请求失败' );
  311. return;
  312. }
  313. }
  314. })
  315. } else if (res.cancel) {
  316. console.log('用户点击取消')
  317. }
  318. }
  319. })
  320. }
  321. }
  322. })
  323. },
  324. /**
  325. * 生命周期函数--监听页面隐藏
  326. */
  327. onHide: function () {
  328. },
  329. /**
  330. * 生命周期函数--监听页面卸载
  331. */
  332. onUnload: function () {
  333. },
  334. /**
  335. * 页面相关事件处理函数--监听用户下拉动作
  336. */
  337. onPullDownRefresh: function () {
  338. },
  339. /**
  340. * 页面上拉触底事件的处理函数
  341. */
  342. onReachBottom: function () {
  343. //获取数据
  344. var that = this;
  345. if ((that.totalCount+that.pageSize-1)/that.pageSize <= that.page){ //提示页码到了
  346. that.setData({
  347. lType:"end"
  348. })
  349. return
  350. }
  351. that.page +=1
  352. wx.request( {
  353. url: "http://49.234.19.130:8081/v1/pdd/ddk/search",
  354. // url: "http://127.0.0.1:8081/v1/pdd/ddk/search",
  355. header: {
  356. "Content-Type": "application/json"
  357. },
  358. method: "POST",
  359. //data: { cityname: "上海", key: "1430ec127e097e1113259c5e1be1ba70" },
  360. data: { page: that.page.toString(), page_size: that.pageSize.toString(),with_coupon:"true", activity_tags: that.activity_tags,keyword:that.keyword,pid:that.pid},
  361. complete: function( res ) {
  362. wx.hideLoading();
  363. console.log(res)
  364. that.totalCount = res.data.data.goods_search_response.total_count
  365. for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) {
  366. that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]);
  367. }
  368. that.setData({
  369. goodsList: that.data.goodsList,
  370. })
  371. console.log(res.data.data.goods_search_response)
  372. if( res == null || res.data == null ) {
  373. console.error( '网络请求失败' );
  374. return;
  375. }
  376. }
  377. })
  378. },
  379. goodsDetail:function(e){
  380. const goodsSign=e.currentTarget.dataset.sign;
  381. const searchId=e.currentTarget.dataset.searchid;
  382. wx.navigateTo({
  383. url: `/pages/details/details?goodsSign=${goodsSign}&searchId=${searchId}`,
  384. // url: `/pages/goods-detail/index`,
  385. })
  386. },
  387. /**
  388. * 用户点击右上角分享
  389. */
  390. onShareAppMessage: function () {
  391. }
  392. })