integralEvent.js 5.4 KB

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