import React, { Component } from 'react'
import {
  Form,
  Spin,
  Table,
  Modal,
  Radio,
  Col,
  Upload,
  Input,
  Button,
} from 'antd'
import { getMaterialStatus, getUrgentStatus } from '@/tools'
import './checkProjectStyle.less'

const radioGroupStyle = {
  display: 'flex',
  flexFlow: 'row nowrap',
  alignItems: 'flex-start',
  flex: 1,
}

const layout = {
  labelCol: {
    span: 8,
  },
  wrapperCol: {
    span: 16,
  },
};

const tailLayout = {
  wrapperCol: {
    offset: 8,
    span: 16,
  },
};

const radioStyle = {
  display: 'flex',
  flexFlow: 'row nowrap',
}

const FormItem = Form.Item

class CheckProject extends Component {
  constructor(props) {
    super(props)
    this.state = {
      value: '',
      loading: false,
      previewImage: '',
      previewVisible: false,
      previewPayVisible: false,
      // 专利
      ContactsListsNew: [
        {
          title: '供应商名称',
          dataIndex: 'companyName',
          key: 'companyName',
          render: (text, record, index) => {
            if (text) {
              return <span>{text}</span>
            }
          },
        },
        {
          title: '单价（万元）',
          dataIndex: 'unitPrice',
          key: 'unitPrice',
          render: (text, record) => {
            if (text) {
              return <span>{text}</span>
            }
          },
        },
        {
          title: '数量',
          dataIndex: 'quantity',
          key: 'quantity',
          render: (text, record) => {
            if (text) {
              return <span>{text}</span>
            }
          },
        },
        {
          title: '总价(万元)',
          dataIndex: 'totalAmount',
          key: 'totalAmount',
          render: (text, record) => {
            if (text) {
              return <span>{text}</span>
            }
          },
        },
        {
          title: '材料',
          dataIndex: 'material',
          key: 'material',
          render: (text, record) => {
            return getMaterialStatus(text)
          },
        },
        {
          title: '加急',
          dataIndex: 'urgent',
          key: 'urgent',
          render: (text, record) => {
            return getUrgentStatus(text)
          },
        },
        {
          title: '操作',
          dataIndex: 'action',
          key: 'action',
          render: (text, record) => {
            return (
              <div>
                <Button type="primary" onClick={() => {
                  this.setState({
                    previewPayVisible: true
                  })
                }}>
                  申请付款
                </Button>
              </div>
            )
          },
        },
      ],
      //付款节点表头
      PayNodeTableColunms: [
        {
          title: '供应商名称',
          dataIndex: 'companyName',
          key: 'companyName',
          render: (text, record, index) => {
            if (text) {
              return <span>{text}</span>
            }
          },
        },
        {
          title: '付款科目',
          dataIndex: 'dunType',
          key: 'dunType',
          render: (text, record) => {
            if (text) {
              return <span>{text}</span>
            }
          },
        },
        {
          title: '付款时间',
          dataIndex: 'partyTimes',
          key: 'partyTimes',
          render: (text, record) => {
            if (text) {
              return <span>{text}</span>
            }
          },
        },
        {
          title: '数量',
          dataIndex: 'quantity',
          key: 'quantity',
          render: (text, record) => {
            if (text) {
              return <span>{text}</span>
            }
          },
        },
        {
          title: '总价(万元)',
          dataIndex: 'totalAmount',
          key: 'totalAmount',
          render: (text, record) => {
            if (text) {
              return <span>{text}</span>
            }
          },
        },
        {
          title: '付款(万元)',
          dataIndex: 'partyAmount',
          key: 'partyAmount',
          render: (text, record) => {
            if (text) {
              return <span>{text}</span>
            }
          },
        },
      ],
    }
  }

  onChange() {
    this.setState({
      value: e.target.value,
    })
  }

  tableRowClickOne(record) {}

  //点击付款节点详情
  payNodeTableRowClickOne(record) {}

  //第三方信息 新增支付
  addOrderPayment(id) {
    $.ajax({
      method: 'POST',
      dataType: 'json',
      crossDomain: false,
      url: globalConfig.context + '/api/admin/company/addOrderPayment',
      data: {},
    }).done(
      function (data) {
        this.setState({
          loading: false,
        })
        if (!data.error.length) {
          message.success('保存成功！')
          this.noCancel()
        } else {
          message.warning(data.error[0].message)
        }
      }.bind(this)
    )
  }

  handleSubmit(e){
    e.preventDefault();
    console.log('Success:',this.props.form);
  }

