index.js 6.9 KB
Newer Older
王绍森's avatar
王绍森 committed
1 2 3 4 5 6 7 8 9 10 11
/**
 * 事务页面。 根据一站式服务大厅的事务接口。达到增删发起事务流程
 * 2019年10月23日 09:48:13
 * 钟是志
 *
 * */

import { message } from 'antd';
import React, { Fragment } from 'react';
import * as service from '../publicApiService';
import * as destructionFunc from '../destruction';
钟是志's avatar
钟是志 committed
12
import { Link } from 'dva/router';
王绍森's avatar
王绍森 committed
13
import { getApplyPage } from '../publicApiService';
14
import { getToken } from '@/utils/authority';
王绍森's avatar
王绍森 committed
15 16 17 18 19 20 21 22 23 24 25

import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import List from './List';
import pageSetting from './pageSetting';
import ButtonDiy from '@/baseComponent/ButtonDiy';
import Shell from '@/baseComponent/Shell';
import config from '@/config/config';

export default class AffairPage extends React.Component {
  constructor(props) {
    super(props);
26
    let pathname = this.props.location.pathname;
27
    const { dataBaseId, workId } = this.props;
王绍森's avatar
王绍森 committed
28 29 30
    this.state = {
      showIframe: false,
      columns: [],
31
      pathname,
32
      workId: workId || '',
王绍森's avatar
王绍森 committed
33
      searchCondition: [],
34
      dataBaseId: '',
王绍森's avatar
王绍森 committed
35
      addFields: [], // 新增时填写的字段。
钟是志's avatar
钟是志 committed
36
      renderIframe: true,
王绍森's avatar
王绍森 committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    };
  };

  getFormDetail = (workId) => {
    service.getFormDetail(workId).then((response) => {
      if (typeof response.unifiedServicePatternModel === 'undefined') {
        return false;
      }
      destructionFunc.destructionGetDetail(response).then((x) => {
        const { addFields, tableInfo, allConfigSetInfo } = x;
        this.setState({
          addFields,
          tableInfo,
          allConfigSetInfo,
        }, () => {
          this.giveDetailColumns();
        });
      });
    });
  };

  giveDetailColumns = () => {
    const { columns, workId, dataBaseId, addFields } = this.state;
    columns.push(
      {
        dataIndex: 'operation',
        title: '操作',
        fixed: columns.length > 12 ? 'right' : false,
        render: (text, record) => {
          return (<Link to={
            {
              pathname: './Detail',
              state: {
                workId,
                dataBaseId,
                record,
                addFields,
              },

            }}>
            详情
          </Link>);
        },
      },
    );
    this.setState({
      columns,
    });
  };

  handleButtonSet = () => {
钟是志's avatar
钟是志 committed
88 89 90 91
    const { canApply } = this.props;
    if(canApply === false){
      return [];
    }
王绍森's avatar
王绍森 committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
    return [
      {
        type: 'add',
        name: '申请',
        component: 'Normal',
        handleClick: () => {
          this.setState({
            showIframe: true,
          }, () => {
          });
        },
      },
    ];
  };

  handleSearchSet = () => {
    const { columns, searchCondition } = this.state;
109
    const { onResponse } = this.props;
王绍森's avatar
王绍森 committed
110 111 112 113 114
    const pageSearch = {
      search: {
        field: {},
        getPageService: getApplyPage,
        responseCallBack: (response) => {
115 116 117
          if (onResponse) {
            onResponse(response);
          }
王绍森's avatar
王绍森 committed
118 119 120 121 122 123 124 125 126 127 128 129
          return response;
        },
        condition: searchCondition,
        nameSpan: { big: 8, small: 9 },
        fileSpan: { big: 4, small: 4 },
      },
      tableRowKey: 'id',
      columns,
    };
    return pageSearch;
  };

130
  getColumns = () => {
王绍森's avatar
王绍森 committed
131 132 133 134 135 136 137 138 139 140
    const { workId } = this.state;
    service.getColumns(workId).then((response) => {
      if (response) {
        this.setState({
          columns: response,
        }, () => {
          this.getFormDetail(workId);
        });
      }
    });
141 142 143 144 145 146 147 148
  };

