index.js 20 KB

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