integralEvent.js 5.4 KB

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