  render() {
    return (
      <div className="App">
        <div className="projectType">
          <div className="typeTitle">
            <div className="required">*</div>
            <div>类型:</div>
          </div>
          <Radio.Group style={radioGroupStyle} value={this.props.startType}>
            <Radio value={0} style={radioStyle}>
              <div>
                <div>供应商信息(外包派单,不走总部)</div>
                <div className="tipsText">提示高于总部价格,费用个人承担</div>
              </div>
            </Radio>
            <Radio value={1} style={radioStyle}>
              供应商信息(普通单)
            </Radio>
          </Radio.Group>
        </div>
        <div className="thirdParty">
          <div>
            <span
              style={{
                fontSize: '18px',
              }}
            >
              第三方信息
            </span>
          </div>
          <div
            className="clearfix"
            style={
              {
                // display: this.state.type == 1 ? 'block' : 'block',
              }
            }
          >
            <Spin spinning={this.state.loading}>
              <Form layout="horizontal">
                <Table
                  pagination={false}
                  columns={this.state.ContactsListsNew}
                  dataSource={this.props.thirdInfoList}
                  onRowClick={this.tableRowClickOne}
                  scroll={{ x: 'max-content', y: 0 }}
                  bordered
                  size="small"
                />
                <Col span={24} offset={9} style={{ marginTop: '15px' }}></Col>
              </Form>
            </Spin>
          </div>
        </div>
        <div className="thirdParty">
          <div>
            <span
              style={{
                fontSize: '18px',
              }}
            >
              付款节点
            </span>
          </div>
          <div
            className="clearfix"
            style={
              {
                // display: this.state.type == 1 ? 'block' : 'block',
              }
            }
          >
            <Spin spinning={this.state.loading}>
              <Form layout="horizontal">
                <Table
                  pagination={false}
                  columns={this.state.PayNodeTableColunms}
                  dataSource={this.props.dataSource}
                  onRowClick={this.payNodeTableRowClickOne}
                  scroll={{ x: 'max-content', y: 0 }}
                  bordered
                  size="small"
                />
                <Col span={24} offset={9} style={{ marginTop: '15px' }}></Col>
              </Form>
            </Spin>
          </div>
        </div>
        <div
          className="clearfix"
          style={{
            borderTop: '1px #000000 dashed',
            paddingTop: '20px',
          }}
        >
          <FormItem
            labelCol={{ span: 2 }}
            wrapperCol={{ span: 8 }}
            label="备注"
          >
            <Input
              type="textarea"
              placeholder="请输入备注"
              rows={4}
              value={this.props.outsourceRemarks}
            />
          </FormItem>
        </div>
        <div className="clearfix">
          <FormItem
            labelCol={{ span: 3 }}
            wrapperCol={{ span: 18 }}
            label="合同/协议扫描件"
          >
            <Upload
              className="demandDetailShow-upload"
              listType="picture-card"
              fileList={this.props.fileList}
              onPreview={(file) => {
                this.setState({
                  previewImage: file.url || file.thumbUrl,
                  previewVisible: true,
                })
              }}
            />
            <Modal
              maskClosable={false}
              footer={null}
              visible={this.state.previewVisible}
              onCancel={() => {
                this.setState({ previewVisible: false })
              }}
            >
              <img
                alt=""
                style={{ width: '100%' }}
                src={this.state.previewImage || ''}
              />
            </Modal>
          </FormItem>
        </div>
        {/* 申请付款 */}
        <Modal
          maskClosable={false}
          footer={null}
          visible={this.state.previewPayVisible}
          onCancel={() => {
            this.setState({ previewPayVisible: false })
          }}
        >
          <div>
            <div>支付供应商费用</div>
            <Form
                {...layout}
                name="basic"
                initialValues={{
                  remember: true,
                }}
                onSubmit={this.handleSubmit}
            >
              <Form.Item
                  style={{
                    display:'flex'
                  }}
                  label="付款单位/个人:"
                  name="company"
                  rules={[
                    {
                      required: true,
                      message: '请输入付款单位/个人!',
                    },
                  ]}
              >
                <Input style={{ width: '200px' }} placeholder="请输入付款单位/个人"/>
              </Form.Item>
              <Form.Item
                  style={{
                    display:'flex'
                  }}
                  label="单价(万元):"
                  name="unitPrice"
                  rules={[
                    {
                      required: true,
                      message: '请输入单价!',
                    },
                  ]}
              >
                <Input style={{ width: '200px' }} placeholder="请输入单价" type={'number'}/>
              </Form.Item>
              <Form.Item
                  style={{
                    display:'flex'
                  }}
                  label="数量:"
                  name="num"
                  rules={[
                    {
                      required: true,
                      message: '请输入數量!',
                    },
                  ]}
              >
                <Input style={{ width: '200px' }} placeholder="请输入數量" type={'number'}/>
              </Form.Item>
              <Form.Item
                  style={{
                    display:'flex'
                  }}
                  label="总价(万元):"
                  name="totalPrice"
                  rules={[
                    {
                      required: true,
                      message: '请输入总价!',
                    },
                  ]}
              >
                <Input style={{ width: '200px' }} placeholder="请输入总价" type={'number'}/>
              </Form.Item>
              <Form.Item
                  style={{
                    display:'flex'
                  }}
                  label="已付(万元):"
                  name="paid"
                  rules={[
                    {
                      required: true,
                      message: '请输入已付金额!',
                    },
                  ]}
              >
                <Input style={{ width: '200px' }} placeholder="请输入已付金额" type={'number'}/>
              </Form.Item>
              <Form.Item
                  style={{
                    display:'flex'
                  }}
                  label="本次申请支付金额(万元):"
                  name="payment"
                  rules={[
                    {
                      required: true,
                      message: '请输入本次申请支付金额!',
                    },
                  ]}
              >
                <Input style={{ width: '200px' }} placeholder="请输入本次申请支付金额(" type={'number'}/>
              </Form.Item>
              <Form.Item
                  style={{
                    display:'flex'
                  }}
                  label="备注:"
                  name="remarks"
                  rules={[
                    {
                      required: true,
                      message: '请输入本次申请支付金额!',
                    },
                  ]}
              >
                <Input style={{ width: '200px' }} placeholder="请输入本次申请支付金额(" type={'textarea'}/>
              </Form.Item>
              <Form.Item>
                <Button type="primary" htmlType="submit">
                  确定申请支付
                </Button>
              </Form.Item>
            </Form>
          </div>
        </Modal>
      </div>
    )
  }
}

export default CheckProject
