// 私有渠道列表
import React, { Component } from "react";
import {
  Form,
  Button,
  message,
  Spin,
  Input,
  DatePicker,
  Select,
  Tabs,
  Table,
  Modal,
  AutoComplete,
} from "antd";
import { ChooseList } from "../../../manageCenter/order/orderNew/chooseList";
import { provinceList } from "../../../NewDicProvinceList";
import $ from "jquery/src/ajax";
import { ShowModal } from "@/tools";
import moment from "moment";
import AddChannel from "./addchannel"; //新增渠道
import ChannelLog from "./channellog"; //转交日志
import ChangeLog from "./changelog"; //更名日志
import ChannelDetail from "./channeldetail"; //渠道详情
import FollowDetail from "../../../../component/manageCenter/customer/NEW/intentionCustomer/followDetail";//新增渠道跟进
const { TabPane } = Tabs;
const FormItem = Form.Item;
const Option = Select.Option;
const { RangePicker } = DatePicker;
class ChannelUnit extends Component {
  constructor(props) {
    super(props);
    this.state = {
      query: { type: 1 },
      changeList: undefined,
      selectedRowKeys: [],
      selectedRows: [],//列表多选
      columns: [
        {
          title: "渠道名称",
          dataIndex: "name",
          key: "name",
        },
        {
          title: "地区",
          dataIndex: "province",
          key: "province",
          width: 250,
          render: (text, record) => {
            return (record.province || "") + (!record.city ? "" : "-") + (record.city || "") + (!record.area ? "" : "-") + (record.area || "");
          },
        },
        {
          title: "渠道类别",
          dataIndex: "type",
          key: "type",
          width: 120,
          render: (text) =>
            [
              "",
              "政府部门",
              "民主党派",
              "园区",
              "民间组织",
              "其他战略合作单位",
            ][text],
        },
        {
          title: "初始时间",
          dataIndex: "transferTime",
          key: "transferTime",
          width: 160,
        },
        {
          title: "跟进人",
          dataIndex: "aName",
          key: "aName",
        },
        {
          title: "剩余天数",
          dataIndex: "remainingDays",
          key: "remainingDays",
          width: 80,
        },
        {
          title: "跟进操作",
          dataIndex: "op",
          key: "op",
          render: (text, record) => (
            
          ),
        },
      ],
      dataSource: [],
      pagination: {
        defaultCurrent: 1,
        defaultPageSize: 10,
        showQuickJumper: true,
        pageSize: 10,
        onChange: function (page) {
          this.loadData(page);
        }.bind(this),
        showTotal: function (total) {
          return "共" + total + "条数据";
        },
      },
      channeOb: [
        { name: "政府部门", val: 1 },
        { name: "民主党派", val: 2 },
        { name: "园区", val: 3 },
        { name: "民间组织", val: 4 },
        { name: "其他战略合作单位", val: 5 },
      ],
      fjlist: [], // 查询到的更进人列表
      loading: false,
      cityList: [],
      areaList: [],
      searchInfor: {}, // 查询条件
      mvisible: "", //控制弹窗变量
      customerArr: [], //查询到的转交人列表
      rowdata: {}, //双击行数据
      categoryArr: [],
      visitModuls: false,
    };
    this.tabelContentRef = null;
    this.autoCompleteSearchRef = {};
  }
  componentWillMount() {
    this.loadData();
    this.category();
  }
  //
  getVal(arr, val) {
    if (!val || arr.length == 0) {
      return undefined;
    } else {
      for (const items of arr) {
        if (items.id == val) {
          return items.name;
        }
      }
    }
  }
  changeList(arr) {
    const newArr = [];
    this.state.columns.forEach((item) => {
      arr.forEach((val) => {
        if (val === item.title) {
          newArr.push(item);
        }
      });
    });
    this.setState({
      changeList: newArr,
    });
  }
  // 重置
  resetAll() {
    this.setState(
      {
        searchInfor: JSON.parse(JSON.stringify({})),
        selectedRowKeys: [],
        selectedRows: [],
        cityList: [],
        areaList: [],
        auto: "",
      },
      () => {
        this.loadData();
      }
    );
  }
  // 列表接口
  loadData(pageNo) {
    const { searchInfor, pagination } = this.state;
    this.setState({
      loading: true,
    });
    let datas = Object.assign(searchInfor, {
      pageNo: pageNo || 1,
      pageSize: pagination.pageSize,
    });
    $.ajax({
      method: "get",
      dataType: "json",
      crossDomain: false,
      url: globalConfig.context + "/api/admin/customer/channelUserList",
      data: datas,
      success: function (data) {
        ShowModal(this);
        this.setState({
          loading: false,
        });
        if (data.error && data.error.length === 0) {
          if (data.data.list) {
            pagination.current = data.data.pageNo;
            pagination.total = data.data.totalCount;
            if (data.data && data.data.list && !data.data.list.length) {
              pagination.current = 0;
              pagination.total = 0;
            }
            this.setState({
              dataSource: data.data.list,
              pagination: this.state.pagination,
              pageNo: data.data.pageNo,
            });
          } else {
            this.setState({
              dataSource: data.data,
              pagination: false,
            });
          }
        } else {
          message.warning(data.error[0].message);
        }
      }.bind(this),
    }).always(
      function () {
        this.setState({
          loading: false,
        });
      }.bind(this)
    );
  }
  //值改变时请求客户名称
  httpChange(e) {
    if (e.length >= 1) {
      this.supervisor(e);
    }
    this.setState({
      auto: e,
    });
  }
  // 指定转交人自动补全
  supervisor(e) {
    $.ajax({
      method: "get",
      dataType: "json",
      crossDomain: false,
      url: globalConfig.context + "/api/admin/customer/listAdminByName",
      data: {
        adminName: 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({
          customerArr: thedata,
        });
      }.bind(this),
    }).always(
      function () {
        this.setState({
          loading: false,
        });
      }.bind(this)
    );
  }
  // 失去焦点
  blurChange(e) {
    let theType = "";
    let contactLists = this.state.customerArr || [];
    if (e) {
      contactLists.map(function (item) {
        if (item.name == e.toString()) {
          theType = item.id;
        }
      });
    }
    this.setState({
      theTypes: theType,
    });
  }
  // 选择行
  onSelectChange(selectedRowKeys, selectedRows) {
    this.setState({
      selectedRowKeys,
      selectedRows
    });
  }
  //
  addClick() {
    this.setState({
      mvisible: "add",
    });
  }
  // 关闭弹窗
  closeDesc() {
    this.setState({
      mvisible: "",
    });
    this.loadData(this.state.pageNo);
  }
  // 转交提示
  showConfirm() {
    const { selectedRows } = this.state;
    if (!this.state.theTypes) {
      message.warning("请输入转交人姓名");
      return;
    }
    let _this = this;
    Modal.confirm({
      title: "提示",
      content: (
        
          确定要转交以下渠道吗?
          {
            selectedRows.map((item, index) =>