shouye.js 11 KB

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