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.
239 lines
7.2 KiB
239 lines
7.2 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.fragmentHeight - 100,
|
|
hostList: [],
|
|
chartList: null,
|
|
momentList: [],
|
|
requesting: false,
|
|
finished: false,
|
|
idList: '',
|
|
form: {
|
|
pageNum: 1
|
|
}
|
|
},
|
|
lifetimes: {
|
|
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
|
|
attached: function () {
|
|
this.setData({ height: app.globalData.fragmentHeight - 100 })
|
|
event.on('EventMessage', this, this.onEvent)
|
|
},
|
|
detached: function () {
|
|
event.remove('EventMessage', this)
|
|
}
|
|
},
|
|
methods: {
|
|
onRestart: function () {
|
|
// this.fetchMessageNumber()
|
|
if (!this.data.firstShow) {
|
|
this.fetchHostList()
|
|
this.fetchChartList()
|
|
this.onRefreshList()
|
|
}
|
|
this.data.firstShow = true
|
|
},
|
|
onEvent: function (message) {
|
|
if (message.what == 502) {
|
|
this.fetchChartList()
|
|
}
|
|
},
|
|
//***********************************fetchHostList*****************************************//
|
|
fetchHostList: function(){
|
|
request.get('/information-center/paper-bar/get/top-paper-bar-list').then(result => {
|
|
//成功回调
|
|
this.setData({ hostList: result.data })
|
|
})
|
|
},
|
|
toHost: function(e){
|
|
var item = this.data.hostList[e.currentTarget.dataset.index]
|
|
wx.navigateTo({
|
|
url: '/pages/moment/host-detail/index?id=' + item.id
|
|
})
|
|
},
|
|
//***********************************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: [],
|
|
['form.pageNum']: 1,
|
|
finished: false
|
|
})
|
|
this.fetchMomentList()
|
|
},
|
|
fetchMomentList: function(){
|
|
if (this.data.requesting || this.data.finished) {
|
|
return
|
|
}
|
|
this.data.requesting = true
|
|
request.get('/information-center/get/prefer-post-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
|
|
})
|
|
} else {
|
|
this.setData({ finished: true })
|
|
}
|
|
this.data.requesting = false
|
|
}).catch(err => {
|
|
//异常回调
|
|
this.data.requesting = false
|
|
})
|
|
},
|
|
lookItem: function(e){
|
|
var item = this.data.momentList[e.currentTarget.dataset.page][e.currentTarget.dataset.index]
|
|
wx.navigateTo({
|
|
url: '/pages/moment/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)
|
|
})
|
|
},
|
|
toMomentList: function(){
|
|
wx.navigateTo({
|
|
url: '/pages/moment/list/index'
|
|
})
|
|
},
|
|
toPaperList: function(){
|
|
wx.navigateTo({
|
|
url: '/pages/moment/paper/index'
|
|
})
|
|
}
|
|
}
|
|
})
|