import React from 'react';
import { AutoComplete, Switch, Tabs, Table, Icon, Tooltip, Modal, Popover, message, Spin, Upload, Input, InputNumber, Select, DatePicker, Button, Radio, Form, Cascader, Tag } from 'antd';
import moment from 'moment';
import '../techDemand.less';
import ajax from 'jquery/src/ajax/xhr.js';
import $ from 'jquery/src/ajax';
import { IndustryObject, getIndustryCategory } from '../../../DicIndustryList.js';
import { getTechField } from '../../../DicTechFieldList.js';
import { beforeUploadFile, getTechAuditStatus, splitUrl, companySearch, getDemandType, getAchievementCategory,beforeUpload, getBase64 } from '../../../tools.js';
import throttle from '../../../throttle.js';

const KeyWordTagGroup = React.createClass({
    getInitialState() {
        return {
            tags: [],
            inputVisible: false,
            inputValue: ''
        };
    },
    handleClose(removedTag) {
        const tags = this.state.tags.filter(tag => tag !== removedTag);
        this.props.tagsArr(tags);
        this.setState({ tags });
    },
    showInput() {
        this.setState({ inputVisible: true }, () => this.input.focus());
    },
    handleInputChange(e) {
        this.setState({ inputValue: e.target.value });
    },
    handleInputConfirm() {
        const state = this.state;
        const inputValue = state.inputValue;
        let tags = state.tags;
        if (inputValue && tags.indexOf(inputValue) === -1 && inputValue.replace(/(^\s*)|(\s*$)/g, "").length != 0) {
            tags = [...tags, inputValue.replace(/(^\s*)|(\s*$)/g, "")];
        }
        this.props.tagsArr(tags);
        this.setState({
            tags,
            inputVisible: false,
            inputValue: '',
        });
    },
    componentWillMount() {
        this.state.tags = this.props.keyWordArr;
    },
    componentWillReceiveProps(nextProps) {
        if (this.props.keyWordArr != nextProps.keyWordArr) {
            this.state.tags = nextProps.keyWordArr;
        };
    },
    render() {
        const { tags, inputVisible, inputValue } = this.state;
        return (
            <div className="keyWord-tips">
                {tags.map((tag, index) => {
                    const isLongTag = tag.length > 10;
                    const tagElem = (
                        <Tag key={tag} closable={index !== -1} afterClose={() => this.handleClose(tag)}>
                            {isLongTag ? `${tag.slice(0, 10)}...` : tag}
                        </Tag>
                    );
                    return isLongTag ? <Tooltip title={tag}>{tagElem}</Tooltip> : tagElem;
                })}
                {inputVisible && (
                    <Input
                        ref={input => this.input = input}
                        type="text"
                        style={{ width: 78 }}
                        value={inputValue}
                        onChange={this.handleInputChange}
                        onBlur={this.handleInputConfirm}
                        onPressEnter={this.handleInputConfirm}
                    />
                )}
                {!inputVisible && <Button className="addtips" type="dashed" disabled={tags.length > 9 ? true : false} onClick={this.showInput}>+ 新关键词</Button>}
            </div>
        );
    }
});

const PicturesWall = React.createClass({
    getInitialState() {
        return {
            previewVisible: false,
            previewImage: '',
            fileList: [],
        }
    },
    handleCancel() {
        this.setState({ previewVisible: false })
    },
    handlePreview(file) {
        this.setState({
            previewImage: file.url || file.thumbUrl,
            previewVisible: true,
        });
    },
    handleChange(info) {
        let fileList = info.fileList;
        this.setState({ fileList });
        this.props.fileList(fileList);
    },
    componentWillReceiveProps(nextProps) {
        this.state.fileList = nextProps.pictureUrl;
    },
    render() {
        const { previewVisible, previewImage, fileList } = this.state;
        const uploadButton = (
            <div>
                <Icon type="plus" />
                <div className="ant-upload-text">点击上传</div>
            </div>
        );
        return (
            <div className="clearfix">
                <Upload
                    action={globalConfig.context + "/api/admin/demand/uploadPicture"}                                      
                    data={{ 'sign': this.props.pictureSign, 'uid': this.props.uid}}
                    listType="picture-card"
                    fileList={fileList}
                    onPreview={this.handlePreview}
                    onChange={this.handleChange} >
                    {fileList.length >= 5 ? null : uploadButton}
                </Upload>
                <Modal maskClosable={false} visible={previewVisible} footer={null} onCancel={this.handleCancel}>
                    <img alt="example" style={{ width: '100%' }} src={previewImage} />
                </Modal>
            </div>
        );
    }
});

