integralEvent.js 5.8 KB

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