shouye.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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. //获取数据
  117. setTimeout(that._asyncData, 0);
  118. wx.request( {
  119. url: link + "/v1/pdd/ddk/search",
  120. header: {
  121. "Content-Type": "application/json"
  122. },
  123. method: "POST",
  124. data: { page: that.page.toString(), page_size: that.pageSize.toString()},
  125. complete: function( res ) {
  126. wx.hideLoading();
  127. console.log(res)
  128. that.totalCount = res.data.data.goods_search_response.total_count
  129. for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) {
  130. that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]);
  131. }
  132. that.setData({
  133. goodsList: that.data.goodsList,
  134. })
  135. console.log(res.data.data.goods_search_response)
  136. if( res == null || res.data == null ) {
  137. console.error( '网络请求失败' );
  138. return;
  139. }
  140. }
  141. })
  142. },
  143. search:function(e){
  144. var that = this
  145. console.log(e)
  146. that.keyword = e.detail.value
  147. that.activity_tags = ""
  148. that.pid = "9112489_209622235"
  149. console.log(that.keyword)
  150. console.log(that.pid)
  151. that.page = 1
  152. that.pageSize = 18
  153. wx.request( {
  154. url: link + "/v1/pdd/ddk/search",
  155. header: {
  156. "Content-Type": "application/json"
  157. },
  158. method: "POST",
  159. data: { page: that.page.toString(), page_size: that.pageSize.toString(), activity_tags: that.activity_tags, pid:that.pid, keyword: that.keyword},
  160. complete: function( res ) {
  161. wx.hideLoading();
  162. console.log(res)
  163. that.totalCount = res.data.data.goods_search_response.total_count
  164. that.data.goodsList = res.data.data.goods_search_response.goods_list
  165. // for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) {
  166. // that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]);
  167. // }
  168. that.setData({
  169. goodsList: that.data.goodsList,
  170. })
  171. console.log(res.data.data.goods_search_response)
  172. if( res == null || res.data == null ) {
  173. console.error( '网络请求失败' );
  174. return;
  175. }
  176. }
  177. })
  178. // wx.navigateTo({
  179. // url: '../search/search'
  180. // })
  181. },
  182. keyData:function(e){
  183. var that = this
  184. that.keyword = ""
  185. if (e.detail.activeKey == "0"){
  186. that.activity_tags = ""
  187. } else{
  188. that.activity_tags = "["+e.detail.activeKey + "]"
  189. }
  190. console.log(e)
  191. that.page = 1
  192. that.pageSize = 18
  193. wx.request( {
  194. url: link + "/v1/pdd/ddk/search",
  195. header: {
  196. "Content-Type": "application/json"
  197. },
  198. method: "POST",
  199. data: { page: that.page.toString(), page_size: that.pageSize.toString(), activity_tags: that.activity_tags},
  200. complete: function( res ) {
  201. wx.hideLoading();
  202. console.log(res)
  203. that.totalCount = res.data.data.goods_search_response.total_count
  204. that.data.goodsList = res.data.data.goods_search_response.goods_list
  205. // for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) {
  206. // that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]);
  207. // }
  208. that.setData({
  209. goodsList: that.data.goodsList,
  210. })
  211. console.log(res.data.data.goods_search_response)
  212. if( res == null || res.data == null ) {
  213. console.error( '网络请求失败' );
  214. return;
  215. }
  216. }
  217. })
  218. },
  219. goodsCollection: function(e){
  220. var that=this
  221. var currentPage=that.data.page+1;
  222. wx.request({
  223. url: link + '/v1/pdd/ddk/search',
  224. data: {
  225. listId:that.data.listId,
  226. pageSize:10,
  227. page: that.data.page+1,
  228. },
  229. method:'GET',
  230. header:{
  231. 'Accept': 'application/json'
  232. },
  233. success (res) {
  234. wx.hideLoading();
  235. for (var i = 0; i < res.data.goodsSearchInfo.goodsSearchResponse.goodsList.length; i++) {
  236. that.data.goodsList.push( res.data.goodsSearchInfo.goodsSearchResponse.goodsList[i]);
  237. }
  238. that.setData({
  239. goodsList: that.data.goodsList,//res.data.goodsSearchInfo.goodsSearchResponse.goodsList,
  240. listId:res.data.goodsSearchInfo.goodsSearchResponse.listId,
  241. currentPage:currentPage
  242. })
  243. }
  244. })
  245. },
  246. /**
  247. * 生命周期函数--监听页面初次渲染完成
  248. */
  249. onReady: function () {
  250. },
  251. /**
  252. * 生命周期函数--监听页面显示
  253. */
  254. onShow: function () {
  255. var that = this
  256. wx.getClipboardData({
  257. success (res){
  258. console.log(res.data)
  259. var da = res.data
  260. if (res.data != 0){
  261. console.log('不为0')
  262. wx.setClipboardData({
  263. data: '0',
  264. success (res) {
  265. }
  266. })
  267. wx.showModal({
  268. title: '搜索产品',
  269. content: res.data,
  270. success: function(res) {
  271. if (res.confirm) {
  272. console.log('用户点击确认')
  273. //搜索数据
  274. that.page = 1
  275. that.pageSize = 18
  276. that.pid = "9112489_209622235"
  277. that.keyword = da
  278. that.activity_tags = ""
  279. wx.request( {
  280. url: link + "/v1/pdd/ddk/search",
  281. header: {
  282. "Content-Type": "application/json"
  283. },
  284. method: "POST",
  285. // data: { page: that.page.toString(), page_size: that.pageSize.toString(),with_coupon:"true", activity_tags: that.activity_tags},
  286. data: { page: that.page.toString(), page_size: that.pageSize.toString(), pid:that.pid, activity_tags: that.activity_tags,keyword: that.keyword},
  287. complete: function( res ) {
  288. wx.hideLoading();
  289. console.log(res)
  290. that.totalCount = res.data.data.goods_search_response.total_count
  291. that.data.goodsList = res.data.data.goods_search_response.goods_list
  292. that.setData({
  293. goodsList: that.data.goodsList,
  294. })
  295. console.log(res.data.data.goods_search_response)
  296. if( res == null || res.data == null ) {
  297. console.error( '网络请求失败' );
  298. return;
  299. }
  300. }
  301. })
  302. } else if (res.cancel) {
  303. console.log('用户点击取消')
  304. }
  305. }
  306. })
  307. }
  308. }
  309. })
  310. },
  311. /**
  312. * 生命周期函数--监听页面隐藏
  313. */
  314. onHide: function () {
  315. },
  316. /**
  317. * 生命周期函数--监听页面卸载
  318. */
  319. onUnload: function () {
  320. },
  321. /**
  322. * 页面相关事件处理函数--监听用户下拉动作
  323. */
  324. onPullDownRefresh: function () {
  325. },
  326. /**
  327. * 页面上拉触底事件的处理函数
  328. */
  329. onReachBottom: function () {
  330. //获取数据
  331. var that = this;
  332. if ((that.totalCount+that.pageSize-1)/that.pageSize <= that.page){ //提示页码到了
  333. that.setData({
  334. lType:"end"
  335. })
  336. return
  337. }
  338. that.page +=1
  339. wx.request( {
  340. url: link + "/v1/pdd/ddk/search",
  341. // url: "http://127.0.0.1:8081/v1/pdd/ddk/search",
  342. header: {
  343. "Content-Type": "application/json"
  344. },
  345. method: "POST",
  346. //data: { cityname: "上海", key: "1430ec127e097e1113259c5e1be1ba70" },
  347. data: { page: that.page.toString(), page_size: that.pageSize.toString(), activity_tags: that.activity_tags,keyword:that.keyword,pid:that.pid},
  348. complete: function( res ) {
  349. wx.hideLoading();
  350. console.log(res)
  351. that.totalCount = res.data.data.goods_search_response.total_count
  352. for (var i = 0; i < res.data.data.goods_search_response.goods_list.length; i++) {
  353. that.data.goodsList.push( res.data.data.goods_search_response.goods_list[i]);
  354. }
  355. that.setData({
  356. goodsList: that.data.goodsList,
  357. })
  358. console.log(res.data.data.goods_search_response)
  359. if( res == null || res.data == null ) {
  360. console.error( '网络请求失败' );
  361. return;
  362. }
  363. }
  364. })
  365. },
  366. goodsDetail:function(e){
  367. const goodsSign=e.currentTarget.dataset.sign;
  368. const searchId=e.currentTarget.dataset.searchid;
  369. wx.navigateTo({
  370. url: `/pages/details/details?goodsSign=${goodsSign}&searchId=${searchId}`,
  371. // url: `/pages/goods-detail/index`,
  372. })
  373. },
  374. /**
  375. * 用户点击右上角分享
  376. */
  377. // onShareAppMessage: function () {
  378. // }
  379. })