const DemandDetailShow = Form.create()(React.createClass({
    getInitialState() {
        return {
            visible: false,
            loading: false,
            contactsObj: {},
            salesmanObj: {},
            data: {},
            tags: [],
            pictureUrl: [],
            coverImg: []           
        };
    },
    loadData(id, detailApiUrl,dataCategory) {
        this.setState({
            loading: true
        });
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/demand/orgDemandDetail",
            data: {
                id: id,
                dataCategory:dataCategory?dataCategory:this.props.data.dataCategory
            },
            success: function (data) {
            	
                let thisData = data.data;              
                if (!thisData) {
                    if (data.error && data.error.length) {
                        message.warning(data.error[0].message);
                    };
                    thisData = {};
                };
                this.setState({
                    data: thisData,
                    switchValue: Boolean(!thisData.employerId),
                    radios: thisData.hot == '1' ? true : false,
                    tags: thisData.keyword ? (thisData.keyword.replace(/(，|、)/g, ",")).split(',') : [],
                    pictureUrl: thisData.pictureUrl ? splitUrl(thisData.pictureUrl, ',', globalConfig.avatarHost + '/upload') : [],
                    coverImg: thisData.coverImg ? splitUrl(thisData.coverImg, ',', globalConfig.avatarHost + '/upload') : []
                });
            }.bind(this),
        }).always(function () {
            this.setState({
                loading: false
            });
        }.bind(this));
    },
    getContactsList(theUid) {
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/getContacts",
            data: {
                uid: theUid
            },
            success: function (data) {
                let theOption = [];
                if (!data.data) {
                    if (data.error && data.error.length) {
                        message.warning(data.error[0].message);
                    };
                } else {
                    this.setState({
                        contactsObj: data.data
                    });
                };
            }.bind(this),
        });
    },
    ShelfCancel(){
    	let api=0;
    	this.offShelf(api);
    },
    ShelfOk(){
    	let api=1;
    	this.offShelf(api);
    },
    offShelf(nub) {
        this.setState({
            loading: true
        });
        $.ajax({
            method: "post",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/demand/offShelf",
            data: { 
            	"id": this.props.data.id,
            	releaseStatus:nub,
            	auditStatus:3
            }
        }).done(function (data) {
            if (!data.error.length) {
                message.success('操作成功！');
                this.props.handleOk();
            } else {
                message.warning(data.error[0].message);
            };
            this.setState({
                loading: false,
                releaseSubmitVisible: false
            });
        }.bind(this));
    },
    modifyBroker() {
        this.props.form.validateFields((err, values) => {
            if (!err) {
                this.setState({
                    loading: true
                });
                $.ajax({
                    method: "POST",
                    dataType: "json",
                    crossDomain: false,
                    url: globalConfig.context + '/api/admin/audit/modifyDemandTechBroker',
                    data: {
                        id: this.props.data.id,
                        techBrokerId: values.modifyTechBrokerId
                    }
                }).done(function (data) {
                    this.state.auditStatus = 0;
                    this.setState({
                        loading: false
                    });
                    if (data.error && data.error.length) {
                        message.warning(data.error[0].message);
                    } else {
                        message.success('保存成功！');
                        this.props.handleOk();
                    };
                }.bind(this));
            }
        });
    },
    formSubmit() {
        this.props.form.validateFields((err, values) => {
            if (values.auditStatus == 3 && !values.techBrokerId) {
                message.warning('必须选择一个技术经纪人！');
                return
            };
            if (!err) {
                this.setState({
                    loading: true
                });
                $.ajax({
                    method: "POST",
                    dataType: "json",
                    crossDomain: false,
                    url: globalConfig.context + '/api/admin/audit/demand',
                    data: {
                        id: this.props.data.id,
                        techBroderId: values.techBrokerId,
                        auditStatus: values.auditStatus
                    }
                }).done(function (data) {
                    this.state.auditStatus = 0;
                    if (!data.error.length) {
                        message.success('保存成功！');
                        this.setState({ formSubmitVisible: false });
                        this.props.handleOk();
                    } else {
                        message.warning(data.error[0].message);
                        this.setState({
                            loading: false,
                        });
                    }
                }.bind(this));
            }
        });
    },
    handleSubmit(e) {
        e.preventDefault();
        this.props.form.validateFields((err, values) => {
            if (values.auditStatus == 4) {
                this.setState({
                    formSubmitVisible: true
                });
            } else {
                this.formSubmit();
            };
        });
    },
    buildMatchList() {
        this.setState({
            buttonLoading: true
        });
        $.ajax({
            method: "POST",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + '/api/admin/demand/matchAchievement',
            data: {
                id: this.props.data.id,
            }
        }).done(function (data) {
            this.setState({
                buttonLoading: false
            });
            if (!data.error.length) {
                message.success('匹配完成！匹配到' + data.data + '条记录');
            } else {
                message.warning(data.error[0].message);
            };
        }.bind(this));
    },
    componentWillMount() {
        this.loadData(this.props.data.id, this.props.detailApiUrl);
        if (this.props.data.employerId && this.props.data.dataCategory) {
            this.getContactsList(this.props.data.employerId);
        };
    },
    componentWillReceiveProps(nextProps) {
        if (!this.props.visible && nextProps.visible) {
            this.loadData(nextProps.data.id, nextProps.detailApiUrl,nextProps.data.dataCategory);
            if (nextProps.data.employerId && nextProps.data.dataCategory) {
                this.getContactsList(nextProps.data.employerId);
            };
            this.props.form.resetFields();
        };
    },
    render() {
        const theData = this.state.data || {};
        const { getFieldDecorator } = this.props.form;
        const FormItem = Form.Item
        const formItemLayout = {
            labelCol: { span: 6 },
            wrapperCol: { span: 12 },
        };
        return (
            <Form horizontal onSubmit={this.handleSubmit} id="demand-form">
                <Spin spinning={this.state.loading}>
                    <div className="clearfix">
                        <FormItem className="half-item"
                            {...formItemLayout}
                            label="编号" >
                            <span>{theData.serialNumber}</span>
                        </FormItem>
                        <FormItem className="half-item"
                            {...formItemLayout}
                            label="需求名称" >
                            <span>{theData.name}</span>
                        </FormItem>                       
                    </div>
                    <div>
                    <FormItem className="half-item"
                            {...formItemLayout}
                            label="精品需求" >
                            {(() => {
                                switch (theData.boutique) {
                                    case "0":
                                        return <span>否</span>;
                                    case "1":
                                        return <span>是</span>;
                                }
                            })()}
                        </FormItem>
                         <FormItem className="half-item"
                            {...formItemLayout}
                            label="首页展示" >
                            {(() => {
                                switch (theData.hot) {
                                    case "0":
                                        return <span>否</span>;
                                    case "1":
                                        return <span>是</span>;
                                }
                            })()}
                        </FormItem>                        
                     </div>                    
                     {this.state.radios==true ? <div>
                    	<FormItem
	                        labelCol={{ span: 3 }}
	                        wrapperCol={{ span: 18 }}
	                        label="首页展示图片:" >
	                        <div className="clearfix">
	                            <Upload className="demandDetailShow-upload"
	                                listType="picture-card"
	                                fileList={this.state.coverImg}
	                                onPreview={(file) => {
	                                    this.setState({
	                                        previewImage: file.url || file.thumbUrl,
	                                        previewVisible: true,
	                                    });
	                                }} >	                               
	                            </Upload>
	                            <Modal maskClosable={false} footer={null}
	                                visible={this.state.previewVisible}
	                                onCancel={() => { this.setState({ previewVisible: false }) }}>
	                                <img alt="" style={{ width: '100%' }} src={this.state.previewImage || ''} />
	                            </Modal>
	                        </div>
	                   	 </FormItem>
                    </div> :<div></div>}                
                    {this.state.switchValue ? <div>
                        <FormItem className="half-item"
                            {...formItemLayout}
                            label="雇主名称" >
                            <span>{theData.employerName}</span>
                        </FormItem>
                        <FormItem className="half-item"
                            {...formItemLayout}
                            label="联系电话" >
                            <span>{theData.employerContactsMobile}</span>
                        </FormItem>
                        <FormItem className="half-item"
                            {...formItemLayout}
                            label="电子邮箱" >
                            <span>{theData.employerContactsMailbox}</span>
                        </FormItem>
                        <FormItem className="half-item"
                            {...formItemLayout}
                            label="通讯地址" >
                            <span>{theData.employerAddress}</span>
                        </FormItem>
                    </div> : <div className="clearfix">
                            <FormItem className="half-item"
                                {...formItemLayout}
                                label="雇主名称" >
                                <span>{theData.username}</span>
                            </FormItem>
                            {this.props.data.dataCategory ? <FormItem className="half-item"
                                {...formItemLayout}
                                label="联系人" >
                                <span>{this.state.contactsObj[theData.contacts]}</span>
                            </FormItem> : <FormItem className="half-item"
                                {...formItemLayout}
                                label="联系人" >
                                    <span>{theData.contactsName}</span>
                                </FormItem>}
                        </div>}
                    <div className="clearfix">
                        <FormItem className="half-item"
                            {...formItemLayout}
                            label="负责人" >
                            <span>{this.props.techBrodersObj[theData.techBrokerId]}</span>
                        </FormItem>
                    </div>
                    <div className="clearfix">
                        <FormItem className="half-item"
                            {...formItemLayout}
                            label="是否发布" >
                           {(() => {
                                switch (theData.releaseStatus) {
                                    case "0":
                                        return <div><span>未发布</span>
                                        <Button style={{ marginLeft: '10px' }} onClick={() => { this.setState({ releaseSubmitVisible: true }); }}>发布</Button>
                                            <Modal maskClosable={false} title="确认"
                                                visible={this.state.releaseSubmitVisible}
                                                width='400px'
                                                footer={null}
                                                onCancel={() => { this.setState({ releaseSubmitVisible: false }) }} >
                                                <span>确认要发布吗？</span>
                                                <Button className="modal-submit" type="primary" onClick={this.ShelfOk} >确认</Button>
                                                <Button className="modal-submit" type="ghost" onClick={() => { this.setState({ releaseSubmitVisible: false }) }}>取消</Button>
                                        </Modal></div>
                                        ;
                                    case "1":
                                        return <div>
                                            <span>已发布</span>
                                            <Button style={{ marginLeft: '10px' }} onClick={() => { this.setState({ releaseSubmitVisible: true }); }}>撤消发布</Button>
                                            <Modal maskClosable={false} title="确认"
                                                visible={this.state.releaseSubmitVisible}
                                                width='400px'
                                                footer={null}
                                                onCancel={() => { this.setState({ releaseSubmitVisible: false }) }} >
                                                <span>确认要撤销发布吗？</span>
                                                <Button className="modal-submit" type="primary" onClick={this.ShelfCancel} >确认</Button>
                                                <Button className="modal-submit" type="ghost" onClick={() => { this.setState({ releaseSubmitVisible: false }) }}>取消</Button>
                                            </Modal>
                                        </div>;
                                }
                            })()}
                        </FormItem>
                        <FormItem className="half-item"
                            {...formItemLayout}
                            label="发布时间" >
                            <span>{theData.releaseDateFormattedDate}</span>
                        </FormItem>
                    </div>
                    <FormItem className="half-item"
                        {...formItemLayout}
                        label="加急天数" >
                        <span>{theData.urgentDays}</span>
                    </FormItem>
                    <FormItem className="half-item"
                        {...formItemLayout}
                        label="加急报酬" >
                        <span>{theData.urgentMoney}</span>
                    </FormItem>
                    <div className="clearfix">
                        <FormItem className="half-item"
                            {...formItemLayout}
                            label="需求状态" >
                            {(() => {
                                switch (theData.status) {
                                    case "0":
                                        return <span>未解决</span>;
                                    case "1":
                                        return <span>已解决</span>;
                                }
                            })()}
                        </FormItem>
                        <FormItem className="half-item"
                            {...formItemLayout}
                            label="审核状态" >
                            {(() => {
                                switch (theData.auditStatus) {
                                    case 0:
                                        return <span>未提交审核(草稿)</span>;
                                    case 1:
                                        return <span>提交审核</span>;
                                    case 2:
                                        return <span>审核中</span>;
                                    case 3:
                                        return <span>审核通过</span>;
                                    case 4:
                                        return <span>审核未通过</span>;
                                }
                            })()}
                        </FormItem>
                    </div>
                    <div className="clearfix">
                        <FormItem className="half-item"
                            {...formItemLayout}
                            label="信息来源" >
                            {(() => {
                                switch (theData.infoSources) {
                                    case "0":
                                        return <span>平台采集</span>;
                                    case "1":
                                        return <span>客户发布</span>;
                                    case "2":
                                        return <span>批量导入</span>;
                                    case "3":
                                        return <span>三方对接</span>;
                                }
                            })()}
                        </FormItem>
                    </div>
                    <FormItem
                        labelCol={{ span: 3 }}
                        wrapperCol={{ span: 20 }}
                        label="关键词" >
                        {this.state.tags.map((tag) => {
                            return <Tooltip key={tag} title={tag}>
                                <Tag key={tag}>{tag}</Tag>
                            </Tooltip>;
                        })}
                    </FormItem>
                    <FormItem
                        labelCol={{ span: 3 }}
                        wrapperCol={{ span: 18 }}
                        label="行业类别" >
                        <span>{getIndustryCategory(theData.industryCategoryA, theData.industryCategoryB)}</span>
                    </FormItem>
                    <div className="clearfix">
                        <FormItem className="half-item"
                            {...formItemLayout}
                            label="需求类型" >
                            <span>{getDemandType(theData.demandType)}</span>
                        </FormItem>
                    </div>
                    <FormItem
                        labelCol={{ span: 3 }}
                        wrapperCol={{ span: 18 }}
                        label="问题说明" >
                        <span>{theData.problemDes}</span>
                    </FormItem>
                    <FormItem
                        labelCol={{ span: 3 }}
                        wrapperCol={{ span: 18 }}
                        label="备注" >
                        <span>{theData.remark}</span>
                    </FormItem>
                    <FormItem
                        labelCol={{ span: 3 }}
                        wrapperCol={{ span: 18 }}
                        label="技术指标要求" >
                        <span>{theData.technicalRequirements}</span>
                    </FormItem>
                    <FormItem
                        labelCol={{ span: 3 }}
                        wrapperCol={{ span: 18 }}
                        label="需求文件(图片)" >
                        <div className="clearfix">
                            <Upload className="demandDetailShow-upload"
                                listType="picture-card"
                                fileList={this.state.pictureUrl}
                                onPreview={(file) => {
                                    this.setState({
                                        previewImage: file.url || file.thumbUrl,
                                        previewVisible: true,
                                    });
                                }} >
                            </Upload>
                            <Modal maskClosable={false} footer={null}
                                visible={this.state.previewVisible}
                                onCancel={() => { this.setState({ previewVisible: false }) }}>
                                <img alt="" style={{ width: '100%' }} src={this.state.previewImage || ''} />
                            </Modal>
                        </div>
                    </FormItem>
                    <FormItem
                        labelCol={{ span: 3 }}
                        wrapperCol={{ span: 6 }}
                        label="需求文件(文本)" >
                        <div>{theData.textFileUrl ?
                            <span className="download-file">
                                <a onClick={() => { window.open(globalConfig.context + '/api/admin/demand/download?id=' + this.props.data.id) }}>需求文件(文本文件)</a>
                            </span>
                            : <span><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传！</span>}</div>
                    </FormItem>
                    <FormItem
                        labelCol={{ span: 3 }}
                        wrapperCol={{ span: 18 }}
                        label="需求文件(视频地址)" >
                        <span>{theData.videoUrl}</span>
                    </FormItem>
                    <div className="clearfix">
                        <FormItem className="half-item"
                            {...formItemLayout}
                            label="固定周期" >
                            <span>{theData.fixedCycle}</span>
                        </FormItem>
                        <FormItem className="half-item"
                            {...formItemLayout}
                            label="固定人数" >
                            <span>{theData.peopleNumber || 0} 人</span>
                        </FormItem>
                    </div>
                    <FormItem
                        labelCol={{ span: 3 }}
                        wrapperCol={{ span: 18 }}
                        label="固定方案" >
                        <span>{theData.fixedScheme}</span>
                    </FormItem>
                    <div className="clearfix">
                        <FormItem className="half-item"
                            {...formItemLayout}
                            label="预算费用" >
                            <span>{theData.budgetCost || 0} 万元</span>
                        </FormItem>
                        <FormItem className="half-item"
                            {...formItemLayout}
                            label="费用托管" >
                            {(() => {
                                switch (theData.costEscrow) {
                                    case 0:
                                        return <span>否</span>;
                                    case 1:
                                        return <span>是</span>;
                                }
                            })()}
                        </FormItem>
                       
                        <FormItem className="half-item"
                            {...formItemLayout}
                            label="有效期限" >
                            <span>{theData.validityPeriodFormattedDate}</span>
                        </FormItem>
                    </div>
                </Spin>
            </Form >
        )
    }
}));