  componentDidMount() {
    if (!getToken()) {
      message.error('您的数据未同步,请联系管理员!');
      return false;
    }
    const {  pathname } = this.state;
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
    const { dataBaseId, workId } = this.props;
    if(dataBaseId || workId){
      this.setState({
        workId,
        dataBaseId,
      },()=>{
        this.getColumns();
      });
    }else{
      service.getId(pathname).then((x)=>{
        this.setState({
          workId: x.workId,
          dataBaseId: x.dataBaseId,
        },()=>{
          this.getColumns();
        })
      });
    }

王绍森's avatar
王绍森 committed
168 169 170

    window.addEventListener('message', (event) => {
      if (event.data === 'returnList') {
钟是志's avatar
钟是志 committed
171
        this.returnList(true);
王绍森's avatar
王绍森 committed
172
      }
173
      if (event && event.data && event.data.indexOf && event.data.indexOf('iframeHeight') > -1) {
王绍森's avatar
王绍森 committed
174
        let height = Number(event.data.split('-')[1]);
175 176 177 178
        const iframe = document.getElementById('applyIframeId');
        if (iframe) {
          iframe.height = height;
        }
王绍森's avatar
王绍森 committed
179 180 181 182 183 184
      }
    }, false);

    return true;
  }

钟是志's avatar
钟是志 committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198
  returnList = (needSearchList = false) => {
    this.setState({
      renderIframe: false,
    },()=>{
      if(needSearchList){
        this.ListComponent.getPage();
      }
      this.setState({
        showIframe: false,
        renderIframe: true, // 重新挂载IFrame 保证申请数据不会再次显示出来
      });
    });
  };

王绍森's avatar
王绍森 committed
199
  render() {
钟是志's avatar
钟是志 committed
200
    const { workId, dataBaseId, addFields, showIframe, renderIframe } = this.state;
201 202 203
    if(!workId){
      return null;
    }
王绍森's avatar
王绍森 committed
204
    const url = config.onestopPC.split('/#/');
205
    let iframeUrl = `${url[0]}/#/IFrameForApply?id=${workId}&token=${getToken()}`;
钟是志's avatar
钟是志 committed
206
    console.log(iframeUrl);
钟是志's avatar
钟是志 committed
207
  //  iframeUrl = `http://localhost:8000/onestop/IFrameForApply?id=${workId}&token=${getToken()}`;
王绍森's avatar
王绍森 committed
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
    return (
      <PageHeaderWrapper title="">
        <div style={{
          display: showIframe ? 'none' : 'block',
        }}>
          <List listConfig={pageSetting.listConfig}
                pageButton={this.handleButtonSet({})}
                pageSearch={this.handleSearchSet({})}
                addFields={addFields}
                ref={ListComponent => this.ListComponent = ListComponent}
                workId={workId}
                dataBaseId={dataBaseId}
          />
        </div>
        <div style={{
          visibility: showIframe ? 'visible' : 'hidden',
          width: '100%',
          backgroundColor: '#fff',
          paddingLeft: '24px',
        }}>
          <Shell>
            <div style={{
              height: '54px',
              padding: '12px 0 12px 12px',
              display: showIframe ? 'block' : 'none',
            }}>
              <ButtonDiy name="返回"
                         className="defaultBlue"
钟是志's avatar
钟是志 committed
236
                         handleClick={this.returnList}
王绍森's avatar
王绍森 committed
237 238 239 240
                         icon="arrow-left"
              />
            </div>
          </Shell>
钟是志's avatar
钟是志 committed
241 242 243 244 245 246 247 248 249 250
          {
            renderIframe ?
              <iframe src={iframeUrl}
                      frameBorder={0}
                      id='applyIframeId'
                      name='applyIframe'
                      marginWidth="0"
                      marginHeight="0"
                      allowTransparency="yes"
                      seamless
251
                      scrolling={'auto'}
钟是志's avatar
钟是志 committed
252 253 254 255 256 257 258 259 260
                      style={{
                        width: '100%',
                        minHeight: '800px',
                        overflowY: 'hidden',
                        backgroundColor: '#fff',
                      }}
              /> : null
          }

王绍森's avatar
王绍森 committed
261 262 263 264 265 266
        </div>
      </PageHeaderWrapper>
    );

  }
}