import React, { Component } from "react"; import { Button, Modal, Form, AutoComplete, TreeSelect, Input, message, Spin, Select, Tabs, Table, } from "antd"; import $ from "jquery/src/ajax"; import { ShowModal, getBarLevel } from "@/tools"; import moment from "moment"; import './index.less' import ShowModalDiv from "@/showModal.jsx"; import { ChooseList } from "../../order/orderNew/chooseList"; import Operation from "./operation" const { TabPane } = Tabs; const FormItem = Form.Item; const confirm = Modal.confirm; class Source extends Component { constructor(props) { super(props); this.state = { visible: '', // 弹窗控制 level1Data: [], // 体系数据 searchValues: {}, // 列表筛选条件 pagination: { defaultCurrent: 1, defaultPageSize: 10, showQuickJumper: true, pageSize: 10, onChange: function (page) { this.loadData(page); }.bind(this), showTotal: function (total) { return "共" + total + "条数据"; }, }, loading: false, changeList: undefined, dataSource: [], // 列表数据 selectedRowKeys: [], // 选中列表数据 selectedRows: [], // 选中列表数据 info: {}, //单条详情数据 columns: [ { title: "巴名称", dataIndex: "name", key: "name", }, { title: "巴主", dataIndex: "leaderName", key: "leaderName", }, { title: "所属战区", dataIndex: "name5", key: "name5", render: (text, record) => {getBarLevel(record.ancestorsNames)[4]} }, { title: "所属事业部", dataIndex: "name4", key: "name4", render: (text, record) => {getBarLevel(record.ancestorsNames)[3]} }, { title: "所属区", dataIndex: "name3", key: "name3", render: (text, record) => {getBarLevel(record.ancestorsNames)[2]} }, { title: "所属大区", dataIndex: "name2", key: "name2", render: (text, record) => {getBarLevel(record.ancestorsNames)[1]} }, { title: "所属体系", dataIndex: "name1", key: "name1", render: (text, record) => {getBarLevel(record.ancestorsNames)[0]} }, { title: "财务", dataIndex: "financeName", key: "financeName", }, { title: "会计", dataIndex: "accountantName", key: "accountantName", }, { title: "状态", dataIndex: "status", key: "status", render: (text) => {text == 0 ? "正常" : text == 1 ? "停用" : "-"} }, { title: "创建时间", dataIndex: "createTimes", key: "createTimes", }, ], }; this.supervisor = this.supervisor.bind(this); this.httpChange = this.httpChange.bind(this); this.blurChange = this.blurChange.bind(this); this.selectAuto = this.selectAuto.bind(this); this.handleCancel = this.handleCancel.bind(this); this.handleCancel = this.handleCancel.bind(this); } // 根据id获取子集 getSubset(id, list, key = "id", valus = "list") { let newList = []; if (!list) { return newList } list.forEach((item) => { if (item[key] == id) { newList = item[valus] } }) return newList } // 筛选数据 getList() { this.setState({ loading: true, }); $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/amb/selectAll", success: function (data) { this.setState({ loading: false, }); if (data.error && data.error.length === 0) { let menuList = data.data this.setState({ level1Data: menuList ? this.handleTreeData(menuList) : [] }); } else { message.warning(data.error[0].message); } }.bind(this), }).always( function () { this.setState({ loading: false, }); }.bind(this) ); } // 树状默认数据处理 handleTreeData(treeData) { let nodeDta = []; treeData.map(item => { let treeObj = {}; treeObj.id = item.id treeObj.label = item.name treeObj.value = item.id treeObj.key = item.id treeObj.lvl = item.lvl treeObj.parentId = item.parentId item.list ? treeObj.children = this.handleTreeData(item.list) : null; nodeDta.push(treeObj) }) return nodeDta } // 更改表格显示数据 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( { auto: "", searchValues: JSON.parse(JSON.stringify({})), selectedRowKeys: [], selectedRows: [], }, () => { this.loadData(); } ); } // 搜索 submit() { this.setState({ params: this.state.searchValues }) this.loadData() } // 列表接口 loadData(pageNo) { const { searchValues, pagination } = this.state; this.setState({ loading: true, }); let datas = Object.assign(searchValues, { pageNo: pageNo || 1, pageSize: pagination.pageSize, lvl: 6, }); $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/amb/select", 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) ); } // 查询用户 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 () { }.bind(this) ); } // 输入触发 httpChange(e) { if (e.length >= 1) { this.supervisor(e); } this.setState({ auto: e, }); } // 选中 selectAuto(value, options) { const { searchValues } = this.state let contactLists = this.state.customerArr || []; if (value) { contactLists.map(function (item) { if (item.name == value.toString()) { searchValues["leader"] = item.id; } }); } this.setState({ auto: value, searchValues: searchValues, }); } // 失去焦点 blurChange(e) { const { searchValues } = this.state let contactLists = this.state.customerArr || []; if (e) { contactLists.map(function (item) { if (item.name == e.toString()) { searchValues["leader"] = item.id; } }); } this.setState({ searchValues: searchValues, }); } // 选择行 onSelectChange(selectedRowKeys, selectedRows) { this.setState({ selectedRowKeys, selectedRows }); } // 删除巴 delete() { const { selectedRows } = this.state this.setState({ loading: true, }) $.ajax({ method: "post", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/amb/delete", data: { id: selectedRows[0].id }, success: function (data) { if (data.error.length) { if (data.error && data.error.length) { message.warning(data.error[0].message) } } else { message.success('删除成功'); this.getList(); this.loadData(); this.setState({ selectedRowKeys: [], selectedRows: [], }); } }.bind(this), }).always( function () { this.setState({ loading: false, }) }.bind(this) ); } // 关闭弹窗 handleCancel() { this.setState({ visible: "", info: {}, }, () => { this.getList(); this.loadData(); }) } componentWillMount() { this.getList(); this.loadData(); } render() { const { searchValues, columns, selectedRowKeys, selectedRows, changeList, level1Data } = this.state; const rowSelection = { selectedRowKeys, onChange: this.onSelectChange.bind(this), hideDefaultSelections: true, type: "radio", }; const dataSources = this.state.customerArr || []; const options = dataSources.map((group) => ( {group.name} )); return (
巴列表数据
{ }}>
{ searchValues["name"] = e.target.value; this.setState({ searchValues: searchValues, }); }} /> { searchValues["ancestors"] = e; this.setState({ searchValues: searchValues, }); }} />
{ // 新建编辑巴 this.state.visible != "" && } ); } } export default Source;