import React from 'react';
import Item from './Item';
import { Input, Tooltip, message, Dropdown, Menu, Row, Col } from 'antd';
import { observer } from 'mobx-react';
import { toJS } from 'mobx';
import { WeaInput, WeaLocaleProvider, WeaProgress, WeaError, WeaBrowser, WeaRangePicker, WeaTextarea } from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import $ from "jquery";
@observer
export default class Column extends React.Component {
isShow = false;//是否依然显示
constructor(props) {
super(props);
const { data } = props;
this.state = {
visible: false,
btnVisible: false,
changeGroupVisible: false,
isEdit: false,
title: data.title,
loading: false,
groupName: "",
baseGroupName:"",
editGroupNameVisible: false,
taskInfo: {
taskName: "",
hrmid: "",
startDate: this.getNowFormatDate(),
endDate: this.getNowFormatDate(),
hrmname: ""
},
userInfo: {
userid: "",
username: "",
usericons: ""
},
groupName: "",
baseGroupName:"",
editGroupNameVisible: false, };
}
componentDidMount() {
//新增Column元素,当前元素渲染到页面上后将元素添加到muuri
const { userInfo, data, boardStore } = this.props;
if (data.id.endsWith('_new')) {
const element = document.getElementById('column_' + data.id);
let column = boardStore.boardGrid.add([element], { index: boardStore.boardGrid._items.length - 2 });
boardStore.initItem(column[0]._element.querySelector('.board-column-content'));
}
this.setState({
taskInfo: {
taskName: "",
hrmid: userInfo.userid,
hrmname: userInfo.username,
startDate: this.getNowFormatDate(),
endDate:this.getNowFormatDate(),
},
userInfo: {
userid: userInfo.userid,
username: userInfo.username,
usericons: userInfo.usericons
},
groupName: data.title,
editGroupNameVisible: false,
});
}
componentDidUpdate() {
if(this.refs.editTitle){
this.refs.editTitle['refs'].inputNormal.refs.input.refs.input.focus();
}
}
render() {
this.isShow = false;
const { data, boardStore } = this.props;
const { canEditBoard, canAddTask, searchType, showLandMark } = boardStore;
const menu = (
);
if(searchType=="stageid"){
return
{ canEditBoard&&this.editGropName(true) }}>
{!this.state.editGroupNameVisible && {data.title}}
{!this.state.editGroupNameVisible && {this.getCountNum().finishNum}}
{!this.state.editGroupNameVisible && /{this.getCountNum().countNum}}
{
this.state.editGroupNameVisible &&
{
this.setState({ groupName: value })
}}
onBlur={() => { this.editGropName(false) }}
/>
}
{data.items && data.items.map(item => {
return - { boardStore.setLandMark(id, value) }}
onTaskClick={(value) => { boardStore.showSlideModal(true, value) }}
finish={item.finish}
key={boardStore.timestamp + "" + item.id}
refreshItems={boardStore.refreshItems}
/>
})}
{canAddTask &&
{/*
{ this.showAddComs() }} >+{getLabel('84046', "新任务")}
*/}
{ this.showAddComs() }}>+{getLabel('15266', '新建任务')}
{/*
*/}
}
}else{
return
{!this.state.editGroupNameVisible && {data.title}}
{!this.state.editGroupNameVisible && {this.getCountNum().finishNum}}
{!this.state.editGroupNameVisible && /{this.getCountNum().countNum}}
{data.items && data.items.map(item => {
return - { boardStore.setLandMark(id, value) }}
onTaskClick={(value) => { boardStore.showSlideModal(true, value) }}
finish={item.finish}
key={boardStore.timestamp + "" + item.id}
refreshItems={boardStore.refreshItems}
/>
})}
}
}
editGropName = (visible) => {
if (!visible) {
if (!this.state.groupName) {
message.error("阶段名称必填!");
} else {
if(this.state.groupName !== this.state.baseGroupName){
const repeat = this.checkGroupRepeat(this.state.groupName, this.props.groupid);
if (repeat) {
this.props.saveGroupName(this.state.groupName, this.props.groupid);
this.setState({ editGroupNameVisible: visible });
} else {
message.error(getLabel('387703',"阶段名称重复!"));
}
}else{
this.setState({ editGroupNameVisible: visible });
}
}
} else {
this.setState({ editGroupNameVisible: visible });
}
}
getFinishNum = () => {
const { data, boardStore } = this.props;
let nums = 0;
data.items && data.items.map(item=>{
if(item.finish == 100){
nums ++;
}
})
// console.log(nums);
return nums ;
}
checkGroupRepeat = (name, id) => {
let checked = true;
const stages = toJS(this.props.boardStore.columns);
stages.map(item => {
if (item.id !== id && item.title == name) {
checked = false;
}
});
return checked;
}
getNowFormatDate() {
var date = new Date();
var seperator1 = "-";
var year = date.getFullYear();
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = year + seperator1 + month + seperator1 + strDate;
return currentdate;
}
closeAddComs = (bool) => {
const { userInfo } = this.props;
const {data} = this.props;
this.setState({
taskInfo: {
taskName: "",
hrmid: userInfo.userid,
hrmname: userInfo.username,
startDate: this.getNowFormatDate(),
endDate: this.getNowFormatDate(),
},
userInfo: {
userid: userInfo.userid,
username: userInfo.username,
usericons: userInfo.usericons
},
});
this.setState({ visible: !this.state.visible });
$("#footer-card-"+data.id).slideUp(200);
}
showAddComs = () => {
let checked = true;
const that = this;
const {data} = this.props;
if (this.state.visible) {
if (!this.state.taskInfo.taskName) {
this.refs.taskname.showError();
checked = false;
} else if (!this.state.taskInfo.hrmid) {
this.refs.taskhrm.showError();
checked = false;
} else if (!this.state.taskInfo.startDate) {
this.refs.taskstart.showError();
checked = false;
} else if (!this.state.taskInfo.endDate) {
this.refs.taskstart.showError();
checked = false;
} else if (this.state.taskInfo.endDate < this.state.taskInfo.startDate) {
message.error(getLabel('387700', "任务结束时间必须大于任务开始时间!"));
checked = false;
}
if (checked) {
this.props.saveTask({
stageid: this.props.groupid,
subject: this.state.taskInfo.taskName.replace('\n',''),
begindate: this.state.taskInfo.startDate,
enddate: this.state.taskInfo.endDate,
hrmid: this.state.taskInfo.hrmid,
});
const { userid, username, usericons } = this.props;
this.setState({
taskInfo: {
taskName: "",
hrmid: userid,
startDate: "",
endDate: ""
},
userInfo: {
userid: userid,
username: username,
usericons: usericons
}
});
this.setState({ visible: !this.state.visible });
$("#footer-card-"+data.id).slideUp(200);
}
} else {
checked && this.setState({ visible: !this.state.visible });
// jQuery("#area_"+this.props.groupid).focus()
// this.refs.area+this.props.groupid.focus();
$("#footer-card-"+data.id).slideDown(200);
setTimeout(function(){
let h = $("#column_content_"+data.id).height();
$("#board-column-content-scroll"+data.id).scrollTop(h+200);
},200);
}
}
setTaskValue = (fieldname, v) => {
if (fieldname == "startAndEndDate") {
this.setState({
taskInfo: {
...this.state.taskInfo,
startDate: v[0],
endDate: v[1],
},
});
} else if (fieldname == "endDate") {
this.setState({
taskInfo: {
...this.state.taskInfo,
endDate: v,
},
});
} else if (fieldname == "subject") {
this.setState({
taskInfo: {
...this.state.taskInfo,
taskName: v
},
});
} else if (fieldname == "hrmid") {
this.setState({
taskInfo: {
...this.state.taskInfo,
hrmid: v.hrmid,
hrmname: v.hrmname,
},
});
}
}
getCountNum = () => {
const { columnGrids_map, columnGrids } = this.props.boardStore;
const { data } = this.props;
const nodeList = columnGrids_map["column_content_"+data.id] && columnGrids_map["column_content_"+data.id]._element.childNodes;
let finishNum = 0;
const countNum = nodeList && nodeList.length;
// console.log(countNum);
if(typeof(nodeList)!=="undefined"){
for(var i = 0 ; i < nodeList.length; i ++){
if(nodeList[i]){
if(nodeList[i].getAttribute('finish')==100){
finishNum ++ ;
}
}
}
}
return {
finishNum : finishNum,
countNum : countNum,
percent : (finishNum/countNum)*100,
}
}
}