integralEvent.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. var app = getApp()
  2. var that;
  3. var typeArr = [];
  4. Page({
  5. data: {
  6. date: app.globalData.month,
  7. minuteIndex: 0,//条件选择
  8. minuteArray: [
  9. { id: 0, name: '总分' },
  10. { id: 1, name: '加班' },
  11. { id: 2, name: '迟到' },
  12. ],
  13. showDate: false,//是否显示时间组件
  14. selectDateVal: '本月',
  15. showStaff: false,//显示员工选择
  16. staffVal: '员工',
  17. types: [],//积分分类
  18. typesIndex: '0',
  19. showRuleTwo: false,
  20. ruleVal: "规则分类",
  21. page: 1,
  22. },
  23. onLoad(e) {
  24. that = this;
  25. var userData = app.globalData.userData;
  26. typeArr = [{ id: 0, name: '全部' }];
  27. var arr = typeArr.concat(app.globalData.types);
  28. arr = app.globalData.arrRemoveObj(arr, arr[1]);
  29. dd.setNavigationBar({ title: "积分事件" });
  30. if (e.month) {
  31. var typesIndex = "0";
  32. if (e.type) {
  33. arr.map((item, index) => {
  34. if (item.code == e.type) {
  35. typesIndex = index
  36. }
  37. })
  38. }
  39. this.setData({
  40. date: e.month,
  41. typesIndex: typesIndex,
  42. employee_ids: [userData.id],
  43. staffVal: userData.name,
  44. selectDateVal: e.month == app.globalData.month ? '本月' : '月',
  45. defaultDate: { type: '1', date: e.month },
  46. })
  47. }
  48. },
  49. onShow() {
  50. typeArr = [{ id: 0, name: '全部' }];
  51. var arr = typeArr.concat(app.globalData.types);
  52. arr = app.globalData.arrRemoveObj(arr, arr[1]);
  53. if(arr){
  54. this.setData({ types: arr })
  55. }
  56. if(this.data.page==1){
  57. this.getData();
  58. }
  59. },
  60. getData(is) {
  61. var data = {
  62. page: that.data.page,
  63. page_size: 20,
  64. rule_id: that.data.rule_id,
  65. pt_id: that.data.types.length > 0 ? that.data.types[that.data.typesIndex].id : '2',
  66. employee_ids: that.data.employee_ids
  67. }
  68. if (that.data.date_type == 2) {
  69. data.start_day = that.data.dateObj[0];
  70. data.end_day = that.data.dateObj[1];
  71. } else {
  72. data.month = that.data.dateObj || that.data.date;
  73. }
  74. app.$get('api/integral/statistics/integral', data).then((res) => {
  75. var data = res.data.data.list;
  76. data.map((item) => {
  77. item.ptObj = app.getTypesItem(item.pt_id);
  78. })
  79. if (is) {
  80. if (data.length == 0) {
  81. this.setData({
  82. isData: true
  83. })
  84. return;
  85. }
  86. var list = that.data.list;
  87. this.setData({
  88. list: list.concat(data)
  89. })
  90. } else {
  91. this.setData({ list: [] });
  92. this.setData({
  93. list: data,
  94. isData: false
  95. })
  96. }
  97. })
  98. },
  99. //上啦加载
  100. onScrollToLower() {
  101. if (!that.data.isData) {
  102. this.setData({ page: ++that.data.page })
  103. this.getData(true);
  104. }
  105. },
  106. //打开兴趣
  107. openDetail(e) {
  108. var item = e.target.dataset.item;
  109. dd.navigateTo({
  110. url: '../prizeBuckleDetail/prizeBuckleDetail?id=' + item.id
  111. })
  112. },
  113. //显示规则组件
  114. selectRule() {
  115. this.setData({
  116. showRuleTwo: true
  117. })
  118. },
  119. //显示选择时间组件
  120. selectDate() {
  121. this.setData({
  122. showDate: true
  123. })
  124. },
  125. //显示选择员工
  126. selectStaff() {
  127. this.setData({
  128. showStaff: true
  129. })
  130. },
  131. //选择时间
  132. onConfirmDate(data) {
  133. that.setData({
  134. defaultDate: data,
  135. dateObj: data.date,
  136. date_type: data.type == 1 ? 3 : data.type,
  137. page: 1,
  138. selectDateVal: data.type == 1 ? (data.date == that.data.date ? '本月' : '月') : '日',
  139. })
  140. this.getData();
  141. },
  142. //关闭弹窗
  143. onClose() {
  144. this.setData({
  145. showDate: false,
  146. showStaff: false,
  147. showRuleTwo: false
  148. })
  149. },
  150. //选择积分分类
  151. bingIntegralType(e) {
  152. this.setData({
  153. typesIndex: e.detail.value,
  154. page: 1
  155. });
  156. this.getData();
  157. },
  158. //选择员工
  159. onConfirmStaff(data) {
  160. if (!data) {
  161. this.setData({ staffVal: '员工', employee_ids: '', page: 1 })
  162. this.getData();
  163. return false;
  164. }
  165. if (data.length > 0) {
  166. if (data.length > 1) {
  167. var str = "";
  168. var arr = [];
  169. data.forEach((item) => {
  170. str += item.name + ','
  171. arr.push(item.id);
  172. })
  173. var employee_ids = arr.join(',');
  174. this.setData({ staffVal: str.substring(0, str.length - 1), employee_ids: employee_ids, page: 1 })
  175. } else {
  176. this.setData({ staffVal: data[0].name, employee_ids: [data[0].id], page: 1 })
  177. }
  178. } else {
  179. this.setData({ staffVal: '员工', employee_ids: [], page: 1 })
  180. }
  181. this.getData();
  182. },
  183. //选择规则
  184. onConfirmRule(e) {
  185. this.setData({
  186. rule_id: e.id ? e.id : '',
  187. page: 1,
  188. ruleVal: e.name
  189. })
  190. this.getData();
  191. },
  192. });