index.jsx 10.2 KB
Newer Older
钟是志's avatar
钟是志 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/**
 * 徐立
 * 2019年9月18日
 * 发起流程表单申请列表
 */
import React, { Component } from 'react';
import styles from './styles.less';
import { Form, Button, Spin } from 'antd';
import AddModal from './AddModal';
import openToast from '@/webPublic/one_stop_public/DetailForAudit/components/Notification';
import { connect } from 'dva';
import ZdyTable from '@/webPublic/one_stop_public/Table';
import { preHandle } from '@/webPublic/one_stop_public/utils/myutils';
import router from 'umi/router';
import { isEmpty } from 'lodash';
import { callbackApplyData } from '@/webPublic/one_stop_public/models/callbackExamineProcess';
import { isJSON } from '@/webPublic/one_stop_public/tableCompon/Split_Index/staticInfo';
import { getModal } from '@/webPublic/one_stop_public/utils/utils';
import beforeApplySubmit from '@/webPublic/one_stop_public/utils/beforeApplySubmit';
20
import { uaaRequest } from '@/webPublic/one_stop_public/utils/request';
21
import { deepCopy } from '@/webPublic/zyd_public/utils/utils';
钟是志's avatar
钟是志 committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 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

const Modal = getModal();

class SponsorForm extends Component {
  constructor(props) {
    super(props);
    this.setEditor = editor => {
      this.editor = editor;
    };
    this.focusEditor = () => {
      if (this.editor) {
        this.editor.focus();
      }
    };
    const { propsState } = props;
    this.state = {
      visible: false, // 确认弹框状态
      img: '', // 上传图片路径
      items: [], // 动态列表数据
      left: 0,
      top: 0,
      max: 4,
      width: 100,
      init: {}, // 默认值
      disabled: false, // 按钮控制状态
      data: '', //当前用户数据
      appId: propsState.appId,
      postData: propsState.postData,
      isLoading: propsState.isLoading,
      draftId: propsState.draftId,
    };
  }

  countHeight = () => {
    let dom = document.getElementById('tabsTableFromIframe');
    let top = 0;
    if (dom && dom.offsetHeight) {
      let height = dom.offsetHeight;
      if (height > 700) {
        top = height - 700;
      }
    }
    return top;
  };

  /**
   * 提交完成后用户提示
   */
钟是志's avatar
钟是志 committed
70 71 72 73
  info = (applySubmitModalProps = undefined) => {
    let method = applySubmitModalProps && applySubmitModalProps.method ? applySubmitModalProps.method : 'info'; // 从流程发起回调里面拿配置项
    let config = (applySubmitModalProps && applySubmitModalProps.config) || {};
    Modal[method]({
钟是志's avatar
钟是志 committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
      title: '提交申请',
      centered: true,
      content: (
        <div>
          <p
            style={{
              width: '100%',
              textAlign: 'center',
              fontSize: 14,
              color: '#666666',
            }}
          >
            已提交申请!请耐心等待审核。
          </p>
        </div>
      ),
      okText: '确定',
      onOk: () => {
92 93 94
        if(this.props.returnList){
          this.props.returnList(true);
        }
钟是志's avatar
钟是志 committed
95 96
        return new Promise((resolve, reject) => {
          resolve(true);
97 98
        })
        return true;
钟是志's avatar
钟是志 committed
99
      },
钟是志's avatar
钟是志 committed
100
      ...config,
钟是志's avatar
钟是志 committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
    });
  };
  /**
   * 用户最终确认 发起提交
   */
  userTrue = () => {
    this.setState({
      isUser: true,
    });
  };
  /**
   * 展示确认级弹框状态
   */
  showModal = e => {
    e.preventDefault();
    this.props.form.validateFields((err, values) => {
      if (!err) {
        this.setState({
          visible: true,
        });
      } else {
        console.error(err);
      }
    });
  };
  /**
   * 隐藏弹框
   */
  handleCancel = e => {
    this.setState({
      visible: false,
    });
  };
  /**
   * 删除已添加人物
   */
  // removePeo = (id) => {
  //     this.setState({
  //         people: this.state.people.filter(item => item.id !== id)
  //     })
  // }
  /**
   * 下拉选择框事件
   */
  onChange = value => {
    console.log(`selected ${value}`);
  };
  /**
   * 确认提交后触发提交申请,返回true时提示用户提交完成
   */
  handleOk = e => {
    this.handleSubmit();
    // 关闭弹框
    this.handleCancel();
  };
  /**
   * 上传文件函数
   */
  normFile = e => {
    console.log('Upload event:', e);
    if (Array.isArray(e)) {
      return e;
    }
    return e && e.fileList;
  };
  /**
   * 确认完用户状态发起请求
   */
  handleSubmit = () => {
    let { dispatch, radioValue } = this.props;
    let isCloseFlowPath = sessionStorage.getItem('isCloseFlowPath')
      ? JSON.parse(sessionStorage.getItem('isCloseFlowPath'))
      : false;
    this.props.form.validateFields((err, values) => {
      if (!err) {
        if (isCloseFlowPath) {
        } else if (!radioValue) {
          openToast('success', '请选择紧急度');
          return;
        }
181 182
        let newValues = deepCopy(values);
        preHandle(newValues);
钟是志's avatar
钟是志 committed
183
        //如果是从流程仿真进入
184
        if (this.props.onSub && false) {
钟是志's avatar
钟是志 committed
185 186 187
          dispatch({
            type: 'affair/startProcessByService',
            payload: {
188
              content: JSON.stringify(newValues), // 表单数据
钟是志's avatar
钟是志 committed
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
              level: radioValue, // 流程紧急度 非必填 可以不传
              appId: this.state.appId, // 这里应该由上级路由跳转传入 事务Id
              id: !!this.state.draftId ? this.state.draftId : null, // 确认是否存在草稿表单Id存在即传入
              startUser: this.props.startUser ? this.props.startUser : null,
            },
            callback: val => {
              if (val) {
                this.props.onSub(val);
              } else {
                openToast('error', '保存失败', '请尝试');
              }
            },
          });
        } else {
          let params = {
204
            content: JSON.stringify(newValues), // 表单数据
钟是志's avatar
钟是志 committed
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
            level: radioValue, // 流程紧急度 非必填 可以不传
            appId: this.state.appId, // 这里应该由上级路由跳转传入 事务Id
            id: !!this.state.draftId ? this.state.draftId : null, // 确认是否存在草稿表单Id存在即传入
            userNowInfo:
              (localStorage.getItem('user') &&
                isJSON(localStorage.getItem('user')) &&
                JSON.parse(localStorage.getItem('user'))) ||
              {}, // 用户信息
          };

          params = callbackApplyData(params);
          if (!params) {
            return;
          }
          beforeApplySubmit(params).then(resParams => {
            if (!resParams) {
              return false;
            }
钟是志's avatar
钟是志 committed
223 224 225
            let applySubmitModalProps = resParams?.applySubmitModalProps  || undefined;
            delete resParams.applySubmitModalProps;
            message.info('正在提交申请,请等待');
226
            uaaRequest('/UnifiedAppFormApi/startProcess', resParams).then((val) => {
227 228 229 230 231 232 233 234 235 236 237 238
              if (val) {
                this.info(applySubmitModalProps);
              } else {
                openToast('error', '保存失败', '请尝试');
              }
            })
            // dispatch({
            //   type: 'affair/startProcess',
            //   payload: resParams,
            //   callback: val => {
            //   },
            // });
钟是志's avatar
钟是志 committed
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
          });
        }
      } else {
        openToast('error', '提交失败', '请填写必填项');
      }
    });
  };

