index.js 16 KB

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