import React from 'react'
import { connect } from 'dva'
import { Button, Row, Col, Form, Input, Select, Upload, Icon, Modal, Spin } from 'antd';
import config from "../../../config.js"
import storage from '../../../utils/storage'
import Edit from '../../Edit/Edit.js'
import EditComponent from '../../../baseComponents/EditComponent/index.js'
import { message } from "antd/lib/index";
import { guid, initFilter, extendRule, extendInclude } from '../../../utils/common.js';

class FoTeamActivity extends EditComponent {

  //保存前处理事件
  onBeforeSaveHandleRecord(params) {
    const { editCode, record, srcRecord } = params ? params : {};
    record.OpType = 0;
    if (params.customParams) {    //判断是否有通过系统配置界面进行“按钮自定义传参”
      record.OpType = 1;
    }
    record.TaskID = this.props.data.TaskID    //TaskID传递消息表ID
  }
  //加载前处理事件(加载附件显示，通过数组遍历，只需修改导航属性Nav_TeamActivityFile)
  onBeforeEdit(params) {
    super.onBeforeEdit(params);
    const { isNew, isCopy, copySrcData, login, updateSubTableData, stateData, dispatch } = params ? params : {};
    const updateLoadFileList = [];
    if (this.state.data && this.state.data.Nav_TeamActivityFile) {
      this.state.data.Nav_TeamActivityFile.forEach(t => {
        updateLoadFileList.push({
          uid: t.ID,
          name: t.name ? t.name : (t.Nav_ImgFile ? t.Nav_ImgFile.FILE_NAME : '未知文件'),
          status: t.status ? t.status : 'done',
          response: { Data: { imgFileID: t.IMG_FILE_ID }, file: t },
          url: t.Nav_ImgFile ? (config.picServerHost + t.Nav_ImgFile.Nav_File.FILE_PATH) : '',
        });
      });
    }

    if (isNew) {
      const json = initFilter();
      extendRule(json, 'CHARGE_PERSON_ID', 1, login.user.PERSON_ID);
      extendInclude(json, 'Nav_TeamPersons.Nav_Person.Nav_User');
      dispatch({
        type: 'app/getDataByPost',
        url: 'FM/FMTeam/TeamOrderPaged',
        payload: json,
        onComplete: (ret) => {
          if (ret && ret.length > 0) {
            let teamPersons = ret[0].Nav_TeamPersons;
            let person = [];
            let rowNo = 1;
            if (teamPersons && teamPersons.length > 0) {
              teamPersons.forEach(item => {
                let objPerson = {
                  Nav_User: {
                    Nav_Person: {
                      Nav_Post: {
                        NAME: ''
                      }
                    }
                  },
                  CODE: '',
                  NAME: ''
                }
                objPerson.Nav_User.CODE = item.Nav_Person.CODE;
                objPerson.Nav_User.NAME = item.Nav_Person.NAME;
                objPerson.Nav_User.Nav_Person.Nav_Post.NAME = item.Nav_Person?.Nav_Post?.NAME;
                objPerson.ROW_NO = rowNo;
                objPerson.ID = guid();
                objPerson.TEAM_ACTIVITY_ID = stateData.ID;
                objPerson.USER_ID = item.Nav_Person?.Nav_User?.ID;
                objPerson.ATTEND_STATUS = 1;
                person.push(objPerson);
                rowNo++;
              })
            }
            stateData["Nav_TeamActivityUser"] = person
            this.setState({
              stateData
            })
          }
        }
      })
    }
    this.setState({
      updateLoadFileList,
    })
  }
}

export default connect(({ login, loading, EMemOrder, custom, app, btnSaveNotice }) => ({ login, loading, EMemOrder, custom, app, btnSaveNotice }))(Form.create()(FoTeamActivity))





