shouye.js 11 KB

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