home.js 14 KB

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