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 BS044EditPage 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' };

    let urldeal = '';
    let sopVisibledeal = { display: 'none' };
    let btnVisibledeal = { display: 'inline' };
    if (this.state.data.ISDEALSIGN && this.state.data.Nav_UserDeal.Nav_UserSignFiles.length > 0) {
      //如果 整改责任人已经签名   赋值
      urldeal = config.picServerHost + this.state.data.Nav_UserDeal.Nav_UserSignFiles[0].Nav_ImgFile.Nav_File.FILE_PATH;
      sopVisibledeal = { display: 'inline' };
      btnVisibledeal = { display: 'none' };
    }


    if (this.state.data.ISCHECKSIGN && this.state.data.Nav_UserCheck.Nav_UserSignFiles?.length > 0) {
      //如果 验收人已经签名 赋值
      url = config.picServerHost + this.state.data.Nav_UserCheck.Nav_UserSignFiles[0].Nav_ImgFile.Nav_File.FILE_PATH;
      // url = config.picServerHost + this.state.data.Nav_ListCheckUserSign[0].Nav_User.Nav_UserSignFiles[0].Nav_ImgFile.Nav_File.FILE_PATH;
      sopVisible = { display: 'inline' };
      btnVisible = { display: 'none' };
    }

    // 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,
      urldeal,
      sopVisibledeal,
      btnVisibledeal
    })
  }
  handleSopShowUserSign = () => {
    // var a = login
    // let file = this.state.updateLoadFileList;
    if (this.state.data.Nav_UserDeal) {
      // this.state.data.Nav_ListCheckUserSign[0].IS_DELETED = false
      //给导航属性赋值
      // Nav_ListUserSign
      var userSign = {
        "SUBMIT_CONTENT_DEAL_ID": this.state.data.ID,
        "SIGNTYPE": 10,
        "SUSER_ID": this.state.data.DEAL_USER_ID,
        "IMG_FILE_ID": this.state.data.Nav_UserCheck.Nav_UserSignFiles[0].Nav_ImgFile.ID
      }
      this.state.data.Nav_ListUserSign.push(userSign)
      this.setState({
        urldeal: config.picServerHost + this.state.data.Nav_UserDeal.Nav_UserSignFiles[0].Nav_ImgFile.Nav_File.FILE_PATH,//"https://t7.baidu.com/it/u=4162611394,4275913936&fm=193&f=GIF",//
        sopVisibledeal: { display: 'inline' },
        btnVisibledeal: { display: 'none' }
      });
    }
  };

  handleSopShowCheckUserSign = () => {
    if (this.state.data.Nav_UserCheck) {
      //给导航属性赋值
      // Nav_ListCheckUserSign
      var checkUserSign = {
        "SUBMIT_CONTENT_DEAL_ID": this.state.data.ID,
        "SIGNTYPE": 20,
        "SUSER_ID": this.state.data.CHECK_USER_ID,
        "IMG_FILE_ID": this.state.data.Nav_UserCheck.Nav_UserSignFiles[0].Nav_ImgFile.ID
      }
      this.state.data.Nav_ListCheckUserSign.push(checkUserSign)
      this.setState({
        url: config.picServerHost + this.state.data.Nav_UserCheck.Nav_UserSignFiles[0].Nav_ImgFile.Nav_File.FILE_PATH,//"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_ListUserSign') {
      const that = this;
      const viewSopProps = {

      }
      return <>
        <Button {...viewSopProps} type="primary" onClick={() => this.handleSopShowUserSign()} style={this.state.btnVisibledeal}>
          签名
        </Button>
        <div>
          <img width={200} height={100} style={this.state.sopVisibledeal} src={this.state.urldeal} alt="" />
        </div>
      </>
    } else if (colConfig.field === 'Nav_ListCheckUserSign') {
      const that = this;
      const viewSopProps = {

      }
      return <>
        <Button {...viewSopProps} type="primary" onClick={() => this.handleSopShowCheckUserSign()} 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()(BS044EditPage))
