var _request = require('../../utils/request.js') var util = require('../../utils/util.js') Page ({ data: { ceshi: 'false', swiper: { indicatorDots: true, autoplay: true, interval: 4000 }, swiperCurrent: 0, firstProject: [], secondProject: [], recommend: { title: 'Microlab/麦博 M200十周年蓝牙版台式电脑音箱 家用音响电脑音箱蓝牙版', price: 3900, url: 'https://img10.360buyimg.com/n7/jfs/t11821/47/132726032/183731/677590e/59e85492N24686ba9.jpg', point: 3999 }, products: { rd: 0, page: 1, per_page: 5 }, productsList: [], bannerList: [], categories: [], vershow: true, percent: [], zhunongList: [], page1: 1, per_page1: 50, balance: 0, bgcolor: '#eee', progress: 0, progress1: 0, // day: '00', hour: '00', min: '00', second: '00', timer: '', leftTime: 0, // msecond: '00', currentTab: util.formatChDate1(new Date()), navScrollLeft: 0, iconslist: [], seckilltimelist: [], today: util.formatChDate1(new Date()), killgoodslist: [], firsttime: '', change: false, clock: '', changeshow: 'seckill', toView: '', is_copartnershow: '', showpyq: 0, todaysend: Date.parse(new Date()) / 1000, showtime: '', projects_more:true, }, onLoad: function () { // this.getzhunongList() this.setData({ vershow: getApp().globalData.vershow, // is_copartnershow: getApp().globalData.is_copartner, }) if (getApp().globalData.wx_id) { this.info() } this.getBanners() this.getCategories() this.getList() //this.getBalanceInfo() // this.showprogress() // this.starttime() wx.getSystemInfo({ success: (res) => { this.setData({ windowWidth: res.windowWidth }) } }) this.geticons() this.getkilltime() }, onShow: function () { // this.getzhunongList() // this.getCategories() const screenWidth = wx.getSystemInfoSync().windowWidth const screenHeight = wx.getSystemInfoSync().windowHeight this.setData({ //获取页面初始状态图片数量,0.63为图片容器的高度值(63vw),将代码中0.63改为你的容器对应高度 listIndex: screenHeight / (screenWidth * 0.50), screenWidth: screenWidth, screenHeight: screenHeight }) }, onPullDownRefresh: function () { this.getBanners() this.getCategories() this.getList() // this.getzhunongList() wx.stopPullDownRefresh() this.geticons() this.getkilltime() }, getList: function () { if (this.data.vershow) { this.getProjects() } else { this.getVersion() } }, swiperChange: function (e) { this.setData({ swiperCurrent: e.detail.current }) }, getVersion: function () { var that = this var url = 'v1/cat/3/products' var params = { page: this.data.products.page, per_page: this.data.products.per_page } var success = function (res) { that.setData({ productsList: res.data.list }) } _request.$get(url, params, success) }, getProjects: function () { var that = this var url = 'v1/products' var params = { rd: this.data.products.rd, page: this.data.products.page, per_page: this.data.products.per_page } var success = function (res) { that.setData({ projects_more: res.data.list_count > that.data.productsList.length, productsList: that.data.productsList.concat(res.data.list || []), }) } _request.$get(url, params, success) }, onReachBottom: function () { if (this.data.projects_more) { var page = this.data.products.page + 1 this.setData({ ['products.page']: page }) this.getProjects() } }, getBanners: function () { var item = 'home' if (!this.data.vershow) { item = 'test' } var that = this var url = 'v1/ad/' + item + '/items' var params = { } var success = function (res) { that.setData({ bannerList: res.data }) } _request.$get(url, params, success) }, toProject: function (val) { var id = val.currentTarget.dataset.val wx.navigateTo({ url: '/pages/projects/project-detail/project-detail?id=' + id }) }, toCustom: function () { wx.reLaunch({ url: '/pages/customservice/customservice' }) }, getCategories: function () { var that = this var url = 'v1/categories?platform=wx_hot' var params = { } var success = function (res) { if (res.data && res.data.wx_hot) { if (res.data.wx_hot.length >= 2) { var list1 = res.data.wx_hot.slice(0,2) that.setData({ firstProject: list1 }) } if (res.data.wx_hot.length >= 6) { var list2 = res.data.wx_hot.slice(2,6) that.setData({ secondProject: list2 }) } } that.setData({ categories: res.data }) } _request.$get(url, params, success) }, onShareAppMessage: function (val) { return _request.share({ title: '欢迎来到FOHOW玖玖', path: '/pages/start/start', imageUrl: 'http://fohow.oss-cn-shenzhen.aliyuncs.com/xcx/share/sharemain.jpg', sc: 'xcx_home', ri: 0, rp: 0 }) }, toColumn: function (val) { var type = val.currentTarget.dataset.val.url_type var url = val.currentTarget.dataset.val.url var id = val.currentTarget.dataset.val.id this.getClick(id) if (type === 0) { wx.navigateTo({ url: url }) } if (type === 1) { wx.navigateTo({ url: '/pages/web/web?id=' + url }) } }, // newyear: function () { // wx.navigateTo({ // url: '/pages/activity/redpacket/redpacket?rid=1' // }) // } toview (val) { var type = val.currentTarget.dataset.val.url_type var url = val.currentTarget.dataset.val.url var id = val.currentTarget.dataset.val.product_cat_index if (type === 0) { if (url === '/pages/projects/projects') { getApp().globalData.isshow = id getApp().globalData.isupdate = false } if (url === '/pages/user/all/all' || url === '/pages/helpfarm/helpfarm' || url === '/pages/projects/projects' || url === '/pages/customservice/customservice') { wx.switchTab({ url: url }) } else { wx.navigateTo({ url: url }) } } if (type === 1) { wx.navigateTo({ url: '/pages/web/web?id=' + url }) } }, getClick (id) { var url = 'v1/ad/' + id + '/click' var params = {} var success = function () { } _request.$get(url, params, success) }, getzhunongList () { var that = this var url = 'v1/projects?state=0,1' var params = { page: this.data.page1, per_page: this.data.per_page1 } var success = function (res) { // var percent = res.data.list.current_funding / res.data.list.min_funding var countArr = [] for (var index in res.data.list) { var count = parseInt(res.data.list[index].current_funding) / parseInt(res.data.list[index].min_funding) *100 // console.log(count) var count1 = (count).toFixed(2) // var count1 = parseInt(count) countArr.push(count1) } that.setData({ zhunongList: res.data.list, percent: countArr }) // that.showprogress() } _request.$get(url, params, success) }, toZhunong (val) { var id1 = val.currentTarget.dataset.val wx.navigateTo({ url: '/pages/helpfarm/helpfarm-detail/helpfarm-detail?id=' + id1 }) }, getBalanceInfo () { var that = this var url = 'v1/user/balance/info' var params = { } var success = function (res) { var result = res.data.total that.setData({ balance: result }) } _request.$get(url, params, success) }, starttime () { var that = this that.setData({ timer: setInterval(function () { // var date = new Date(); // var now = date.getTime(); // var endDate = new Date("2019-01-03 23:14:53");//设置截止时间 // var end = that.data.clock * 1000;//设置截止时间 // var end = endDate.getTime(); // var leftTime = end - now; //时间差 var t = Date.parse(new Date()) t = t / 1000; var leftTime = that.data.clock - t var d, h, m, s, ms; if (leftTime >= 0) { // day = parseInt(ctime / 86400) h = parseInt(leftTime / 3600) m = parseInt(leftTime / 60 ) - parseInt(leftTime / 3600) * 60 s = parseInt(leftTime) - parseInt(leftTime / 60 ) * 60 // d = Math.floor(leftTime / 1000 / 60 / 60 / 24); // h = Math.floor(leftTime / 1000 / 60 / 60 % 24); // m = Math.floor(leftTime / 1000 / 60 % 60); // s = Math.floor(leftTime / 1000 % 60); // ms = Math.floor(leftTime % 1000); // ms = ms < 100 ? "0" + ms : ms s = s < 10 ? "0" + s : s m = m < 10 ? "0" + m : m h = h < 10 ? "0" + h : h that.setData({ hour: h, min: m, second: s, // msecond: ms, leftTime: leftTime }) } if (leftTime < 0) { clearInterval(that.data.timer); that.setData({ leftTime: 0, hour: '00', min: '00', second: '00', // msecond: '00' }) } },100), }); }, switchtime (e) { var cur = e.currentTarget.dataset.current var idx = e.currentTarget.dataset.val var killtime = e.currentTarget.dataset.time var nowtime = util.formatTime(new Date(e.currentTarget.dataset.showtime * 1000)) var singleNavWidth = this.data.windowWidth / 5 this.setData({ navScrollLeft: (idx - 2) * singleNavWidth }) if (this.data.currentTab == idx || this.data.today == killtime) { return false } this.setData ({ currentTab: idx, today: killtime, firsttime: killtime, change: true, changeshow: cur, showtime: nowtime.substring(11,13) }) this.getkillgoods() }, geticons () { var that = this var url = 'v1/navigate/icons' var params = {} var success = function (res) { var icons = res.data that.setData({ iconslist: icons }) } _request.$get(url, params, success) }, getkilltime () { var that = this var url = 'v1/seckill/dates' var params = { cache: false } var success = function (res) { var seclist = res.data.ret_item_list var singleNavWidth = that.data.windowWidth / 5 for (var index in seclist) { if (seclist[index].state == 'seckill') { that.setData({ firsttime: seclist[index].date_format, clock: seclist[index].end_time, // navScrollLeft: singleNavWidth, toView: 'a' + seclist[index].date_format, changeshow: 'seckill' }) } if (seclist[index].state == 'end' && seclist[index].date_format == that.data.currentTab) { that.setData({ toView: 'a' + seclist[index].date_format, changeshow: 'end' }) } if (seclist[index].state == 'preparing' && seclist[index].date_format == that.data.currentTab) { var nowtime = util.formatTime(new Date(seclist[index].start_time * 1000)) that.setData({ toView: 'a' + seclist[index].date_format, changeshow: 'preparing', showtime: nowtime.substring(11,13), }) } if (seclist[index].state == 'none' && seclist[index].date_format == that.data.currentTab) { that.setData({ toView: 'a' + seclist[index].date_format, changeshow: 'none' }) } } that.setData({ seckilltimelist: seclist, }) that.getkillgoods() that.starttime() } _request.$get(url, params, success) }, getkillgoods () { var that = this var url = 'v1/seckill/products' var params = { query_date: that.data.firsttime, cache: false } var success = function (res) { // if (res.data.product_list.length > 0) { var killgoodslist = res.data.product_list that.setData({ killgoodslist: killgoodslist, }) // } } _request.$get(url, params, success) }, toabout () { // var host = getApp().globalData.d5c // if (host === 'tfhwx.hiwavo.com') { // wx.navigateTo({ // url: '/pages/parse/parse?id=2' // }) // } else if (host === 'fhwx.hiwavo.com') { wx.navigateTo({ url: '/pages/parse/parse?id=1' }) // } }, topyq () { wx.navigateTo({ url: '/packageUser/pages/user/invite/material/material' }) }, info(){ var that = this var url = 'v1/user/info' var params = {} var success = function (res) { that.setData({ showpyq: res.data.wx_user.show_invite_mode }) } _request.$get(url, params, success) }, videoTap:function(e){ var index = e.currentTarget.dataset['index']; //获取video this.videoContext = wx.createVideoContext('video'+index); if(this.data.productsList[index].video_play){ this.videoContext.pause(); this.setData({ ['productsList[' + index + '].video_play']: false }) }else{ this.videoContext.play(); this.setData({ ['productsList[' + index + '].video_play']: true }) } }, // 滚动事件 onPageScroll(e) { //滚动距离+屏幕高度换算vw倍数 let listIndex = (e.scrollTop + this.data.screenHeight) / (this.data.screenWidth * 0.63) this.setData({ listIndex: listIndex }) } })