You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
296 lines
9.8 KiB
296 lines
9.8 KiB
// pages/stock/index.js
|
|
const request = require('../../../utils/request') //导入模块
|
|
const util = require('../../../utils/util')
|
|
const storage = require('../../../utils/storage')
|
|
const math = require('../../../utils/math')
|
|
const event = require('../../../utils/event.js')
|
|
var wxCharts = require('../../../utils/wxcharts.js')
|
|
const app = getApp()
|
|
var lineChart = null
|
|
const colors = ['#FF4229', '#FFAD2A', '#297BFF', '#29FF46', '#AD29FF']
|
|
|
|
Component({
|
|
options: {
|
|
addGlobalClass: true,
|
|
multipleSlots: true
|
|
},
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
height: app.globalData.safeFragmentHeight - 190,
|
|
chartList: null,
|
|
momentList: [],
|
|
requesting: false,
|
|
finished: false,
|
|
idList: '',
|
|
form: {
|
|
pageNum: 1
|
|
},
|
|
noticeList: [],
|
|
loopIndex: 0,
|
|
noticeIndex: 0,
|
|
loopRequesting: false,
|
|
content: '',
|
|
factoryList: []
|
|
},
|
|
lifetimes: {
|
|
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
|
|
attached: function () {
|
|
this.setData({ height: app.globalData.safeFragmentHeight - 190 })
|
|
event.on('EventMessage', this, this.onEvent)
|
|
},
|
|
detached: function () {
|
|
event.remove('EventMessage', this)
|
|
}
|
|
},
|
|
methods: {
|
|
onRestart: function () {
|
|
if (!this.data.firstShow) {
|
|
// this.fetchChartList()
|
|
|
|
this.onRefreshList()
|
|
}
|
|
if(!this.data.noticeList.length && !this.data.status){
|
|
this.fetchNoticeList()
|
|
}
|
|
this.data.firstShow = true
|
|
},
|
|
onEvent: function (message) {
|
|
if (message.what == 502) {
|
|
// this.fetchChartList()
|
|
} else if (message.what == 505) {
|
|
// 纸厂排队的纸厂选择
|
|
this.fetchFactoryList()
|
|
} else if (message.what == 570 || message.what == 571 || message.what == 572 || message.what == 573) {
|
|
// 帖子发布刷新
|
|
this.onRefreshList()
|
|
}
|
|
},
|
|
//***********************************参与纸厂讨论*****************************************//
|
|
fetchFactoryList: function(){
|
|
var recommendedString = storage.get('recommended' + app.globalData.userInfo.userId)
|
|
if(!util.isEmpty(recommendedString)){
|
|
this.setData({ factoryList: JSON.parse(recommendedString) })
|
|
return
|
|
}
|
|
// /recycle-service/get/paper-mill-list
|
|
request.get('/recycle-service/get/all-paper-mill').then(result => {
|
|
result.data.sort((a, b)=> b.isRecommended - a.isRecommended)
|
|
this.setData({ factoryList: result.data.slice(0, 8) })
|
|
})
|
|
},
|
|
toFactoryList: function(){
|
|
wx.navigateTo({ url: '/pages/article/factory/index' })
|
|
},
|
|
toFactory: function(e){
|
|
var item = this.data.factoryList[e.currentTarget.dataset.index]
|
|
wx.navigateTo({ url: '/pages/agent/factory/index?tabIndex=1&id=' + item.paperMillId })
|
|
},
|
|
toPaperList: function(){
|
|
wx.navigateTo({ url: '/pages/moment/paper/index' })
|
|
},
|
|
//***********************************fetchChartList*****************************************//
|
|
// fetchChartList: function(){
|
|
// var cateIds = storage.get('cateIdList' + app.globalData.userInfo.userId)
|
|
// if(!util.isEmpty(cateIds)){
|
|
// this.data.idList = cateIds
|
|
// }
|
|
// request.get('/information-center/getPaperCategoryPrice', {idList: this.data.idList}).then(result => {
|
|
// //成功回调
|
|
// if(result.data.length <= 0){
|
|
// return
|
|
// }
|
|
// var respList = result.data
|
|
// var categoriesList = []
|
|
// var serieList = []
|
|
// var min = Number.MAX_VALUE
|
|
// var max = 0
|
|
// for (let index = 0; index < respList.length; index++) {
|
|
// const element = respList[index]
|
|
// var dataList = []
|
|
// if(index == 0){
|
|
// element.list.forEach(item => {
|
|
// categoriesList.push(item.data.substring(5))
|
|
// var price = math.times(item.unitPrice, 1000)
|
|
// if(min > price){
|
|
// min = price
|
|
// }
|
|
// if(max < price){
|
|
// max = price
|
|
// }
|
|
// dataList.push(price)
|
|
// })
|
|
// } else {
|
|
// element.list.forEach(item => {
|
|
// var price = math.times(item.unitPrice, 1000)
|
|
// if(min > price){
|
|
// min = price
|
|
// }
|
|
// dataList.push(price)
|
|
// })
|
|
// }
|
|
// var series = {
|
|
// name: element.list[0].name,
|
|
// data: dataList,
|
|
// format: function (val, name) {
|
|
// return val + '元/吨'
|
|
// },
|
|
// color: colors[index]
|
|
// }
|
|
// serieList.push(series)
|
|
// }
|
|
// this.setData({ chartList: { categories: categoriesList, serieList: serieList } })
|
|
// // if(min < 50){
|
|
// // min = 50
|
|
// // }
|
|
// this.initChart(min - 50, max + 50)
|
|
// })
|
|
// },
|
|
// touchHandler: function (e) {
|
|
// if(lineChart){
|
|
// lineChart.scrollStart(e)
|
|
// }
|
|
// },
|
|
// moveHandler: function (e) {
|
|
// if(lineChart){
|
|
// lineChart.scroll(e)
|
|
// }
|
|
// },
|
|
// touchEndHandler: function (e) {
|
|
// if(lineChart){
|
|
// lineChart.scrollEnd(e)
|
|
// lineChart.showToolTip(e, {
|
|
// format: function (item, category) {
|
|
// return category + ' ' + item.name + ':' + item.data
|
|
// }
|
|
// })
|
|
// }
|
|
// },
|
|
// initChart: function (min, max) {
|
|
// lineChart = new wxCharts({
|
|
// canvasId: 'lineChart',
|
|
// type: 'line',
|
|
// categories: this.data.chartList.categories,
|
|
// animation: false,
|
|
// title: { name: '纸品单价 (元/吨)' },
|
|
// series: this.data.chartList.serieList,
|
|
// xAxis: { disableGrid: false },
|
|
// yAxis: {
|
|
// // title: '纸品单价 (元/吨)',
|
|
// format: function (val) {
|
|
// return val
|
|
// },
|
|
// min,
|
|
// max
|
|
// },
|
|
// width: 350,
|
|
// height: 200,
|
|
// dataLabel: false,
|
|
// dataPointShape: 'circle',
|
|
// enableScroll: true,
|
|
// extra: { lineStyle: 'curve' }
|
|
// }, this)
|
|
// },
|
|
//*************************************************momentList************************************************//
|
|
onRefreshList: function () {
|
|
this.setData({
|
|
momentList: [],
|
|
factoryList: [],
|
|
['form.pageNum']: 1,
|
|
finished: false
|
|
})
|
|
this.fetchFactoryList()
|
|
this.fetchMomentList()
|
|
},
|
|
fetchMomentList: function(){
|
|
if (this.data.requesting || this.data.finished) {
|
|
return
|
|
}
|
|
this.data.requesting = true
|
|
// /article/get/article-list 查询文章列表
|
|
request.get('/information-center/article/get/Article-list/', this.data.form).then(result => {
|
|
//成功回调
|
|
if (result.data.records.length) {
|
|
var respList = result.data.records
|
|
let nowList = `momentList[${this.data.momentList.length}]`
|
|
var num = this.data.form.pageNum
|
|
var finished = this.data.form.pageNum >= result.data.pages
|
|
this.setData({
|
|
[nowList]: respList,
|
|
['form.pageNum']: (num + 1),
|
|
finished,
|
|
requesting: false
|
|
})
|
|
} else {
|
|
this.setData({ finished: true, requesting: false })
|
|
}
|
|
}).catch(err => {
|
|
//异常回调
|
|
this.setData({ requesting: false })
|
|
})
|
|
},
|
|
lookItem: function(e){
|
|
var item = this.data.momentList[e.currentTarget.dataset.page][e.currentTarget.dataset.index]
|
|
wx.navigateTo({ url: '/pages/article/detail/index?id=' + item.id })
|
|
},
|
|
likeItem: function(e){
|
|
var item = this.data.momentList[e.currentTarget.dataset.page][e.currentTarget.dataset.index]
|
|
if(item.isLiked){
|
|
util.showToast('请勿重复点赞')
|
|
return
|
|
}
|
|
request.post('/information-center/like-or-cancel/post', {postId: item.id}).then(result => {
|
|
this.setData({
|
|
['momentList[' + e.currentTarget.dataset.page + '][' + e.currentTarget.dataset.index + '].likeQuantity']: result.data.likeQuantity,
|
|
['momentList[' + e.currentTarget.dataset.page + '][' + e.currentTarget.dataset.index + '].isLiked']: 1
|
|
})
|
|
}).catch(error => {
|
|
util.showToast(error)
|
|
})
|
|
},
|
|
//*************************************************noticeList************************************************//
|
|
fetchNoticeList: function(){
|
|
if (this.data.loopRequesting) {
|
|
return
|
|
}
|
|
this.data.loopRequesting = true
|
|
request.get('/recycle-service/get/index-info-id').then(result => {
|
|
//成功回调
|
|
this.data.loopRequesting = false
|
|
this.data.noticeList = result.data
|
|
if(result.data && result.data.length){
|
|
this.data.noticeIndex = 0
|
|
this.data.loopIndex = 0
|
|
this.setData({ content: result.data[0].title})
|
|
}
|
|
}).catch(err => {
|
|
//异常回调
|
|
this.data.loopRequesting = false
|
|
})
|
|
},
|
|
onLoop: function(){
|
|
if(!this.data.noticeList.length){
|
|
this.data.loopIndex++
|
|
if(this.data.loopIndex >= 600){
|
|
this.fetchNoticeList()
|
|
}
|
|
return
|
|
}
|
|
this.data.noticeIndex++
|
|
if(this.data.noticeIndex >= this.data.noticeList.length){
|
|
this.data.loopIndex++
|
|
this.data.noticeIndex = 0
|
|
}
|
|
if(this.data.loopIndex >= 60){
|
|
this.fetchNoticeList()
|
|
}
|
|
this.setData({ content: this.data.noticeList[this.data.noticeIndex].title })
|
|
this.notice = this.notice || this.selectComponent('#wux-notice-bar')
|
|
this.notice.resetAnimation()
|
|
},
|
|
onClick: function(){
|
|
wx.navigateTo({ url: '/pages/html/notice/index?id=' + this.data.noticeList[this.data.noticeIndex].id })
|
|
}
|
|
}
|
|
})
|