import * as React from 'react'; import './index.scss'; import AddedList from '../Common/AddedList' import DataSource from './dataSource'; import { isOpenApp, getBSGlobal } from '&/helper' import ShowName from './showName' import DataType from './dataType' import JumpPage from './jumpPage' import DataColor from './dataColor' import { getCloudApiUrl } from '&/helper/getCloudApi.js' interface Props { data:any, update:Function } interface app{ appId: number; } interface digitalBoardListSetting{ type:string } const options = ['待办','','','本周准时上班率', '本周计划完成率', '本周过期计划', '本周完成任务', '团队日报(昨日)', '团队日报(本周)', '团队签到(今日)', '团队签到(本周)']; const nameMap = ['todo','employeeAvgWork','vacationRemainDetail','signinWeekTimely', 'getMyPlanTaskRate','getMyExpiredPlanTask','getMyFinishedPlanTask','getTeamPlanDailyYestoday', 'getTeamPlanDaily','getTeamSigninYestoday','getTeamSignin'] const color = [ '#ff7360', '#ff9500', '#36b336', '#8a92ff', '#349af6']; const URI = ['widget/todocount','','', 'widget/signinweektimely', 'widget/getmyplantaskrate', 'widget/getmyexpiredplantask', 'widget/getmyfinishedplantask', 'widget/getteamplandaily?dataType=0', 'widget/getteamplandaily?dataType=1', 'widget/getteamsignin?dataType=0', 'widget/getteamsignin?dataType=1'] const pageUrls = ['', '', ''] const defaultColorId = [0,1,2,4,4,4,4,4,4,4,4]; const defaultDataTypeId = [0,0,0,2,2,1,1,1,1,1,1]; const defaultState = { popShow:false, sourceId:0, nameValue:'', dataTypeId:0, colorId:0 } export default class DigitalBoardListSetting extends React.Component { pageUrlKaoQin = '' + getCloudApiUrl('/attendance/#/indexPage?metaObjName=Attendance.AttendanceStatistics&app=Attendance&navViewName=Attendance.AttendanceDataRecordWapNavView&mtitle=考勤') pageUrlNianJia = '' + getCloudApiUrl('/attendance/#/basePage?pageType=RemainVacationPage&bgColorTransparent=true&mtitle=年假余额&bgColor=38C1CE') state = defaultState componentWillMount(){ if(isOpenApp(909)) {//开通假勤业务的才有这俩GET options[1] = '异常考勤'; options[2] = '年假余额'; URI[1] = 'proxy/attendance/employeeAvgWork?date=""'; URI[2] = 'proxy/attendance/vacationRemainDetail'; pageUrls[1] = this.pageUrlKaoQin; pageUrls[2] = this.pageUrlNianJia; } } upLinkItem = (index:number) => { const { update, data } = this.props; const temp = data[index]; if (index == 0 && data[1]) { data[0] = data[1] data[1] = temp; update(data) } else if(index == 0 && !data[1]){ } else { data[index] = data[index - 1] data[index - 1] = temp; update(data) } } deleteLinkItem = (index:number) =>{ const { data } = this.props; const { update } = this.props; if(data.length > 1){ // 最少1条 data.splice(index, 1); update(data) } } addNewLink = () => { // const tempState = defaultState; // tempState.popShow = true // this.setState(tempState) this.setState({popShow:true}) } returnState = () => { this.setState(defaultState); } noAddNewLink = () => { this.returnState() } addNewLinkSure = () => { //这里组合数据,并update const { sourceId, nameValue, colorId, dataTypeId } = this.state; let { update } = this.props; let trueData = this.getData(); if( trueData.length > 2 ){ //不超过3条 } else { const api = URI[sourceId] //--api const type = nameMap[sourceId]; const name = options[sourceId]; const names = nameValue.replace(' ','') == '' ? options[sourceId].slice(0,6) : nameValue.slice(0,6); //--names const pageUrl = pageUrls[sourceId] || ''; //-- 跳转页面 const dataType = dataTypeId; //--数据形式 const dataColor = color[colorId] //--dataColor const state = 0; const value = 0 const addedData = { api, names, type, pageUrl, name, dataType, dataColor, state, value } trueData.push(addedData) update(trueData); } this.returnState() } dataSourceChange = (index:number)=>{ this.setState({ sourceId: index, colorId: defaultColorId[index], dataTypeId: defaultDataTypeId[index] })} nameChange = (val:string) => { this.setState({nameValue:val}) } onCompositionEnd=()=>{ const {nameValue} = this.state; this.setState({nameValue:nameValue.slice(0,6)}) } changeStyle = (index:number) => { this.setState({dataTypeId:index}) } changeColor = (index: number) => { this.setState({colorId: index}) } getData = () => { const {data} = this.props; const apps = getBSGlobal('apps'); let jiaqin = apps.filter((a:app,k:number)=>a.appId == 909); let trueData = data; if(jiaqin.length < 1 && data){ //没有开通假勤 trueData = data.filter((d:digitalBoardListSetting,k:number)=>{ if(d.type == 'employeeAvgWork' || d.type == 'vacationRemainDetail'){ return ; }else{ return d; } }) } return trueData||[]; } render(){ const { popShow, sourceId, nameValue, dataTypeId, colorId } = this.state; let trueData = this.getData() return (
2 } changeStyle={this.changeStyle} />
2 ? 'none' : 'inline-block' }} onClick={ this.addNewLink } href='javaScript:;'> +新增
取消 确定
) } }