import React from 'react';
import ReactDom from 'react-dom';
import ajax from 'jquery/src/ajax/xhr.js';
import $ from 'jquery/src/ajax';
import {
Form, Icon, Button, Input, Select, AutoComplete, Spin, Table,
message, DatePicker, Modal, TreeSelect, Popconfirm, Tabs
} from 'antd';
import Newuser from "./newUser.jsx"
import { ShowModal } from "@/tools";
import { ChooseList } from "../../order/orderNew/chooseList";
const { TabPane } = Tabs
const Team = Form.create()(React.createClass({
getInitialState() {
return {
info: {},
searchValues: {}, // 列表筛选条件
loading: false, //加载动画
changeList: undefined, // 更改后的表格显示数据
departmentArr: [], // 部门
dataSource: [], // 列表数据
teamList: [], // 上级
fjlist: [],
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',
},
{
title: '队长',
dataIndex: 'adminName',
key: 'adminName',
},
{
title: '等级',
dataIndex: 'lvl',
key: 'lvl',
render: (text, record) => {
return (
{["", "一级", "二级", "三级"][text]}
)
}
},
{
title: '部门',
dataIndex: 'depName',
key: 'depName',
},
{
title: '上级团队',
dataIndex: 'superName',
key: 'superName',
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
render: (text, record) => {
return (
{["正常", "解散"][text]}
)
}
},
],
visible: "",
};
},
componentWillMount() {
this.loadData();
this.departmentList();
},
// 列表接口
loadData(pageNo) {
const { searchValues, pagination } = this.state;
this.setState({
loading: true,
});
let datas = Object.assign(searchValues, {
pageNo: pageNo || 1,
pageSize: pagination.pageSize,
});
$.ajax({
method: "get",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/salesTeam/pageList",
data: datas,
success: function (data) {
ShowModal(this);
this.setState({
loading: false,
});
let theArr = [];
if (data.error && data.error.length === 0) {
if (data.data) {
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 {
message.warning(data.error[0].message);
}
}.bind(this),
}).always(
function () {
this.setState({
loading: 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));
},
// 团队
salesTeam(lvl) {
this.setState({
loading: true
});
$.ajax({
method: "get",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/salesTeam/list",
data: {
lvl: lvl - 1
},
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({
name: item.name,
id: item.id,
})
})
}
this.setState({
teamList: theArr,
})
}.bind(this),
}).always(function () {
this.setState({
loading: false
});
}.bind(this));
},
followUp(e) {
const { info } = this.state;
this.setState({
info: Object.assign(info, {
adminName: 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({
fjlist: thedata,
});
}.bind(this),
}).always(
function () {
this.setState({
loading: false,
});
}.bind(this)
);
},
selectF(value) {
const { info, fjlist } = this.state;
const newdataSources = JSON.stringify(fjlist) == "{}" ? [] : fjlist;
info["aid"] = newdataSources.find((item) => item.name == value).id;
this.setState({
info
});
},
tableRowClick(record, index) {
this.salesTeam(record.lvl)
this.setState({
visible: "edit",
info: record,
})
},
search() {
this.loadData();
},
reset() {
this.setState({
searchValues: {}
}, () => {
this.loadData();
})
},
changeList(arr) {
const newArr = [];
this.state.columns.forEach(item => {
arr.forEach(val => {
if (val === item.title) {
newArr.push(item);
}
});
});
this.setState({
changeList: newArr
});
},
// 保存
handleOk() {
const { info } = this.state
if (!info.name) {
message.warn("团队名称不能为空!")
return
}
if (!info.adminName) {
message.warn("队长姓名不能为空!")
return
}
if (!info.lvl) {
message.warn("请选择等级!")
return
}
if (!info.depId) {
message.warn("请选择部门!")
return
}
// if (!info.superId) {
// message.warn("请选择上级团队!")
// return
// }
if (!info.status && info.status != 0) {
message.warn("请选择状态!")
return
}
let obj = {
id: info.id,
name: info.name,
aid: info.aid,
lvl: info.lvl,
depId: info.depId,
superId: info.superId,
status: info.status,
}
this.setState({
loading: true
});
$.ajax({
method: "POST",
dataType: "json",
crossDomain: false,
url: globalConfig.context + (!info.id ? "/api/admin/salesTeam/add" : "/api/admin/salesTeam/update"),
data: obj
}).done(function (data) {
this.setState({
loading: false
});
if (!data.error.length) {
message.success('保存成功!');
this.handleCancel();
this.loadData();
} else {
message.warning(data.error[0].message);
}
}.bind(this));
},
handleCancel() {
this.setState({
visible: "",
info: {},
})
},
render() {
const { searchValues, departmentArr, teamList, info } = this.state
const FormItem = Form.Item
const formItemLayout = {
labelCol: { span: 8 },
wrapperCol: { span: 14 },
};
const newdataSources = this.state.fjlist || [];
const newoptions = newdataSources.map((group) => (
{group.name}
));
return (
);
}
}));
export default Team;