| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668 |
- 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,
- userinfo:{},
- nowseckill_data:'',
-
- statusBarHeight:20,
- navBarHeight:45,
- windowWidth:375,
- word:''
- },
- 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.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()
- },
- 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].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
- }
- 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) {
- // 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'
- // })
- // }
- // }
-
- 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({
- 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
- })
- }
- })
|