integralEvent.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. onReset() {
  89. this.setData({
  90. page: 1,
  91. isVal: false,
  92. keyword: ''
  93. })
  94. this.getData();
  95. },
  96. bindKeyInput(e) {
  97. this.setData({
  98. page: 1,
  99. isVal: e.detail.value ? true : false,
  100. keyword: e.detail.value ? e.detail.value : '',
  101. })
  102. this.getData();
  103. },
  104. getData(is) {
  105. var data = {
  106. page: that.data.page,
  107. page_size: 20,
  108. rule_id: that.data.rule_id,
  109. pt_id: that.data.types.length > 0 ? that.data.types[that.data.typesIndex].id : '2',
  110. employee_ids: that.data.employee_ids,
  111. keyword:that.data.keyword,
  112. dc_status: JSON.stringify([1]),
  113. order_key:'update_time'
  114. }
  115. if (that.data.date_type == 2) {
  116. data.start_day = that.data.dateObj[0];
  117. data.end_day = that.data.dateObj[1];
  118. } else {
  119. data.month = that.data.dateObj || that.data.date;
  120. }
  121. if (that.data.rule_item_id) {//周报进来的细则ID
  122. data.item_id = that.data.rule_item_id
  123. }
  124. app.$get('api/integral/statistics/integral', data).then((res) => {
  125. var data = res.data.data.list;
  126. data.map((item) => {
  127. item.ptObj = app.getTypesItem(item.pt_id);
  128. })
  129. if (is) {
  130. if (data.length == 0) {
  131. this.setData({
  132. isData: true
  133. })
  134. return;
  135. }
  136. var list = that.data.list;
  137. this.setData({
  138. list: list.concat(data)
  139. })
  140. } else {
  141. this.setData({ list: [] });
  142. this.setData({
  143. list: data,
  144. isData: false
  145. })
  146. }
  147. })
  148. },
  149. //上啦加载
  150. onScrollToLower() {
  151. if (!that.data.isData) {
  152. this.setData({ page: ++that.data.page })
  153. this.getData(true);
  154. }
  155. },
  156. //打开兴趣
  157. openDetail(e) {
  158. var item = e.target.dataset.item;
  159. dd.navigateTo({
  160. url: '../prizeBuckleDetail/prizeBuckleDetail?id=' + item.id
  161. })
  162. },
  163. //显示规则组件
  164. selectRule() {
  165. this.setData({
  166. popupCx: 'container__mask',
  167. showRuleTwo: true
  168. })
  169. },
  170. //显示选择时间组件
  171. selectDate() {
  172. this.setData({
  173. popupCx: 'container__mask',
  174. showDate: true
  175. })
  176. },
  177. //显示选择员工
  178. selectStaff() {
  179. this.setData({
  180. popupCx: 'container__mask',
  181. showStaff: true
  182. })
  183. },
  184. //选择时间
  185. onConfirmDate(data) {
  186. that.setData({
  187. defaultDate: data,
  188. dateObj: data.date,
  189. date_type: data.type == 1 ? 3 : data.type,
  190. page: 1,
  191. selectDateVal: data.type == 1 ? (data.date == that.data.date ? '本月' : '月') : '日',
  192. rule_item_id: ''
  193. })
  194. this.getData();
  195. },
  196. //关闭弹窗
  197. onClose() {
  198. this.setData({
  199. showDate: false,
  200. showStaff: false,
  201. showRuleTwo: false,
  202. popupCx: '',
  203. rule_item_id: ''
  204. })
  205. },
  206. //选择积分分类
  207. bingIntegralType(e) {
  208. this.setData({
  209. typesIndex: e.detail.value,
  210. page: 1,
  211. rule_item_id: ''
  212. });
  213. this.getData();
  214. },
  215. //选择员工
  216. onConfirmStaff(data) {
  217. if (!data) {
  218. this.setData({ staffVal: '员工', employee_ids: '', page: 1, rule_item_id: '' })
  219. this.getData();
  220. return false;
  221. }
  222. if (data.length > 0) {
  223. if (data.length > 1) {
  224. var str = "";
  225. var arr = [];
  226. data.forEach((item) => {
  227. str += item.name + ','
  228. arr.push(item.id);
  229. })
  230. var employee_ids = arr.join(',');
  231. this.setData({ staffVal: str.substring(0, str.length - 1), employee_ids: employee_ids, page: 1, rule_item_id: '' })
  232. } else {
  233. this.setData({ staffVal: data[0].name, employee_ids: [data[0].id], page: 1, rule_item_id: '' })
  234. }
  235. } else {
  236. this.setData({ staffVal: '员工', employee_ids: [], page: 1, rule_item_id: '' })
  237. }
  238. this.getData();
  239. },
  240. //选择规则
  241. onConfirmRule(e) {
  242. this.setData({
  243. rule_id: e.id ? e.id : '',
  244. page: 1,
  245. ruleVal: e.name,
  246. rule_item_id: ''
  247. })
  248. this.getData();
  249. },
  250. });