home.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. var _request = require('../../utils/request.js')
  2. var util = require('../../utils/util.js')
  3. Page ({
  4. data: {
  5. ceshi: 'false',
  6. swiper: {
  7. indicatorDots: true,
  8. autoplay: true,
  9. interval: 4000
  10. },
  11. swiperCurrent: 0,
  12. firstProject: [],
  13. secondProject: [],
  14. recommend: {
  15. title: 'Microlab/麦博 M200十周年蓝牙版台式电脑音箱 家用音响电脑音箱蓝牙版',
  16. price: 3900,
  17. url: 'https://img10.360buyimg.com/n7/jfs/t11821/47/132726032/183731/677590e/59e85492N24686ba9.jpg',
  18. point: 3999
  19. },
  20. products: {
  21. rd: 0,
  22. page: 1,
  23. per_page: 5
  24. },
  25. productsList: [],
  26. bannerList: [],
  27. categories: [],
  28. vershow: true,
  29. percent: [],
  30. zhunongList: [],
  31. page1: 1,
  32. per_page1: 50,
  33. balance: 0,
  34. bgcolor: '#eee',
  35. progress: 0,
  36. progress1: 0,
  37. // day: '00',
  38. hour: '00',
  39. min: '00',
  40. second: '00',
  41. timer: '',
  42. leftTime: 0,
  43. // msecond: '00',
  44. currentTab: util.formatChDate1(new Date()),
  45. navScrollLeft: 0,
  46. iconslist: [],
  47. seckilltimelist: [],
  48. today: util.formatChDate1(new Date()),
  49. killgoodslist: [],
  50. firsttime: '',
  51. change: false,
  52. clock: '',
  53. changeshow: 'seckill',
  54. toView: '',
  55. is_copartnershow: '',
  56. showpyq: 0,
  57. todaysend: Date.parse(new Date()) / 1000,
  58. showtime: '',
  59. projects_more:true,
  60. userinfo:{},
  61. nowseckill_data:'',
  62. statusBarHeight:20,
  63. navBarHeight:45,
  64. windowWidth:375,
  65. word:'',
  66. price_sort:0,
  67. sale_sort:0
  68. },
  69. onLoad: function () {
  70. const info = wx.getSystemInfoSync();
  71. console.log('info',info);
  72. this.setData({
  73. statusBarHeight:info.statusBarHeight
  74. })
  75. // this.getzhunongList()
  76. this.setData({
  77. vershow: getApp().globalData.vershow,
  78. // is_copartnershow: getApp().globalData.is_copartner,
  79. })
  80. if (getApp().globalData.wx_id) {
  81. this.info()
  82. }
  83. this.getData()
  84. this.getBanners()
  85. this.getCategories()
  86. this.getList()
  87. //this.getBalanceInfo()
  88. // this.showprogress()
  89. // this.starttime()
  90. wx.getSystemInfo({
  91. success: (res) => {
  92. this.setData({
  93. windowWidth: res.windowWidth
  94. })
  95. }
  96. })
  97. this.geticons()
  98. this.getkilltime()
  99. },
  100. onShow: function () {
  101. // this.getzhunongList()
  102. // this.getCategories()
  103. const screenWidth = wx.getSystemInfoSync().windowWidth
  104. const screenHeight = wx.getSystemInfoSync().windowHeight
  105. this.setData({
  106. //获取页面初始状态图片数量,0.63为图片容器的高度值(63vw),将代码中0.63改为你的容器对应高度
  107. listIndex: screenHeight / (screenWidth * 0.50),
  108. screenWidth: screenWidth,
  109. screenHeight: screenHeight
  110. })
  111. },
  112. onPullDownRefresh: function () {
  113. this.getBanners()
  114. this.getCategories()
  115. this.getList()
  116. // this.getzhunongList()
  117. wx.stopPullDownRefresh()
  118. this.geticons()
  119. this.getkilltime()
  120. },
  121. getList: function () {
  122. if (this.data.vershow) {
  123. this.getProjects()
  124. } else {
  125. this.getVersion()
  126. }
  127. },
  128. swiperChange: function (e) {
  129. this.setData({
  130. swiperCurrent: e.detail.current
  131. })
  132. },
  133. getData: function () {
  134. var that = this
  135. var url = 'v1/product/commend_words'
  136. var params = {}
  137. var success = function (res) {
  138. console.log('res',res.data.list);
  139. that.setData({
  140. word:res.data.list[0]?res.data.list[0].title:''
  141. })
  142. }
  143. _request.$get(url, params, success)
  144. },
  145. getVersion: function () {
  146. var that = this
  147. var url = 'v1/cat/3/products'
  148. var params = {
  149. page: this.data.products.page,
  150. per_page: this.data.products.per_page
  151. }
  152. var success = function (res) {
  153. that.setData({
  154. productsList: res.data.list
  155. })
  156. }
  157. _request.$get(url, params, success)
  158. },
  159. getProjects: function () {
  160. var that = this
  161. var url = 'v1/products'
  162. var params = {
  163. rd: this.data.products.rd,
  164. page: this.data.products.page,
  165. per_page: this.data.products.per_page,
  166. price_sort:this.data.price_sort,
  167. sale_sort:this.data.sale_sort
  168. }
  169. var success = function (res) {
  170. that.setData({
  171. projects_more: res.data.list_count > that.data.productsList.length,
  172. productsList: that.data.productsList.concat(res.data.list || []),
  173. })
  174. }
  175. _request.$get(url, params, success)
  176. },
  177. onReachBottom: function () {
  178. if (this.data.projects_more) {
  179. var page = this.data.products.page + 1
  180. this.setData({
  181. ['products.page']: page
  182. })
  183. this.getProjects()
  184. }
  185. },
  186. getBanners: function () {
  187. var item = 'home'
  188. if (!this.data.vershow) {
  189. item = 'test'
  190. }
  191. var that = this
  192. var url = 'v1/ad/' + item + '/items'
  193. var params = {
  194. }
  195. var success = function (res) {
  196. that.setData({
  197. bannerList: res.data
  198. })
  199. }
  200. _request.$get(url, params, success)
  201. },
  202. toProject: function (val) {
  203. var id = val.currentTarget.dataset.val;
  204. wx.navigateTo({
  205. url: '/pages/projects/project-detail/project-detail?id=' + id
  206. })
  207. },
  208. tosearch: function (val) {
  209. var id = val.currentTarget.dataset.val;
  210. wx.navigateTo({
  211. url: '/pages/search/search'
  212. })
  213. },
  214. toCustom: function () {
  215. wx.reLaunch({
  216. url: '/pages/customservice/customservice'
  217. })
  218. },
  219. getCategories: function () {
  220. var that = this
  221. var url = 'v1/categories?platform=wx_hot'
  222. var params = {
  223. }
  224. var success = function (res) {
  225. if (res.data && res.data.wx_hot) {
  226. if (res.data.wx_hot.length >= 2) {
  227. var list1 = res.data.wx_hot.slice(0,2)
  228. that.setData({
  229. firstProject: list1
  230. })
  231. }
  232. if (res.data.wx_hot.length >= 6) {
  233. var list2 = res.data.wx_hot.slice(2,6)
  234. that.setData({
  235. secondProject: list2
  236. })
  237. }
  238. }
  239. that.setData({
  240. categories: res.data
  241. })
  242. }
  243. _request.$get(url, params, success)
  244. },
  245. onShareAppMessage: function (val) {
  246. return _request.share({
  247. title: '欢迎来到凤凰菁选商城',
  248. path: '/pages/start/start',
  249. imageUrl: 'http://fohow.oss-cn-shenzhen.aliyuncs.com/xcx/share/sharemain.jpg',
  250. sc: 'xcx_home',
  251. ri: 0,
  252. rp: 0
  253. })
  254. },
  255. toColumn: function (val) {
  256. var type = val.currentTarget.dataset.val.url_type
  257. var url = val.currentTarget.dataset.val.url
  258. var id = val.currentTarget.dataset.val.id
  259. this.getClick(id)
  260. if (type === 0) {
  261. wx.navigateTo({
  262. url: url
  263. })
  264. }
  265. if (type === 1) {
  266. wx.navigateTo({
  267. url: '/pages/web/web?id=' + url
  268. })
  269. }
  270. if(type === 2){
  271. wx.reLaunch({
  272. url: url
  273. })
  274. }
  275. },
  276. // newyear: function () {
  277. // wx.navigateTo({
  278. // url: '/pages/activity/redpacket/redpacket?rid=1'
  279. // })
  280. // }
  281. toviewfunc (val) {
  282. var type = val.currentTarget.dataset.val.url_type
  283. var url = val.currentTarget.dataset.val.url
  284. var id = val.currentTarget.dataset.val.product_cat_index
  285. if (type === 0) {
  286. if (url === '/pages/projects/projects') {
  287. getApp().globalData.isshow = id
  288. getApp().globalData.isupdate = false
  289. }
  290. if (url === '/pages/user/all/all' || url === '/pages/helpfarm/helpfarm' || url === '/pages/projects/projects' || url === '/pages/customservice/customservice') {
  291. wx.switchTab({
  292. url: url
  293. })
  294. } else {
  295. if(id == 0){
  296. wx.navigateTo({
  297. url: url
  298. })
  299. }else{
  300. wx.reLaunch({
  301. url: url+id
  302. })
  303. }
  304. }
  305. }
  306. if (type === 1) {
  307. wx.navigateTo({
  308. url: '/pages/web/web?id=' + url
  309. })
  310. }
  311. },
  312. getClick (id) {
  313. var url = 'v1/ad/' + id + '/click'
  314. var params = {}
  315. var success = function () {
  316. }
  317. _request.$get(url, params, success)
  318. },
  319. getzhunongList () {
  320. var that = this
  321. var url = 'v1/projects?state=0,1'
  322. var params = {
  323. page: this.data.page1,
  324. per_page: this.data.per_page1
  325. }
  326. var success = function (res) {
  327. // var percent = res.data.list.current_funding / res.data.list.min_funding
  328. var countArr = []
  329. for (var index in res.data.list) {
  330. var count = parseInt(res.data.list[index].current_funding) / parseInt(res.data.list[index].min_funding) *100
  331. // console.log(count)
  332. var count1 = (count).toFixed(2)
  333. // var count1 = parseInt(count)
  334. countArr.push(count1)
  335. }
  336. that.setData({
  337. zhunongList: res.data.list,
  338. percent: countArr
  339. })
  340. // that.showprogress()
  341. }
  342. _request.$get(url, params, success)
  343. },
  344. toZhunong (val) {
  345. var id1 = val.currentTarget.dataset.val
  346. wx.navigateTo({
  347. url: '/pages/helpfarm/helpfarm-detail/helpfarm-detail?id=' + id1
  348. })
  349. },
  350. getBalanceInfo () {
  351. var that = this
  352. var url = 'v1/user/balance/info'
  353. var params = {
  354. }
  355. var success = function (res) {
  356. var result = res.data.total
  357. that.setData({
  358. balance: result
  359. })
  360. }
  361. _request.$get(url, params, success)
  362. },
  363. starttime () {
  364. var that = this
  365. that.setData({
  366. timer: setInterval(function () {
  367. // var date = new Date();
  368. // var now = date.getTime();
  369. // var endDate = new Date("2019-01-03 23:14:53");//设置截止时间
  370. // var end = that.data.clock * 1000;//设置截止时间
  371. // var end = endDate.getTime();
  372. // var leftTime = end - now; //时间差
  373. var t = Date.parse(new Date())
  374. t = t / 1000;
  375. var leftTime;
  376. if(that.data.nowseckill_data['state'] == 'seckill'){
  377. leftTime = that.data.clock - t
  378. }else if(that.data.nowseckill_data['state'] == 'preparing'){
  379. leftTime = that.data.nowseckill_data['start_time'] - t
  380. }
  381. var d, h, m, s, ms;
  382. if (leftTime >= 0) {
  383. // day = parseInt(ctime / 86400)
  384. h = parseInt(leftTime / 3600)
  385. m = parseInt(leftTime / 60 ) - parseInt(leftTime / 3600) * 60
  386. s = parseInt(leftTime) - parseInt(leftTime / 60 ) * 60
  387. // d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
  388. // h = Math.floor(leftTime / 1000 / 60 / 60 % 24);
  389. // m = Math.floor(leftTime / 1000 / 60 % 60);
  390. // s = Math.floor(leftTime / 1000 % 60);
  391. // ms = Math.floor(leftTime % 1000);
  392. // ms = ms < 100 ? "0" + ms : ms
  393. s = s < 10 ? "0" + s : s
  394. m = m < 10 ? "0" + m : m
  395. h = h < 10 ? "0" + h : h
  396. that.setData({
  397. hour: h,
  398. min: m,
  399. second: s,
  400. // msecond: ms,
  401. leftTime: leftTime
  402. })
  403. }
  404. if (leftTime < 0) {
  405. clearInterval(that.data.timer);
  406. that.setData({
  407. leftTime: 0,
  408. hour: '00',
  409. min: '00',
  410. second: '00',
  411. // msecond: '00'
  412. })
  413. }
  414. },100),
  415. });
  416. },
  417. switchtime (e) {
  418. var cur = e.currentTarget.dataset.current
  419. var idx = e.currentTarget.dataset.val
  420. var killtime = e.currentTarget.dataset.time
  421. var nowtime = util.formatTime(new Date(e.currentTarget.dataset.showtime * 1000))
  422. var singleNavWidth = this.data.windowWidth / 5
  423. this.setData({
  424. navScrollLeft: (idx - 2) * singleNavWidth
  425. })
  426. if (this.data.currentTab == idx || this.data.today == killtime) {
  427. return false
  428. }
  429. this.setData ({
  430. currentTab: idx,
  431. today: killtime,
  432. firsttime: killtime,
  433. change: true,
  434. changeshow: cur,
  435. showtime: nowtime.substring(11,13)
  436. })
  437. this.getkillgoods()
  438. },
  439. geticons () {
  440. var that = this
  441. var url = 'v1/navigate/icons'
  442. var params = {}
  443. var success = function (res) {
  444. var icons = res.data
  445. that.setData({
  446. iconslist: icons
  447. })
  448. }
  449. _request.$get(url, params, success)
  450. },
  451. getkilltime () {
  452. var that = this
  453. var url = 'v1/seckill/dates'
  454. var params = {
  455. cache: false
  456. }
  457. var success = function (res) {
  458. var seclist = res.data.ret_item_list
  459. var singleNavWidth = that.data.windowWidth / 5
  460. // for (var index in seclist) {
  461. // if (seclist[index].state == 'seckill') {
  462. // that.setData({
  463. // firsttime: seclist[index].date_format,
  464. // clock: seclist[index].end_time,
  465. // // navScrollLeft: singleNavWidth,
  466. // toView: 'a' + seclist[index].date_format,
  467. // changeshow: 'seckill'
  468. // })
  469. // }
  470. // if (seclist[index].state == 'end' && seclist[index].date_format == that.data.currentTab) {
  471. // that.setData({
  472. // toView: 'a' + seclist[index].date_format,
  473. // changeshow: 'end'
  474. // })
  475. // }
  476. // if (seclist[index].state == 'preparing' && seclist[index].date_format == that.data.currentTab) {
  477. // var nowtime = util.formatTime(new Date(seclist[index].start_time * 1000))
  478. // that.setData({
  479. // toView: 'a' + seclist[index].date_format,
  480. // changeshow: 'preparing',
  481. // showtime: nowtime.substring(11,13),
  482. // })
  483. // }
  484. // if (seclist[index].state == 'none' && seclist[index].date_format == that.data.currentTab) {
  485. // that.setData({
  486. // toView: 'a' + seclist[index].date_format,
  487. // changeshow: 'none'
  488. // })
  489. // }
  490. // }
  491. var nsdata;
  492. for (var index in seclist) {
  493. if (seclist[index].state == 'seckill') {
  494. nsdata = seclist[index];
  495. var showtime = util.formatTime(new Date(nsdata['start_time']* 1000));
  496. nsdata['showtime'] = showtime.substring(11,13);
  497. nsdata['clock'] = seclist[index].end_time;
  498. break;
  499. }else if (seclist[index].state == 'preparing') {
  500. nsdata = seclist[index];
  501. var showtime = util.formatTime(new Date(nsdata['start_time'] * 1000));
  502. nsdata['showtime'] = showtime.substring(11,13)
  503. break;
  504. }
  505. }
  506. console.log('nsdata',nsdata);
  507. that.setData({
  508. seckilltimelist: seclist,
  509. clock:nsdata ? nsdata['clock'] : 0,
  510. nowseckill_data:nsdata
  511. })
  512. if(nsdata){
  513. that.getkillgoods()
  514. that.starttime()
  515. }
  516. }
  517. _request.$get(url, params, success)
  518. },
  519. getkillgoods () {
  520. var that = this
  521. var url = 'v1/seckill/products'
  522. var params = {
  523. query_date: that.data.nowseckill_data ? that.data.nowseckill_data['date_format'] : '',
  524. cache: false
  525. }
  526. var success = function (res) {
  527. // if (res.data.product_list.length > 0) {
  528. var killgoodslist = res.data.product_list
  529. that.setData({
  530. killgoodslist: killgoodslist,
  531. })
  532. // }
  533. }
  534. _request.$get(url, params, success)
  535. },
  536. toabout () {
  537. // var host = getApp().globalData.d5c
  538. // if (host === 'tfhwx.hiwavo.com') {
  539. // wx.navigateTo({
  540. // url: '/pages/parse/parse?id=2'
  541. // })
  542. // } else if (host === 'fhwx.hiwavo.com') {
  543. wx.navigateTo({
  544. url: '/pages/parse/parse?id=1'
  545. })
  546. // }
  547. },
  548. tofhvd () {
  549. wx.navigateTo({
  550. url: '/pages/parse/parse?id=2'
  551. })
  552. },
  553. toyszq () {
  554. wx.reLaunch({
  555. url: '/pages/projects/projects?currentTab=4'
  556. })
  557. },
  558. togrhl () {
  559. wx.reLaunch({
  560. url: '/pages/projects/projects?currentTab=2'
  561. })
  562. },
  563. tojjry () {
  564. wx.reLaunch({
  565. url: '/pages/projects/projects?currentTab=3'
  566. })
  567. },
  568. toygyp () {
  569. wx.reLaunch({
  570. url: '/pages/projects/projects?currentTab=5'
  571. })
  572. },
  573. tothzq () {
  574. wx.reLaunch({
  575. url: '/pages/projects/projects?currentTab=1'
  576. })
  577. },
  578. todz () {
  579. if(this.data.userinfo.rank < 2){
  580. wx.navigateTo({
  581. url: '/packageUser/pages/user/applyLeader/applyLeader'
  582. })
  583. }else{
  584. wx.navigateTo({
  585. url: '/pages/areacart/areacart'
  586. })
  587. }
  588. },
  589. tocentcart () {
  590. wx.navigateTo({
  591. url: '/pages/centcart/centcart'
  592. })
  593. },
  594. topyq () {
  595. wx.navigateTo({
  596. url: '/packageUser/pages/user/invite/material/material'
  597. })
  598. },
  599. info(){
  600. var that = this
  601. var url = 'v1/user/info'
  602. var params = {}
  603. var success = function (res) {
  604. that.setData({
  605. userinfo:res.data.wx_user,
  606. showpyq: res.data.wx_user.show_invite_mode
  607. })
  608. }
  609. _request.$get(url, params, success)
  610. },
  611. videoTap:function(e){
  612. var index = e.currentTarget.dataset['index'];
  613. //获取video
  614. this.videoContext = wx.createVideoContext('video'+index);
  615. if(this.data.productsList[index].video_play){
  616. this.videoContext.pause();
  617. this.setData({
  618. ['productsList[' + index + '].video_play']: false
  619. })
  620. }else{
  621. this.videoContext.play();
  622. this.setData({
  623. ['productsList[' + index + '].video_play']: true
  624. })
  625. }
  626. },
  627. tolive:function(e){
  628. // var that = this
  629. // var url = 'v1/live_broad/current'
  630. // var params = {}
  631. // var success = function (res) {
  632. // let roomId = [res.data.room_id] // 填写具体的房间号,可通过下面【获取直播房间列表】 API 获取
  633. // let customParams = encodeURIComponent(JSON.stringify({ path: 'pages/index/index', pid: 1 })) // 开发者在直播间页面路径上携带自定义参数(如示例中的path和pid参数),后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断)
  634. // wx.navigateTo({
  635. // url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}&custom_params=${customParams}`
  636. // })
  637. // }
  638. // _request.$get(url, params, success)
  639. wx.navigateTo({
  640. url: '/pages/livelist/livelist'
  641. })
  642. },
  643. // 滚动事件
  644. onPageScroll(e) {
  645. //滚动距离+屏幕高度换算vw倍数
  646. let listIndex = (e.scrollTop + this.data.screenHeight) / (this.data.screenWidth * 0.63)
  647. this.setData({
  648. listIndex: listIndex
  649. })
  650. }
  651. ,
  652. sortchangenormal(){
  653. this.setData({
  654. products: {
  655. rd: 0,
  656. page: 1,
  657. per_page: 5
  658. },
  659. productsList: [],
  660. price_sort:0,
  661. sale_sort:0
  662. })
  663. this.getList();
  664. },
  665. salesort(){
  666. var type = this.data.sale_sort+1;
  667. if(type>2) type = 0;
  668. this.setData({
  669. products: {
  670. rd: 0,
  671. page: 1,
  672. per_page: 5
  673. },
  674. productsList: [],
  675. sale_sort:type,
  676. })
  677. this.getList();
  678. },
  679. pricesort(e){
  680. var type = this.data.price_sort+1;
  681. if(type>2) type = 0;
  682. this.setData({
  683. products: {
  684. rd: 0,
  685. page: 1,
  686. per_page: 5
  687. },
  688. productsList: [],
  689. price_sort:type,
  690. })
  691. this.getList();
  692. }
  693. })