  render() {
    let { disabled, visible, postData, isLoading } = this.state;
    let { init, noNeedApplyButton } = this.props;
    let routerState = {
      history: this.props?.history,
      location: this.props?.location,
      match: this.props?.match,
      computedMatch: this.props?.computedMatch,
      route: this.props?.route,
    };
    return (
      <>
        {isLoading ? (
          <>
            <div className={styles.form} id="add_form">
              {isEmpty(postData) === false ? (
                <ZdyTable
钟是志's avatar
钟是志 committed
264
                  isCg={undefined}
钟是志's avatar
钟是志 committed
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
                  get="web"
                  postData={postData}
                  form={this.props.form}
                  routerState={routerState}
                  init={init}
                />
              ) : (
                ''
              )}
              {isEmpty(postData) === false && !postData?.isUpdate && !noNeedApplyButton ? (
                <Form.Item
                  wrapperCol={{
                    span: 12,
                    offset: 6,
                  }}
                >
                  <Button
                    disabled={disabled}
                    type="primary"
                    loading={this.props.loading}
                    onClick={this.showModal}
                    style={{ marginLeft: 16 }}
                  >
                    提交
                  </Button>
                </Form.Item>
              ) : (
                ''
              )}
              <AddModal
                visible={visible}
                handleOk={this.handleOk}
                userTrue={this.userTrue}
                loading={this.props.loading}
                handleCancel={this.handleCancel}
              />
            </div>
          </>
        ) : (
          <div
            style={{
              width: '100%',
              height: 200,
              display: 'flex',
              justifyContent: 'center',
              alignItems: 'center',
            }}
          >
            <Spin size="large" />
          </div>
        )}
      </>
    );
  }
}

@connect(({ affair, loading }) => ({
  affair,
  loading: loading.models.affair,
}))
export default class SponsorFormDetail extends Component {
  constructor(props) {
    super(props);
    this.state = {
      postData: null,
    };
  }

  componentDidMount() {
钟是志's avatar
钟是志 committed
334
    let { id, dispatch } = this.props;
钟是志's avatar
钟是志 committed
335 336 337 338 339 340 341 342 343 344 345 346 347
    dispatch({
      type: 'modileHome/getDetail',
      payload: {
        id: id,
        userCode: this.props.startUser ? this.props.startUser : null,
      },
      callback: val => {
        if (val) {
          this.setState(
            {
              appId: val.id,
              isLoading: true,
              postData: val,
钟是志's avatar
钟是志 committed
348
              draftId:  '',
钟是志's avatar
钟是志 committed
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
            },
            () => {},
          );
        }
      },
    });
  }

  render() {
    const { postData } = this.state;
    if (!postData) {
      return null;
    } else {
      const SponsorFormNew = Form.create(
        window.zdyTableTemplateWillMountProps?.formCreateOptions || undefined,
      )(SponsorForm);
      return <SponsorFormNew {...this.props} propsState={this.state} />;
    }
  }
}