contract_panel.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. $(document).ready(function() {
  2. autoFlashHeight();
  3. const expensesPieValues = [
  4. {value: _.filter(expensesList, function (item) {
  5. return !item.settle_code && item.yf_price < item.total_price;
  6. }).length, name: '履行中'},
  7. {value: _.filter(expensesList, function (item) {
  8. return !item.settle_code && item.yf_price >= item.total_price;
  9. }).length, name: '已完成'},
  10. {value: _.filter(expensesList, function (item) {
  11. return !!item.settle_code;
  12. }).length, name: '已结算'}
  13. ];
  14. console.log(expensesPieValues);
  15. const expensesPieChart = echarts.init(document.getElementById('expensesPieChart'));
  16. const expensesPieOption = {
  17. color: ['#c7b8a1','#9ca8b8','#7b8b6f','#d8caaf'],
  18. tooltip: {
  19. trigger: 'item',
  20. formatter: '{a} <br/>{b}: {c} ({d}%)'
  21. },
  22. legend: {
  23. orient: 'horizontal',
  24. left: 0,
  25. data: ['履行中', '已完成', '已结算']
  26. },
  27. series: [
  28. {
  29. name: '合同',
  30. type: 'pie',
  31. radius: ['50%', '70%'],
  32. avoidLabelOverlap: false,
  33. label: {
  34. show: false,
  35. position: 'center'
  36. },
  37. emphasis: {
  38. label: {
  39. show: true,
  40. fontSize: '20',
  41. fontWeight: 'bold'
  42. }
  43. },
  44. labelLine: {
  45. show: false
  46. },
  47. data: expensesPieValues,
  48. }
  49. ]
  50. };
  51. expensesPieChart.setOption(expensesPieOption);
  52. // 按pay_time月份整理expensesPayList数据
  53. const expensesBarDatas = [];
  54. for (const expenses of expensesPayList) {
  55. const yearMonth = moment(expenses.pay_time).format('YYYY年MM月');
  56. const ymExpenses = _.find(expensesBarDatas, { yearMonth });
  57. if (ymExpenses) {
  58. ymExpenses.yf_price = ZhCalc.add(ymExpenses.yf_price, expenses.yf_price);
  59. } else {
  60. expensesBarDatas.push({ yearMonth, yf_price: expenses.yf_price });
  61. }
  62. }
  63. for (const e of expensesBarDatas) {
  64. e.rate = ZhCalc.round(ZhCalc.div(e.yf_price, prices.expenses_total_price) * 100, 2);
  65. }
  66. expensesBarDatas.sort((a, b) => {
  67. return moment(a.yearMonth, 'YYYY年MM月').diff(moment(b.yearMonth, 'YYYY年MM月'));
  68. });
  69. console.log(expensesBarDatas);
  70. const expensesBarChart = echarts.init(document.getElementById('expensesBarChart'));
  71. // 判断是万元还是元
  72. const yfPrices = _.map(expensesBarDatas, 'yf_price');
  73. const useWang = yfPrices.some(v => v >= 10000000);
  74. const displayData = useWang ? yfPrices.map(v => v / 10000) : yfPrices;
  75. const expensesBarOption = {
  76. color: ['#b5c4b1','#965454','#9ca8b8','#d8caaf'],
  77. title : {
  78. text: '支出合同结算趋势'
  79. },
  80. tooltip : {
  81. trigger: 'axis'
  82. },
  83. calculable : true,
  84. legend: {
  85. data:[`支付金额${useWang ? '(万元)' : '(元)'}`,'占总金额比例']
  86. },
  87. dataZoom: [
  88. {show: true,start: 0, end: 100}
  89. ],
  90. xAxis : [
  91. {
  92. type : 'category',
  93. splitLine : {show : true},
  94. data : _.map(expensesBarDatas, 'yearMonth'),
  95. }
  96. ],
  97. yAxis : [
  98. {
  99. type : 'value',
  100. name : '金额',
  101. position:'left',
  102. axisLabel : {
  103. formatter: value => useWang ? `${value}万元` : `${value}元`
  104. },
  105. splitArea : {show : true}
  106. },
  107. {
  108. type : 'value',
  109. name:'占总金额比例',
  110. axisLabel : {
  111. formatter: '{value} %'
  112. },
  113. position: 'right',
  114. splitArea : {show : true}
  115. }
  116. ],
  117. series : [
  118. {
  119. name:`支付金额${useWang ? '(万元)' : '(元)'}`,
  120. type:'bar',
  121. tooltip : {formatter: "{b}<br/>{a}:{c} %"},
  122. stack: '结算金额',
  123. data: displayData,
  124. },
  125. {
  126. name:'占总金额比例',
  127. type:'line',
  128. tooltip : {trigger: 'axis',formatter: "{b}<br/>{a}:{c} %"},
  129. yAxisIndex: 1,
  130. data: _.map(expensesBarDatas, 'rate'),
  131. },
  132. ]
  133. };
  134. expensesBarChart.setOption(expensesBarOption);
  135. const incomePieValues = [
  136. {value: _.filter(incomeList, function (item) {
  137. return !item.settle_code && item.yf_price < item.total_price;
  138. }).length, name: '履行中'},
  139. {value: _.filter(incomeList, function (item) {
  140. return !item.settle_code && item.yf_price >= item.total_price;
  141. }).length, name: '已完成'},
  142. {value: _.filter(incomeList, function (item) {
  143. return !!item.settle_code;
  144. }).length, name: '已结算'}
  145. ];
  146. console.log(incomePieValues);
  147. const incomePieChart = echarts.init(document.getElementById('incomePieChart'));
  148. const incomePieOption = {
  149. color: ['#c7b8a1','#9ca8b8','#7b8b6f','#d8caaf'],
  150. tooltip: {
  151. trigger: 'item',
  152. formatter: '{a} <br/>{b}: {c} ({d}%)'
  153. },
  154. legend: {
  155. orient: 'horizontal',
  156. left: 0,
  157. data: ['履行中', '已完成', '已结算']
  158. },
  159. series: [
  160. {
  161. name: '合同',
  162. type: 'pie',
  163. radius: ['50%', '70%'],
  164. avoidLabelOverlap: false,
  165. label: {
  166. show: false,
  167. position: 'center'
  168. },
  169. emphasis: {
  170. label: {
  171. show: true,
  172. fontSize: '20',
  173. fontWeight: 'bold'
  174. }
  175. },
  176. labelLine: {
  177. show: false
  178. },
  179. data: incomePieValues,
  180. }
  181. ]
  182. };
  183. // 为echarts对象加载数据
  184. incomePieChart.setOption(incomePieOption);
  185. const incomeBarDatas = [];
  186. for (const income of incomePayList) {
  187. const yearMonth = moment(income.pay_time).format('YYYY年MM月');
  188. const ymIncome = _.find(incomeBarDatas, { yearMonth });
  189. if (ymIncome) {
  190. ymIncome.yf_price = ZhCalc.add(ymIncome.yf_price, income.yf_price);
  191. } else {
  192. incomeBarDatas.push({ yearMonth, yf_price: income.yf_price });
  193. }
  194. }
  195. for (const i of incomeBarDatas) {
  196. i.rate = ZhCalc.round(ZhCalc.div(i.yf_price, prices.income_total_price) * 100, 2);
  197. }
  198. // 按日期排序
  199. incomeBarDatas.sort((a, b) => {
  200. return moment(a.yearMonth, 'YYYY年MM月').diff(moment(b.yearMonth, 'YYYY年MM月'));
  201. });
  202. console.log(incomeBarDatas);
  203. const incomeBarChart = echarts.init(document.getElementById('incomeBarChart'));
  204. // 判断是万元还是元
  205. const incomeYfPrices = _.map(incomeBarDatas, 'yf_price');
  206. const incomeUseWang = incomeYfPrices.some(v => v >= 10000000);
  207. const incomeDisplayData = incomeUseWang ? incomeYfPrices.map(v => v / 10000) : incomeYfPrices;
  208. const incomeBarOption = {
  209. color: ['#a27e7e','#656565','#b5c4b1','#d8caaf'],
  210. title : {
  211. text: '收入合同结算趋势'
  212. },
  213. tooltip : {
  214. trigger: 'axis'
  215. },
  216. calculable : true,
  217. legend: {
  218. data:[`回款金额${incomeUseWang ? '(万元)' : '(元)'}`,'占总金额比例']
  219. },
  220. dataZoom: [
  221. {show: true,start: 0, end: 100}
  222. ],
  223. xAxis : [
  224. {
  225. type : 'category',
  226. splitLine : {show : true},
  227. data : _.map(incomeBarDatas, 'yearMonth'),
  228. }
  229. ],
  230. yAxis : [
  231. {
  232. type : 'value',
  233. name : '金额',
  234. position:'left',
  235. axisLabel : {
  236. formatter: value => incomeUseWang ? `${value}万元` : `${value}元`
  237. },
  238. splitArea : {show : true}
  239. },
  240. {
  241. type : 'value',
  242. name:'占总金额比例',
  243. axisLabel : {
  244. formatter: '{value} %'
  245. },
  246. position: 'right',
  247. splitArea : {show : true}
  248. }
  249. ],
  250. series : [
  251. {
  252. name:`回款金额${incomeUseWang ? '(万元)' : '(元)'}`,
  253. type:'bar',
  254. tooltip : {formatter: "{b}<br/>{a}:{c} %"},
  255. stack: '回款金额',
  256. data: incomeDisplayData,
  257. },
  258. {
  259. name:'占总金额比例',
  260. type:'line',
  261. tooltip : {trigger: 'axis',formatter: "{b}<br/>{a}:{c} %"},
  262. yAxisIndex: 1,
  263. data: _.map(incomeBarDatas, 'rate'),
  264. },
  265. ]
  266. };
  267. incomeBarChart.setOption(incomeBarOption);
  268. let resizeTimer = null;
  269. $(window).bind('resize', function () {
  270. if (resizeTimer) clearTimeout(resizeTimer);
  271. resizeTimer = setTimeout(function () {
  272. echartsReset();
  273. }, 500);
  274. });
  275. function echartsReset() {
  276. expensesPieChart.resize();
  277. incomePieChart.resize();
  278. expensesBarChart.resize();
  279. incomeBarChart.resize();
  280. }
  281. $.subMenu({
  282. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  283. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  284. key: 'menu.1.0.0',
  285. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  286. callback: function (info) {
  287. if (info.mini) {
  288. $('.panel-title').addClass('fluid');
  289. $('#sub-menu').removeClass('panel-sidebar');
  290. } else {
  291. $('.panel-title').removeClass('fluid');
  292. $('#sub-menu').addClass('panel-sidebar');
  293. }
  294. autoFlashHeight();
  295. }
  296. });
  297. });