import React from "react";
import {
  Icon,
  Button,
  AutoComplete,
  Cascader,
  Input,
  Select,
  Spin,
  Table,
  message,
  DatePicker,
  Tooltip,
  Form,
  Tabs,
  Modal,
  Tag,
} from "antd";
import $ from "jquery/src/ajax";
import moment from "moment";
import { citySelect, provinceList } from "@/NewDicProvinceList";
import AddIntention from "./addIntention.jsx";
import { industry, lvl, currentMember } from "@/dataDic.js";
import ZhuanjiaoDetail from "@/zhuanjiaoDetail.jsx";
import { getSocialAttribute, ShowModal } from "@/tools.js";
import FollowDetail from "./followDetail.jsx";
import IntentionDetail from "./intentionDetail/intentionDetail.jsx";
import ShowModalDiv from "@/showModal.jsx";
import "./customer.less";
import { ChooseList } from "../../../order/orderNew/chooseList";
import EnterpriseNameChange from "../../../../common/enterpriseNameChange";
const { TabPane } = Tabs;
const IntentionCustomer = Form.create()(
  React.createClass({
    loadData(pageNo, apiUrl) {
      this.setState({
        visitModul: false,
        loading: true,
        modalVisible: false,
      });
      let api = apiUrl ? apiUrl : this.props.ApiUrl;
      $.ajax({
        method: "post",
        dataType: "json",
        crossDomain: false,
        url: globalConfig.context + api,
        data: {
          pageNo: pageNo || 1,
          pageSize: this.state.pagination.pageSize,
          level: this.state.level ? this.state.level : undefined,
          name: this.state.nameSearch,
          province: !this.state.addressSearch.length
            ? this.state.provinceSearch
            : this.state.addressSearch[0],
          city: !this.state.addressSearch.length
            ? ""
            : this.state.addressSearch[1],
          startDate: this.state.releaseDate[0],
          endDate: 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];
              let diqu =
                (thisdata.province == null ? "" : thisdata.province) +
                (thisdata.city == null ? "" : "-" + thisdata.city) +
                (thisdata.area == null ? "" : "-" + thisdata.area);
              thisdata.key = i;
              thisdata.id = thisdata.uid;
              thisdata.lastFollowTime =
                thisdata.lastFollowTime &&
                thisdata.lastFollowTime.split(" ")[0];
              thisdata.transferTime =
                thisdata.transferTime && thisdata.transferTime.split(" ")[0];
              thisdata.surplusFollowTime =
                thisdata.surplusFollowTime &&
                thisdata.surplusFollowTime.split(" ")[0];
              thisdata.surplusSignTime =
                thisdata.surplusSignTime &&
                thisdata.surplusSignTime.split(" ")[0];
              thisdata.locationProvince = diqu;
              theArr.push(thisdata);
            }
            this.state.pagination.current = data.data.pageNo;
            this.state.pagination.total = data.data.totalCount;
            this.setState({
              ispage: data.data.pageNo,
            });
          }
          if (data.data && data.data.list && !data.data.list.length) {
            this.state.pagination.current = 0;
            this.state.pagination.total = 0;
          }
          if (
            JSON.stringify(theArr) !== JSON.stringify(this.state.dataSource)
          ) {
            this.setState({
              selectedRowKeys: [],
            });
          }
          this.setState({
            dataSource: theArr,
            pagination: this.state.pagination,
          });
        }.bind(this),
      }).always(
        function () {
          this.setState({
            loading: false,
          });
        }.bind(this)
      );
    },
    //品类数据获取
    category() {
      $.ajax({
        method: "get",
        dataType: "json",
        crossDomain: false,
        url: globalConfig.context + "/api/admin/Varieties/getSuperList",
        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({
                value: item.id,
                key: item.cname,
              });
            });
          }
          this.setState({
            categoryArr: theArr,
          });
        }.bind(this),
      });
    },
    getInitialState() {
      return {
        addressSearch: [],
        orgCodeUrl: [],
        companyLogoUrl: [],
        visible: false,
        zhuanjiaoVisible: false,
        searchMore: true,
        releaseDate: [],
        categoryArr: [],
        visitModul: false,
        keys: false,
        detailApi: "",
        followData: {},
        selectedRowKeys: [],
        selectedRowKey: [],
        selectedRows: [],
        loading: false,
        modalVisible: 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: "name",
            key: "name",
            width: 150,
            render: (text) => {
              return (
                
                   {
                      e.stopPropagation();
                      let input = document.getElementById("copyText");
                      input.value = text;
                      input.select();
                      document.execCommand("copy");
                      message.success("复制成功");
                    }}
                    style={{
                      maxWidth: "150px",
                      overflow: "hidden",
                      textOverflow: "ellipsis",
                      whiteSpace: "nowrap",
                      cursor: "pointer",
                    }}
                  >
                    {text}
                  
                
              );
            },
          },
          {
            title: "地区",
            dataIndex: "locationProvince",
            key: "locationProvince",
          },
          // {
          //   title: "联系人",
          //   dataIndex: "contacts",
          //   key: "contacts",
          // },
          // {
          //   title: "联系电话",
          //   dataIndex: "contactMobile",
          //   key: "contactMobile",
          // },
          {
            title: "社会性质",
            dataIndex: "societyTag",
            key: "societyTag",
            render: (text) => {
              return getSocialAttribute(text);
            },
          },
          {
            title: "客户初始时间",
            dataIndex: "transferTime",
            key: "transferTime",
          },
          {
            title: "剩余私有天数",
            dataIndex: "surplusFollowTime",
            key: "surplusFollowTime",
          },
          {
            title: "剩余签单天数",
            dataIndex: "surplusSignTime",
            key: "surplusSignTime",
          },
          {
            title: "最新跟进时间",
            dataIndex: "lastFollowTime",
            key: "lastFollowTime",
          },
          {
            title: "客户等级",
            dataIndex: "level",
            key: "level",
            render: (text) => {
              if (text == 0) {
                return 一般客户;
              } else if (text == 1) {
                return 意向客户;
              } else if (text == 2) {
                return 重点客户;
              } else {
                return "";
              }
            },
          },
          {
            title: "跟进操作",
            dataIndex: "abc",
            key: "abc",
            render: (text, record, index) => {
              return (
                
                  
                
              );
            },
          },
          {
            title: "指导意见",
            dataIndex: "guidance",
            key: "guidance",
            render: (text, record, index) => {
              return (
                
                  {/*指导 0无 1未读 2已读*/}
                  {text === 1 || text === 2 ? (
                    
                  ) : (
                    
暂无指导
                  )}
                
                {value.name}
              
            ))}
          
        ),
        onOk() {
          _this.setState({
            informationTransferVisible: true,
          });
        },
        onCancel() {},
      });
    },
    changeList(arr) {
      const newArr = [];
      this.state.columns.forEach((item) => {
        arr.forEach((val) => {
          if (val === item.title) {
            newArr.push(item);
          }
        });
      });
      this.setState({
        changeList: newArr,
      });
    },
    showConfirms(fn, record) {
      Modal.confirm({
        title: "您确定将以下客户移至公共客户吗?",
        content: (
          
            移除后,以下客户将被别人领取!
            {this.state.selectedRows.map((value, index) => (
              
                {value.name}
              
            ))}
          
        ),
        onOk() {
          fn(record);
        },
        onCancel() {},
      });
    },
    release() {
      this.setState({
        loading: true,
      });
      let deletedIds = "";
      for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
        let rowItem = this.state.selectedRows[idx];
        if (rowItem.id) {
          deletedIds =
            this.state.selectedRows.length - 1 === idx
              ? deletedIds + rowItem.id
              : deletedIds + rowItem.id + ",";
        }
      }
      $.ajax({
        method: "get",
        dataType: "json",
        crossDomain: false,
        url: globalConfig.context + "/api/admin/customer/pushReleaseUser",
        data: {
          id: deletedIds,
        },
        success: function (data) {
          let thedata = data.data;
          if (!thedata) {
            if (data.error && data.error.length) {
              message.warning(data.error[0].message);
            }
            thedata = {};
          } else {
            message.success("移除成功");
            this.loadData(
              this.state.dataSource.length === 1
                ? this.state.ispage === 1
                  ? 1
                  : this.state.ispage - 1
                : this.state.ispage
            );
          }
        }.bind(this),
      }).always(
        function () {
          this.setState({
            loading: false,
          });
        }.bind(this)
      );
    },
    render() {
      const FormItem = Form.Item;
      const rowSelection = {
        hideDefaultSelections: true,
        selectedRowKeys: this.state.selectedRowKeys,
        onChange: (selectedRowKeys, selectedRows) => {
          this.setState({
            modalVisible: false,
            selectedRows: selectedRows,
            selectedRowKeys: selectedRowKeys,
          });
        },
        onSelect: (recordt, selected, selectedRows) => {
          this.setState({
            modalVisible: false,
            recordt: recordt.id,
          });
        },
      };
      const hasSelected = this.state.selectedRowKeys.length > 0;
      const { RangePicker } = DatePicker;
      const dataSources = this.state.customerArr || [];
      const options = dataSources.map((group) => (
        
          {group.name}
        
      ));
      const intentionState = this.props.intentionState || "";
      return (
        
          
          
            {!intentionState ? "私有单位客户" : "私有专家客户"}
          
          
      );
    },
  })
);
export default IntentionCustomer;