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: '', 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, userinfo:{}, info:{}, nowseckill_data:'', statusBarHeight:0,//20 navBarHeight:45, windowWidth:375, word:'', price_sort:0, sale_sort:0, zones:[], currentZones:0 }, onLoad: function () { const info = wx.getSystemInfoSync(); console.log('info',info); // this.setData({ // statusBarHeight:info.statusBarHeight // }) // this.getzhunongList() this.setData({ vershow: getApp().globalData.vershow, // is_copartnershow: getApp().globalData.is_copartner, }) if (getApp().globalData.wx_id) { this.info() } this.getZones() this.getData() 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() }, getZones:function(){ var that = this var url = 'v1/zones' var params = {} var success = function (res) { that.setData({ zones: res.data }) } _request.$get(url, params, success) }, getList: function () { if (this.data.vershow) { this.getProjects() } else { this.getVersion() } }, swiperChange: function (e) { this.setData({ swiperCurrent: e.detail.current }) }, getData: function () { var that = this var url = 'v1/product/commend_words' var params = {} var success = function (res) { console.log('res',res.data.list); that.setData({ word:res.data.list[0]?res.data.list[0].title:'' }) } _request.$get(url, params, success) }, 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, price_sort:this.data.price_sort, sale_sort:this.data.sale_sort, sale_zone: this.data.currentZones } 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 }) }, tosearch: function (val) { var id = val.currentTarget.dataset.val; wx.navigateTo({ url: '/pages/search/search' }) }, 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: '欢迎来到凤凰菁选商城', 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 }) } if(type === 2){ wx.reLaunch({ url: url }) } }, // newyear: function () { // wx.navigateTo({ // url: '/pages/activity/redpacket/redpacket?rid=1' // }) // } toviewfunc (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 { if(id == 0){ wx.navigateTo({ url: url }) }else{ wx.reLaunch({ url: url+id }) } } } 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; if(that.data.nowseckill_data['state'] == 'seckill'){ leftTime = that.data.clock - t }else if(that.data.nowseckill_data['state'] == 'preparing'){ leftTime = that.data.nowseckill_data['start_time'] - t } var d, h, m, s, ms; if (leftTime >= 0) { let day = parseInt(leftTime / 86400) h = parseInt(leftTime / 3600 / 24) 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({ day:day, 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', day:'' // 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?source=xcx' 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' // }) // } // } var nsdata; for (var index in seclist) { if (seclist[index].state == 'seckill') { nsdata = seclist[index]; var showtime = util.formatTime(new Date(nsdata['start_time']* 1000)); nsdata['showtime'] = showtime.substring(11,13); nsdata['clock'] = seclist[index].end_time; break; }else if (seclist[index].state == 'preparing') { nsdata = seclist[index]; var showtime = util.formatTime(new Date(nsdata['start_time'] * 1000)); nsdata['showtime'] = showtime.substring(11,13) break; } } console.log('nsdata',nsdata); that.setData({ seckilltimelist: seclist, clock:nsdata ? nsdata['clock'] : 0, nowseckill_data:nsdata }) if(nsdata){ that.getkillgoods() that.starttime() } } _request.$get(url, params, success) }, getkillgoods () { var that = this var url = 'v1/seckill/products' var params = { query_date: that.data.nowseckill_data ? that.data.nowseckill_data['date_format'] : '', 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' }) // } }, tofhvd () { wx.navigateTo({ url: '/pages/parse/parse?id=2' }) }, toyszq () { wx.reLaunch({ url: '/pages/projects/projects?currentTab=4' }) }, togrhl () { wx.reLaunch({ url: '/pages/projects/projects?currentTab=2' }) }, tojjry () { wx.reLaunch({ url: '/pages/projects/projects?currentTab=3' }) }, toygyp () { wx.reLaunch({ url: '/pages/projects/projects?currentTab=5' }) }, tothzq () { wx.reLaunch({ url: '/pages/projects/projects?currentTab=1' }) }, todz () { if(this.data.userinfo.rank < 2){ wx.navigateTo({ url: '/packageUser/pages/user/applyLeader/applyLeader' }) }else{ wx.navigateTo({ url: '/pages/areacart/areacart' }) } }, tocentcart () { wx.navigateTo({ url: '/pages/centcart/centcart' }) }, 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({ info:res.data, userinfo:res.data.wx_user, 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 }) } }, tolive:function(e){ // var that = this // var url = 'v1/live_broad/current' // var params = {} // var success = function (res) { // let roomId = [res.data.room_id] // 填写具体的房间号,可通过下面【获取直播房间列表】 API 获取 // let customParams = encodeURIComponent(JSON.stringify({ path: 'pages/index/index', pid: 1 })) // 开发者在直播间页面路径上携带自定义参数(如示例中的path和pid参数),后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断) // wx.navigateTo({ // url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}&custom_params=${customParams}` // }) // } // _request.$get(url, params, success) wx.navigateTo({ url: '/pages/livelist/livelist' }) }, // 滚动事件 onPageScroll(e) { //滚动距离+屏幕高度换算vw倍数 let listIndex = (e.scrollTop + this.data.screenHeight) / (this.data.screenWidth * 0.63) this.setData({ listIndex: listIndex }) } , sortchangenormal(){ this.setData({ products: { rd: 0, page: 1, per_page: 5 }, productsList: [], price_sort:0, sale_sort:0 }) this.getList(); }, salesort(){ var type = this.data.sale_sort+1; if(type>2) type = 0; this.setData({ products: { rd: 0, page: 1, per_page: 5 }, productsList: [], sale_sort:type, }) this.getList(); }, pricesort(e){ var type = this.data.price_sort+1; if(type>2) type = 0; this.setData({ products: { rd: 0, page: 1, per_page: 5 }, productsList: [], price_sort:type, }) this.getList(); }, selectzones(e){ var cur = e.currentTarget.dataset.id; if (this.data.currentZones == cur) { return false } else { this.setData({ currentZones: cur, products: { rd: 0, page: 1, per_page: 5 }, productsList: [] }) this.getList() } } })