prize_buckle.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. open2(){
  46. dd.navigateTo({
  47. url: '../../statistics/integralEventTwo/integralEventTwo?month='+that.data.date+'&id='+that.data.userData.id
  48. })
  49. },
  50. onInitChart(F2, config) {
  51. chart1 = new F2.Chart(config);
  52. chart1.source(that.data.chartData, {
  53. time: {
  54. // type: 'timeCat',
  55. tickCount: 5,
  56. range: [0, 1]
  57. }
  58. });
  59. chart1.legend(false);
  60. chart1.axis('time', {
  61. label: function label(text, index, total) {
  62. const textCfg = {};
  63. if (index === 0) {
  64. textCfg.textAlign = 'left';
  65. } else if (index === total - 1) {
  66. textCfg.textAlign = 'right';
  67. }
  68. return textCfg;
  69. },
  70. });
  71. chart1.line().position('time*value').color('type', ['#F56C6C', '#67C23A']);
  72. chart1.render();
  73. return chart1;
  74. },
  75. onInitChart2(F2, config) {
  76. chart2 = new F2.Chart(config);
  77. chart2.source(that.data.chartData, {
  78. time: {
  79. // type: 'timeCat',
  80. tickCount: 5,
  81. range: [0, 1]
  82. }
  83. });
  84. chart2.legend(false);
  85. chart2.axis('time', {
  86. label: function label(text, index, total) {
  87. const textCfg = {};
  88. if (index === 0) {
  89. textCfg.textAlign = 'left';
  90. } else if (index === total - 1) {
  91. textCfg.textAlign = 'right';
  92. }
  93. return textCfg;
  94. },
  95. });
  96. chart2.line().position('time*value').color('type', ['#F56C6C', '#67C23A']);
  97. chart2.render();
  98. that.getIncidentLsit();
  99. return chart2;
  100. },
  101. getIncidentLsit() {
  102. app.$get("api/integral/statistics/prize", { employee_id: that.data.employee_id, month: that.data.date }).then((res) => {
  103. const { chart } = res.data.data;
  104. const { reward, deduct } = chart;
  105. var rewardArr = reward.map((item) => {
  106. return { time: item.date, value: item.point, type: '奖分' };
  107. })
  108. var deductArr = deduct.map((item) => {
  109. return { time: item.date, value: item.point, type: '扣分' };
  110. })
  111. var rewardArrCount = reward.map((item) => {
  112. return { time: item.date, value: item.count, type: '奖分人次' };
  113. })
  114. var deductArrCount = deduct.map((item) => {
  115. return { time: item.date, value: item.count, type: '扣分人次' };
  116. })
  117. var charData = rewardArr.concat(deductArr);
  118. var charData2 = rewardArrCount.concat(deductArrCount);
  119. chart1.changeData(charData);
  120. chart2.changeData(charData2);
  121. })
  122. },
  123. //时间选择
  124. openDate() {
  125. that.setData({ showDate: true });
  126. dd.datePicker({
  127. format: 'yyyy-MM',
  128. currentDate: that.data.date,
  129. success: (res) => {
  130. if (res.date) {
  131. that.setData({
  132. date: res.date,
  133. isDb: false
  134. })
  135. that.getUserData();
  136. that.getIncidentLsit();
  137. }
  138. },
  139. complete: (res) => {
  140. that.setData({
  141. showDate: false
  142. })
  143. }
  144. });
  145. },
  146. //获取个人统计
  147. getUserData() {
  148. app.$get("api/integral/statistics", { employee_id: that.data.employee_id, month: that.data.date }).then((res) => {
  149. var data = res.data.data;
  150. var task = data.task;
  151. dd.setNavigationBar({ title: data.name });
  152. var ratio = task.reward.point === 0 || task.deduction.point === 0 ? '-' : `${task.ratio.ratio}:1`
  153. var target_ratio = task.ratio.target_ratio <= 0 ? '0:0' : `${task.ratio.target_ratio}:1`
  154. 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) {
  155. if (task.ratio.ratio >= task.ratio.target_ratio) {
  156. this.setData({
  157. isDb: true
  158. })
  159. }
  160. }
  161. data.ratio = {
  162. ratio: ratio,
  163. target_ratio: target_ratio
  164. }
  165. this.setData({
  166. userData: data
  167. })
  168. })
  169. },
  170. });