微信小程序
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.

436 lines
10 KiB

  1. // pages/statistics/statistics.js
  2. import * as UTIL from '../../utils/util.js';
  3. import * as API from '../../utils/API.js';
  4. import * as echarts from '../../ec-canvas/echarts';
  5. let EVN_CONFIG = require('../../env/env');
  6. const app = getApp();
  7. function setOption(chart, rowRows1, rowRows2) {
  8. var option = {
  9. title: [
  10. { // 第一个圆环标题
  11. text: '收入', // 主标题
  12. textStyle: { // 主标题样式
  13. color: '#5CAE77',
  14. fontWeight: '400',
  15. fontSize: 14
  16. },
  17. left: '27%', // 定位到适合的位置
  18. top: '45%', // 定位到适合的位置
  19. textAlign: 'center' // 主、副标题水平居中显示
  20. },
  21. {// 第二个圆环标题
  22. text: '支出',
  23. textStyle: {
  24. color: '#E90000',
  25. fontWeight: '400',
  26. fontSize: 14
  27. },
  28. left: '76%',
  29. top: '45%',
  30. textAlign: 'center'
  31. }
  32. ],
  33. tooltip: {
  34. trigger: 'item'
  35. },
  36. series: [
  37. { // 第一个圆环
  38. type: 'pie',
  39. radius: ['30%', '50%'],
  40. center: ['28%', '50%'],
  41. avoidLabelOverlap: false,
  42. label: {
  43. show: true,
  44. position: 'outside', // 数据会显示在图形上,'center':会显示在圆环的内部
  45. color: '#333',
  46. },
  47. labelLine:{
  48. length:'5',
  49. length2:'5',
  50. },
  51. data: rowRows1,
  52. },
  53. { // 第二个圆环
  54. type: 'pie',
  55. radius: ['30%', '50%'],
  56. center: ['77%', '50%'],
  57. avoidLabelOverlap: false,
  58. itemStyle: {
  59. },
  60. label: {
  61. show: true,
  62. position: 'outside', // 数据会显示在图形上,'center':会显示在圆环的内部
  63. color: '#333',
  64. },
  65. labelLine:{
  66. length:'5',
  67. length2:'5',
  68. },
  69. data: rowRows2,
  70. }
  71. ]
  72. };
  73. chart.setOption(option);
  74. }
  75. function initChart3(chart, rowRows1) {
  76. var option = {
  77. tooltip: {
  78. trigger: 'item'
  79. },
  80. series: [
  81. { // 第一个圆环
  82. type: 'pie',
  83. radius: ['50%', '70%'],
  84. center: ['50%', '50%'],
  85. avoidLabelOverlap: false,
  86. label: {
  87. show: true,
  88. color: '#333',
  89. },
  90. data: rowRows1
  91. }
  92. ]
  93. };
  94. chart.setOption(option);
  95. }
  96. function initChart4(chart, rowRows2) {
  97. var option = {
  98. tooltip: {
  99. trigger: 'item'
  100. },
  101. series: [
  102. { // 第二个圆环
  103. type: 'pie',
  104. radius: ['50%', '70%'],
  105. center: ['50%', '50%'],
  106. avoidLabelOverlap: false,
  107. label: {
  108. show: true,
  109. color: '#333',
  110. },
  111. data:rowRows2,
  112. }
  113. ]
  114. };
  115. chart.setOption(option);
  116. }
  117. function initChartLine(chart,lineRowsSR,lineRowsZC) {
  118. console.log(lineRowsSR);
  119. var option = {
  120. legend: {
  121. data: ['收入', '支出'],
  122. top: 0,
  123. left: 'center',
  124. z: 100
  125. },
  126. grid: {
  127. left: '0',
  128. top:'20%',
  129. right: '3%',
  130. bottom: '3%',
  131. containLabel: true
  132. },
  133. tooltip: {
  134. show: true,
  135. trigger: 'axis'
  136. },
  137. xAxis: {
  138. type: 'category',
  139. boundaryGap: false,
  140. data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
  141. // show: false
  142. },
  143. yAxis: {
  144. x: 'center',
  145. type: 'value',
  146. splitLine: {
  147. lineStyle: {
  148. type: 'dashed'
  149. }
  150. }
  151. // show: false
  152. },
  153. series: [{
  154. name: '收入',
  155. type: 'line',
  156. smooth: true,
  157. data: lineRowsSR
  158. }, {
  159. name: '支出',
  160. type: 'line',
  161. smooth: true,
  162. data: lineRowsZC
  163. }]
  164. };
  165. chart.setOption(option);
  166. }
  167. Page({
  168. /**
  169. * 页面的初始数据
  170. */
  171. data: {
  172. isIPX: app.globalData.isIPX,
  173. currentDate: new Date().getTime(),
  174. minDate: new Date().getTime(),
  175. ec: {
  176. lazyLoad: true,
  177. },
  178. ec2: {
  179. lazyLoad: true
  180. },
  181. ec3: {
  182. lazyLoad: true
  183. },
  184. ec4: {
  185. lazyLoad: true
  186. },
  187. showList:false,
  188. showZC:false,
  189. showSR:false,
  190. date:'2022',
  191. topDetail:[],
  192. },
  193. showList(){
  194. this.setData({
  195. showList:!this.data.showList,
  196. showSR:true
  197. })
  198. if (this.data.showList) {
  199. this.oneComponent2 = this.selectComponent('#mychart-one2');
  200. this.init_one2(this.data.rowRows1)
  201. }
  202. },
  203. bindDateChange(e){
  204. this.setData({
  205. showList:false,
  206. showSR:false,
  207. showZC:false,
  208. })
  209. this.setData({
  210. date: e.detail.value
  211. })
  212. this.onLoad();
  213. },
  214. CloseList(){
  215. this.setData({
  216. showList:!this.data.showList,
  217. showSR:false,
  218. showZC:false,
  219. })
  220. this.oneComponent = this.selectComponent('#mychart-one');
  221. this.init_one(this.data.rowRows1,this.data.rowRows2)
  222. },
  223. /**
  224. * 生命周期函数--监听页面加载
  225. */
  226. onLoad(options) {
  227. var that = this;
  228. that.oneComponent = that.selectComponent('#mychart-one');
  229. that.oneComponent4 = that.selectComponent('#mychart-one4');
  230. let sendData = {
  231. year:that.data.date,
  232. method:'GET'
  233. }
  234. //收入类型字典
  235. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'income_type', {method:'GET'}, {
  236. success: (res) => {
  237. this.setData({
  238. incomeTypeOptions:res.data,
  239. })
  240. }
  241. })
  242. //支出类型字典
  243. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'capital_expenditure_type', {method:'GET'}, {
  244. success: (res) => {
  245. this.setData({
  246. expenditureTypeOptions:res.data,
  247. })
  248. }
  249. })
  250. wx.showLoading({
  251. title: '加载中',
  252. })
  253. setTimeout(function () {
  254. wx.hideLoading()
  255. }, 2000)
  256. setTimeout(function(){
  257. UTIL.httpRequest(API.URL_GET_GETSTATISTICS, sendData,{
  258. success: (res) => {
  259. let lineRowsSR = [];
  260. let lineRowsZC = [];
  261. for (let i = 0; i < res.rows.length; i++) {
  262. const element = res.rows[i];
  263. lineRowsSR.push(element.jieAmount)
  264. lineRowsZC.push(element.daiAmount)
  265. element.daiAmount = Number(element.daiAmount).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => { return $1 + ","; }).replace(/\.$/, "");
  266. element.jieAmount = Number(element.jieAmount).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => { return $1 + ","; }).replace(/\.$/, "");
  267. }
  268. that.setData({
  269. list:res.rows,
  270. })
  271. that.init_one4(lineRowsSR,lineRowsZC)
  272. }
  273. })
  274. UTIL.httpRequest(API.URL_GET_GETSUMSTATISTICS, sendData,{
  275. success: (res) => {
  276. res.data.jieAmount = Number(res.data.jieAmount).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => { return $1 + ","; }).replace(/\.$/, "");
  277. res.data.daiAmount = Number(res.data.daiAmount).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => { return $1 + ","; }).replace(/\.$/, "");
  278. that.setData({
  279. topDetail:res.data
  280. })
  281. }
  282. })
  283. UTIL.httpRequest(API.URL_GET_GETSUMGROUPTYPE, sendData,{
  284. success: (res) => {
  285. console.log(res);
  286. let rowRows1 = [];
  287. let rowRows2 = [];
  288. res.data[1].forEach(rr=>{
  289. console.log('aaa');
  290. rowRows1.push({
  291. value: rr.percentage,
  292. name: UTIL.getTransform(rr.incomeType,that.data.incomeTypeOptions).substr(0,2)+'\n'+rr.percentage+'%'
  293. })
  294. rr.jieAmount = Number(rr.jieAmount).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => { return $1 + ","; }).replace(/\.$/, "");
  295. })
  296. res.data[2].forEach(rrr=>{
  297. rowRows2.push({
  298. value: rrr.percentage,
  299. name: UTIL.getTransform(rrr.expenditureType,that.data.expenditureTypeOptions).substr(0,2)+'\n'+rrr.percentage+'%'
  300. })
  301. rrr.daiAmount = Number(rrr.daiAmount).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => { return $1 + ","; }).replace(/\.$/, "");
  302. })
  303. that.setData({
  304. centerRow:res.data,
  305. rowRows1:rowRows1,
  306. rowRows2:rowRows2
  307. })
  308. that.init_one(rowRows1,rowRows2)
  309. }
  310. })
  311. },2000)
  312. },
  313. init_one: function (rowRows1,rowRows2) {//饼图汇总
  314. this.oneComponent.init((canvas, width, height) => {
  315. const chart = echarts.init(canvas, null, {
  316. width: width,
  317. height: height
  318. });
  319. setOption(chart, rowRows1 , rowRows2)
  320. });
  321. },
  322. init_one2: function (rowRows1) {//收入饼图
  323. this.oneComponent2.init((canvas, width, height) => {
  324. const chart2 = echarts.init(canvas, null, {
  325. width: width,
  326. height: height
  327. });
  328. initChart3(chart2, rowRows1)
  329. });
  330. },
  331. init_one3: function (rowRows2) {//支出饼图
  332. this.oneComponent3.init((canvas, width, height) => {
  333. const chart3 = echarts.init(canvas, null, {
  334. width: width,
  335. height: height
  336. });
  337. initChart4(chart3, rowRows2)
  338. });
  339. },
  340. init_one4: function (lineRowsSR,lineRowsZC) {//折线图
  341. this.oneComponent4.init((canvas, width, height) => {
  342. const chart4 = echarts.init(canvas, null, {
  343. width: width,
  344. height: height
  345. });
  346. initChartLine(chart4, lineRowsSR,lineRowsZC)
  347. });
  348. },
  349. goSR(){
  350. this.setData({
  351. showZC:false,
  352. showSR:true
  353. })
  354. this.oneComponent2 = this.selectComponent('#mychart-one2');
  355. this.init_one2(this.data.rowRows1)
  356. },
  357. goZC(){
  358. this.setData({
  359. showZC:true,
  360. showSR:false
  361. })
  362. this.oneComponent3 = this.selectComponent('#mychart-one3');
  363. this.init_one3(this.data.rowRows2)
  364. },
  365. onInput(event) {
  366. this.setData({
  367. currentDate: event.detail,
  368. });
  369. },
  370. onTimeShow(e){
  371. this.setData({
  372. timeShow:true
  373. })
  374. },
  375. back:function(){
  376. wx.navigateBack({
  377. delta: 1
  378. })
  379. },
  380. /**
  381. * 生命周期函数--监听页面初次渲染完成
  382. */
  383. onReady() {
  384. },
  385. /**
  386. * 生命周期函数--监听页面显示
  387. */
  388. onShow() {
  389. },
  390. /**
  391. * 生命周期函数--监听页面隐藏
  392. */
  393. onHide() {
  394. },
  395. /**
  396. * 生命周期函数--监听页面卸载
  397. */
  398. onUnload() {
  399. },
  400. /**
  401. * 页面相关事件处理函数--监听用户下拉动作
  402. */
  403. onPullDownRefresh() {
  404. },
  405. /**
  406. * 页面上拉触底事件的处理函数
  407. */
  408. onReachBottom() {
  409. },
  410. /**
  411. * 用户点击右上角分享
  412. */
  413. onShareAppMessage() {
  414. }
  415. })