import React from 'react';
import {
  Tooltip,
  Button,
  AutoComplete,
  Input,
  Select,
  Spin,
  Popconfirm,
  Table,
  message,
  DatePicker,
  Upload,
  Form,
  Modal,
  Col,
  Tag,
  Tabs,
  Radio
} from 'antd';
import $ from 'jquery/src/ajax';
import moment from 'moment';
import { boutique, tepi, jiedian, salesList, cuiJieDian } from '@/dataDic.js';
import {
  getLiquidationStatus,
  getProcessStatus,
  splitUrl,
  getCuikuan,
  moneyVerify,
  ShowModal
} from "@/tools.js";
import './customer.less';
import ShowModalDiv from "@/showModal.jsx"
import OrderRiZi from "@/orderRiZi.jsx";
import ResolutionDetail from "@/resolutionDetail";
import ImgList from "../../../common/imgList";
import { ChooseList } from "./chooseList";
import OrderItemStatus from "../../../common/orderItemStatus";
import EnterpriseNameChange from "../../../common/enterpriseNameChange";
import OrderCoor from './changeComponent/orderCoor';
import ProjectOperation from "../../../common/projectOperation";
import ContentUrl from './contentUrl';
import UpdateSales from './updatesales';//修改销售类型
//图片组件
const PicturesWall = React.createClass({
  getInitialState() {
    return {
      fileList: [],
    }
  },
  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 { fileList } = this.state;
    return (
      
         {
            this.handleChange(infor)
          }}
          fileList={fileList}
        />
       
    );
  }
});
const IntentionCustomer = 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/newOrder/orderNewList",
        data: {
          pageNo: pageNo || 1,
          pageSize: this.state.pagination.pageSize,
          specially: 2, //审核列表
          name: this.state.customerName, //名称
          orderNo: this.state.orderNoSearch, //订单编号
          starTime: this.state.releaseDate[0], //开始时间
          endTime: this.state.releaseDate[1], //结束时间
        },
        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];
              thisdata.key = i;
              thisdata.totalAmount = thisdata.totalAmount + ""; //签单金额
              theArr.push(thisdata);
            }
            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 {
        page: 1,
        orderNos: '',
        patentTypeList: [],
        releaseDate: [],
        orderStatus: 0,
        processStatus: 0,
        selectedRowKeys: [],
        orgCodeUrl: [],
        replenishUrl: [],
        contentUrl: [],
        customerArr: [],
        resVisible: false,
        pagination: {
          defaultCurrent: 1,
          defaultPageSize: 10,
          showQuickJumper: true,
          pageSize: 10,
          onChange: function (page) {
            this.loadData(page);
          }.bind(this),
          showTotal: function (total) {
            return "共" + total + "条数据";
          },
        },
        columns: [
          {
            title: "驳回编号",
            dataIndex: "backId",
            key: "backId",
          },
          {
            title: "驳回日期",
            dataIndex: "backDate",
            key: "backDate",
          },
          {
            title: "下单时间",
            dataIndex: "createDate",
            key: "createDate",
          },
          {
            title: "订单编号",
            dataIndex: "orderNo",
            key: "orderNo",
          },
          {
            title: "客户名称",
            dataIndex: "userName",
            key: "userName",
            render: (text) => {
              return (
                
                  {text}
                
              )
            },
          },
          {
            title: "驳回人",
            dataIndex: "initiateName",
            key: "initiateName",
          },
          {
            title: "驳回原因",
            dataIndex: "reason",
            key: "reason",
            render: (text) => {
              return text && text.length > 24
                ? text.substr(0, 24) + "..."
                : text;
            },
          },
        ],
        columnsrizhi: [
          {
            title: "流程",
            dataIndex: "processName",
            key: "processName",
          },
          {
            title: "操作人",
            dataIndex: "adminName",
            key: "adminName",
          },
          {
            title: "时间",
            dataIndex: "createDate",
            key: "createDate",
          },
        ],
        data: [],
        dataSource: [],
        columnsX: [
          {
            title: "业务项目名称",
            dataIndex: "commodityName",
            key: "commodityName",
            render: (text, record) => {
              return {text}{record.patentTypeName}{"-" + record.id}
            }
          },
          {
            title: "项目类别",
            dataIndex: "cname",
            key: "cname",
          },
          {
            title: "项目数量",
            dataIndex: "commodityQuantity",
            key: "commodityQuantity",
            render: (text, record) => {
              if (record.splitStatus == 1) {
                return (
                  
                    {text}{" "}
                     {
                        e.stopPropagation();
                        this.showRes(record);
                      }}
                    >
                      已拆
                    
                  
                );
              } else {
                return text;
              }
            },
          },
          {
            title: "金额(万元)",
            dataIndex: "commodityPrice",
            key: "commodityPrice",
          },
          {
            title: "负责人",
            dataIndex: "contacts",
            key: "contacts",
          },
          {
            title: "负责人电话",
            dataIndex: "contactsMobile",
            key: "contactsMobile",
          },
          {
            title: "主要项目",
            dataIndex: "main",
            key: "main",
            render: (text) => {
              return text ? "是" : "否";
            },
          },
          {
            title: "项目说明",
            dataIndex: "taskComment",
            key: "taskComment",
            render: (text) => {
              return text && text.length > 8 ? text.substr(0, 8) + "…" : text;
            },
          },
          {
            title: "操作",
            dataIndex: "ABC",
            key: "ABC",
            render: (text, record) => {
              return (
                
                  {this.state.processStatus == 0 ? (
                    
 {
                        this.delectRow(record);
                      }}
                      okText="是"
                      cancelText="否"
                    >
                      
                    
                  ) : (
                    ""
                  )}
                
 
              );
            },
          },
        ],
        dataSourceX: [],
        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) => {
              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 record.customizeName;
                }
                return {text};
              }
              if (this.state.getLoad) {
                let arr = record.arr || [];
                return (
                  
                    
                    {record.dunType == 0 ? (
                       {
                          record.customizeName = e.target.value;
                          this.setState({
                            contactList: this.state.contactList,
                          });
                        }}
                        style={{ width: "120px" }}
                      />
                    ) : (
                      ""
                    )}
                  
                );
              } else {
                return (
                  
                );
              }
            },
          },
          {
            title: "收款时间(特批需选择时间)",
            dataIndex: "waitDay",
            key: "waitDay",
            render: (text, record) => {
              if (record.dunTypeName) {
                if (record.customizeTimes) {
                  return record.customizeTimes;
                }
                if (text == 0) {
                  var str = "当天";
                } else if (!text) {
                  var str = "";
                } else {
                  var str = text + "天";
                }
                return {str};
              }
              return (
                
                  {record.dunType == 0 ? (
                     {
                        record.customizeTimes = t;
                      }}
                    />
                  ) : (
                    
                  )}
                
              );
            },
          },
          {
            title: "金额(万元)",
            dataIndex: "money",
            key: "money",
            render: (text, record) => {
              if (record.dunTypeName) {
                if (record.appropriationRatio) {
                  let percent = Number(record.appropriationRatio * 100);
                  percent += "%";
                  return {percent}(拨款比例);
                } else {
                  return {text};
                }
              }
              return (
                
              );
              // if (this.state.boFlag) {
              //   return (
              //     
              //       
              //         
              //       
              //       
              //          {
              //             record.money = e.target.value;
              //             this.setState({
              //               contactList: this.state.contactList,
              //             });
              //           }}
              //           style={{ width: "120px" }}
              //         />
              //       
              //     
 
              //   );
              // } else {
              //   return (
              //     
              //        {
              //           record.money = e.target.value;
              //           this.setState({ contactList: this.state.contactList });
              //         }}
              //         style={{ width: "120px" }}
              //       />
              //     
              //   );
              // }
            },
          },
          {
            title: "服务年限",
            dataIndex: "startDate",
            key: "startDate",
            render: (text, record) => {
              if (record.dunTypeName) {
                return {text};
              }
              return (
                
                  {
                    record.dunType != 0 ?
                      
 : 
                  }
                
 
              );
            },
          },
          {
            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 ? (
                    
                  ) : (
                    ""
                  )}
                
 
              );
            },
          },
        ],
        ContactsLists: [
          {
            title: "催款科目",
            dataIndex: "dunSubject",
            key: "dunSubject",
            render: (text, record) => {
              return (
                
              );
            },
          },
          {
            title: "金额(万元)",
            dataIndex: "money",
            key: "money",
            render: (text, record) => {
              return (
                 {
                    record.money = e.target.value;
                    this.setState({ contactList: this.state.contactList });
                  }}
                  style={{ width: "120px" }}
                />
              );
            },
          },
          {
            title: "催款状态",
            dataIndex: "dunStatus",
            key: "dunStatus",
            render: (text) => {
              return getCuikuan(text);
            },
          },
          {
            title: "操作",
            dataIndex: "dels",
            key: "dels",
            render: (text, record) => {
              return (
                
                  {
                    
 {
                        this.confirmDelet(record.key);
                      }}
                      okText="删除"
                      cancelText="不删除"
                    >
                      
                    
                  }
                  {record.id ? (
                    ""
                  ) : (
                    
                  )}
                
 
              );
            },
          },
        ],
        updatas: {},
      };
    },
    //删除
    delectRow(record) {
      this.setState({
        loading: true,
      });
      $.ajax({
        method: "post",
        dataType: "json",
        crossDomain: false,
        url: globalConfig.context + "/api/admin/newOrder/deleteOrderTask",
        data: {
          id: record.id,
        },
      }).done(
        function (data) {
          if (!data.error.length) {
            message.success("删除成功!");
            this.setState({
              loading: false,
            });
            this.xiangmu(this.state.orderNo);
            this.jiedianNew(this.state.orderNo);
            this.jiedian(this.state.orderNo);
            this.loadData(this.state.pageNo);
          } else {
            message.warning(data.error[0].message);
          }
        }.bind(this)
      );
    },
    //页面加载函数
    componentWillMount() {
      this.loadData();
    },
    //整行点击
    tableRowClick(record) {
      this.setState({
        visible: true,
        orderNos: record.orderNo,
        orderStatus: record.orderStatus,
        processStatus: record.orderStatus
      });
      this.xiangqing(record.orderNo);
      this.xiangmu(record.orderNo);
      this.jiedian(record.orderNo);
      this.jiedianNew(record.orderNo);
      this.departmentList();
      this.getpatentTypeList();
    },
    //点击打卡项目详情
    tableRowClickX(record) {
      this.setState({
        projectOperationVisible: true,
        dataInfor: record,
      })
    },
    //项目详情关闭
    nextCancel() {
      this.setState({
        projectOperationVisible: false,
        gid: "",
        dataInfor: {},
      }, () => {
        this.xiangmu(this.state.orderNo);
      });
    },
    //订单详情
    xiangqing(orderNos) {
      $.ajax({
        method: "get",
        dataType: "json",
        crossDomain: false,
        url: globalConfig.context + "/api/admin/newOrder/getOrderNewDetail",
        data: {
          orderNo: orderNos,
        },
        success: function (data) {
          if (data.error.length || data.data.list == "") {
            if (data.error && data.error.length) {
              message.warning(data.error[0].message);
            }
          } else {
            let thisdata = data.data;
            if (thisdata.approval == 0) {
              thisdata.approval = 0;
            } else {
              thisdata.approval = 1;
            }
            // if (thisdata.approval == 2) {
            //   thisdata.approval = "特批通过";
            // } else if (thisdata.approval == 3) {
            //   thisdata.approval = "特批驳回";
            // }
            this.setState({
              id: thisdata.id,
              orderUid: thisdata.uid,
              kehuId: thisdata.buyerId,
              orderNo: thisdata.orderNo, //订单编号
              contractNo: thisdata.contractNo, //合同编号
              userName: thisdata.userName, //客户名称
              signDate: thisdata.signDate, //签单时间
              processStatus: thisdata.processStatus, //流程状态
              liquidationStatus: thisdata.liquidationStatus, //结算状态
              contacts: thisdata.contacts, //企业联系人
              contactMobile: thisdata.contactMobile, //联系人电话
              legalPerson: thisdata.legalPerson, //法人
              legalPersonTel: thisdata.legalPersonTel, //法人电话
              firstAmount: thisdata.firstAmount + "", //签单金额
              totalAmount: thisdata.totalAmount + "", //首付金额
              settlementAmount: thisdata.settlementAmount, //已收款项
              orderRemarks: thisdata.orderRemarks, //订单留言
              orgCodeUrl: thisdata.contractPictureUrl
                ? splitUrl(
                  thisdata.contractPictureUrl,
                  ",",
                  globalConfig.avatarHost + "/upload"
                )
                : [], //图片地址
              replenishUrl: thisdata.agreementUrl
                ? splitUrl(
                  thisdata.agreementUrl,
                  ",",
                  globalConfig.avatarHost + "/upload"
                )
                : [], //图片地址
              contentUrl: thisdata.serviceContent
                ? splitUrl(
                  thisdata.serviceContent,
                  ",",
                  globalConfig.avatarHost + "/upload"
                )
                : [], //图片地址
              salesmanName: thisdata.salesmanName, //营销员名称
              salesmanMobile: thisdata.salesmanMobile, //营销员电话
              oldSalesmanName: thisdata.oldSalesmanName, //营销员名称
              oldSalesmanMobile: thisdata.oldSalesmanMobile, //营销员电话
              financeName: thisdata.financeName, //财务名称
              financeMobile: thisdata.financeMobile, //财务电话
              nowFinance: thisdata.nowFinance, //财务名称
              nowFinanceMobile: thisdata.nowFinanceMobile, //财务电话
              initiateName: thisdata.initiateName, //驳回人
              backDate: thisdata.backDate, //驳回时间
              reason: thisdata.reason, //驳回原因
              approval: thisdata.approval, //特批状态
              organizationSearch: thisdata.orderDep,
              //approval:thisdata.approval==0?thisdata.approval.toString():thisdata.approval,//特批状态
              outsource: thisdata.outsource == 0 ? "否" : "是",
              deleteSign: thisdata.deleteSign,
              updatas: {
                salesType: thisdata.salesType,//销售类型
                userType: thisdata.userType,//客户所属类型
                other: thisdata.other,//3渠道名 4,5描述
              },
              channelName: thisdata.salesType == "3" ? thisdata.other : "",//销售类型为渠道的时候给编辑出的渠道名称赋值
            });
          }
        }.bind(this),
      }).always(
        function () {
          this.setState({
            loading: false,
          });
        }.bind(this)
      );
    },
    // 拆分详细
    showRes(record) {
      this.setState({
        resVisible: true,
        resRecord: record,
      });
    },
    resCancel() {
      this.setState({
        resVisible: false,
      });
    },
    //项目列表
    xiangmu(orderNos) {
      $.ajax({
        method: "get",
        dataType: "json",
        crossDomain: false,
        url: globalConfig.context + "/api/admin/newOrder/getOrderTask",
        data: {
          orderNo: orderNos,
        },
        success: function (data) {
          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.length; i++) {
              let thisdata = data.data[i];
              thisdata.key = i;
              thisdata.sort = thisdata.cSort;
              theArr.push(thisdata);
            }
          }
          this.setState({
            dataSourceX: theArr,
            paginations: false,
          });
        }.bind(this),
      }).always(
        function () {
          this.setState({
            loading: false,
          });
        }.bind(this)
      );
    },
    //节点列表
    jiedian(orderNos) {
      $.ajax({
        method: "get",
        dataType: "json",
        crossDomain: false,
        url: globalConfig.context + "/api/admin/newOrder/selectOrderDun",
        data: {
          orderNo: orderNos,
        },
        success: function (data) {
          let theArr = [];
          let thisData = [];
          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.length; i++) {
              thisData = data.data[i];
              theArr.push({
                key: i,
                dunSubject: thisData.dunSubject
                  ? thisData.dunSubject.toString()
                  : "", //催款科目
                id: thisData.id, //节点Id
                money: thisData.money, //催款金额
                dunStatus: thisData.dunStatus, //催款状态
                orderNo: thisData.orderNo,
              });
            }
            this.setState({
              contactList: theArr,
            });
          }
        }.bind(this),
      }).always(
        function () {
          this.setState({
            loading: false,
          });
        }.bind(this)
      );
    },
    //查看催款节点
    jiedianNew(orderNos) {
      $.ajax({
        method: "get",
        dataType: "json",
        crossDomain: false,
        url:
          globalConfig.context + "/api/admin/newOrderDun/selectListNewOrderDun",
        data: {
          orderNo: orderNos,
        },
        success: function (data) {
          if (data.error && data.error.length) {
            message.warning(data.error[0].message);
          } else {
            let theArr = [];
            let thisData = [];
            let arr = data.data || [];
            let totalCui = 0;
            for (let i = 0; i < arr.length; i++) {
              thisData = arr[i];
              totalCui += +thisData.money;
              theArr.push({
                key: i,
                dunSubject: thisData.dunSubject
                  ? thisData.dunSubject.toString()
                  : "", //催款科目
                id: thisData.id, //节点Id
                money: thisData.money, //催款金额
                // orderNo: record ? record.orderNo : this.props.datauser.orderNo,
                commodityName: thisData.commodityName,
                projectType: thisData.projectType,
                dunTypeName: thisData.dunTypeName,
                status: thisData.status,
                waitDay: thisData.waitDay,
                effectiveCount: thisData.effectiveCount,
                startDate: thisData.startDate,
                dunType: thisData.dunType,
                appropriationRatio: thisData.appropriationRatio,
                customizeName: thisData.customizeName,
                customizeTimes: thisData.customizeTimes,
                tid: thisData.tid,
              });
            }
            if (!totalCui) {
              totalCui = 0;
            }
            totalCui = (Math.round(totalCui * 1000000) / 1000000).toFixed(6);
            this.setState({
              contactListNew: theArr,
              totalCui: parseFloat(totalCui),
            });
          }
        }.bind(this),
      }).always(
        function () {
          this.setState({
            loading: false,
          });
        }.bind(this)
      );
    },
    //催款节点保存
    contactSave() {
      for (let i = 0; i < this.state.contactList.length; i++) {
        if (moneyVerify(this.state.contactList[i].money)) {
          return;
        }
      }
      this.setState({
        loading: true,
      });
      $.ajax({
        url: globalConfig.context + "/api/admin/newOrder/createOrderDun",
        method: "post",
        data: {
          orderNo: this.state.orderNo,
          orderDun: JSON.stringify(this.state.contactList),
        },
      }).done(
        function (data) {
          this.setState({
            loading: false,
          });
          if (!data.error.length) {
            message.success("保存成功!");
            this.jiedian(this.state.orderNo);
          } else {
            message.warning(data.error[0].message);
          }
        }.bind(this)
      );
    },
    //催款节点保存
    contactSaveNew(record) {
      if (record.dunType == 0) {
        if (!record.customizeTimes) {
          message.warning("请输入自定义时间");
          return;
        } else if (!record.customizeName) {
          message.warning("请输入自定义科目");
          return;
        }
      }
      if (record.boStatus == "false") {
        record.boStatus = false;
      } else if (record.boStatus == "true") {
        record.boStatus = true;
      }
      if (!this.state.yearFlag) {
        if (!record.effectiveCount && !record.dunTypeCustom) {
          message.warning("请选择服务年限");
          return;
        }
      } else {
        record.effectiveCount = "";
      }
      if (record.money == "") {
        message.warning("请填写金额");
        return;
      }
      if (record.boStatus) {
        if (
          typeof +record.money == "number" &&
          +record.money >= 0 &&
          +record.money <= 1
        ) {
          record.appropriationRatio = record.money;
        } else {
          message.warning("金额比例填写错误,比例范围0~1");
          return;
        }
      }
      if (!record.dunType && record.dunType != 0) {
        message.warning("请选择对应科目");
        return;
      }
      if (record.dunType != 1) {
        record.waitDay = "";
      }
      this.setState({
        loading: true,
      });
      if (record.boStatus) {
        $.ajax({
          url: globalConfig.context + "/api/admin/newOrderDun/createDun",
          method: "post",
          data: {
            orderNo: record.orderNo,
            tid: record.tid,
            projectType: record.sort,
            dunType: record.dunType,
            appropriationRatio: record.appropriationRatio,
            waitDay: record.waitDay,
            effectiveCount: record.effectiveCount,
            customizeTimes:
              record.dunType == 0 ? record.customizeTimes : undefined,
            customizeName:
              record.dunType == 0 ? record.customizeName : undefined,
          },
        }).done(
          function (data) {
            this.setState({
              loading: false,
            });
            if (!data.error.length) {
              message.success("保存成功!");
              this.setState({
                cuiFlag: false,
                boFlag: false,
              });
              this.jiedianNew(record.orderNo);
            } else {
              message.warning(data.error[0].message);
            }
          }.bind(this)
        );
      } else {
        $.ajax({
          url: globalConfig.context + "/api/admin/newOrderDun/createDun",
          method: "post",
          data: {
            orderNo: record.orderNo,
            tid: record.tid,
            projectType: record.sort,
            dunType: record.dunType,
            money: record.money,
            waitDay: record.waitDay,
            effectiveCount: record.effectiveCount,
            customizeTimes:
              record.dunType == 0 ? record.customizeTimes : undefined,
            customizeName:
              record.dunType == 0 ? record.customizeName : undefined,
          },
        }).done(
          function (data) {
            this.setState({
              loading: false,
            });
            if (!data.error.length) {
              message.success("保存成功!");
              this.setState({
                cuiFlag: false,
                boFlag: false,
              });
              this.jiedianNew(record.orderNo);
            } else {
              message.warning(data.error[0].message);
            }
          }.bind(this)
        );
      }
    },
    //点击新增催款节点
    addcontact() {
      this.state.contactList.push({
        key: this.state.contactList.length,
        money: "",
        dunSubject: undefined,
        orderNo: this.state.orderNo,
        dunTarget: this.state.kehuId,
      });
      this.setState({
        contactList: this.state.contactList,
      });
    },
    //点击新增催款节点
    addcontactNew() {
      this.state.contactListNew.push({
        key: this.state.contactListNew.length,
        money: "",
        dunSubject: undefined,
        orderNo: this.state.orderNo,
        dunTarget: this.state.kehuId,
      });
      this.setState({
        contactListNew: this.state.contactListNew,
        cuiFlag: true,
      });
    },
    //删除收款节点
    confirmDelet(index) {
      this.state.contactList.splice(index, 1);
      this.setState({
        contactList: this.state.contactList,
      });
      this.contactSave();
    },
    //删除收款节点
    confirmDeletNew(index) {
      if (index.id) {
        this.state.contactListNew.splice(index.key, 1);
        this.setState({
          contactListNew: this.state.contactListNew,
          cuiFlag: false,
          addFlag: false,
          boFlag: false,
        });
        $.ajax({
          url: globalConfig.context + "/api/admin/newOrderDun/deleteDun",
          method: "post",
          data: {
            id: index.id,
          },
        }).done(
          function (data) {
            this.setState({
              loading: false,
            });
            if (!data.error.length) {
              message.success("删除成功!");
              this.setState({
                cuiFlag: false,
              });
              this.jiedianNew(this.state.orderNo);
            } else {
              message.warning(data.error[0].message);
            }
          }.bind(this)
        );
      } else {
        this.state.contactListNew.splice(index.key, 1);
        this.setState({
          contactListNew: this.state.contactListNew,
          cuiFlag: false,
          addFlag: false,
          boFlag: false,
        });
      }
    },
    //重新提交
    examOk() {
      let theorgCodeUrl = [];
      if (this.state.orgCodeUrl.length) {
        let picArr = [];
        this.state.orgCodeUrl.map(function (item) {
          if (
            item.response &&
            item.response.data &&
            item.response.data.length
          ) {
            picArr.push(item.response.data);
          }
        });
        theorgCodeUrl = picArr.join(",");
      }
      let theReplenishUrl = [];
      if (this.state.replenishUrl.length) {
        let picArr = [];
        this.state.replenishUrl.map(function (item) {
          if (
            item.response &&
            item.response.data &&
            item.response.data.length
          ) {
            picArr.push(item.response.data);
          }
        });
        theReplenishUrl = picArr.join(",");
      }
      // 服务内容上传图片
      let contentUrl = [];
      if (this.state.contentUrl.length) {
        let picArr = [];
        this.state.contentUrl.map(function (item) {
          if (
            item.response &&
            item.response.data &&
            item.response.data.length
          ) {
            picArr.push(item.response.data);
          }
        });
        contentUrl = picArr.join(",");
      } else {
        message.warning("请上传服务内容图片")
        return
      }
      if (moneyVerify(this.state.totalAmount)) {
        return;
      }
      if (moneyVerify(this.state.firstAmount)) {
        return;
      }
      if (!this.state.totalAmount) {
        message.warning("签单金额不能为空");
        this.refs.signFirstPayment.focus();
        return false;
      }
      if (!this.state.firstAmount) {
        message.warning("首付金额不能为空");
        this.refs.signFirstPayment.focus();
        return false;
      }
      if (!theorgCodeUrl) {
        message.warning("企业负责人不能为空");
        this.refs.signFirstPayment.focus();
        return false;
      }
      if (
        this.state.approval == "特批通过" ||
        this.state.approval == "特批驳回"
      ) {
        message.warning("特批状态不正确,请重新填写");
        return false;
      }
      const arr = this.state.contactListNew || [];
      for (let i = 0; i < arr.length; i++) {
        if (
          arr[i].dunType == 1 &&
          arr[i].waitDay != null &&
          this.state.approval == 0
        ) {
          message.warning(
            "非特批存在填写催款节点首付时间的情况,请删除后重新填写保存"
          );
          return false;
        } else if (
          arr[i].dunType == 1 &&
          arr[i].waitDay == null &&
          this.state.approval == 1
        ) {
          message.warning(
            "特批存在首付催款节点未填写时间的情况,请删除后重新填写保存"
          );
          return false;
        }
        if (!this.state.contactListNew[i].id) {
          message.warning("请保存催款节点");
          return false;
        }
      }
      if (this.state.updatas.salesType == null) {
        message.warning("请选择销售类型!");
        return
      }
      this.setState({
        flag: true,
      });
      $.ajax({
        method: "post",
        dataType: "json",
        crossDomain: false,
        url: globalConfig.context + "/api/admin/newOrder/updateServiceOrderNew",
        data: {
          orderNo: this.state.orderNo, //订单编号
          totalAmount: this.state.totalAmount, //总金额
          firstAmount: this.state.firstAmount, //首付
          isSubmit: 1, //保存草稿还是提交
          signDate: this.state.signDate, //签单日期
          contacts: this.state.contacts, //企业负责人
          contactMobile: this.state.contactMobile, //负责人联系方式
          legalPerson: this.state.legalPerson, //企业法人
          legalPersonTel: this.state.legalPersonTel, //企业法人联系电话
          approval: this.state.approval, //特批状态
          contractNo: this.state.contractNo, //合同编号
          orderRemarks: this.state.orderRemarks, //订单备注
          contractPictureUrl: theorgCodeUrl.length ? theorgCodeUrl : "",
          agreementUrl: theReplenishUrl.length ? theReplenishUrl : "",
          serviceContent: contentUrl.length ? contentUrl : "",
          orderDep: this.state.organizationSearch,
        },
        success: function (data) {
          if (data.error.length || data.data.list == "") {
            if (data.error && data.error.length) {
              message.warning(data.error[0].message);
              this.setState({
                flag: false,
              });
            }
          } else {
            message.success("该订单已重新提交~");
            this.setState({
              visible: false,
              flag: false,
            });
            this.loadData(this.state.pageNo);
          }
        }.bind(this),
      }).always(
        function () {
          this.setState({
            loading: false,
          });
        }.bind(this)
      );
    },
    //订单作废
    examOks() {
      this.setState({
        flag: true,
      });
      $.ajax({
        method: "post",
        dataType: "json",
        crossDomain: false,
        url: globalConfig.context + "/api/admin/newOrder/deleteOrderNew",
        data: {
          orderNo: this.state.orderNo, //订单编号
        },
        success: function (data) {
          if (data.error.length || data.data.list == "") {
            if (data.error && data.error.length) {
              message.warning(data.error[0].message);
            }
          } else {
            message.success("该订单已作废~");
            this.setState({
              visible: false,
              flag: false,
            });
            this.loadData(this.state.pageNo);
          }
        }.bind(this),
      }).always(
        function () {
          this.setState({
            loading: false,
            flag: false,
          });
        }.bind(this)
      );
    },
    departmentList() {
      this.setState({
        loading: true,
      });
      $.ajax({
        method: "get",
        dataType: "json",
        crossDomain: false,
        url: globalConfig.context + "/api/admin/organization/selectSuperId",
        data: {},
        success: function (data) {
          let thedata = data.data;
          let theArr = [];
          if (!thedata) {
            if (data.error && data.error.length) {
              message.warning(data.error[0].message);
            }
            thedata = {};
          } else {
            thedata.map(function (item, index) {
              theArr.push({
                key: index,
                name: item.name,
                id: item.id,
                depNo: item.depNo,
              });
            });
          }
          this.setState({
            departmentArr: theArr,
          });
        }.bind(this),
      }).always(
        function () {
          this.setState({
            loading: false,
          });
        }.bind(this)
      );
    },
    rizhi() {
      this.setState({
        loading: true,
      });
      $.ajax({
        method: "get",
        dataType: "json",
        crossDomain: false,
        url: "/api/admin/newOrder/selectOrderLog",
        data: {
          orderNo: this.state.orderNo,
        },
        success: function (data) {
          let theArr = [];
          let thisData = data.data;
          if (!thisData.length) {
            if (data.error && data.error.length) {
              message.warning(data.error[0].message);
            }
            thisData = {};
          } else {
            for (let i = 0; i < data.data.length; i++) {
              let thisdata = data.data[i];
              theArr.push({
                processName: thisdata.processName,
                adminName: thisdata.adminName,
                createDate: thisdata.createDate,
                remarks: thisdata.remarks,
              });
            }
          }
          this.setState({
            dataSourcerizhi: theArr,
          });
        }.bind(this),
      }).always(
        function () {
          this.setState({
            loading: false,
          });
        }.bind(this)
      );
    },
    //查看订单日志
    getOrderLog() {
      this.setState({
        rizhivisible: true,
      });
      this.rizhi();
    },
    closeOrderLog() {
      this.setState({
        rizhivisible: false,
      });
    },
    //点击签单
    handleCancels() {
      this.setState({
        isSubmit: 1,
      });
    },
    //点击签单
    handleCancelq() {
      this.setState({
        isSubmit: 0,
      });
    },
    resets() {
      this.state.orderNoSearch = "";
      this.state.customerName = "";
      this.state.releaseDate[0] = undefined;
      this.state.releaseDate[1] = undefined;
      this.loadData();
    },
    //点击添加项目明细
    addDetailed() {
      this.setState({
        projectOperationVisible: true,
      });
    },
    //搜索
    search() {
      this.setState({
        //signBillVisible:false
      });
      this.loadData();
    },
    getOrgCodeUrl(e) {
      this.setState({ orgCodeUrl: e });
    },
    getReplenishUrl(e) {
      this.setState({ replenishUrl: e });
    },
    getContentUrl(e) {
      this.setState({ contentUrl: e });
    },
    //关闭详情
    visitCancel() {
      this.setState({
        visible: false,
        cuiFlag: false,
        addFlag: false,
        boFlag: false,
      });
      this.loadData(this.state.pageNo);
    },
    visitOk() {
      this.setState({
        visible: false,
      });
      this.resets();
    },
    //客户
    selectAutoCUT(value) {
      let autoIds;
      let fwList = this.state.customerArr;
      fwList.map(function (item) {
        if (value == item.name) {
          autoIds = item.id;
        }
      });
      this.setState({
        customerName: value,
        autoId: autoIds,
      });
    },
    getpatentTypeList() {
      $.ajax({
        method: "get",
        dataType: "json",
        crossDomain: false,
        url: globalConfig.context + '/api/admin/orderProject/getPatentType',
        success: function (data) {
          if (data.error.length === 0) {
            this.setState({
              patentTypeList: data.data
            })
          } else {
            message.warning(data.error[0].message);
          };
        }.bind(this)
      });
    },
    //加载(自动补全)
    supervisor(e, state) {
      //客户名称与服务名称自动补全
      let api = state
        ? "/api/admin/customer/getCustomerByName"
        : "/api/admin/order/getBusinessProjectByName";
      $.ajax({
        method: "get",
        dataType: "json",
        crossDomain: false,
        url: globalConfig.context + api,
        data: state
          ? {
            name: e,
            type: this.state.customType,
          }
          : {
            businessName: e,
          },
        success: function (data) {
          let thedata = data.data;
          if (!thedata) {
            if (data.error && data.error.length) {
              message.warning(data.error[0].message);
            }
            thedata = {};
          }
          this.setState({
            states: state,
            customerArr: thedata,
          });
        }.bind(this),
      }).always(
        function () {
          this.setState({
            loading: false,
          });
        }.bind(this)
      );
    },
    //上级主管输入框失去焦点是判断客户是否存在
    selectAuto(value) {
      let kid = [];
      let fwList = this.state.customerArr;
      fwList.map(function (item) {
        if (value == item.bname) {
          kid = item;
        }
      });
      if (kid.type == "1") {
        this.setState({
          displayFees: "block",
        });
      } else {
        this.setState({
          displayFees: "none",
        });
      }
      this.setState({
        commodityName: value,
        gid: kid.id,
        //commodityPrice:kid.price==0?kid.price.toString():kid.price,
        commodityFirstPayment:
          kid.firstPayment == 0
            ? kid.firstPayment.toString()
            : kid.firstPayment,
      });
    },
    //服务值改变时请求客户名称
    httpChange(e) {
      this.state.gid = "";
      if (e.length >= 1) {
        this.supervisor(e, false);
      }
      this.setState({
        commodityName: e,
      });
    },
    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 { RangePicker } = DatePicker;
      const rowSelection = {
        selectedRowKeys: this.state.selectedRowKeys,
        onChange: (selectedRowKeys, selectedRows) => {
          this.setState({
            modalVisible: false,
            selectedRows: selectedRows.slice(-1),
            selectedRowKeys: selectedRowKeys.slice(-1),
          });
        },
        onSelect: (recordt) => {
          this.setState({
            modalVisible: false,
            recordt: recordt.id,
          });
        },
      };
      const cuiDataList = this.state.contactList || [];
      const dataSources = this.state.customerArr || [];
      let departmentArr = this.state.departmentArr || [];
      const options = this.state.states
        ? dataSources.map((group) => (
          
            {group.name}
          
        ))
        : dataSources.map((group, index) => (
          
            {group.bname}
          
        ));
      const { TabPane } = Tabs;
      return (
        
          {this.state.resVisible ? (
            
          ) : (
            ""
          )}
          
          
            驳回订单列表
          
          
            
              
                 {
                    this.setState({ customerName: e.target.value });
                  }}
                />
                 {
                    this.setState({ orderNoSearch: e.target.value });
                  }}
                />
                下单时间 :
                 {
                    this.setState({ releaseDate: dataString });
                  }}
                />
                
                
              
              
                
                  
                
              
            
            
            {this.state.visible ? 
              
             : 
}
            {/* 
            
           */}
            
           
          {this.state.projectOperationVisible ? 
 0 && this.state.processStatus !== 0}
            orderNo={this.state.orderNo}
            visible={this.state.projectOperationVisible}
            dataInfor={this.state.dataInfor}
            onCancel={this.nextCancel}
          /> : null}
         
      );
    },
  })
);
export default IntentionCustomer;