index.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  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 { setCache, getCache } from '../../../utils/util'
  9. import { contactAdminToUseApp } from 'dingtalk-design-libs';
  10. Page({
  11. data: {
  12. headDayBs: {},
  13. userData: {},
  14. isBh: false,
  15. chartData: [],//折线图数据
  16. pieData: [1],//饼型图数据
  17. isAdministrator: app.globalData.isAdministrator,//是否管理员角色
  18. rankingTotal: 0,
  19. rankingList: [],
  20. getRole_four: app.globalData.isCreator,//是否系统管理员
  21. setECharts: [],//柱形图数据
  22. pieTotal: 1,
  23. total: '',
  24. menuList: [
  25. { name: '审批', imgUrl: '../../../image/sp.png', url: '../my_approve/my_approve', 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. isGz:false,
  44. islog:true,
  45. announcementList:[],
  46. isShowYy:false,
  47. isShowAn:true,
  48. },
  49. onLoad() {
  50. that = this;
  51. chart1, chart2, chart3 = '';
  52. },
  53. onShow() {
  54. if (app.globalData.userData) {
  55. dd.setNavigationBar({ title: app.globalData.userData.name });
  56. that.getUserData();
  57. that.getGg();
  58. that.getNotice();
  59. let isShowYy=false;
  60. app.globalData.userData.employee_detail.role_list.forEach(item=>{
  61. if(item.name=='admin'||item.name=='creator'|| item.name == 'point_manager'){
  62. isShowYy=true;
  63. }
  64. })
  65. that.setData({
  66. isAdministrator: app.globalData.isAdministrator,
  67. getRole_four: app.globalData.isCreator,
  68. isSubject: app.globalData.userData.is_personal == 1 ? true : false,
  69. mainCorpId: app.globalData.userData.main_corp_id,
  70. isShowYy:isShowYy,
  71. isShowAn:getCache('isShowAn')? false:true,
  72. })
  73. if(that.data.isShowYy&&that.data.isShowAn){
  74. that.getAnnouncement();
  75. }
  76. if(!getCache('init_rule_check')){
  77. app.globalData.userData.init_rule_check? '':that.setData({ isGz: true})
  78. }
  79. if (app.globalData.isCreator) {
  80. that.setMenuList("creator");
  81. } else if (app.globalData.isAdministrator) {
  82. that.setMenuList("admin");
  83. } else if (!app.globalData.isCreator && !app.globalData.isAdministrator) {
  84. that.setMenuList("employee");
  85. }
  86. } else {
  87. app.login(app.globalData.corpId,function (is) {
  88. if (is) {
  89. dd.setNavigationBar({ title: app.globalData.userData.name });
  90. if (app.globalData.isCreator) {
  91. that.setMenuList("creator");
  92. } else if (app.globalData.isAdministrator) {
  93. that.setMenuList("admin");
  94. } else if (!app.globalData.isCreator && !app.globalData.isAdministrator) {
  95. that.setMenuList("employee");
  96. }
  97. that.getUserData();
  98. that.getGg();
  99. that.getNotice();
  100. if(!getCache('init_rule_check')){
  101. app.globalData.userData.init_rule_check? '':that.setData({ isGz: true})
  102. }
  103. let isShowYy=false;
  104. app.globalData.userData.employee_detail.role_list.forEach(item=>{
  105. if(item.name=='admin'||item.name=='creator'|| item.name == 'point_manager'){
  106. isShowYy=true;
  107. }
  108. })
  109. that.setData({
  110. isAdministrator: app.globalData.isAdministrator,
  111. getRole_four: app.globalData.isCreator,
  112. isSubject: app.globalData.userData.is_personal == 1 ? true : false,
  113. mainCorpId: app.globalData.userData.main_corp_id,
  114. isShowYy:isShowYy,
  115. isShowAn:getCache('isShowAn')? false:true,
  116. })
  117. if(that.data.isShowYy&&that.data.isShowAn){
  118. that.getAnnouncement();
  119. }
  120. } else {
  121. dd.reLaunch({
  122. url: '../../noJurisdiction/noJurisdiction'
  123. })
  124. }
  125. },function(){},true)
  126. }
  127. },
  128. closeAn(){
  129. setCache('isShowAn',true);
  130. this.setData({
  131. isShowYy:false,
  132. })
  133. },
  134. openaN(e){
  135. var index = e.target.dataset.index;
  136. dd.navigateTo({
  137. url: '../noticeDetailTow/noticeDetailTow?id=' + this.data.announcementList[index].id+'&index='+index
  138. })
  139. },
  140. getAnnouncement(){
  141. app.$get("api/announcement/list",{type:3}).then((res) => {
  142. let list=res.data.data.list;
  143. that.setData({ announcementList:list})
  144. })
  145. },
  146. gettrees(fn) {
  147. app.$get2("api/integral/rule/trees", {cycle_type: 3 }).then((res)=>{
  148. var rule_tree = res.data.data.rule_tree
  149. if(rule_tree.length==0&&app.globalData.isCreator){
  150. fn(false)
  151. }else{
  152. fn(true)
  153. }
  154. })
  155. },
  156. openWs(){
  157. if(!that.data.islog){
  158. return false;
  159. }
  160. that.setData({
  161. islog:false
  162. })
  163. app.globalData.socketApi.sendData({type:'init_rule'}, function(e){
  164. that.setData({islog:true})
  165. if (e.type == 'init_rule') {
  166. if(e.code==1&&e.result.done){
  167. that.setData({ isGz:false})
  168. app.globalData.showToast('已导入');
  169. app.globalData.socketApi.closewebsocket();
  170. }else{
  171. // app.globalData.showToast(e.msg);
  172. }
  173. }
  174. });
  175. },
  176. openWs2(){
  177. app.$post("api/integral/employee/init_rule_notice").then((res) => {
  178. app.globalData.showToast('已发送通知');
  179. setCache('init_rule_check',true)
  180. that.setData({ isGz:false})
  181. }, (err) => { })
  182. },
  183. openGly() {
  184. contactAdminToUseApp({ id: '55493', corpId: that.data.mainCorpId })
  185. .catch((err) => {
  186. // 入参不正确,或者遇到技术异常时才会进入这个链路
  187. console.error(err);
  188. })
  189. },
  190. openUrl(e) {
  191. var url = e.target.dataset.url;
  192. if (url == 'all') {
  193. dd.switchTab({
  194. url: '../../statistics/index/index'
  195. })
  196. return
  197. }
  198. dd.navigateTo({
  199. url: url
  200. })
  201. },
  202. openUrl2() {
  203. dd.navigateTo({
  204. url: '../noticeDetail/noticeDetail?id=' + that.data.noticeId
  205. })
  206. },
  207. openText() {
  208. that.colseText();
  209. dd.navigateTo({
  210. url: '../../deploy/upgradeDetail/upgradeDetail?id=' + that.data.textId
  211. })
  212. },
  213. //获取缓存的公告
  214. getReviewerObj(fuc) {
  215. dd.getStorage({
  216. key: 'isShowMessage',
  217. success: function (res) {
  218. if (res.data) {
  219. fuc(res.data);
  220. } else {
  221. fuc({});
  222. }
  223. }
  224. });
  225. },
  226. // 获取公告
  227. getNotice() {
  228. app.$get("api/information/index", { page: 1, page_size: 1 }).then((res) => {
  229. let data= res.data.data;
  230. that.setData({
  231. noticeTitle: data[0]? data[0].name:'',
  232. noticeId: data[0]? data[0].id:'',
  233. });
  234. })
  235. },
  236. // 获取公告
  237. getGg() {
  238. if (that.data.title) {
  239. return
  240. }
  241. app.$get("api/announcement/list", { page: 1, page_size: 1 }).then((res) => {
  242. var data = res.data.data.list[0];
  243. AParse.aParse('article', 'html', data.focus, that, 5);
  244. that.setData({
  245. title: data.title,
  246. textId: data.id
  247. });
  248. that.getReviewerObj(function (res) {
  249. if (res != data.id) {
  250. that.colseText();
  251. dd.setStorage({
  252. key: 'isShowMessage',
  253. data: data.id,
  254. });
  255. }
  256. })
  257. })
  258. },
  259. setMenuList(str) {
  260. var arr = [];
  261. that.data.menuList.forEach(item => {
  262. if (item.code.indexOf(str) >= 0) {
  263. arr.push(item)
  264. }
  265. })
  266. that.setData({
  267. menuList: arr
  268. })
  269. },
  270. colseText() {
  271. this.setData({ isUpdate: !this.data.isUpdate })
  272. },
  273. showText() {
  274. this.setData({ isBh: !this.data.isBh })
  275. },
  276. openViewRanking(e) {
  277. var item = e.target.dataset.item;
  278. var url = '';
  279. if (item.type == 'normal') {
  280. url = '../../statistics/sectionRanking/sectionRanking';
  281. } else if (item.type == 'all') {
  282. url = '../../statistics/B_ranking/B_ranking';
  283. } else {
  284. url = '../../statistics/C_ranking/C_ranking?id=' + item.target_id + '&name=' + item.group_name + '&date_interval=' + item.date_interval;
  285. }
  286. dd.navigateTo({
  287. url: url
  288. })
  289. },
  290. //跳转
  291. openView(e) {
  292. var index = e.target.dataset.index - 1;
  293. var urls;
  294. if (e.target.dataset.item) {
  295. urls = [
  296. { url: '../statistics_B/statistics_B', query: '' },
  297. { url: '../statistics_A/statistics_A', query: '' },
  298. { url: '../jk_B/jk_B', query: 'type=B' },
  299. { url: '../jk_B/jk_B', query: 'type=A' },
  300. { url: '../apply/apply', query: '' },
  301. { url: '../my_approve/my_approve', query: '' },
  302. { url: '../prize_buckle/prize_buckle', query: '' },
  303. { url: '../../statistics/prizeBuckleDetail/prizeBuckleDetail', query: 'id=' + e.target.dataset.item.id },
  304. { url: '../../statistics/integralEvent/integralEvent', query: '' },
  305. { url: '../../statistics/userRamking/userRamking', query: '' },
  306. { url: '../../statistics/glz_execute/glz_execute', query: '' },
  307. ];
  308. } else {
  309. urls = [
  310. { url: '../statistics_B/statistics_B', query: '' },
  311. { url: '../statistics_A/statistics_A', query: '' },
  312. { url: '../jk_B/jk_B', query: 'type=B' },
  313. { url: '../jk_B/jk_B', query: 'type=A' },
  314. { url: '../apply/apply', query: '' },
  315. { url: '../my_approve/my_approve', query: '' },
  316. { url: '../prize_buckle/prize_buckle', query: '' },
  317. { url: '../../statistics/prizeBuckleDetail/prizeBuckleDetail', query: '' },
  318. { url: '../../statistics/integralEvent/integralEvent', query: '' },
  319. { url: '../../statistics/userRamking/userRamking', query: '' },
  320. { url: '../../statistics/glz_execute/glz_execute', query: '' },
  321. ];
  322. }
  323. dd.navigateTo({
  324. url: urls[index].url + '?' + urls[index].query
  325. })
  326. },
  327. //则线图
  328. onInitChart(F2, config) {
  329. chart1 = new F2.Chart(config);
  330. chart1.source(that.data.chartData, {
  331. date: { tickCount: 4 }
  332. });
  333. chart1.tooltip({
  334. showCrosshairs: true,
  335. showItemMarker: true,
  336. onShow: function onShow(ev) {
  337. const items = ev.items;
  338. items[0].name = "月份:" + items[0].origin.date;
  339. items[0].value = "分值:" + items[0].value;
  340. }
  341. });
  342. chart1.axis('date', {
  343. label: function label(text, index, total) {
  344. const textCfg = {};
  345. if (index === 0) {
  346. textCfg.textAlign = 'left';
  347. } else if (index === total - 1) {
  348. textCfg.textAlign = 'right';
  349. }
  350. return textCfg;
  351. }
  352. });
  353. chart1.line().position('date*value');
  354. chart1.point().position('date*value').style({
  355. stroke: '#fff',
  356. lineWidth: 1
  357. });
  358. chart1.render();
  359. return chart1;
  360. },
  361. //饼型图
  362. onInitChart2(F2, config) {
  363. chart2 = new F2.Chart(config);
  364. chart2.source(that.data.pieData, {
  365. percent: {
  366. formatter: function formatter(val) {
  367. return val * 100 + '%';
  368. }
  369. }
  370. });
  371. chart2.legend({
  372. position: 'right',
  373. itemFormatter: function itemFormatter(val, index) {
  374. var str = '';
  375. that.data.pieData.forEach(item => {
  376. if (item.name == val) {
  377. str = val + ' ' + item.point + '分';
  378. }
  379. })
  380. return str;
  381. }
  382. });
  383. chart2.tooltip(false);
  384. chart2.coord('polar', {
  385. transposed: true,
  386. radius: 0.85
  387. });
  388. chart2.axis(false);
  389. chart2.interval()
  390. .position('a*percent')
  391. .color('name', ['#1890FF', '#13C2C2', '#2FC25B', '#FACC14', '#F04864', '#8543E0'])
  392. .adjust('stack')
  393. .style({ lineWidth: 1, stroke: '#fff', lineJoin: 'round', lineCap: 'round' }).animate({
  394. appear: { duration: 1200, easing: 'bounceOut' }
  395. });
  396. chart2.render();
  397. // 注意:需要把chart return 出来
  398. // that.getLsit();
  399. return chart2;
  400. },
  401. //柱形图
  402. onInitChart3(F2, config) {
  403. chart3 = new F2.Chart(config);
  404. chart3.source(that.data.setECharts, {
  405. date: { tickCount: 5 }
  406. });
  407. chart3.axis('field', {
  408. grid: {
  409. lineDash: null,
  410. stroke: '#e8e8e8',
  411. lineWidth: 1
  412. }
  413. });
  414. chart3.legend(false);
  415. chart3.interval().position('name*val').color('type', (type) => { // 通过回调函数
  416. if (type === '奖分') {
  417. return 'l(90) 0:#4ECFFF 1:#26A2FF';
  418. }
  419. return 'l(90) 0:#F8C748 1:#F2A640';
  420. }).adjust({
  421. type: 'dodge',
  422. marginRatio: 0.05 // 设置分组间柱子的间距
  423. });
  424. chart3.render()
  425. return chart3;
  426. },
  427. //获取统计数据
  428. getLsit() {
  429. var date1 = new Date();
  430. var date2 = new Date(date1);
  431. date2.setDate(date1.getDate() - 30);
  432. var start_date = date2.getFullYear() + "-" + (date2.getMonth() + 1) + "-" + date2.getDate();
  433. var incident = app.$get2("api/integral/statistics/b", { employee_id: 0, start_date: start_date, end_date: app.globalData.day, show_type: '1' });
  434. Promise.all([incident]).then(resArr => {
  435. if (resArr[0].data.code == 1) {
  436. const { b, chart, good, bad } = resArr[0].data.data
  437. const points = chart.reward.map((rewardItem, index) => {
  438. return { date: rewardItem.date, value: rewardItem.point - (chart.deduction[index].point || 0) }
  439. })
  440. chart1.changeData(points);
  441. that.setData({
  442. data_b: b,
  443. data_good: good,
  444. data_bad: bad,
  445. });
  446. }
  447. }).catch(e => {
  448. console.error(e)
  449. })
  450. },
  451. //获取个人统计
  452. getUserData() {
  453. var http1 = app.$get2("api/integral/statistics", { employee_id: 0, month: app.globalData.month })
  454. var http2 = app.$get2("api/integral/statistics/integral", {
  455. month: app.globalData.month,
  456. page: 1,
  457. page_size: 5,
  458. order_key:'update_time',
  459. employee_ids: app.globalData.isCreator ? '' : app.globalData.userData.id
  460. })
  461. var http3 = app.$get2("api/integral/review/list", { type: 'waiting', source_type: 0, page: 1, pt_id: 0 })
  462. var ranking = app.$get('api/integral/statistics/ranking/list', { page: 1, page_size: 5 })// 获取排行榜
  463. var task = app.$get('api/integral/statistics/task/pie', { month: app.globalData.month })// 管理者奖扣任务柱状图
  464. var work = app.$get('api/integral/work/list', { status: 'running', page: 1, pt_id: 0, source_type: 0 })// 管理者奖扣任务柱状图
  465. var headDayBs = app.$get2("api/integral/statistics", { employee_id: app.globalData.userData.id, day: app.globalData.day },'application/vnd.test.v2+json')//获取个人统计-当天B分 - V2
  466. var config = app.$get('api/integral/site/config',{})// 系统配置
  467. Promise.all([http1, http2, http3, ranking, task, work, headDayBs,config]).then(function (values) {
  468. if (values[0]) {
  469. let data = values[0].data.data;
  470. var task = data.task;
  471. var ratio = task.reward.point === 0 || task.deduction.point === 0 ? '-' : `${task.ratio.ratio}:1`
  472. var target_ratio = task.ratio.target_ratio <= 0 ? '0:0' : `${task.ratio.target_ratio}:1`
  473. data.ratio = {
  474. ratio: ratio,
  475. target_ratio: target_ratio
  476. }
  477. that.getLsit();
  478. that.setData({
  479. userData: data
  480. })
  481. }
  482. if (values[1]) {
  483. let data = values[1].data.data.list;
  484. data.map((item) => {
  485. item.ptObj = app.getTypesItem(item.pt_id);
  486. })
  487. that.setData({
  488. incidentLsit: data,
  489. incidentLsitTotal: values[1].data.data.total
  490. })
  491. }
  492. if (values[2]) {
  493. let data = values[2].data.data;
  494. that.setData({
  495. total: data.total
  496. })
  497. }
  498. if (values[3]) {
  499. that.setData({
  500. rankingList: values[3].data.data.list,
  501. rankingTotal: values[3].data.data.total
  502. })
  503. }
  504. if (values[4]) {
  505. if (that.data.isAdministrator) {
  506. var data = values[4].data.data.list
  507. if (data.length > 5) {
  508. data.pop()
  509. }
  510. that.setData({
  511. pieTotal: values[4].data.data.total
  512. })
  513. if (that.data.pieTotal != 0) {
  514. var employees = [];
  515. data.forEach((item) => {
  516. var obj = [{
  517. type: '奖分',
  518. name: item.employee_name,
  519. val: item.reward
  520. }, {
  521. type: '扣分',
  522. name: item.employee_name,
  523. val: item.deduction
  524. }]
  525. employees.push(...obj)
  526. })
  527. chart3.changeData(employees);
  528. }
  529. }
  530. }
  531. if (values[5]) {
  532. let data = values[5].data.data;
  533. that.setData({
  534. workTotal: data.total
  535. })
  536. }
  537. if(values[6]){
  538. let data = values[6].data.data;
  539. that.setData({
  540. headDayBs:data
  541. })
  542. }
  543. if(values[7]){
  544. let data = values[7].data.data;
  545. app.globalData.config=data;
  546. let menuList=JSON.parse(JSON.stringify( that.data.menuList))
  547. if(data.shop_status==1){
  548. if(menuList[menuList.length-2].name!='福利兑换'){
  549. menuList.splice(menuList.length-1,0, { name: '福利兑换', imgUrl: '../../../image/fl.png', url: '../../exchange/exchange/exchange', code: 'creator admin employee' })
  550. that.setData({
  551. menuList:menuList
  552. })
  553. }
  554. }else{
  555. if(menuList[menuList.length-2].name=='福利兑换'){
  556. menuList.splice(menuList.length-2,1)
  557. that.setData({
  558. menuList:menuList
  559. })
  560. }
  561. }
  562. }
  563. })
  564. },
  565. //获取积分事件
  566. getIncidentLsit() {
  567. app.$get("api/integral/statistics/integral", { month: app.globalData.month, page: 1, page_size: 5, employee_ids: app.globalData.userData.id }).then((res) => {
  568. var data = res.data.data.list;
  569. data.map((item) => {
  570. item.ptObj = app.getTypesItem(item.pt_id);
  571. })
  572. this.setData({
  573. incidentLsit: data,
  574. incidentLsitTotal: res.data.data.total
  575. })
  576. }, (err) => { })
  577. },
  578. });