const DemandDetail = React.createClass({
    getInitialState() {
        return {
            visible: false,
            techBrodersObj: {},
            tabsKey: "1",
            columns: [
                {
                    title: '编号',
                    dataIndex: 'serialNumber',
                    key: 'serialNumber',
                }, {
                    title: '名称',
                    dataIndex: 'name',
                    key: 'name',
                }, {
                    title: '关键字',
                    dataIndex: 'keyword',
                    key: 'keyword',
                }, {
                    title: '类型',
                    dataIndex: 'category',
                    key: 'category',
                    render: text => { return getAchievementCategory(text); }
                }, {
                    title: '所有人名称',
                    dataIndex: 'theName',
                    key: 'theName',
                }, {
                    title: '所有人类型',
                    dataIndex: 'ownerType',
                    key: 'ownerType',
                    render: text => {
                        switch (text) {
                            case "0":
                                return <span>个人</span>;
                            case "1":
                                return <span>组织</span>
                        }
                    }
                }, {
                    title: '发布时间',
                    dataIndex: 'releaseDateFormattedDate',
                    key: 'releaseDateFormattedDate',
                }
            ],
            dataSource: [],
        };
    },
    getTechBrodersList() {
        this.setState({
            loading: true
        });
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/audit/techBroders",
            success: function (data) {
                if (!data.data) {
                    if (data.error && data.error.length) {
                        message.warning(data.error[0].message);
                    }
                    return;
                };
                let _me = this, theArr = [];
                for (var item in data.data) {
                    theArr.push(
                        <Select.Option key={item}>{data.data[item]}</Select.Option>
                    )
                };
                this.setState({
                    techBrodersOption: theArr,
                    techBrodersObj: data.data
                });
            }.bind(this),
        }).always(function () {
            this.setState({
                loading: false
            });
        }.bind(this));
    },
    getTableList() {
        this.setState({
            loading: true
        });
        $.ajax({
            method: "get",
            dataType: "json",
            crossDomain: false,
            url: globalConfig.context + "/api/admin/demand/achievementDemand",
            data: { id: this.props.data.id },
            success: function (data) {
                let theArr = [];
                if (!data.data) {
                    if (data.error && data.error.length) {
                        message.warning(data.error[0].message);
                    };
                } else if (data.data.length) {
                    for (let i = 0; i < data.data.length; i++) {
                        let thisdata = data.data[i];
                        theArr.push({
                            key: i,
                            id: thisdata.id,
                            serialNumber: thisdata.serialNumber,
                            dataCategory: thisdata.dataCategory,
                            name: thisdata.name,
                            keyword: thisdata.keyword,
                            category: thisdata.category,
                            ownerType: thisdata.ownerType,
                            theName: thisdata.username || thisdata.unitName,
                            releaseDate: thisdata.releaseDate,
                            releaseDateFormattedDate: thisdata.releaseDateFormattedDate
                        });
                    };
                };
                this.setState({
                    dataSource: theArr,
                });
            }.bind(this),
        }).always(function () {
            this.setState({
                loading: false
            });
        }.bind(this));
    },
    tableRowClick(record, index) {
        window.open(globalConfig.context + '/portal/detail/achievementDetail.html?id=' + record.id + '&type=' + record.ownerType);
    },
    handleCancel(e) {
        this.setState({
            visible: false,
        });
        this.props.closeDesc(false);
    },
    handleOk(e) {
        this.setState({
            visible: false,
        });
        this.props.closeDesc(false, true);
    },
    componentWillMount() {
        this.getTechBrodersList();
    },
    componentWillReceiveProps(nextProps) {
        if (!this.state.visible && nextProps.showDesc) {
            this.state.tabsKey = "1";
        };
        this.state.visible = nextProps.showDesc;
    },
    render() {
        if (this.props.data) {
            return (
                <div className="patent-desc">
                    <Modal maskClosable={false} visible={this.state.visible}
                        onOk={this.checkPatentProcess} onCancel={this.handleCancel}
                        width='1000px'
                        footer=''
                        className="admin-desc-content">
                        <Spin spinning={this.state.loading}>
                            <Tabs activeKey={this.state.tabsKey}
                                onChange={(e) => {
                                    this.setState({ tabsKey: e });
                                    if (e == "2") {
                                        this.getTableList();
                                    };
                                }} >
                                <Tabs.TabPane tab="需求详情" key="1">
                                    <DemandDetailShow
                                        data={this.props.data}
                                        detailApiUrl={this.props.detailApiUrl}
                                        techBrodersOption={this.state.techBrodersOption}
                                        techBrodersObj={this.state.techBrodersObj}
                                        demandTypeOption={this.props.demandTypeOption}
                                        closeDesc={this.handleCancel}
                                        visible={this.state.visible}
                                        handleOk={this.handleOk} />
                                </Tabs.TabPane>
                                <Tabs.TabPane tab="匹配列表" key="2" disabled={!this.props.data.id}>
                                    <Table columns={this.state.columns}
                                        dataSource={this.state.dataSource}
                                        pagination={false}
                                        onRowClick={this.tableRowClick} />
                                </Tabs.TabPane>
                            </Tabs>
                        </Spin>
                    </Modal>
                </div>
            );
        } else {
            return <div></div>
        }
    },
});

export default DemandDetail;