import AuthService from '../../utils/api/testapi'; const app = getApp(); var defaultAvatarUrl = ''; const date = new Date() Page({ data: { progress1: '60%', progress2: '80%', progress3: '90%', progress4: '40%', curTab: 1, isExpand: false, //简介展开和收起 collapseText: '收起', expandText: '查看更多>>', isAreaExpand: false, //投资环境展开和收起 isShowAreaExpand: false, //是否显示投资环境展开收起 years: [], year: date.getFullYear(), tempYear: '', yearValue: [0], showActionsheet: false, motto: 'Hello World', userInfo: { avatarUrl: defaultAvatarUrl, nickName: '', }, hasUserInfo: false, overtop: true, //是否显示收起和展开 canIUseGetUserProfile: wx.canIUse('getUserProfile'), canIUseNicknameComp: wx.canIUse('input.type.nickname'), triggered: false, list: [], isLoading: false, count: 1, hasMore: true, isFixed: false, opacity: 1, activeTab: 0, indicatorWidth: 0, scrollWidth: 0, //滚动视图的总宽度 screenWidth: 0, //屏幕宽度 sliderWidth: 20, //指示器宽度 lastScrollLeft: 0, defaultSliderWidth: 20, //默认指示器宽度 isShowDot: false, //是否显示指示器 testList: [], showPageLoading: true }, onLoad(e) { this.setData({ list: this.data.list, overtop: false }) var temp = [] for (let i = 2010; i < 2041; i++) { temp.push(i) } this.setData({ years: temp }) var _self = this _self.setData({ 'yearValue[0]': _self.data.years.indexOf(_self.data.year) }) //屏幕宽度 var window = wx.getWindowInfo() var screenWidth = window.screenWidth this.setData({ screenWidth: screenWidth - 34 }) setTimeout(() => { var temp = [] for (let i = 0; i < 10; i++) { temp.push(i) } _self.setData({ testList: temp }) _self.countWidth() }, 2000); setTimeout(() => { _self.setData({ showPageLoading: false }) }, 5000); }, //计算滚动框的宽度 countWidth() { var _self = this //计算滑动区域宽度 setTimeout(_ => { const query = wx.createSelectorQuery().in(this) query.selectAll('.superiority-item').boundingClientRect() query.exec(res => { let width = 0 let count = 0 if (res) { res[0].forEach(x => { width += x.width }) count = res[0].length - 1 } //总长度 //剩余宽度 var totalWidth = count * 10 + width _self.setData({ isShowDot: (totalWidth / 343) > 1 }) var surplus = totalWidth - 343 _self.setData({ scrollWidth: surplus }) }) }, 5) }, //监听scroll-view滚动 scrollPlates(e) { var _self = this var offsetLeft = e.detail.scrollLeft var scale = _self.data.scrollWidth / 20 //缩放比例 var offsetX = offsetLeft / scale _self.setData({ sliderWidth: _self.data.defaultSliderWidth + offsetX, lastScrollLeft: offsetLeft }) }, expandClick() { this.setData({ isExpand: !this.data.isExpand }) }, changeTab(e) { this.setData({ curTab: e.currentTarget.dataset.index }) }, showYears() { console.log('点击') this.setData({ showActionsheet: !this.data.showActionsheet }) }, closeSheet() { this.setData({ showActionsheet: !this.data.showActionsheet }) }, //选中日期 confirmSheet() { this.setData({ showActionsheet: !this.data.showActionsheet, year: this.data.tempYear }) }, //投资环境查看更多 areaShowAll() { var _self = this _self.setData({ isAreaExpand: !_self.data.isAreaExpand }) console.log(_self.data.isAreaExpand) }, bindChange(e) { var _self = this var index = e.detail.value[0] _self.setData({ tempYear: _self.data.years[index] }) }, doRefresh() { var _self = this; console.log('刷新中...') setTimeout(() => { var tempList = []; for (var i = 0; i < 30; i++) { tempList.push("ssss") } _self.setData({ list: tempList, hasMore: true, triggered: false }) }, 3000); }, onPageScroll(e) { if (e.scrollTop < 10) { this.setData({ opacity: 1 }) } else { this.setData({ opacity: e.scrollTop / 100 }) } if (e.scrollTop >= 130) { this.setData({ isFixed: true }) } else { this.setData({ isFixed: false }) } }, doLoadMore() { var _self = this; if (_self.data.isLoading || !_self.data.hasMore) { return } console.log('触底了') _self.setData({ isLoading: true }) setTimeout(() => { var tempList = [] for (let i = 0; i < 20; i++) { tempList.push(`新添加==${i}`) } var c = ++_self.data.count console.log(`页面=${c}`) _self.setData({ count: c, hasMore: c < 3 }) _self.setData({ list: _self.data.list.concat(tempList), isLoading: false }) }, 3000); }, bindViewTap() { AuthService.login({ name: '223', pwd: '1234' }) .then(res => { console.log(res) }, err => { console.log(err) }) }, onChooseAvatar(e) { const { avatarUrl } = e.detail const { nickName } = this.data.userInfo this.setData({ "userInfo.avatarUrl": avatarUrl, hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl, }) }, onInputChange(e) { const nickName = e.detail.value const { avatarUrl } = this.data.userInfo this.setData({ "userInfo.nickName": nickName, hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl, }) }, getUserProfile(e) { // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 wx.getUserProfile({ desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { console.log(res) this.setData({ userInfo: res.userInfo, hasUserInfo: true }) } }) }, onTabClick(e) { const index = e.detail.index this.setData({ activeTab: index }) }, onChange(e) { const index = e.detail.index this.setData({ activeTab: index }) }, handleClick(e) { wx.navigateTo({ url: './webview', }) }, //投资机会-全部 showInvest() { wx.navigateTo({ url: '/pages/invest/invest', }) } })