index.js 18 KB

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