index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. var app = getApp();
  2. var that;
  3. var chart1;
  4. var chart2;
  5. var chart3;
  6. var AParse = require('../../../Component/aParse/aParse.js');
  7. import 'dingtalk-jsapi/entry/union';
  8. import { contactAdminToUseApp } from 'dingtalk-design-libs';
  9. Page({
  10. data: {
  11. userData: {},
  12. isBh: false,
  13. chartData: [],//折线图数据
  14. pieData: [1],//饼型图数据
  15. isAdministrator: app.globalData.isAdministrator,//是否管理员角色
  16. rankingTotal: 0,
  17. rankingList: [],
  18. getRole_four: app.globalData.isCreator,//是否创始人
  19. setECharts: [],//柱形图数据
  20. pieTotal: 1,
  21. total: '',
  22. menuList: [
  23. { name: '审批', imgUrl: '../../../image/sp.png', url: '../my_approve/my_approve', code: 'creator admin' },
  24. { name: '任务', imgUrl: '../../../image/a7.png', url: '../../statistics/my_task/my_task', code: 'admin employee' },
  25. { name: '奖扣B分', imgUrl: '../../../image/point_entry.png', url: '../jk_B/jk_B?type=B', code: 'creator admin' },
  26. { name: '指派任务', imgUrl: '../../../image/my_publish.png', url: '../../statistics/assaign/assaign', code: 'creator admin' },
  27. { name: '申请积分', imgUrl: '../../../image/a_apply.png', url: '../apply/apply', code: 'admin employee' },
  28. { name: '奖扣A分', imgUrl: '../../../image/a_entry.png', url: '../jk_B/jk_B?type=A', code: 'creator admin' },
  29. { name: '领任务', imgUrl: '../../../image/task_hall.png', url: '../../statistics/getTask/getTask', code: 'admin employee' },
  30. { name: '发布悬赏', imgUrl: '../../../image/caback6.png', url: '../../statistics/offerAreward/offerAreward', code: 'creator admin' },
  31. { name: '发放奖票', imgUrl: '../../../image/add_ticket.png', url: '../../statistics/grant/grant', code: 'creator admin' },
  32. { name: '全部', imgUrl: '../../../image/all2.png', url: 'all', code: 'creator admin employee' },
  33. ],
  34. isUpdate: false,
  35. title: '',//系统消息标题
  36. textId: '',//系统消息ID
  37. isSubject: false,//判断是否是个人版进入
  38. mainCorpId: '',//如果是个人版,这个企业ID是登录者所在的企业ID,不是钉钉那边提供的隐藏企业ID
  39. },
  40. onLoad() {
  41. that = this;
  42. chart1, chart2, chart3 = '';
  43. },
  44. onShow() {
  45. if (app.globalData.userData) {
  46. that.getUserData();
  47. that.getGg();
  48. that.setData({
  49. isAdministrator: app.globalData.isAdministrator,
  50. getRole_four: app.globalData.isCreator,
  51. isSubject: app.globalData.userData.is_personal == 1 ? true : false,
  52. mainCorpId: app.globalData.userData.main_corp_id
  53. })
  54. if (app.globalData.isCreator) {
  55. that.setMenuList("creator");
  56. } else if (app.globalData.isAdministrator) {
  57. that.setMenuList("admin");
  58. } else if (!app.globalData.isCreator && !app.globalData.isAdministrator) {
  59. that.setMenuList("employee");
  60. }
  61. } else {
  62. app.login(app.globalData.corpId, function (is) {
  63. if (is) {
  64. if (app.globalData.isCreator) {
  65. that.setMenuList("creator");
  66. } else if (app.globalData.isAdministrator) {
  67. that.setMenuList("admin");
  68. } else if (!app.globalData.isCreator && !app.globalData.isAdministrator) {
  69. that.setMenuList("employee");
  70. }
  71. that.getGg();
  72. that.getUserData();
  73. that.setData({
  74. isAdministrator: app.globalData.isAdministrator,
  75. getRole_four: app.globalData.isCreator,
  76. isSubject: app.globalData.userData.is_personal == 1 ? true : false,
  77. mainCorpId: app.globalData.userData.main_corp_id
  78. })
  79. } else {
  80. dd.reLaunch({
  81. url: '../noJurisdiction/noJurisdiction'
  82. })
  83. }
  84. })
  85. }
  86. },
  87. openGly() {
  88. contactAdminToUseApp({ id: '55493', corpId: that.data.mainCorpId })
  89. .catch((err) => {
  90. // 入参不正确,或者遇到技术异常时才会进入这个链路
  91. console.error(err);
  92. })
  93. },
  94. openUrl(e) {
  95. var url = e.target.dataset.url;
  96. if (url == 'all') {
  97. dd.switchTab({
  98. url: '../../statistics/index/index'
  99. })
  100. return
  101. }
  102. dd.navigateTo({
  103. url: url
  104. })
  105. },
  106. openText() {
  107. that.colseText();
  108. dd.navigateTo({
  109. url: '../../deploy/upgradeDetail/upgradeDetail?id=' + that.data.textId
  110. })
  111. },
  112. //获取缓存的公告
  113. getReviewerObj(fuc) {
  114. dd.getStorage({
  115. key: 'isShowMessage',
  116. success: function (res) {
  117. if (res.data) {
  118. fuc(res.data);
  119. } else {
  120. fuc({});
  121. }
  122. }
  123. });
  124. },
  125. // 获取公告
  126. getGg() {
  127. if (that.data.title) {
  128. return
  129. }
  130. app.$get("api/announcement/list", { page: 1, page_size: 1 }).then((res) => {
  131. var data = res.data.data.list[0];
  132. AParse.aParse('article', 'html', data.focus, that, 5);
  133. that.setData({
  134. title: data.title,
  135. textId: data.id
  136. });
  137. that.getReviewerObj(function (res) {
  138. if (res != data.id) {
  139. that.colseText();
  140. dd.setStorage({
  141. key: 'isShowMessage',
  142. data: data.id,
  143. });
  144. }
  145. })
  146. })
  147. },
  148. setMenuList(str) {
  149. var arr = [];
  150. that.data.menuList.forEach(item => {
  151. if (item.code.indexOf(str) >= 0) {
  152. arr.push(item)
  153. }
  154. })
  155. that.setData({
  156. menuList: arr
  157. })
  158. },
  159. colseText() {
  160. this.setData({ isUpdate: !this.data.isUpdate })
  161. },
  162. showText() {
  163. this.setData({ isBh: !this.data.isBh })
  164. },
  165. openViewRanking(e) {
  166. var item = e.target.dataset.item;
  167. var url = '';
  168. if (item.type == 'normal') {
  169. url = '../../statistics/sectionRanking/sectionRanking';
  170. } else if (item.type == 'all') {
  171. url = '../../statistics/B_ranking/B_ranking';
  172. } else {
  173. url = '../../statistics/C_ranking/C_ranking?id=' + item.target_id + '&name=' + item.group_name + '&date_interval=' + item.date_interval;
  174. }
  175. dd.navigateTo({
  176. url: url
  177. })
  178. },
  179. //跳转
  180. openView(e) {
  181. var index = e.target.dataset.index - 1;
  182. var urls;
  183. if (e.target.dataset.item) {
  184. urls = [
  185. { url: '../statistics_B/statistics_B', query: '' },
  186. { url: '../statistics_A/statistics_A', query: '' },
  187. { url: '../jk_B/jk_B', query: 'type=B' },
  188. { url: '../jk_B/jk_B', query: 'type=A' },
  189. { url: '../apply/apply', query: '' },
  190. { url: '../my_approve/my_approve', query: '' },
  191. { url: '../prize_buckle/prize_buckle', query: '' },
  192. { url: '../../statistics/prizeBuckleDetail/prizeBuckleDetail', query: 'id=' + e.target.dataset.item.id },
  193. { url: '../../statistics/integralEvent/integralEvent', query: '' },
  194. { url: '../../statistics/userRamking/userRamking', query: '' },
  195. { url: '../../statistics/glz_execute/glz_execute', query: '' },
  196. ];
  197. } else {
  198. urls = [
  199. { url: '../statistics_B/statistics_B', query: '' },
  200. { url: '../statistics_A/statistics_A', query: '' },
  201. { url: '../jk_B/jk_B', query: 'type=B' },
  202. { url: '../jk_B/jk_B', query: 'type=A' },
  203. { url: '../apply/apply', query: '' },
  204. { url: '../my_approve/my_approve', query: '' },
  205. { url: '../prize_buckle/prize_buckle', query: '' },
  206. { url: '../../statistics/prizeBuckleDetail/prizeBuckleDetail', query: '' },
  207. { url: '../../statistics/integralEvent/integralEvent', query: '' },
  208. { url: '../../statistics/userRamking/userRamking', query: '' },
  209. { url: '../../statistics/glz_execute/glz_execute', query: '' },
  210. ];
  211. }
  212. dd.navigateTo({
  213. url: urls[index].url + '?' + urls[index].query
  214. })
  215. },
  216. //则线图
  217. onInitChart(F2, config) {
  218. chart1 = new F2.Chart(config);
  219. chart1.source(that.data.chartData, {
  220. date: { tickCount: 4 }
  221. });
  222. chart1.tooltip({
  223. showCrosshairs: true,
  224. showItemMarker: true,
  225. onShow: function onShow(ev) {
  226. const items = ev.items;
  227. items[0].name = "月份:" + items[0].origin.date;
  228. items[0].value = "分值:" + items[0].value;
  229. }
  230. });
  231. chart1.axis('date', {
  232. label: function label(text, index, total) {
  233. const textCfg = {};
  234. if (index === 0) {
  235. textCfg.textAlign = 'left';
  236. } else if (index === total - 1) {
  237. textCfg.textAlign = 'right';
  238. }
  239. return textCfg;
  240. }
  241. });
  242. chart1.line().position('date*value');
  243. chart1.point().position('date*value').style({
  244. stroke: '#fff',
  245. lineWidth: 1
  246. });
  247. chart1.render();
  248. return chart1;
  249. },
  250. //饼型图
  251. onInitChart2(F2, config) {
  252. chart2 = new F2.Chart(config);
  253. chart2.source(that.data.pieData, {
  254. percent: {
  255. formatter: function formatter(val) {
  256. return val * 100 + '%';
  257. }
  258. }
  259. });
  260. chart2.legend({
  261. position: 'right',
  262. itemFormatter: function itemFormatter(val, index) {
  263. var str = '';
  264. that.data.pieData.forEach(item => {
  265. if (item.name == val) {
  266. str = val + ' ' + item.point + '分';
  267. }
  268. })
  269. return str;
  270. }
  271. });
  272. chart2.tooltip(false);
  273. chart2.coord('polar', {
  274. transposed: true,
  275. radius: 0.85
  276. });
  277. chart2.axis(false);
  278. chart2.interval()
  279. .position('a*percent')
  280. .color('name', ['#1890FF', '#13C2C2', '#2FC25B', '#FACC14', '#F04864', '#8543E0'])
  281. .adjust('stack')
  282. .style({ lineWidth: 1, stroke: '#fff', lineJoin: 'round', lineCap: 'round' }).animate({
  283. appear: { duration: 1200, easing: 'bounceOut' }
  284. });
  285. chart2.render();
  286. // 注意:需要把chart return 出来
  287. // that.getLsit();
  288. return chart2;
  289. },
  290. //柱形图
  291. onInitChart3(F2, config) {
  292. chart3 = new F2.Chart(config);
  293. chart3.source(that.data.setECharts, {
  294. date: { tickCount: 5 }
  295. });
  296. chart3.axis('field', {
  297. grid: {
  298. lineDash: null,
  299. stroke: '#e8e8e8',
  300. lineWidth: 1
  301. }
  302. });
  303. chart3.legend(false);
  304. chart3.interval().position('name*val').color('type', (type) => { // 通过回调函数
  305. if (type === '奖分') {
  306. return 'l(90) 0:#4ECFFF 1:#26A2FF';
  307. }
  308. return 'l(90) 0:#F8C748 1:#F2A640';
  309. }).adjust({
  310. type: 'dodge',
  311. marginRatio: 0.05 // 设置分组间柱子的间距
  312. });
  313. chart3.render()
  314. return chart3;
  315. },
  316. //获取统计数据
  317. getLsit() {
  318. var date1 = new Date();
  319. var date2 = new Date(date1);
  320. date2.setDate(date1.getDate() - 30);
  321. var start_date = date2.getFullYear() + "-" + (date2.getMonth() + 1) + "-" + date2.getDate();
  322. var incident = app.$get2("api/integral/statistics/b", { employee_id: 0, start_date: start_date, end_date: app.globalData.day, show_type: '1' });
  323. Promise.all([incident]).then(resArr => {
  324. if (resArr[0].data.code == 1) {
  325. const { b, chart, good, bad } = resArr[0].data.data
  326. const points = chart.reward.map((rewardItem, index) => {
  327. return { date: rewardItem.date, value: rewardItem.point - (chart.deduction[index].point || 0) }
  328. })
  329. chart1.changeData(points);
  330. that.setData({
  331. data_b: b,
  332. data_good: good,
  333. data_bad: bad,
  334. });
  335. }
  336. }).catch(e => {
  337. console.error(e)
  338. })
  339. },
  340. //获取个人统计
  341. getUserData() {
  342. var http1 = app.$get2("api/integral/statistics", { employee_id: 0, month: app.globalData.month })
  343. var http2 = app.$get2("api/integral/statistics/integral", {
  344. month: app.globalData.month,
  345. page: 1,
  346. page_size: 5,
  347. employee_ids: app.globalData.isCreator ? '' : app.globalData.userData.id
  348. })
  349. var http3 = app.$get2("api/integral/review/list", { type: 'waiting', source_type: 0, page: 1, pt_id: 0 })
  350. var ranking = app.$get('api/integral/statistics/ranking/list', { page: 1, page_size: 5 })// 获取排行榜
  351. var task = app.$get('api/integral/statistics/task/pie', { month: app.globalData.month })// 管理者奖扣任务柱状图
  352. var work = app.$get('api/integral/work/list', { status: 'running', page: 1, pt_id: 0, source_type: 0 })// 管理者奖扣任务柱状图
  353. Promise.all([http1, http2, http3, ranking, task, work]).then(function (values) {
  354. if (values[0]) {
  355. let data = values[0].data.data;
  356. var task = data.task;
  357. dd.setNavigationBar({ title: data.name });
  358. var ratio = task.reward.point === 0 || task.deduction.point === 0 ? '-' : `${task.ratio.ratio}:1`
  359. var target_ratio = task.ratio.target_ratio <= 0 ? '0:0' : `${task.ratio.target_ratio}:1`
  360. data.ratio = {
  361. ratio: ratio,
  362. target_ratio: target_ratio
  363. }
  364. that.getLsit();
  365. that.setData({
  366. userData: data
  367. })
  368. }
  369. if (values[1]) {
  370. let data = values[1].data.data.list;
  371. data.map((item) => {
  372. item.ptObj = app.getTypesItem(item.pt_id);
  373. })
  374. that.setData({
  375. incidentLsit: data,
  376. incidentLsitTotal: values[1].data.data.total
  377. })
  378. }
  379. if (values[2]) {
  380. let data = values[2].data.data;
  381. that.setData({
  382. total: data.total
  383. })
  384. }
  385. if (values[3]) {
  386. that.setData({
  387. rankingList: values[3].data.data.list,
  388. rankingTotal: values[3].data.data.total
  389. })
  390. }
  391. if (values[4]) {
  392. if (that.data.isAdministrator) {
  393. var data = values[4].data.data.list
  394. if (data.length > 5) {
  395. data.pop()
  396. }
  397. that.setData({
  398. pieTotal: values[4].data.data.total
  399. })
  400. if (that.data.pieTotal != 0) {
  401. var employees = [];
  402. data.forEach((item) => {
  403. var obj = [{
  404. type: '奖分',
  405. name: item.employee_name,
  406. val: item.reward
  407. }, {
  408. type: '扣分',
  409. name: item.employee_name,
  410. val: item.deduction
  411. }]
  412. employees.push(...obj)
  413. })
  414. chart3.changeData(employees);
  415. }
  416. }
  417. }
  418. if (values[5]) {
  419. let data = values[5].data.data;
  420. that.setData({
  421. workTotal: data.total
  422. })
  423. }
  424. })
  425. },
  426. //获取积分事件
  427. getIncidentLsit() {
  428. app.$get("api/integral/statistics/integral", { month: app.globalData.month, page: 1, page_size: 5, employee_ids: app.globalData.userData.id }).then((res) => {
  429. var data = res.data.data.list;
  430. data.map((item) => {
  431. item.ptObj = app.getTypesItem(item.pt_id);
  432. })
  433. this.setData({
  434. incidentLsit: data,
  435. incidentLsitTotal: res.data.data.total
  436. })
  437. }, (err) => { })
  438. },
  439. });