import React from "react";
import {
  Icon,
  Button,
  Input,
  Select,
  Spin,
  Table,
  message,
  DatePicker,
  Upload,
  Form,
  Modal,
  Tabs,
  Col,
  Popconfirm,
  Tag
} from "antd";
import $ from "jquery/src/ajax";
import moment from "moment";
import {
  getLiquidationStatus,
  getApprovedState,
  getProcessStatus,
  splitUrl,
  getjiedian,
  getboutique,
  getCuikuan,
  getProjectStatus,
  getRefundStatus,
  ShowModal
} from "@/tools.js";
import "./customer.less";
import ShowModalDiv from "@/showModal.jsx";
import ResolutionDetail from "@/resolutionDetail";
const confirm = Modal.confirm;
import OrderRiZi from "@/orderRiZi.jsx";
import ImgList from "../../../common/imgList";
import {ChooseList} from "./chooseList";
import {getProjectName} from "../../../tools";
import ProjectDetailsReadOnly from "../../../common/projectDetailsReadOnly";
//图片组件
const PicturesWall = React.createClass({
  getInitialState() {
    return {
      previewVisible: false,
      previewImage: "",
      declarationBatch: 1,
      dataInfor: {},
      fileList: []
    };
  },
  handleCancel() {
    this.setState({
      previewVisible: false
    });
  },
  handlePreview(file) {
    this.setState({
      previewImage: file.url || file.thumbUrl,
      previewVisible: true
    });
  },
  handleChange(info) {
    let fileList = info.fileList;
    this.setState({
      fileList
    });
    this.props.fileList(fileList);
  },
  componentWillReceiveProps(nextProps) {
    this.state.fileList = nextProps.pictureUrl;
    this.state.pojectApplicationUrl = undefined;
  },
  render() {
    const { previewVisible, previewImage, fileList } = this.state;
    const uploadButton = (
      
    );
    return (
      
        
          {uploadButton}
        
        
           
        
       
    );
  }
});
const outsourcingList = Form.create()(
  React.createClass({
    loadData(pageNo) {
      this.setState({
        visitModul: false,
        loading: true,
        ispage: pageNo,
        modalVisible: false,
      });
      $.ajax({
        method: "get",
        dataType: "json",
        crossDomain: false,
        url:
          globalConfig.context +
          "/api/admin/outsourceOrg/salesmanOrderOutsourceList",
        data: {
          pageNo: pageNo || 1,
          pageSize: this.state.pagination.pageSize,
          contractNo: this.state.contractNoSearch,
          name: this.state.nameSearch, //名称
          orderNo: this.state.orderNoSearch, //订单编号
          starTime: this.state.releaseDate[0], //开始时间
          endTime: this.state.releaseDate[1], //结束时间
          refundStatus: this.state.refundStatusSearch, //外包审核状态
        },
        success: function (data) {
          ShowModal(this);
          let theArr = [];
          if (data.error.length || data.data.list == "") {
            if (data.error && data.error.length) {
              message.warning(data.error[0].message);
            }
          } else {
            for (let i = 0; i < data.data.list.length; i++) {
              let thisdata = data.data.list[i];
              theArr.push({
                key: i,
                id: thisdata.id, //用户ID
                orderNo: thisdata.orderNo, //订单编号
                contractNo: thisdata.contractNo, //签单金额
                createTime: thisdata.createTime, //流程状态
                signTime: thisdata.signTime, //结算状态
                userName: thisdata.userName, //特批状态
                depName: thisdata.depName, //签单时间
                totalAmount: thisdata.totalAmount, //客户名称
                adminName: thisdata.adminName, //营销员名称
                financeName: thisdata.financeName, //财务名称
                liquidationStatus: thisdata.liquidationStatus, //下单时间
                refundStatus: thisdata.refundStatus,
              });
            }
            this.state.pagination.total = data.data.totalCount;
            this.state.pagination.current = data.data.pageNo;
          }
          if (data.data && data.data.list && !data.data.list.length) {
            this.state.pagination.total = 0;
          }
          this.setState({
            dataSource: theArr,
            pageNo: pageNo,
            pagination: this.state.pagination,
            selectedRowKeys: [],
          });
        }.bind(this),
      }).always(
        function () {
          this.setState({
            loading: false,
          });
        }.bind(this)
      );
    },
    getInitialState() {
      return {
        rotateDeg: 0,
        page: 1,
        releaseDate: [],
        selectedRowKeys: [],
        pictureUrl: [],
        fileUrl: [],
        attachmentUrl: [],
        paginations: false,
        resVisible: false,
        activeKey: "1",
        confirmLoading: false,
        aloading: false,
        pagination: {
          defaultCurrent: 1,
          defaultPageSize: 10,
          showQuickJumper: true,
          pageSize: 10,
          onChange: function (page) {
            this.loadData(page);
          }.bind(this),
          showTotal: function (total) {
            return "共" + total + "条数据";
          },
        },
        ContactsListsNew: [
          {
            title: "项目名称",
            dataIndex: "commodityName",
            key: "commodityName",
            render: (text, record, index) => {
              let dataArr = this.state.dataSourceX || [];
              if (text) {
                return {text + "-" + record.tid};
              }
              return (
                
              );
            },
          },
          {
            title: "项目分类",
            dataIndex: "projectType",
            key: "projectType",
            render: (text, record) => {
              // console.log("看分类", record);
              if (text) {
                let arr = this.state.dataSourceX || [];
                let str = "";
                for (let i = 0; i < arr.length; i++) {
                  if (this.state.dataSourceX[i].sort == text) {
                    str = this.state.dataSourceX[i].cname;
                    return {str};
                  }
                }
              }
              if (this.state.getLoad) {
                return (
                  
                );
              } else {
                return (
                  
                );
              }
            },
          },
          {
            title: "催款科目",
            dataIndex: "dunTypeName",
            key: "dunTypeName",
            render: (text, record) => {
              if (text) {
                if (record.customizeName) {
                  return text + record.customizeName;
                }
                return {text};
              }
              if (this.state.getLoad) {
                let arr = record.arr || [];
                // console.log("arrrr", arr);
                return (
                  
                );
              } else {
                return (
                  
                );
              }
            },
          },
          {
            title: "时间(天)",
            dataIndex: "waitDay",
            key: "waitDay",
            render: (text, record) => {
              if (record.dunTypeName) {
                if (record.customizeTimes) {
                  return record.customizeTimes;
                }
                return {text};
              }
              return (
                
              );
            },
          },
          {
            title: "金额(万元)",
            dataIndex: "money",
            key: "money",
            render: (text, record) => {
              if (record.dunTypeName) {
                if (record.appropriationRatio && !record.money) {
                  return {record.appropriationRatio}(拨款比例);
                } else if (record.appropriationRatio && record.money) {
                  return (
                    
                      {text}(比例:{record.appropriationRatio})
                    
                  );
                } else {
                  return {text};
                }
              }
              return (
                
                  {this.state.processStatus == 0 ? (
                     {
                        record.money = e.target.value;
                        this.setState({
                          contactListNew: this.state.contactListNew,
                        });
                      }}
                      style={{ width: "120px" }}
                    />
                  ) : (
                    {text}
                  )}
                
              );
            },
          },
          {
            title: "服务年限",
            dataIndex: "startDate",
            key: "startDate",
            render: (text, record) => {
              if (record.dunTypeName) {
                return {text};
              }
              return (
                
              );
            },
          },
          {
            title: "催款状态",
            dataIndex: "status",
            key: "status",
            render: (text) => {
              return {text == 1 ? "已启动" : "未启动"};
            },
          },
          {
            title: "操作",
            dataIndex: "dels",
            key: "dels",
            render: (text, record, index) => {
              return (
                
                  {/* {this.state.processStatus == 0 ? (
                    
 {
                        this.confirmDeletNew(record);
                      }}
                      okText="删除"
                      cancelText="不删除"
                    >
                      
                    
                  ) : (
                    ""
                  )}
                  {record.isSave ? (
                    
                  ) : (
                    ""
                  )} */}
                
注意
,
        content: (
          
            当前订单为外包单,您确定修改为普通订单?
          
        ),
        okText: "确定",
        okType: "danger",
        cancelText: "取消",
        onOk() {
          fn();
        },
        onCancel() {},
      });
    },
    changeList(arr) {
      const newArr = [];
      this.state.columns.forEach(item => {
        arr.forEach(val => {
          if (val === item.title) {
            newArr.push(item);
          }
        });
      });
      this.setState({
        changeList: newArr
      });
    },
    render() {
      const formItemLayout = {
        labelCol: { span: 8 },
        wrapperCol: { span: 14 },
      };
      const FormItem = Form.Item;
      const { TextArea } = Input;
      const { TabPane } = Tabs;
      const { RangePicker } = DatePicker;
      const cuiDataList = this.state.contactList || [];
      return (
        
          {this.state.resVisible ? (
            
          ) : (
            ""
          )}
          
          
            外包订单列表
          
          
            
              
                 {
                    this.setState({ nameSearch: e.target.value });
                  }}
                />
                 {
                    this.setState({ contractNoSearch: e.target.value });
                  }}
                />
                下单时间 :
                 {
                    this.setState({ releaseDate: dataString });
                  }}
                />
                
                
                
              
              
                
                  
                
              
            
            
            {this.state.visible ? 
              
                
                  {this.state.activeKey === "1" ?  : }
                
                
                  {this.state.refundStatus === 2 ? (
                    
                      
                        
                              *
                              外包公司
                            
                          }
                        >
                           {
                              this.setState({
                                companyName: e.target.value,
                              });
                            }}
                            placeholder="请填写外包公司名称"
                          />
                        
                        如多个公司,请用间隔
                      
                      
                        
                              *
                              单价(万元)
                            
                          }
                        >
                           {
                              this.setState({
                                unitPrice: e.target.value,
                              });
                            }}
                            placeholder="请填写本次外包公司的价格"
                          />
                        
                      
                      
                        
                              *
                              数量(个)
                            
                          }
                        >
                           {
                              this.setState({
                                unitNumber: e.target.value,
                              });
                            }}
                            placeholder="请填写本次外包公司的价格"
                          />
                        
                      
                      
                        
                              *
                              总金额(万元)
                            
                          }
                        >
                           {
                              this.setState({
                                amount: e.target.value,
                              });
                            }}
                            placeholder="请填写本次外包公司的价格"
                          />
                        
                      
                      
                        
                              *备注
                            
                          }
                        >
                          
                      
                      {/*
										
										     {
														return {
															'sign': e.name.substring(0,e.name.lastIndexOf("."))
														}
													}}
													fileList={this.state.fileUrl}
													onChange={(e)=>{
														this.setState({
															attachmentUrl:e.fileList,
															fileUrl:e.fileList
														})
													}}>
												{fileUrl.length>1?null:}
										    
										    支持文件格式: doc,excel,ppt
										
									
*/}
                      
                        首次派单项目,需上传协议,第2次起,同项目,只需写外包公司
                      
                      
                      
                        
                          
                          提示:高于总部价格,费用个人承担
                         
                       
                     
                  ) : (
                    
                      
                        
                          {this.state.companyName}
                        
                      
                      
                        
                          {this.state.unitPrice}
                        
                      
                      
                        
                          {this.state.unitNumber}
                        
                      
                      
                        
                          {this.state.amount}
                        
                      
                      
                        
                          {this.state.outsourceRemarks}
                        
                      
                      {/*
										
											{
														return {
															'sign': e.name.substring(0,e.name.lastIndexOf("."))
														}
													}}
													fileList={this.state.fileUrl}
													showUploadList={{showRemoveIcon:false}}
													onPreview={(e)=>{
														let url = window.location.href.substring(7)
														window.location.href="http://"+url.substring(0,url.indexOf("/"))+"/api/admin/outsourceOrg//downloadFile?path="+e.response.data
													}}
													>
											
										
									
*/}
                      
                        
                          {/* {*/}
                          {/*    this.setState({*/}
                          {/*      previewImage: file.url || file.thumbUrl,*/}
                          {/*      previewVisible: true,*/}
                          {/*    });*/}
                          {/*  }}*/}
                          {/*/>*/}
                          
                            {this.state.visible && this.state.activeKey === "2" && this.state.pictureUrl ? 
 : }
                           
                              
                              
                              
                          
                        
                       
                     
                  )}
                  {this.state.refundStatus ? (
                    
                      
                      
                        
                          {this.state.remarks}
                        
                      
                      
                        
                          
                            {getRefundStatus(this.state.refundStatus)}
                          
                        
                      
                      
                        
                          {this.state.auditTimes}
                        
                      
                     
                  ) : (
                    ""
                  )}
                
              
             : 
}
            
              
            
            {/* 
              
             */}
            
           
          {this.state.addnextVisible && 
}