123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613 |
- var app = getApp();
- var that;
- var chart1;
- var chart2;
- var chart3;
- var AParse = require('../../../Component/aParse/aParse.js');
- import 'dingtalk-jsapi/entry/union';
- import { setCache, getCache } from '../../../utils/util'
- import { contactAdminToUseApp } from 'dingtalk-design-libs';
- Page({
- data: {
- headDayBs: {},
- userData: {},
- isBh: false,
- chartData: [],//折线图数据
- pieData: [1],//饼型图数据
- isAdministrator: app.globalData.isAdministrator,//是否管理员角色
- rankingTotal: 0,
- rankingList: [],
- getRole_four: app.globalData.isCreator,//是否系统管理员
- setECharts: [],//柱形图数据
- pieTotal: 1,
- total: '',
- menuList: [
- { name: '审批', imgUrl: '../../../image/sp.png', url: '../my_approve/my_approve', code: 'creator admin' },
- { name: '任务', imgUrl: '../../../image/a7.png', url: '../../statistics/my_task/my_task', code: 'admin employee' },
- { name: '复核', imgUrl: '../../../image/fuhe.png', url: '../review/review', code: 'creator admin' },
- { name: '奖扣B分', imgUrl: '../../../image/point_entry.png', url: '../jk_B/jk_B?type=B', code: 'creator admin' },
- { name: '指派任务', imgUrl: '../../../image/my_publish.png', url: '../../statistics/assaign/assaign', code: 'creator admin' },
- { name: '申请积分', imgUrl: '../../../image/a_apply.png', url: '../apply/apply', code: 'admin employee' },
- { name: '奖扣A分', imgUrl: '../../../image/a_entry.png', url: '../jk_B/jk_B?type=A', code: 'creator admin' },
- { name: '领任务', imgUrl: '../../../image/task_hall.png', url: '../../statistics/getTask/getTask', code: 'admin employee' },
- { name: '发布悬赏', imgUrl: '../../../image/caback6.png', url: '../../statistics/offerAreward/offerAreward', code: 'creator admin' },
- { name: '发放奖票', imgUrl: '../../../image/add_ticket.png', url: '../../statistics/grant/grant', code: 'creator admin' },
- { name: '全部', imgUrl: '../../../image/all2.png', url: 'all', code: 'creator admin employee' },
- ],
- isUpdate: false,
- title: '',//系统消息标题
- textId: '',//系统消息ID
- isSubject: false,//判断是否是个人版进入
- mainCorpId: '',//如果是个人版,这个企业ID是登录者所在的企业ID,不是钉钉那边提供的隐藏企业ID
- noticeTitle:'',
- isGz:false,
- islog:true,
- announcementList:[],
- isShowYy:false,
- isShowAn:true,
- },
- onLoad() {
- that = this;
- chart1, chart2, chart3 = '';
- },
- onShow() {
- if (app.globalData.userData) {
- dd.setNavigationBar({ title: app.globalData.userData.name });
- that.getUserData();
- that.getGg();
- that.getNotice();
- that.opneWebSocket();
- let isShowYy=false;
- app.globalData.userData.employee_detail.role_list.forEach(item=>{
- if(item.name=='admin'||item.name=='creator'|| item.name == 'point_manager'){
- isShowYy=true;
- }
- })
- that.setData({
- isAdministrator: app.globalData.isAdministrator,
- getRole_four: app.globalData.isCreator,
- isSubject: app.globalData.userData.is_personal == 1 ? true : false,
- mainCorpId: app.globalData.userData.main_corp_id,
- isShowYy:isShowYy,
- isShowAn:getCache('isShowAn')? false:true,
- })
- if(that.data.isShowYy&&that.data.isShowAn){
- that.getAnnouncement();
- }
- if(!getCache('init_rule_check')){
- app.globalData.userData.init_rule_check? '':that.setData({ isGz: true})
- }
- if (app.globalData.isCreator) {
- that.setMenuList("creator");
- } else if (app.globalData.isAdministrator) {
- that.setMenuList("admin");
- } else if (!app.globalData.isCreator && !app.globalData.isAdministrator) {
- that.setMenuList("employee");
- }
- } else {
- app.login(app.globalData.corpId,function (is) {
- if (is) {
- dd.setNavigationBar({ title: app.globalData.userData.name });
- if (app.globalData.isCreator) {
- that.setMenuList("creator");
- } else if (app.globalData.isAdministrator) {
- that.setMenuList("admin");
- } else if (!app.globalData.isCreator && !app.globalData.isAdministrator) {
- that.setMenuList("employee");
- }
- that.getUserData();
- that.getGg();
- that.getNotice();
- that.opneWebSocket();
- if(!getCache('init_rule_check')){
- app.globalData.userData.init_rule_check? '':that.setData({ isGz: true})
- }
- let isShowYy=false;
- app.globalData.userData.employee_detail.role_list.forEach(item=>{
- if(item.name=='admin'||item.name=='creator'|| item.name == 'point_manager'){
- isShowYy=true;
- }
- })
- that.setData({
- isAdministrator: app.globalData.isAdministrator,
- getRole_four: app.globalData.isCreator,
- isSubject: app.globalData.userData.is_personal == 1 ? true : false,
- mainCorpId: app.globalData.userData.main_corp_id,
- isShowYy:isShowYy,
- isShowAn:getCache('isShowAn')? false:true,
- })
- if(that.data.isShowYy&&that.data.isShowAn){
- that.getAnnouncement();
- }
- } else {
- dd.reLaunch({
- url: '../../noJurisdiction/noJurisdiction'
- })
- }
- },function(){},true)
- }
- },
- closeAn(){
- setCache('isShowAn',true);
- this.setData({
- isShowYy:false,
- })
- },
- openaN(e){
- var index = e.target.dataset.index;
- dd.navigateTo({
- url: '../noticeDetailTow/noticeDetailTow?id=' + this.data.announcementList[index].id+'&index='+index
- })
- },
- getAnnouncement(){
- app.$get("api/announcement/list",{type:3}).then((res) => {
- let list=res.data.data.list;
- that.setData({ announcementList:list})
- })
- },
- gettrees(fn) {
- app.$get2("api/integral/rule/trees", {cycle_type: 3 }).then((res)=>{
- var rule_tree = res.data.data.rule_tree
- if(rule_tree.length==0&&app.globalData.isCreator){
- fn(false)
- }else{
- fn(true)
- }
- })
- },
- opneWebSocket() {
- let data={type:"es_info",recorder_id:app.globalData.userData.id,month:app.globalData.month};
- app.globalData.socketApi.sendData(data, (res) => {
- if (res.code == 1&&res.type=='es_info') {
- let data = res.result;
- var task = data.task;
- var ratio = task.ratio.enable== 0 ? '-' : `${task.ratio.reward_ratio}:1`
- var target_ratio = task.ratio.target <= 0 ? '0:0' : `${task.ratio.target}:1`
- data.ratio = {
- ratio: ratio,
- target_ratio: target_ratio
- }
- that.getLsit();
- that.setData({
- userData: data
- })
- app.globalData.socketApi.closewebsocket();
- }
- }, true);
- },
- openWs(){
- if(!that.data.islog){
- return false;
- }
- that.setData({
- islog:false
- })
- app.globalData.socketApi.sendData({type:'init_rule'}, function(e){
- that.setData({islog:true})
- setCache('init_rule_check',true)
- if (e.type == 'init_rule') {
- if(e.code==1&&e.result.done){
- that.setData({ isGz:false})
- app.globalData.showToast('已导入');
- app.globalData.socketApi.closewebsocket();
- }else{
- // app.globalData.showToast(e.msg);
- }
- }
- });
- },
- openWs2(){
- app.$post("api/integral/employee/init_rule_notice").then((res) => {
- app.globalData.showToast('已发送通知');
- setCache('init_rule_check',true)
- that.setData({ isGz:false})
- }, (err) => { })
- },
- openGly() {
- contactAdminToUseApp({ id: '55493', corpId: that.data.mainCorpId })
- .catch((err) => {
- // 入参不正确,或者遇到技术异常时才会进入这个链路
- console.error(err);
- })
- },
- openUrl(e) {
- var url = e.target.dataset.url;
- if (url == 'all') {
- dd.switchTab({
- url: '../../statistics/index/index'
- })
- return
- }
- dd.navigateTo({
- url: url
- })
- },
- openUrl2() {
- dd.navigateTo({
- url: '../noticeDetail/noticeDetail?id=' + that.data.noticeId
- })
- },
- openText() {
- that.colseText();
- dd.navigateTo({
- url: '../../deploy/upgradeDetail/upgradeDetail?id=' + that.data.textId
- })
- },
- //获取缓存的公告
- getReviewerObj(fuc) {
- dd.getStorage({
- key: 'isShowMessage',
- success: function (res) {
- if (res.data) {
- fuc(res.data);
- } else {
- fuc({});
- }
- }
- });
- },
- // 获取公告
- getNotice() {
- app.$get("api/information/index", { page: 1, page_size: 1 }).then((res) => {
- let data= res.data.data;
- that.setData({
- noticeTitle: data[0]? data[0].name:'',
- noticeId: data[0]? data[0].id:'',
- });
- })
- },
- // 获取公告
- getGg() {
- if (that.data.title) {
- return
- }
- app.$get("api/announcement/list", { page: 1, page_size: 1 }).then((res) => {
- var data = res.data.data.list[0];
- AParse.aParse('article', 'html', data.focus, that, 5);
- that.setData({
- title: data.title,
- textId: data.id
- });
- that.getReviewerObj(function (res) {
- if (res != data.id) {
- that.colseText();
- dd.setStorage({
- key: 'isShowMessage',
- data: data.id,
- });
- }
- })
- })
- },
- setMenuList(str) {
- var arr = [];
- that.data.menuList.forEach(item => {
- if(item.name=='复核'){
- app.globalData.userData.employee_detail.role_list.forEach(e=>{
- if(e.name=='admin'||e.name=='creator'|| e.name == 'point_manager'){
- arr.push(item)
- }
- })
- }else{
- if (item.code.indexOf(str) >= 0) {
- arr.push(item)
- }
- }
- })
- that.setData({
- menuList: arr
- })
- },
- colseText() {
- this.setData({ isUpdate: !this.data.isUpdate })
- },
- showText() {
- this.setData({ isBh: !this.data.isBh })
- },
- openViewRanking(e) {
- var item = e.target.dataset.item;
- var url = '';
- if (item.type == 'normal') {
- url = '../../statistics/sectionRanking/sectionRanking';
- } else if (item.type == 'all') {
- url = '../../statistics/B_ranking/B_ranking';
- } else {
- url = '../../statistics/C_ranking/C_ranking?id=' + item.target_id + '&name=' + item.group_name + '&date_interval=' + item.date_interval;
- }
- dd.navigateTo({
- url: url
- })
- },
- //跳转
- openView(e) {
- var index = e.target.dataset.index - 1;
- var urls;
- if (e.target.dataset.item) {
- urls = [
- { url: '../statistics_B/statistics_B', query: '' },
- { url: '../statistics_A/statistics_A', query: '' },
- { url: '../jk_B/jk_B', query: 'type=B' },
- { url: '../jk_B/jk_B', query: 'type=A' },
- { url: '../apply/apply', query: '' },
- { url: '../my_approve/my_approve', query: '' },
- { url: '../prize_buckle/prize_buckle', query: '' },
- { url: '../../statistics/prizeBuckleDetail/prizeBuckleDetail', query: 'id=' + e.target.dataset.item.id },
- { url: '../../statistics/integralEvent/integralEvent', query: '' },
- { url: '../../statistics/userRamking/userRamking', query: '' },
- { url: '../../statistics/glz_execute/glz_execute', query: '' },
- ];
- } else {
- urls = [
- { url: '../statistics_B/statistics_B', query: '' },
- { url: '../statistics_A/statistics_A', query: '' },
- { url: '../jk_B/jk_B', query: 'type=B' },
- { url: '../jk_B/jk_B', query: 'type=A' },
- { url: '../apply/apply', query: '' },
- { url: '../my_approve/my_approve', query: '' },
- { url: '../prize_buckle/prize_buckle', query: '' },
- { url: '../../statistics/prizeBuckleDetail/prizeBuckleDetail', query: '' },
- { url: '../../statistics/integralEvent/integralEvent', query: '' },
- { url: '../../statistics/userRamking/userRamking', query: '' },
- { url: '../../statistics/glz_execute/glz_execute', query: '' },
- ];
- }
- dd.navigateTo({
- url: urls[index].url + '?' + urls[index].query
- })
- },
- //则线图
- onInitChart(F2, config) {
- chart1 = new F2.Chart(config);
- chart1.source(that.data.chartData, {
- date: { tickCount: 4 }
- });
- chart1.tooltip({
- showCrosshairs: true,
- showItemMarker: true,
- onShow: function onShow(ev) {
- const items = ev.items;
- items[0].name = "月份:" + items[0].origin.date;
- items[0].value = "分值:" + items[0].value;
- }
- });
- chart1.axis('date', {
- label: function label(text, index, total) {
- const textCfg = {};
- if (index === 0) {
- textCfg.textAlign = 'left';
- } else if (index === total - 1) {
- textCfg.textAlign = 'right';
- }
- return textCfg;
- }
- });
- chart1.line().position('date*value');
- chart1.point().position('date*value').style({
- stroke: '#fff',
- lineWidth: 1
- });
- chart1.render();
- return chart1;
- },
- //饼型图
- onInitChart2(F2, config) {
- chart2 = new F2.Chart(config);
- chart2.source(that.data.pieData, {
- percent: {
- formatter: function formatter(val) {
- return val * 100 + '%';
- }
- }
- });
- chart2.legend({
- position: 'right',
- itemFormatter: function itemFormatter(val, index) {
- var str = '';
- that.data.pieData.forEach(item => {
- if (item.name == val) {
- str = val + ' ' + item.point + '分';
- }
- })
- return str;
- }
- });
- chart2.tooltip(false);
- chart2.coord('polar', {
- transposed: true,
- radius: 0.85
- });
- chart2.axis(false);
- chart2.interval()
- .position('a*percent')
- .color('name', ['#1890FF', '#13C2C2', '#2FC25B', '#FACC14', '#F04864', '#8543E0'])
- .adjust('stack')
- .style({ lineWidth: 1, stroke: '#fff', lineJoin: 'round', lineCap: 'round' }).animate({
- appear: { duration: 1200, easing: 'bounceOut' }
- });
- chart2.render();
- // 注意:需要把chart return 出来
- // that.getLsit();
- return chart2;
- },
- //柱形图
- onInitChart3(F2, config) {
- chart3 = new F2.Chart(config);
- chart3.source(that.data.setECharts, {
- date: { tickCount: 5 }
- });
- chart3.axis('field', {
- grid: {
- lineDash: null,
- stroke: '#e8e8e8',
- lineWidth: 1
- }
- });
- chart3.legend(false);
- chart3.interval().position('name*val').color('type', (type) => { // 通过回调函数
- if (type === '奖分') {
- return 'l(90) 0:#4ECFFF 1:#26A2FF';
- }
- return 'l(90) 0:#F8C748 1:#F2A640';
- }).adjust({
- type: 'dodge',
- marginRatio: 0.05 // 设置分组间柱子的间距
- });
- chart3.render()
- return chart3;
- },
- //获取统计数据
- getLsit() {
- var date1 = new Date();
- var date2 = new Date(date1);
- date2.setDate(date1.getDate() - 30);
- var start_date = date2.getFullYear() + "-" + (date2.getMonth() + 1) + "-" + date2.getDate();
- var incident = app.$get2("api/integral/statistics/b", { employee_id: 0, start_date: start_date, end_date: app.globalData.day, show_type: '1' });
- Promise.all([incident]).then(resArr => {
- if (resArr[0].data.code == 1) {
- const { b, chart, good, bad } = resArr[0].data.data
- const points = chart.reward.map((rewardItem, index) => {
- return { date: rewardItem.date, value: rewardItem.point - (chart.deduction[index].point || 0) }
- })
- chart1.changeData(points);
- that.setData({
- data_b: b,
- data_good: good,
- data_bad: bad,
- });
- }
- }).catch(e => {
- console.error(e)
- })
- },
- //获取个人统计
- getUserData() {
- var http1 = app.$get2("api/integral/statistics", { employee_id: 0, month: app.globalData.month })
- var http2 = app.$get2("api/integral/statistics/integral", {
- month: app.globalData.month,
- page: 1,
- page_size: 5,
- order_key:'update_time',
- employee_ids: app.globalData.isCreator ? '' : app.globalData.userData.id
- })
- var http3 = app.$get2("api/integral/review/list", { type: 'waiting', source_type: 0, page: 1, pt_id: 0 })
- var ranking = app.$get('api/integral/statistics/ranking/list', { page: 1, page_size: 5 })// 获取排行榜
- var task = app.$get('api/integral/statistics/task/pie', { month: app.globalData.month })// 管理者奖扣任务柱状图
- var work = app.$get('api/integral/work/list', { status: 'running', page: 1, pt_id: 0, source_type: 0 })// 管理者奖扣任务柱状图
- var headDayBs = app.$get2("api/integral/statistics", { employee_id: app.globalData.userData.id, day: app.globalData.day },'application/vnd.test.v2+json')//获取个人统计-当天B分 - V2
- var config = app.$get('api/integral/site/config',{})// 系统配置
- Promise.all([http1, http2, http3, ranking, task, work, headDayBs,config]).then(function (values) {
- if (values[0]) {
- // let data = values[0].data.data;
- // var task = data.task;
- // var ratio = task.reward.point === 0 || task.deduction.point === 0 ? '-' : `${task.ratio.ratio}:1`
- // var target_ratio = task.ratio.target_ratio <= 0 ? '0:0' : `${task.ratio.target_ratio}:1`
- // data.ratio = {
- // ratio: ratio,
- // target_ratio: target_ratio
- // }
- // that.getLsit();
- // that.setData({
- // userData: data
- // })
- }
- if (values[1]) {
- let data = values[1].data.data.list;
- data.map((item) => {
- item.ptObj = app.getTypesItem(item.pt_id);
- })
- that.setData({
- incidentLsit: data,
- incidentLsitTotal: values[1].data.data.total
- })
- }
- if (values[2]) {
- let data = values[2].data.data;
- that.setData({
- total: data.total
- })
- }
- if (values[3]) {
- that.setData({
- rankingList: values[3].data.data.list,
- rankingTotal: values[3].data.data.total
- })
- }
- if (values[4]) {
- if (that.data.isAdministrator) {
- var data = values[4].data.data.list
- if (data.length > 5) {
- data.pop()
- }
- that.setData({
- pieTotal: values[4].data.data.total
- })
- if (that.data.pieTotal != 0) {
- var employees = [];
- data.forEach((item) => {
- var obj = [{
- type: '奖分',
- name: item.employee_name,
- val: item.reward
- }, {
- type: '扣分',
- name: item.employee_name,
- val: item.deduction
- }]
- employees.push(...obj)
- })
- // chart3.changeData(employees);
- }
- }
- }
- if (values[5]) {
- let data = values[5].data.data;
- that.setData({
- workTotal: data.total
- })
- }
- if(values[6]){
- let data = values[6].data.data;
- that.setData({
- headDayBs:data
- })
- }
- if(values[7]){
- let data = values[7].data.data;
- app.globalData.config=data;
- let menuList=JSON.parse(JSON.stringify( that.data.menuList))
- if(data.shop_status==1){
- if(menuList[menuList.length-2].name!='福利兑换'){
- menuList.splice(menuList.length-1,0, { name: '福利兑换', imgUrl: '../../../image/fl.png', url: '../../exchange/exchange/exchange', code: 'creator admin employee' })
- that.setData({
- menuList:menuList
- })
- }
- }else{
- if(menuList[menuList.length-2].name=='福利兑换'){
- menuList.splice(menuList.length-2,1)
- that.setData({
- menuList:menuList
- })
- }
- }
- }
- })
- },
- //获取积分事件
- getIncidentLsit() {
- app.$get("api/integral/statistics/integral", { month: app.globalData.month, page: 1, page_size: 5, employee_ids: app.globalData.userData.id }).then((res) => {
- var data = res.data.data.list;
- data.map((item) => {
- item.ptObj = app.getTypesItem(item.pt_id);
- })
- this.setData({
- incidentLsit: data,
- incidentLsitTotal: res.data.data.total
- })
- }, (err) => { })
- },
- });
|