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