import React from 'react';
import { inject, observer } from 'mobx-react';
import { Button, Tabs,Card,Pagination,Row,Col } from 'antd';
import {toJS} from "mobx";
import {Condition,getAdButtons} from './list/listCondition';
import {WeaTableNew} from 'comsMobx';
const WeaTable = WeaTableNew.WeaTable;
import {WeaRightMenu,WeaTop,WeaTab,WeaErrorPage,WeaBrowser,WeaTools,WeaLeftRightLayout,WeaProgress,WeaLocaleProvider} from 'ecCom';
import ShareDialog from './dialog/shareDialog'
import ListLeftTree from './list/listLeftTree'
import BatchShareDialog from './comp/prj-batch-share'
const getLabel = WeaLocaleProvider.getLabel;
@inject('prjBatchShareStore')
@observer
class BatchShare extends React.Component {
constructor(props) {
super(props);
}
doInit(props){
const {prjBatchShareStore } = props;
const {initTreeDatas,doSearch,initDatas} = prjBatchShareStore;
//doSearch();
initDatas();
//initTreeDatas();
}
componentDidMount(){
this.doInit(this.props);
}
componentWillReceiveProps(nextProps){
if(this.props.location.key !== nextProps.location.key){
const { location,prjBatchShareStore } = nextProps;
prjBatchShareStore.clearStatus();
this.doInit(nextProps);
}
}
componentWillUnmount(){
const { prjBatchShareStore } = this.props;
prjBatchShareStore.clearStatus();
}
render(){
const {prjBatchShareStore} = this.props;
const {loading,tableStore,showSearchAd,form,reLoad,showLeft} = prjBatchShareStore;
const formParams = form.getFormParams() || {};
let {selectedRowKeys} = tableStore;
return (
}
iconBgcolor='#217346'
buttons={this.getTopButtons()}
buttonSpace={10}
showDropIcon={true}
dropMenuDatas={this.getRightMenu()}
onDropMenuClick={this.onRightMenuClick.bind(this)}
>
}
onCollapse={showLeft => prjBatchShareStore.setLeftShow(showLeft)}
>
{prjBatchShareStore.setShowSearchAd(bool)}}
hideSearchAd={()=> prjBatchShareStore.setShowSearchAd(false)}
searchsAd={
}
showSearchAd={showSearchAd}
onSearch={v=>{prjBatchShareStore.doSearch()}}
onSearchChange={v=>{prjBatchShareStore.appendFormFields({name:{value:v}})}}
onChange={ this.changeData }
/>
reLoad()}
getColumns={c=>this.reRenderColumns(c)}
tableWidth={this.tableWidth}
onOperatesClick={this.onOperatesClick.bind(this)}
/>
{
prjBatchShareStore.saveBatchShare({prjids:`${toJS(selectedRowKeys)}`,share:JSON.stringify(v)});
}
}
onCancel={() => {prjBatchShareStore.handleShareDialog(false) }}
/>
)
}
getTopButtons(){
const {prjBatchShareStore} = this.props;
const {rightMenu,tableStore} = prjBatchShareStore;
let {selectedRowKeys} = tableStore;
let btnArr = [];
let that = this;
const isDisabled = !(selectedRowKeys.length>0 && `${toJS(selectedRowKeys)}`);
rightMenu && rightMenu.length>0 && toJS(rightMenu).map(m=>{
m.isTop == '1' && btnArr.length < 4 && btnArr.push(
);
});
return btnArr;
}
getRightMenu(){
const {prjBatchShareStore }= this.props;
const {rightMenu,tableStore} = prjBatchShareStore;
let btnArr = [];
let {selectedRowKeys} = tableStore;
const isDisabled = !(selectedRowKeys.length>0 && `${toJS(selectedRowKeys)}`);
rightMenu && rightMenu.length>0 && rightMenu.map(m=>{
btnArr.push({
icon: ,
content: m.menuName,
disabled: isDisabled && m.isControl == "1"
})
});
return btnArr
}
onRightMenuClick(key){
const {prjBatchShareStore }= this.props;
const {rightMenu,tableStore} = prjBatchShareStore;
let {selectedRowKeys} = tableStore;
let that = this;
rightMenu && rightMenu.length>0 && rightMenu.map((m,i)=>{
if(Number(key) == i){
let fn = m.menuFun.indexOf('this') >= 0 ? `${m.menuFun.split('this')[0]})` : m.menuFun;
if(m.type == "BTN_SEARCH"){ //定制列
prjBatchShareStore.doSearch();
}else if(m.type == "BTN_COLUMN"){ //定制列
prjBatchShareStore.onShowColumn();
}else if(m.type == "BTN_SHAREBATCH"){ //批量共享
prjBatchShareStore.handleShareDialog(true)
}
}
});
}
reRenderColumns(columns){
columns.forEach((c,i)=>{
if(c.dataIndex=='finish'){
c.render = function(text, record){
return
}
} else {
// c.render = function(text, record){
// let valueSpan = record[c.dataIndex + "span"] !== undefined ? record[c.dataIndex + "span"] : record[c.dataIndex];
// return
// }
}
})
return columns;
}
tableWidth = (columns) => {
let width = 0;
let cols = 0;
columns.map(col => {
if (col.display === 'true') {
let oldwidth = col.oldWidth || '10%';
let widthInt = parseFloat(oldwidth.replace('%', ''));
if (widthInt <= 0) {
widthInt = 10;
}
width += widthInt;
cols++
}
})
//超过10列,才出现滚动条,width>100才出现滚动条
if(cols<=10){
width = 100 ;
}
return `${width}%`;
}
changeData=(key)=>{
const {prjBatchShareStore} = this.props;
prjBatchShareStore.setShowSearchAd(false);
prjBatchShareStore.doSearch({
tabkey:key
});
}
onOperatesClick(record,index,operate,flag){
const {prjBatchShareStore} = this.props;
const {shareStore,} = prjBatchShareStore;
let _href = operate && operate.href ? operate.href : "";
let fn = _href.replace("javascript:","");
fn = fn.substring(0,fn.indexOf('('));
let that = this;
if(fn != ""){
if("onShare"==fn){ //共享
shareStore.handleShareDialog(true,"prj",record.randomFieldId)
}
}
}
onEnterSearch = () =>{
const {prjBatchShareStore} = this.props;
prjBatchShareStore.doSearch();
prjBatchShareStore.setShowSearchAd(false);
}
}
export default WeaTools.tryCatch(React,
props => ,
{error: ""}
)(BatchShare);