integralEvent.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. if (app.globalData.userData) {
  52. var arr = typeArr.concat(app.globalData.types);
  53. arr = app.globalData.arrRemoveObj(arr, arr[1]);
  54. if (arr) {
  55. that.setData({ types: arr })
  56. }
  57. if (that.data.page == 1) {
  58. that.getData();
  59. }
  60. } else {
  61. app.login(app.globalData.corpId, function (is) {
  62. if (is) {
  63. var arr = typeArr.concat(app.globalData.types);
  64. arr = app.globalData.arrRemoveObj(arr, arr[1]);
  65. if (arr) {
  66. that.setData({ types: arr })
  67. }
  68. if (that.data.page == 1) {
  69. that.getData();
  70. }
  71. } else {
  72. dd.reLaunch({
  73. url: '../noJurisdiction/noJurisdiction'
  74. })
  75. }
  76. })
  77. }
  78. },
  79. getData(is) {
  80. var data = {
  81. page: that.data.page,
  82. page_size: 20,
  83. rule_id: that.data.rule_id,
  84. pt_id: that.data.types.length > 0 ? that.data.types[that.data.typesIndex].id : '2',
  85. employee_ids: that.data.employee_ids
  86. }
  87. if (that.data.date_type == 2) {
  88. data.start_day = that.data.dateObj[0];
  89. data.end_day = that.data.dateObj[1];
  90. } else {
  91. data.month = that.data.dateObj || that.data.date;
  92. }
  93. app.$get('api/integral/statistics/integral', data).then((res) => {
  94. var data = res.data.data.list;
  95. data.map((item) => {
  96. item.ptObj = app.getTypesItem(item.pt_id);
  97. })
  98. if (is) {
  99. if (data.length == 0) {
  100. this.setData({
  101. isData: true
  102. })
  103. return;
  104. }
  105. var list = that.data.list;
  106. this.setData({
  107. list: list.concat(data)
  108. })
  109. } else {
  110. this.setData({ list: [] });
  111. this.setData({
  112. list: data,
  113. isData: false
  114. })
  115. }
  116. })
  117. },
  118. //上啦加载
  119. onScrollToLower() {
  120. if (!that.data.isData) {
  121. this.setData({ page: ++that.data.page })
  122. this.getData(true);
  123. }
  124. },
  125. //打开兴趣
  126. openDetail(e) {
  127. var item = e.target.dataset.item;
  128. dd.navigateTo({
  129. url: '../prizeBuckleDetail/prizeBuckleDetail?id=' + item.id
  130. })
  131. },
  132. //显示规则组件
  133. selectRule() {
  134. this.setData({
  135. showRuleTwo: true
  136. })
  137. },
  138. //显示选择时间组件
  139. selectDate() {
  140. this.setData({
  141. showDate: true
  142. })
  143. },
  144. //显示选择员工
  145. selectStaff() {
  146. this.setData({
  147. showStaff: true
  148. })
  149. },
  150. //选择时间
  151. onConfirmDate(data) {
  152. that.setData({
  153. defaultDate: data,
  154. dateObj: data.date,
  155. date_type: data.type == 1 ? 3 : data.type,
  156. page: 1,
  157. selectDateVal: data.type == 1 ? (data.date == that.data.date ? '本月' : '月') : '日',
  158. })
  159. this.getData();
  160. },
  161. //关闭弹窗
  162. onClose() {
  163. this.setData({
  164. showDate: false,
  165. showStaff: false,
  166. showRuleTwo: false
  167. })
  168. },
  169. //选择积分分类
  170. bingIntegralType(e) {
  171. this.setData({
  172. typesIndex: e.detail.value,
  173. page: 1
  174. });
  175. this.getData();
  176. },
  177. //选择员工
  178. onConfirmStaff(data) {
  179. if (!data) {
  180. this.setData({ staffVal: '员工', employee_ids: '', page: 1 })
  181. this.getData();
  182. return false;
  183. }
  184. if (data.length > 0) {
  185. if (data.length > 1) {
  186. var str = "";
  187. var arr = [];
  188. data.forEach((item) => {
  189. str += item.name + ','
  190. arr.push(item.id);
  191. })
  192. var employee_ids = arr.join(',');
  193. this.setData({ staffVal: str.substring(0, str.length - 1), employee_ids: employee_ids, page: 1 })
  194. } else {
  195. this.setData({ staffVal: data[0].name, employee_ids: [data[0].id], page: 1 })
  196. }
  197. } else {
  198. this.setData({ staffVal: '员工', employee_ids: [], page: 1 })
  199. }
  200. this.getData();
  201. },
  202. //选择规则
  203. onConfirmRule(e) {
  204. this.setData({
  205. rule_id: e.id ? e.id : '',
  206. page: 1,
  207. ruleVal: e.name
  208. })
  209. this.getData();
  210. },
  211. });