123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394 |
- // pages/data/index.js
- import http from '../../utils/http'
- import util from '../../utils/util'
- import api from '../../utils/api'
- const app = getApp()
- import * as echarts from '../../ec-canvas/echarts';
- let chart = null;
- let option = {}
- function initChart(canvas, width, height, dpr) {
- chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr // new
- });
- canvas.setChart(chart);
- option = {
- legend: {
- data: []
- },
- xAxis: {
- type: 'category',
- data: []
- },
- yAxis: {
- type: 'value',
- show: false
- },
- series: [{
- data: [],
- type: 'bar'
- }]
- };
- chart.setOption(option);
- return chart;
- }
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- projects: [],
- project_id: '',
- project_ids: [],
- sort_types: [
- { text: '筛选类型', value: '' },
- { text: '按年筛选', value: 'year' },
- { text: '按月筛选', value: 'month' }
- ],
- sort_type: '',
- project_names: '',
- year_money: '0',
- month_money: '0',
- projectShow: false,
- index: 0,
- show: false,
- isSearch: true,
- charts: [{
- name: '柱状图',
- type: 'bar'
- }, {
- name: '折线图',
- type: 'line'
- }, {
- name: '饼状图',
- type: 'pie'
- }, {
- name: '明细图',
- type: 'detail'
- }, {
- name: '雷达图',
- type: 'radar'
- }],
- chartIndex: 1,
- dateTypes: [{
- name: '按年',
- type: 'year'
- }, {
- name: '按月',
- type: 'month'
- }],
- dateIndex: 0,
- dateShow: false,
- years_months: [],
- date: '',
- start: '',
- end: '',
- max_date: '',
- min_date: '',
- filter: {},
- data: [],
- ec: {
- onInit: initChart
- },
- detail_data: [],
- orderBy: 'asc'
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- app.resetDataFilter()
- api.getByName(this, 'projects/getAll', 'projects', {type: 'drop_menu'});
- },
- changeChartIndex: function(e) {
- var type = e.currentTarget.dataset.type
- var chartIndex = this.data.chartIndex
- chartIndex = type == '+' ? (chartIndex + 1) : (chartIndex - 1)
- if(chartIndex < 0 || chartIndex > 2) return false;
- this.setData({chartIndex})
- this.getChartData()
- },
- updateValue: function (e) {
- var name = e.currentTarget.dataset.name
- var value = e.currentTarget.dataset.value
- this.setData({
- [name]: value
- })
- if (name == 'orderBy') {
- this.getChartData()
- }
- },
- updateDate(e) {
- this.setData({
- date: e.detail.date
- })
- this.getYearAndMonthMoney()
- this.getChartData()
- },
- getYearAndMonthMoney() {
- var that = this
- http({
- url: 'data/getYearAndMonthMoney',
- data: {
- date: this.data.date
- },
- success: function (res) {
- if (res.code == 0) {
- that.setData(res.data)
- }
- }
- })
- },
- getChartData: function () {
- var chartIndex = this.data.chartIndex
- var that = this
- var data = {
- date: this.data.date,
- orderBy: this.data.orderBy,
- chartIndex: chartIndex,
- project_id: this.data.project_id,
- sort_type: this.data.sort_type
- }
- data = Object.assign({}, data, this.data.filter)
- http({
- url: 'data/projectStat',
- data: data,
- success: function (res) {
- if (res.code == 0) {
- that.setData({
- data: res.data
- })
- that.updateChart()
- }
- }
- })
- },
- onChange(e) {
- var name = e.currentTarget.dataset.name
- var val = e.detail
- this.setData({
- [name]: val
- })
- this.getChartData()
- },
- updateChart: function () {
- var data = this.data.data
- var chartIndex = this.data.chartIndex
- if(chartIndex == 0) {
- option.xAxis = [{
- type: 'value'
- }]
-
- option.legend = {
- data: data.legends,
- bottom: 40
- }
- var title = '设备租赁费用明细'
- var date = this.data.date
- date = date.length > 7 ? date.substr(0, 4) + '年' : ''
- title = (data.project ? data.project.name + '-' : '-') + date + title
- option.title = {
- text: title,
- left: 'center',
- bottom: 20
- }
- option.yAxis = [{
- type: 'category',
- data: data.names
- }];
- var values = data.values
-
- option.series = [{
- label: {
- show: true
- },
- name: data.name,
- type: 'bar',
- data: values
- }]
- option.grid = {
- left: 20,
- right: 20,
- bottom: 60,
- top: 0,
- containLabel: true
- }
- } else if (chartIndex == 1) {
- option.xAxis = [{
- type: 'value'
- }]
-
- option.legend = {
- data: data.legends,
- bottom: 40
- }
- var title = '项目租赁总费用排行'
- var date = this.data.date
- date = date.length > 7 ? date.substr(0, 7) : ''
- title = date + title
- option.title = {
- text: title,
- left: 'center',
- bottom: 20
- }
- option.yAxis = [{
- type: 'category',
- data: data.names
- }];
- var values = data.values
-
- option.series = [{
- label: {
- show: true
- },
- name: '租赁费用',
- type: 'bar',
- data: values
- }]
- option.grid = {
- left: 20,
- right: 20,
- bottom: 60,
- top: 0,
- containLabel: true
- }
- // chart.resize({width: '80vw', height: '80vh'})
- } else {
- option.xAxis = [{
- type: 'value'
- }]
-
- option.legend = {
- data: data.legends,
- bottom: 40
- }
- var title = '设备最大单价费用排行'
- option.title = {
- text: title,
- left: 'center',
- bottom: 20
- }
- option.yAxis = [{
- type: 'category',
- data: data.names
- }];
- var values = data.values
-
- option.series = [{
- label: {
- show: true
- },
- name: '租赁最大单价',
- type: 'bar',
- data: values
- }]
- option.grid = {
- left: 20,
- right: 20,
- bottom: 60,
- top: 0,
- containLabel: true
- }
- }
- chart.setOption(option)
- },
- radioChange: function (e) {
- var dateIndex = e.currentTarget.dataset.index
- if (dateIndex == this.data.dateIndex) return false
- var start_date = this.data.start_date
- var end_date = this.data.end_date
- var start_date = dateIndex == 1 ? start_date + '-01' : start_date.substr(0, 7)
- var end_date = dateIndex == 1 ? end_date + '-01' : end_date.substr(0, 7)
- this.setData({
- dateIndex,
- start_date,
- end_date
- })
- },
- switchShow: function (e) {
- var name = e.currentTarget.dataset.name
- var show = e.currentTarget.dataset.show ? e.currentTarget.dataset.show : !this.data[name]
- this.setData({
- [name]: show
- })
- if (name == 'dateShow' && !show) {
- this.getData()
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.getTabBar().init();
- var filter = wx.getStorageSync('sg-data-filters')
- this.setData({
- filter: filter
- })
- this.getChartData()
- },
- navigate: function (e) {
- var url = e.currentTarget.dataset.url
- wx.navigateTo({
- url: url,
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|