index.js 15 KB

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