gov_propagandize/pages/index/index.js

301 lines
8.2 KiB
JavaScript
Raw Normal View History

2025-01-02 17:31:12 +08:00
import AuthService from '../../utils/api/testapi';
2025-01-18 17:57:49 +08:00
const app = getApp();
var defaultAvatarUrl = '';
const date = new Date()
2024-12-27 17:08:36 +08:00
Page({
data: {
2025-01-17 18:01:48 +08:00
progress1: '60%',
progress2: '80%',
2025-01-18 17:57:49 +08:00
progress3: '90%',
2025-01-17 18:01:48 +08:00
progress4: '40%',
curTab: 1,
isExpand: false, //简介展开和收起
collapseText: '收起',
expandText: '查看更多>>',
2025-01-18 17:57:49 +08:00
isAreaExpand: false, //投资环境展开和收起
isShowAreaExpand: false, //是否显示投资环境展开收起
years: [],
2025-01-17 18:01:48 +08:00
year: date.getFullYear(),
2025-01-18 17:57:49 +08:00
tempYear: '',
yearValue: [0],
2025-01-17 18:01:48 +08:00
showActionsheet: false,
2024-12-27 17:08:36 +08:00
motto: 'Hello World',
userInfo: {
avatarUrl: defaultAvatarUrl,
nickName: '',
},
hasUserInfo: false,
2025-01-17 18:01:48 +08:00
overtop: true, //是否显示收起和展开
2024-12-27 17:08:36 +08:00
canIUseGetUserProfile: wx.canIUse('getUserProfile'),
canIUseNicknameComp: wx.canIUse('input.type.nickname'),
2025-01-07 16:21:18 +08:00
triggered: false,
list: [],
isLoading: false,
count: 1,
hasMore: true,
isFixed: false,
opacity: 1,
2025-01-18 17:57:49 +08:00
activeTab: 0,
indicatorWidth: 0,
scrollWidth: 0, //滚动视图的总宽度
screenWidth: 0, //屏幕宽度
sliderWidth: 20, //指示器宽度
lastScrollLeft: 0,
defaultSliderWidth: 20, //默认指示器宽度
isShowDot: false, //是否显示指示器
testList: [],
showPageLoading: true
2024-12-27 17:08:36 +08:00
},
2025-01-07 16:21:18 +08:00
onLoad(e) {
this.setData({
2025-01-17 18:01:48 +08:00
list: this.data.list,
overtop: false
})
2025-01-18 17:57:49 +08:00
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
})
2025-01-17 18:01:48 +08:00
},
expandClick() {
this.setData({
isExpand: !this.data.isExpand
})
},
changeTab(e) {
this.setData({
curTab: e.currentTarget.dataset.index
2025-01-07 16:21:18 +08:00
})
},
2025-01-18 17:57:49 +08:00
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]
})
},
2025-01-07 16:21:18 +08:00
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);
2025-01-02 17:31:12 +08:00
},
2025-01-07 16:21:18 +08:00
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);
2025-01-02 17:31:12 +08:00
},
2024-12-27 17:08:36 +08:00
bindViewTap() {
2025-01-02 17:31:12 +08:00
AuthService.login({
name: '223',
pwd: '1234'
})
.then(res => {
console.log(res)
}, err => {
console.log(err)
})
2024-12-27 17:08:36 +08:00
},
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
})
}
})
},
2025-01-07 16:21:18 +08:00
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',
})
2025-01-17 18:01:48 +08:00
},
//投资机会-全部
showInvest() {
wx.navigateTo({
url: '/pages/invest/invest',
})
2025-01-07 16:21:18 +08:00
}
2024-12-27 17:08:36 +08:00
})