index.js 15 KB

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