gov_propagandize/pages/index/index.js

398 lines
11 KiB
JavaScript
Raw Normal View History

2025-01-19 17:56:22 +08:00
import IndexService from '../../utils/api/indexApi';
import utils from '../../utils/util';
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
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,
2025-01-07 16:21:18 +08:00
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: [],
2025-01-19 17:56:22 +08:00
showPageLoading: true,
descVideoUrl: '',
descVideoCover: '',
descContent: "",
statisticsList: [], //数据统计
investList: [], //投资机会
investAreaId: "b4945b87-fe05-4af3-8453-65451b3137a3", //投资环境
investAreaBean: null,
imgBasePath: app.globalData.imgPath,
superiorityList: [], //投资优势,
investAreaList: [], //投资环境List
2025-02-07 16:29:25 +08:00
investLoading: 'loading',
2025-01-21 12:33:11 +08:00
isLoading: true,
2025-02-07 16:29:25 +08:00
showInvestLoading: 'loading',
2025-02-08 17:25:58 +08:00
superiorityLoading: 'loading',
statisticsLoading: 'loading'
2024-12-27 17:08:36 +08:00
},
2025-01-07 16:21:18 +08:00
onLoad(e) {
2025-01-19 17:56:22 +08:00
var _self = this
2025-01-18 17:57:49 +08:00
var temp = []
2025-01-19 17:56:22 +08:00
for (let i = 2010; i <= _self.data.year; i++) {
2025-01-18 17:57:49 +08:00
temp.push(i)
}
2025-01-19 17:56:22 +08:00
_self.setData({
years: temp.reverse()
2025-01-18 17:57:49 +08:00
})
_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(() => {
_self.setData({
showPageLoading: false
})
2025-01-20 17:19:30 +08:00
}, 1000);
2025-01-19 17:56:22 +08:00
//获取简介
this.getDescVideo()
//介绍
this.getDesc()
//数据统计
this.getStatistics()
//投资机会
this.getInvest()
//默认获取地区概况
this.getInvestAreaCategory()
//投资环境
this.getSuperiority()
},
2025-01-21 12:33:11 +08:00
onReady() {
this.videoContext = wx.createVideoContext('descVideo', this); // 创建videoContext实例
},
onShow() {
if (this.videoContext) {
this.videoContext.pause()
}
},
2025-01-19 17:56:22 +08:00
//视频介绍
getDescVideo() {
var _self = this
IndexService.doGetDescVideo()
.then(res => {
_self.setData({
descVideoUrl: _self.data.imgBasePath + res.rows[0].fileList[0].contentFileFileId,
descVideoCover: _self.data.imgBasePath + res.rows[0].fileList[0].contentFileCoverId
})
}, err => {
wx.showToast({
2025-01-20 17:19:30 +08:00
icon: "none",
2025-01-19 17:56:22 +08:00
title: '网络错误(video)',
})
})
},
//简介
getDesc() {
var _self = this
IndexService.doGetDescInfo()
.then(res => {
if (res) {
_self.setData({
descContent: res.rows[0].newsContentContent
})
}
}, err => {
console.log(err)
wx.showToast({
2025-01-20 17:19:30 +08:00
icon: "none",
2025-01-19 17:56:22 +08:00
title: '网络错误(简介)',
})
})
},
//数据统计
getStatistics() {
var _self = this
2025-02-08 17:25:58 +08:00
_self.setData({
statisticsLoading: 'loading'
})
2025-01-19 17:56:22 +08:00
IndexService.doGetStatistics({
year: _self.data.year
})
.then(res => {
2025-02-08 17:25:58 +08:00
_self.setData({
statisticsLoading: 'success'
})
2025-01-19 17:56:22 +08:00
if (res) {
res.forEach(item => {
var scale = item.value > 100 ? 100 : 1
item.progress = `${item.value}%`
item.color = utils.randomLight()
item.fontColor = utils.randomDark()
});
_self.setData({
statisticsList: res
})
}
}, err => {
2025-02-08 17:25:58 +08:00
_self.setData({
statisticsLoading: 'error'
})
2025-01-19 17:56:22 +08:00
wx.showToast({
2025-01-20 17:19:30 +08:00
icon: "none",
2025-01-19 17:56:22 +08:00
title: '网络错误(数据统计)',
})
})
},
//投资机会
getInvest() {
var _self = this
2025-01-21 12:33:11 +08:00
_self.setData({
2025-02-07 16:29:25 +08:00
showInvestLoading: 'loading'
2025-01-21 12:33:11 +08:00
})
2025-01-19 17:56:22 +08:00
IndexService.doGetInvest()
.then(res => {
2025-01-21 12:33:11 +08:00
_self.setData({
2025-02-07 16:29:25 +08:00
showInvestLoading: 'success'
2025-01-21 12:33:11 +08:00
})
2025-01-19 17:56:22 +08:00
if (res) {
_self.setData({
investList: res
})
}
}, err => {
2025-02-07 16:29:25 +08:00
_self.setData({
showInvestLoading: 'error'
})
2025-01-19 17:56:22 +08:00
wx.showToast({
2025-01-20 17:19:30 +08:00
icon: "none",
2025-01-19 17:56:22 +08:00
title: '网络错误(投资机会)',
})
})
},
2025-01-20 17:19:30 +08:00
goInvestDetail(e) {
var id = e.currentTarget.dataset.id
wx.navigateTo({
url: '/pages/invest-detail/invest-detail?id=' + id,
})
},
//投资环境详情
2025-01-19 17:56:22 +08:00
getInvestArea(id) {
var _self = this
2025-01-21 12:33:11 +08:00
_self.setData({
2025-02-07 16:29:25 +08:00
investLoading: 'loading'
2025-01-21 12:33:11 +08:00
})
2025-01-19 17:56:22 +08:00
IndexService.doGetInvestArea({
newsDirectoriesId: id
})
.then(res => {
2025-02-07 16:29:25 +08:00
console.log('投资环境成功')
2025-01-21 12:33:11 +08:00
_self.setData({
2025-02-07 16:29:25 +08:00
investLoading: 'success'
2025-01-21 12:33:11 +08:00
})
2025-01-19 17:56:22 +08:00
if (res) {
_self.setData({
investAreaBean: res.rows[0]
})
}
}, err => {
2025-02-07 16:29:25 +08:00
console.log('投资环境错误')
_self.setData({
investLoading: 'error'
})
2025-01-19 17:56:22 +08:00
wx.showToast({
2025-01-20 17:19:30 +08:00
icon: "none",
2025-01-19 17:56:22 +08:00
title: '网络错误(InvestArea)',
})
})
},
2025-01-20 17:19:30 +08:00
//投资优势
2025-01-19 17:56:22 +08:00
getSuperiority() {
var _self = this
2025-02-07 16:29:25 +08:00
_self.setData({
superiorityLoading: 'loading'
})
2025-01-19 17:56:22 +08:00
IndexService.doGetSuperiorityList()
.then(res => {
2025-02-07 16:29:25 +08:00
_self.setData({
superiorityLoading: 'success'
})
2025-01-19 17:56:22 +08:00
if (res) {
_self.setData({
superiorityList: res
})
}
2025-01-20 17:19:30 +08:00
_self.countWidth()
2025-01-19 17:56:22 +08:00
}, err => {
2025-02-07 16:29:25 +08:00
_self.setData({
superiorityLoading: 'error'
})
2025-01-19 17:56:22 +08:00
wx.showToast({
2025-01-20 17:19:30 +08:00
icon: "none",
2025-01-19 17:56:22 +08:00
title: '网络错误(superiority)',
})
})
},
2025-01-20 17:19:30 +08:00
//投资优势详情
goSuperiorityDetail(e) {
wx.navigateTo({
url: '/pages/superiority-detail/superiority-detail?id=' + e.currentTarget.dataset.id,
})
},
2025-01-19 17:56:22 +08:00
//获取投资环境分类
getInvestAreaCategory() {
var _self = this
2025-02-07 16:29:25 +08:00
_self.setData({
investLoading: 'loading'
})
2025-01-19 17:56:22 +08:00
IndexService.doGetInvestAreaCategory()
.then(res => {
if (res) {
_self.setData({
investAreaList: res
})
_self.getInvestArea(_self.data.investAreaId)
}
}, err => {
2025-02-07 16:29:25 +08:00
_self.setData({
investLoading: 'error'
})
2025-01-19 17:56:22 +08:00
wx.showToast({
2025-01-20 17:19:30 +08:00
icon: "none",
2025-01-19 17:56:22 +08:00
title: '网络错误(InvestCategory)',
})
})
2025-01-18 17:57:49 +08:00
},
//计算滚动框的宽度
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
},
2025-01-19 17:56:22 +08:00
//展开或收起简介
2025-01-17 18:01:48 +08:00
expandClick() {
this.setData({
isExpand: !this.data.isExpand
})
},
changeTab(e) {
this.setData({
2025-01-19 17:56:22 +08:00
investAreaId: e.currentTarget.dataset.id
2025-01-07 16:21:18 +08:00
})
2025-01-19 17:56:22 +08:00
this.getInvestArea(this.data.investAreaId)
2025-01-07 16:21:18 +08:00
},
2025-01-18 17:57:49 +08:00
showYears() {
this.setData({
showActionsheet: !this.data.showActionsheet
})
},
closeSheet() {
this.setData({
showActionsheet: !this.data.showActionsheet
})
},
//选中日期
confirmSheet() {
this.setData({
showActionsheet: !this.data.showActionsheet,
year: this.data.tempYear
})
2025-01-19 17:56:22 +08:00
this.getStatistics()
2025-01-18 17:57:49 +08:00
},
//投资环境查看更多
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-17 18:01:48 +08:00
//投资机会-全部
showInvest() {
wx.navigateTo({
url: '/pages/invest/invest',
})
2025-01-19 17:56:22 +08:00
},
2025-01-20 17:19:30 +08:00
onPullDownRefresh() {
var _self = this
_self.setData({
showPageLoading: true
})
setTimeout(() => {
wx.stopPullDownRefresh()
_self.setData({
showPageLoading: false
})
}, 2000);
//获取简介
_self.getDescVideo()
//介绍
_self.getDesc()
//数据统计
_self.getStatistics()
//投资机会
_self.getInvest()
//默认获取地区概况
_self.getInvestAreaCategory()
//投资环境
_self.getSuperiority()
}
2024-12-27 17:08:36 +08:00
})