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.
212 lines
7.4 KiB
212 lines
7.4 KiB
// pages/stock/index.js
|
|
const request = require('../../../utils/request') //导入模块
|
|
const util = require('../../../utils/util')
|
|
const storage = require('../../../utils/storage')
|
|
const event = require('../../../utils/event.js')
|
|
var wxCharts = require('../../../utils/wxcharts.js')
|
|
const app = getApp()
|
|
var queueChart = null
|
|
const colors = ['#FF4229', '#FFAD2A', '#297BFF', '#29FF46', '#AD29FF']
|
|
|
|
Component({
|
|
options: {
|
|
addGlobalClass: true,
|
|
multipleSlots: true
|
|
},
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
dev: app.globalData.dev,
|
|
height: app.globalData.safeFragmentHeight - 190,
|
|
momentList: [],
|
|
requesting: false,
|
|
finished: false,
|
|
form: { categoryId: 2, pageNum: 1 },
|
|
queueId: null,
|
|
queueName: '',
|
|
chartList: null,
|
|
},
|
|
lifetimes: {
|
|
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
|
|
attached: function () {
|
|
this.setData({ dev: app.globalData.dev, height: app.globalData.safeFragmentHeight - 190 })
|
|
this.data.queueId = storage.get('queueId' + app.globalData.userInfo.userId)
|
|
this.data.queueName = storage.get('queueName' + app.globalData.userInfo.userId)
|
|
event.on('EventMessage', this, this.onEvent)
|
|
},
|
|
detached: function () {
|
|
event.remove('EventMessage', this)
|
|
}
|
|
},
|
|
methods: {
|
|
onRestart: function () {
|
|
if (!this.data.firstShow) {
|
|
// this.fetchQueueList(this.data.queueId)
|
|
this.onRefreshList()
|
|
}
|
|
this.data.firstShow = true
|
|
},
|
|
onEvent: function (message) {
|
|
if (message.what == 556) {
|
|
// 纸厂排队的纸厂选择
|
|
this.data.queueId = message.obj.paperMillId
|
|
this.data.queueName = message.obj.name
|
|
storage.put('queueId' + app.globalData.userInfo.userId, this.data.queueId)
|
|
storage.put('queueName' + app.globalData.userInfo.userId, this.data.queueName)
|
|
// this.fetchQueueList(this.data.queueId)
|
|
} else if (message.what == 572) {
|
|
// 帖子发布刷新
|
|
this.onRefreshList()
|
|
}
|
|
},
|
|
//***********************************fetchChartList*****************************************//
|
|
// touchHandler: function (e) {
|
|
// if(queueChart){
|
|
// queueChart.scrollStart(e)
|
|
// }
|
|
// },
|
|
// moveHandler: function (e) {
|
|
// if(queueChart){
|
|
// queueChart.scroll(e)
|
|
// }
|
|
// },
|
|
// touchEndHandler: function (e) {
|
|
// if(queueChart){
|
|
// queueChart.scrollEnd(e)
|
|
// queueChart.showToolTip(e, {
|
|
// format: function (item, category) {
|
|
// return category + ' ' + item.name + ':' + item.data
|
|
// }
|
|
// })
|
|
// }
|
|
// },
|
|
// // 纸品价格>>>>选择纸厂
|
|
// selectFactory: function(event){
|
|
// wx.navigateTo({ url: '/pages/article/factory/index?type=2'})
|
|
// },
|
|
// fetchQueueList: function(millId){
|
|
// if(!millId){
|
|
// request.get('/recycle-service/get/paper-mill-list').then(result => {
|
|
// this.data.queueName = result.data.records[1].name
|
|
// this.fetchQueueList(result.data.records[1].paperMillId)
|
|
// })
|
|
// return
|
|
// }
|
|
// // recycle-service/get/paper-mill-received-weight-trend
|
|
// request.get('/recycle-service/get/paper-mill-received-weight-trend', {paperMillId: millId}).then(result => {
|
|
// //成功回调
|
|
// if(result.data.length <= 0){
|
|
// this.setData({chartList: [], queueName: this.data.queueName})
|
|
// return
|
|
// }
|
|
// var categoriesList = []
|
|
// var serieList = []
|
|
// var dataList = [[]]
|
|
// for (let index = 0; index < result.data.length; index++) {
|
|
// const element = result.data[index]
|
|
// categoriesList.push(element.time.substring(5))
|
|
// dataList[0].push(element.totalQuantity)
|
|
// // dataList[1].push(element.retainedQuantity)
|
|
// }
|
|
// var names = ['收货车辆总数', '排队车辆数']
|
|
// for (let index = 0; index < dataList.length; index++) {
|
|
// var series = {
|
|
// name: names[index],
|
|
// data: dataList[index],
|
|
// format: function (val, name) {
|
|
// return val + '辆'
|
|
// },
|
|
// color: colors[index]
|
|
// }
|
|
// serieList.push(series)
|
|
// }
|
|
// this.setData({ chartList: { categories: categoriesList, serieList: serieList }, queueName: this.data.queueName })
|
|
// this.initChart(0, 0)
|
|
// })
|
|
// },
|
|
// initChart: function (min, max) {
|
|
// queueChart = new wxCharts({
|
|
// canvasId: 'queueChart',
|
|
// type: 'line',
|
|
// legend: false,
|
|
// categories: this.data.chartList.categories,
|
|
// animation: false,
|
|
// 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)
|
|
// },
|
|
// queueList: function(){
|
|
// wx.navigateTo({ url: '/pages/article/queue-detail/index' })
|
|
// },
|
|
//*************************************************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/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
|
|
}
|
|
// /article/like-or-cancel/article-reply/{id} 点赞评论
|
|
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)
|
|
})
|
|
}
|
|
}
|
|
})
|