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 } from '../../../utils/common.js';
import { PlusOutlined } from '@ant-design/icons';
import { Label } from 'bizcharts';
import FormPage from '../../FormPage';

class BS034EditPage extends EditComponent {
  //加载前处理事件(加载附件显示，通过数组遍历，只需修改导航属性Nav_TeamActivityFile)
  onBeforeEdit(params) {
    super.onBeforeEdit(params);
    const { isNew, isCopy, copySrcData, login, updateSubTableData, stateData } = params ? params : {};
    const updateLoadFileList = [];
    let url = '';
    let sopVisible = { display: 'none' };
    let btnVisible = { display: 'inline' };
    if (this.state.data && this.state.data.Nav_ListCheckUserSign) {
      this.state.data.Nav_ListCheckUserSign.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) : '',
        });
      });
    }

    this.setState({
      updateLoadFileList,
      url,
      sopVisible,
      btnVisible
    })
  }
  handleSopShowModal = () => {
    if (this.state.data.Nav_ListCheckUserSign == undefined || this.state.data.Nav_ListCheckUserSign == null || this.state.data.Nav_ListCheckUserSign.length < 1) {
message.error('请完善签名：登录信息=>我的资料=>上传签名照片')
    } else {
      let file = this.state.updateLoadFileList;
      this.state.data.Nav_ListCheckUserSign[0].IS_DELETED = false
      if (file[0]) {
        this.setState({
          url: file[0].url,//"https://t7.baidu.com/it/u=4162611394,4275913936&fm=193&f=GIF",//
          sopVisible: { display: 'inline' },
          btnVisible: { display: 'none' }
        });
      }
    }
  };


  //render加载上传组件（可支持新增上传）
  onRenderHeadControl(params) {

    const { colConfig, record, stateData } = params;
    console.log(stateData)
    if (colConfig.field === 'Nav_ListCheckUserSign') {
      const that = this;
      const viewSopProps = {

      }
      return <>
        <Button {...viewSopProps} type="primary" onClick={() => this.handleSopShowModal()} style={this.state.btnVisible}>
          签名
        </Button>
        <div>
          <img width={200} height={100} style={this.state.sopVisible} src={this.state.url} alt="" />
        </div>
      </>
    }
    return super.onRenderHeadControl(params);
  }
}

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





