home.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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. },
  62. onLoad: function () {
  63. // this.getzhunongList()
  64. this.setData({
  65. vershow: getApp().globalData.vershow,
  66. // is_copartnershow: getApp().globalData.is_copartner,
  67. })
  68. if (getApp().globalData.wx_id) {
  69. this.info()
  70. }
  71. this.getBanners()
  72. this.getCategories()
  73. this.getList()
  74. //this.getBalanceInfo()
  75. // this.showprogress()
  76. // this.starttime()
  77. wx.getSystemInfo({
  78. success: (res) => {
  79. this.setData({
  80. windowWidth: res.windowWidth
  81. })
  82. }
  83. })
  84. this.geticons()
  85. this.getkilltime()
  86. },
  87. onShow: function () {
  88. // this.getzhunongList()
  89. // this.getCategories()
  90. const screenWidth = wx.getSystemInfoSync().windowWidth
  91. const screenHeight = wx.getSystemInfoSync().windowHeight
  92. this.setData({
  93. //获取页面初始状态图片数量,0.63为图片容器的高度值(63vw),将代码中0.63改为你的容器对应高度
  94. listIndex: screenHeight / (screenWidth * 0.50),
  95. screenWidth: screenWidth,
  96. screenHeight: screenHeight
  97. })
  98. },
  99. onPullDownRefresh: function () {
  100. this.getBanners()
  101. this.getCategories()
  102. this.getList()
  103. // this.getzhunongList()
  104. wx.stopPullDownRefresh()
  105. this.geticons()
  106. this.getkilltime()
  107. },
  108. getList: function () {
  109. if (this.data.vershow) {
  110. this.getProjects()
  111. } else {
  112. this.getVersion()
  113. }
  114. },
  115. swiperChange: function (e) {
  116. this.setData({
  117. swiperCurrent: e.detail.current
  118. })
  119. },
  120. getVersion: function () {
  121. var that = this
  122. var url = 'v1/cat/3/products'
  123. var params = {
  124. page: this.data.products.page,
  125. per_page: this.data.products.per_page
  126. }
  127. var success = function (res) {
  128. that.setData({
  129. productsList: res.data.list
  130. })
  131. }
  132. _request.$get(url, params, success)
  133. },
  134. getProjects: function () {
  135. var that = this
  136. var url = 'v1/products'
  137. var params = {
  138. rd: this.data.products.rd,
  139. page: this.data.products.page,
  140. per_page: this.data.products.per_page
  141. }
  142. var success = function (res) {
  143. that.setData({
  144. projects_more: res.data.list_count > that.data.productsList.length,
  145. productsList: that.data.productsList.concat(res.data.list || []),
  146. })
  147. }
  148. _request.$get(url, params, success)
  149. },
  150. onReachBottom: function () {
  151. if (this.data.projects_more) {
  152. var page = this.data.products.page + 1
  153. this.setData({
  154. ['products.page']: page
  155. })
  156. this.getProjects()
  157. }
  158. },
  159. getBanners: function () {
  160. var item = 'home'
  161. if (!this.data.vershow) {
  162. item = 'test'
  163. }
  164. var that = this
  165. var url = 'v1/ad/' + item + '/items'
  166. var params = {
  167. }
  168. var success = function (res) {
  169. that.setData({
  170. bannerList: res.data
  171. })
  172. }
  173. _request.$get(url, params, success)
  174. },
  175. toProject: function (val) {
  176. var id = val.currentTarget.dataset.val
  177. wx.navigateTo({
  178. url: '/pages/projects/project-detail/project-detail?id=' + id
  179. })
  180. },
  181. toCustom: function () {
  182. wx.reLaunch({
  183. url: '/pages/customservice/customservice'
  184. })
  185. },
  186. getCategories: function () {
  187. var that = this
  188. var url = 'v1/categories?platform=wx_hot'
  189. var params = {
  190. }
  191. var success = function (res) {
  192. if (res.data && res.data.wx_hot) {
  193. if (res.data.wx_hot.length >= 2) {
  194. var list1 = res.data.wx_hot.slice(0,2)
  195. that.setData({
  196. firstProject: list1
  197. })
  198. }
  199. if (res.data.wx_hot.length >= 6) {
  200. var list2 = res.data.wx_hot.slice(2,6)
  201. that.setData({
  202. secondProject: list2
  203. })
  204. }
  205. }
  206. that.setData({
  207. categories: res.data
  208. })
  209. }
  210. _request.$get(url, params, success)
  211. },
  212. onShareAppMessage: function (val) {
  213. return _request.share({
  214. title: '欢迎来到FOHOW玖玖',
  215. path: '/pages/start/start',
  216. imageUrl: 'http://fohow.oss-cn-shenzhen.aliyuncs.com/xcx/share/sharemain.jpg',
  217. sc: 'xcx_home',
  218. ri: 0,
  219. rp: 0
  220. })
  221. },
  222. toColumn: function (val) {
  223. var type = val.currentTarget.dataset.val.url_type
  224. var url = val.currentTarget.dataset.val.url
  225. var id = val.currentTarget.dataset.val.id
  226. this.getClick(id)
  227. if (type === 0) {
  228. wx.navigateTo({
  229. url: url
  230. })
  231. }
  232. if (type === 1) {
  233. wx.navigateTo({
  234. url: '/pages/web/web?id=' + url
  235. })
  236. }
  237. },
  238. // newyear: function () {
  239. // wx.navigateTo({
  240. // url: '/pages/activity/redpacket/redpacket?rid=1'
  241. // })
  242. // }
  243. toview (val) {
  244. var type = val.currentTarget.dataset.val.url_type
  245. var url = val.currentTarget.dataset.val.url
  246. var id = val.currentTarget.dataset.val.product_cat_index
  247. if (type === 0) {
  248. if (url === '/pages/projects/projects') {
  249. getApp().globalData.isshow = id
  250. getApp().globalData.isupdate = false
  251. }
  252. if (url === '/pages/user/all/all' || url === '/pages/helpfarm/helpfarm' || url === '/pages/projects/projects' || url === '/pages/customservice/customservice') {
  253. wx.switchTab({
  254. url: url
  255. })
  256. } else {
  257. wx.navigateTo({
  258. url: url
  259. })
  260. }
  261. }
  262. if (type === 1) {
  263. wx.navigateTo({
  264. url: '/pages/web/web?id=' + url
  265. })
  266. }
  267. },
  268. getClick (id) {
  269. var url = 'v1/ad/' + id + '/click'
  270. var params = {}
  271. var success = function () {
  272. }
  273. _request.$get(url, params, success)
  274. },
  275. getzhunongList () {
  276. var that = this
  277. var url = 'v1/projects?state=0,1'
  278. var params = {
  279. page: this.data.page1,
  280. per_page: this.data.per_page1
  281. }
  282. var success = function (res) {
  283. // var percent = res.data.list.current_funding / res.data.list.min_funding
  284. var countArr = []
  285. for (var index in res.data.list) {
  286. var count = parseInt(res.data.list[index].current_funding) / parseInt(res.data.list[index].min_funding) *100
  287. // console.log(count)
  288. var count1 = (count).toFixed(2)
  289. // var count1 = parseInt(count)
  290. countArr.push(count1)
  291. }
  292. that.setData({
  293. zhunongList: res.data.list,
  294. percent: countArr
  295. })
  296. // that.showprogress()
  297. }
  298. _request.$get(url, params, success)
  299. },
  300. toZhunong (val) {
  301. var id1 = val.currentTarget.dataset.val
  302. wx.navigateTo({
  303. url: '/pages/helpfarm/helpfarm-detail/helpfarm-detail?id=' + id1
  304. })
  305. },
  306. getBalanceInfo () {
  307. var that = this
  308. var url = 'v1/user/balance/info'
  309. var params = {
  310. }
  311. var success = function (res) {
  312. var result = res.data.total
  313. that.setData({
  314. balance: result
  315. })
  316. }
  317. _request.$get(url, params, success)
  318. },
  319. starttime () {
  320. var that = this
  321. that.setData({
  322. timer: setInterval(function () {
  323. // var date = new Date();
  324. // var now = date.getTime();
  325. // var endDate = new Date("2019-01-03 23:14:53");//设置截止时间
  326. // var end = that.data.clock * 1000;//设置截止时间
  327. // var end = endDate.getTime();
  328. // var leftTime = end - now; //时间差
  329. var t = Date.parse(new Date())
  330. t = t / 1000;
  331. var leftTime = that.data.clock - t
  332. var d, h, m, s, ms;
  333. if (leftTime >= 0) {
  334. // day = parseInt(ctime / 86400)
  335. h = parseInt(leftTime / 3600)
  336. m = parseInt(leftTime / 60 ) - parseInt(leftTime / 3600) * 60
  337. s = parseInt(leftTime) - parseInt(leftTime / 60 ) * 60
  338. // d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
  339. // h = Math.floor(leftTime / 1000 / 60 / 60 % 24);
  340. // m = Math.floor(leftTime / 1000 / 60 % 60);
  341. // s = Math.floor(leftTime / 1000 % 60);
  342. // ms = Math.floor(leftTime % 1000);
  343. // ms = ms < 100 ? "0" + ms : ms
  344. s = s < 10 ? "0" + s : s
  345. m = m < 10 ? "0" + m : m
  346. h = h < 10 ? "0" + h : h
  347. that.setData({
  348. hour: h,
  349. min: m,
  350. second: s,
  351. // msecond: ms,
  352. leftTime: leftTime
  353. })
  354. }
  355. if (leftTime < 0) {
  356. clearInterval(that.data.timer);
  357. that.setData({
  358. leftTime: 0,
  359. hour: '00',
  360. min: '00',
  361. second: '00',
  362. // msecond: '00'
  363. })
  364. }
  365. },100),
  366. });
  367. },
  368. switchtime (e) {
  369. var cur = e.currentTarget.dataset.current
  370. var idx = e.currentTarget.dataset.val
  371. var killtime = e.currentTarget.dataset.time
  372. var nowtime = util.formatTime(new Date(e.currentTarget.dataset.showtime * 1000))
  373. var singleNavWidth = this.data.windowWidth / 5
  374. this.setData({
  375. navScrollLeft: (idx - 2) * singleNavWidth
  376. })
  377. if (this.data.currentTab == idx || this.data.today == killtime) {
  378. return false
  379. }
  380. this.setData ({
  381. currentTab: idx,
  382. today: killtime,
  383. firsttime: killtime,
  384. change: true,
  385. changeshow: cur,
  386. showtime: nowtime.substring(11,13)
  387. })
  388. this.getkillgoods()
  389. },
  390. geticons () {
  391. var that = this
  392. var url = 'v1/navigate/icons'
  393. var params = {}
  394. var success = function (res) {
  395. var icons = res.data
  396. that.setData({
  397. iconslist: icons
  398. })
  399. }
  400. _request.$get(url, params, success)
  401. },
  402. getkilltime () {
  403. var that = this
  404. var url = 'v1/seckill/dates'
  405. var params = {
  406. cache: false
  407. }
  408. var success = function (res) {
  409. var seclist = res.data.ret_item_list
  410. var singleNavWidth = that.data.windowWidth / 5
  411. for (var index in seclist) {
  412. if (seclist[index].state == 'seckill') {
  413. that.setData({
  414. firsttime: seclist[index].date_format,
  415. clock: seclist[index].end_time,
  416. // navScrollLeft: singleNavWidth,
  417. toView: 'a' + seclist[index].date_format,
  418. changeshow: 'seckill'
  419. })
  420. }
  421. if (seclist[index].state == 'end' && seclist[index].date_format == that.data.currentTab) {
  422. that.setData({
  423. toView: 'a' + seclist[index].date_format,
  424. changeshow: 'end'
  425. })
  426. }
  427. if (seclist[index].state == 'preparing' && seclist[index].date_format == that.data.currentTab) {
  428. var nowtime = util.formatTime(new Date(seclist[index].start_time * 1000))
  429. that.setData({
  430. toView: 'a' + seclist[index].date_format,
  431. changeshow: 'preparing',
  432. showtime: nowtime.substring(11,13),
  433. })
  434. }
  435. if (seclist[index].state == 'none' && seclist[index].date_format == that.data.currentTab) {
  436. that.setData({
  437. toView: 'a' + seclist[index].date_format,
  438. changeshow: 'none'
  439. })
  440. }
  441. }
  442. that.setData({
  443. seckilltimelist: seclist,
  444. })
  445. that.getkillgoods()
  446. that.starttime()
  447. }
  448. _request.$get(url, params, success)
  449. },
  450. getkillgoods () {
  451. var that = this
  452. var url = 'v1/seckill/products'
  453. var params = {
  454. query_date: that.data.firsttime,
  455. cache: false
  456. }
  457. var success = function (res) {
  458. // if (res.data.product_list.length > 0) {
  459. var killgoodslist = res.data.product_list
  460. that.setData({
  461. killgoodslist: killgoodslist,
  462. })
  463. // }
  464. }
  465. _request.$get(url, params, success)
  466. },
  467. toabout () {
  468. // var host = getApp().globalData.d5c
  469. // if (host === 'tfhwx.hiwavo.com') {
  470. // wx.navigateTo({
  471. // url: '/pages/parse/parse?id=2'
  472. // })
  473. // } else if (host === 'fhwx.hiwavo.com') {
  474. wx.navigateTo({
  475. url: '/pages/parse/parse?id=1'
  476. })
  477. // }
  478. },
  479. todz () {
  480. if(this.data.userinfo.rank < 2){
  481. wx.navigateTo({
  482. url: '/packageUser/pages/user/applyLeader/applyLeader'
  483. })
  484. }else{
  485. wx.navigateTo({
  486. url: '/pages/areacart/areacart'
  487. })
  488. }
  489. },
  490. tocentcart () {
  491. wx.navigateTo({
  492. url: '/pages/centcart/centcart'
  493. })
  494. },
  495. topyq () {
  496. wx.navigateTo({
  497. url: '/packageUser/pages/user/invite/material/material'
  498. })
  499. },
  500. info(){
  501. var that = this
  502. var url = 'v1/user/info'
  503. var params = {}
  504. var success = function (res) {
  505. that.setData({
  506. userinfo:res.data.wx_user,
  507. showpyq: res.data.wx_user.show_invite_mode
  508. })
  509. }
  510. _request.$get(url, params, success)
  511. },
  512. videoTap:function(e){
  513. var index = e.currentTarget.dataset['index'];
  514. //获取video
  515. this.videoContext = wx.createVideoContext('video'+index);
  516. if(this.data.productsList[index].video_play){
  517. this.videoContext.pause();
  518. this.setData({
  519. ['productsList[' + index + '].video_play']: false
  520. })
  521. }else{
  522. this.videoContext.play();
  523. this.setData({
  524. ['productsList[' + index + '].video_play']: true
  525. })
  526. }
  527. },
  528. // 滚动事件
  529. onPageScroll(e) {
  530. //滚动距离+屏幕高度换算vw倍数
  531. let listIndex = (e.scrollTop + this.data.screenHeight) / (this.data.screenWidth * 0.63)
  532. this.setData({
  533. listIndex: listIndex
  534. })
  535. }
  536. })