prize_buckle.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. var app = getApp()
  2. var that;
  3. var chart1;
  4. var chart2;
  5. Page({
  6. data: {
  7. date: app.globalData.month,
  8. employee_id: 0,
  9. isDb: false,
  10. showtu: false,
  11. chartData: []
  12. },
  13. onLoad(e) {
  14. that = this;
  15. dd.setNavigationBar({ title: "奖扣统计" });
  16. chart1, chart2 = '';
  17. if (e.id && e.month) {
  18. that.setData({
  19. date: e.month,
  20. employee_id: e.id
  21. })
  22. }
  23. },
  24. onShow() {
  25. if (app.globalData.userData) {
  26. that.setData({
  27. showtu: true
  28. })
  29. that.getUserData();
  30. } else {
  31. app.login(app.globalData.corpId, function (is) {
  32. if (is) {
  33. that.setData({
  34. showtu: true
  35. })
  36. that.getUserData();
  37. } else {
  38. dd.reLaunch({
  39. url: '../noJurisdiction/noJurisdiction'
  40. })
  41. }
  42. },function(){})
  43. }
  44. },
  45. onInitChart(F2, config) {
  46. chart1 = new F2.Chart(config);
  47. chart1.source(that.data.chartData, {
  48. time: {
  49. // type: 'timeCat',
  50. tickCount: 5,
  51. range: [0, 1]
  52. }
  53. });
  54. chart1.legend(false);
  55. chart1.axis('time', {
  56. label: function label(text, index, total) {
  57. const textCfg = {};
  58. if (index === 0) {
  59. textCfg.textAlign = 'left';
  60. } else if (index === total - 1) {
  61. textCfg.textAlign = 'right';
  62. }
  63. return textCfg;
  64. },
  65. });
  66. chart1.line().position('time*value').color('type', ['#F56C6C', '#67C23A']);
  67. chart1.render();
  68. return chart1;
  69. },
  70. onInitChart2(F2, config) {
  71. chart2 = new F2.Chart(config);
  72. chart2.source(that.data.chartData, {
  73. time: {
  74. // type: 'timeCat',
  75. tickCount: 5,
  76. range: [0, 1]
  77. }
  78. });
  79. chart2.legend(false);
  80. chart2.axis('time', {
  81. label: function label(text, index, total) {
  82. const textCfg = {};
  83. if (index === 0) {
  84. textCfg.textAlign = 'left';
  85. } else if (index === total - 1) {
  86. textCfg.textAlign = 'right';
  87. }
  88. return textCfg;
  89. },
  90. });
  91. chart2.line().position('time*value').color('type', ['#F56C6C', '#67C23A']);
  92. chart2.render();
  93. that.getIncidentLsit();
  94. return chart2;
  95. },
  96. getIncidentLsit() {
  97. app.$get("api/integral/statistics/prize", { employee_id: that.data.employee_id, month: that.data.date }).then((res) => {
  98. const { chart } = res.data.data;
  99. const { reward, deduct } = chart;
  100. var rewardArr = reward.map((item) => {
  101. return { time: item.date, value: item.point, type: '奖分' };
  102. })
  103. var deductArr = deduct.map((item) => {
  104. return { time: item.date, value: item.point, type: '扣分' };
  105. })
  106. var rewardArrCount = reward.map((item) => {
  107. return { time: item.date, value: item.count, type: '奖分人次' };
  108. })
  109. var deductArrCount = deduct.map((item) => {
  110. return { time: item.date, value: item.count, type: '扣分人次' };
  111. })
  112. var charData = rewardArr.concat(deductArr);
  113. var charData2 = rewardArrCount.concat(deductArrCount);
  114. chart1.changeData(charData);
  115. chart2.changeData(charData2);
  116. })
  117. },
  118. //时间选择
  119. openDate() {
  120. that.setData({ showDate: true });
  121. dd.datePicker({
  122. format: 'yyyy-MM',
  123. currentDate: that.data.date,
  124. success: (res) => {
  125. if (res.date) {
  126. that.setData({
  127. date: res.date,
  128. isDb: false
  129. })
  130. that.getUserData();
  131. that.getIncidentLsit();
  132. }
  133. },
  134. complete: (res) => {
  135. that.setData({
  136. showDate: false
  137. })
  138. }
  139. });
  140. },
  141. //获取个人统计
  142. getUserData() {
  143. app.$get("api/integral/statistics", { employee_id: that.data.employee_id, month: that.data.date }).then((res) => {
  144. var data = res.data.data;
  145. var task = data.task;
  146. dd.setNavigationBar({ title: data.name });
  147. var ratio = task.reward.point === 0 || task.deduction.point === 0 ? '-' : `${task.ratio.ratio}:1`
  148. var target_ratio = task.ratio.target_ratio <= 0 ? '0:0' : `${task.ratio.target_ratio}:1`
  149. if (data.task.reward.point >= data.task.reward.target_point && data.task.deduction.point >= data.task.deduction.target_point && data.task.exec.count >= data.task.exec.target_count) {
  150. if (task.ratio.ratio >= task.ratio.target_ratio) {
  151. this.setData({
  152. isDb: true
  153. })
  154. }
  155. }
  156. data.ratio = {
  157. ratio: ratio,
  158. target_ratio: target_ratio
  159. }
  160. this.setData({
  161. userData: data
  162. })
  163. })
  164. },
  165. });