123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533 |
- import React from "react";
- import { Modal, Spin, TreeSelect, Form, Button, Input, Select, message, AutoComplete } from "antd";
- import $ from "jquery/src/ajax";
- import './index.less'
- import { newTreeData } from "@/tools";
- const Operation = React.createClass({
- getInitialState() {
- return {
- confirmLoading: false,
- levelData: [],
- };
- },
- componentDidMount() {
- const { levelData, lev, id } = this.props
- !!id && this.getDetails(id)
- this.setState({
- levelData: newTreeData(levelData, lev),
- })
- },
- // 巴详情接口
- getDetails(id) {
- this.setState({
- confirmLoading: true
- })
- $.ajax({
- method: "get",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + "/api/admin/amb/details",
- data: { id },
- success: function (data) {
- this.setState({
- confirmLoading: false,
- });
- let thedata = data.data;
- if (data.error.length === 0) {
- this.setState({
- parentId: thedata.parentId,
- name: thedata.name,
- leader: thedata.leader,
- financeId: thedata.financeId,
- accountant: thedata.accountant,
- remarks: thedata.remarks,
- auto1: thedata.leaderName,
- auto2: thedata.financeName,
- auto3: thedata.accountantName,
- })
- } else {
- message.warning(data.error[0].message);
- }
- }.bind(this),
- }).always(
- function () {
- this.setState({
- confirmLoading: false
- })
- }.bind(this)
- );
- },
- // 巴主查询
- supervisor(e, role) {
- $.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 = {};
- }
- if (role == "bz") {
- this.setState({
- customerArr1: thedata,
- });
- } else if (role == "cw") {
- this.setState({
- customerArr2: thedata,
- });
- } else if (role == "kj") {
- this.setState({
- customerArr3: thedata,
- });
- }
- }.bind(this),
- }).always(
- function () {
- }.bind(this)
- );
- },
- // 巴主输入触发
- httpChange1(e) {
- let str = e.trim()
- if (str.length >= 1) {
- this.supervisor(str, "bz");
- }
- this.setState({
- auto1: str,
- });
- },
- // 巴主选中
- selectAuto1(value, options) {
- let leaderid = "";
- let contactLists = this.state.customerArr1 || [];
- if (value) {
- contactLists.map(function (item) {
- if (item.name == value.toString()) {
- leaderid = item.id
- }
- });
- }
- this.setState({
- auto1: value,
- leader: leaderid,
- });
- },
- // 巴主失去焦点时间
- blurChange1(e) {
- let leaderid = "";
- let contactLists = this.state.customerArr1 || [];
- if (e) {
- contactLists.map(function (item) {
- if (item.name == e.toString()) {
- leaderid = item.id
- }
- });
- }
- this.setState({
- leader: leaderid,
- });
- },
- // 财务输入触发
- httpChange2(e) {
- let str = e.trim()
- if (str.length >= 1) {
- this.supervisor(str, "cw");
- }
- this.setState({
- auto2: str,
- });
- },
- // 财务选中
- selectAuto2(value, options) {
- let financeid = "";
- let contactLists = this.state.customerArr2 || [];
- if (value) {
- contactLists.map(function (item) {
- if (item.name == value.toString()) {
- financeid = item.id
- }
- });
- }
- this.setState({
- auto2: value,
- financeId: financeid,
- });
- },
- // 财务失去焦点时间
- blurChange2(e) {
- let financeid = "";
- let contactLists = this.state.customerArr2 || [];
- if (e) {
- contactLists.map(function (item) {
- if (item.name == e.toString()) {
- financeid = item.id
- }
- });
- }
- this.setState({
- financeId: financeid,
- });
- },
- // 财务输入触发
- httpChange3(e) {
- let str = e.trim()
- if (str.length >= 1) {
- this.supervisor(str, "kj");
- }
- this.setState({
- auto3: str,
- });
- },
- // 会计选中
- selectAuto3(value, options) {
- let accountant = "";
- let contactLists = this.state.customerArr3 || [];
- if (value) {
- contactLists.map(function (item) {
- if (item.name == value.toString()) {
- accountant = item.id
- }
- });
- }
- this.setState({
- auto3: value,
- accountant: accountant,
- });
- },
- // 会计失去焦点时间
- blurChange3(e) {
- let accountant = "";
- let contactLists = this.state.customerArr3 || [];
- if (e) {
- contactLists.map(function (item) {
- if (item.name == e.toString()) {
- accountant = item.id
- }
- });
- }
- this.setState({
- accountant: accountant,
- });
- },
- // 新建巴
- addSubmit() {
- if (this.state.parentId === undefined || !this.state.parentId) {
- message.warning("请选择上级部门!");
- return
- }
- if (!this.state.name) {
- message.warning("请填写巴名称!");
- return
- }
- if (this.state.leader === undefined || !this.state.leader) {
- message.warning("请设置巴主!");
- return
- }
- if (this.state.financeId === undefined || !this.state.financeId) {
- message.warning("请选择财务负责人!");
- return
- }
- if (this.state.accountant === undefined || !this.state.accountant) {
- message.warning("请选择会计负责人!");
- return
- }
- this.setState({
- confirmLoading: true
- })
- let data = {
- parentId: this.state.parentId,
- name: this.state.name,
- leader: this.state.leader,
- financeId: this.state.financeId,
- accountant: this.state.accountant,
- remarks: this.state.remarks,
- }
- $.ajax({
- method: "POST",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + "/api/admin/amb/add",
- data,
- success: function (data) {
- if (data.error.length === 0) {
- message.success("保存成功!");
- this.props.handleCancel();
- } else {
- message.warning(data.error[0].message);
- }
- this.setState({
- confirmLoading: false,
- });
- }.bind(this),
- }).always(
- function () {
- this.setState({
- confirmLoading: false,
- });
- }.bind(this)
- );
- },
- // 编辑巴
- editSubmit() {
- if (this.state.parentId === undefined || !this.state.parentId) {
- message.warning("请选择上级部门!");
- return
- }
- if (!this.state.name) {
- message.warning("请填写巴名称!");
- return
- }
- if (this.state.leader === undefined || !this.state.leader) {
- message.warning("请设置巴主!");
- return
- }
- if (this.state.financeId === undefined || !this.state.financeId) {
- message.warning("请选择财务负责人!");
- return
- }
- if (this.state.accountant === undefined || !this.state.accountant) {
- message.warning("请选择会计负责人!");
- return
- }
- this.setState({
- confirmLoading: true
- })
- let data = {
- id: this.props.id,
- parentId: this.state.parentId,
- name: this.state.name,
- leader: this.state.leader,
- financeId: this.state.financeId,
- accountant: this.state.accountant,
- remarks: this.state.remarks,
- }
- $.ajax({
- method: "POST",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + "/api/admin/amb/update",
- data,
- success: function (data) {
- if (data.error.length === 0) {
- message.success("保存成功!");
- this.props.handleCancel();
- } else {
- message.warning(data.error[0].message);
- }
- this.setState({
- confirmLoading: false,
- });
- }.bind(this),
- }).always(
- function () {
- this.setState({
- confirmLoading: false,
- });
- }.bind(this)
- );
- },
- render() {
- const { confirmLoading, levelData } = this.state
- const { visible, } = this.props;
- const FormItem = Form.Item;
- const formItemLayout = {
- labelCol: { span: 8 },
- wrapperCol: { span: 14 },
- };
- const dataSources1 = this.state.customerArr1 || [];
- const options1 = dataSources1.map((group) => (
- <Select.Option key={group.id} value={group.name}>
- {group.name}
- </Select.Option>
- ));
- const dataSources2 = this.state.customerArr2 || [];
- const options2 = dataSources2.map((group) => (
- <Select.Option key={group.id} value={group.name}>
- {group.name}
- </Select.Option>
- ));
- const dataSources3 = this.state.customerArr3 || [];
- const options3 = dataSources3.map((group) => (
- <Select.Option key={group.id} value={group.name}>
- {group.name}
- </Select.Option>
- ));
- return (
- <Modal
- maskClosable={false}
- width="600px"
- title={visible == "add"
- ? "新增巴" : visible == "edit"
- ? "编辑巴" : ""}
- visible={visible != ""}
- footer=""
- onCancel={this.props.handleCancel}
- >
- <Spin spinning={confirmLoading}>
- <div>
- <Form
- layout="horizontal"
- >
- <div className="clearfix">
- <FormItem
- className="mid-item"
- {...formItemLayout}
- label={<span><span className="mandatory">*</span>上级部门</span>}
- >
- <TreeSelect
- style={{ width: 250 }}
- value={this.state.parentId}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={levelData}
- placeholder="请选择上级部门"
- showSearch
- treeNodeFilterProp="title"
- onChange={(e) => {
- this.setState({
- parentId: e,
- });
- }}
- />
- </FormItem>
- </div>
- <div className="clearfix">
- <FormItem
- className="mid-item"
- {...formItemLayout}
- label={<span><span className="mandatory">*</span>巴名称</span>}
- >
- <Input
- placeholder="请填写巴名称"
- style={{ width: "250px" }}
- value={this.state.name}
- onChange={(e) => {
- this.setState({ name: e.target.value });
- }}
- />
- </FormItem>
- </div>
- <div className="clearfix">
- <FormItem
- className="mid-item"
- {...formItemLayout}
- label={<span><span className="mandatory">*</span>巴主</span>}
- >
- <AutoComplete
- className="certain-category-search"
- dropdownClassName="certain-category-search-dropdown"
- dropdownMatchSelectWidth={false}
- style={{ width: "250px" }}
- dataSource={options1}
- placeholder='输入巴主名称'
- value={this.state.auto1}
- onChange={this.httpChange1}
- filterOption={true}
- onBlur={this.blurChange1}
- onSelect={this.selectAuto1}
- >
- <Input />
- </AutoComplete>
- </FormItem>
- </div>
- <div className="clearfix">
- <FormItem
- className="mid-item"
- {...formItemLayout}
- label={<span><span className="mandatory">*</span>财务负责人</span>}
- >
- <AutoComplete
- className="certain-category-search"
- dropdownClassName="certain-category-search-dropdown"
- dropdownMatchSelectWidth={false}
- style={{ width: "250px" }}
- dataSource={options2}
- placeholder='输入财务负责人名称'
- value={this.state.auto2}
- onChange={this.httpChange2}
- filterOption={true}
- onBlur={this.blurChange2}
- onSelect={this.selectAuto2}
- >
- <Input />
- </AutoComplete>
- </FormItem>
- </div>
- <div className="clearfix">
- <FormItem
- className="mid-item"
- {...formItemLayout}
- label={<span><span className="mandatory">*</span>会计负责人</span>}
- >
- <AutoComplete
- className="certain-category-search"
- dropdownClassName="certain-category-search-dropdown"
- dropdownMatchSelectWidth={false}
- style={{ width: "250px" }}
- dataSource={options3}
- placeholder='输入会计负责人名称'
- value={this.state.auto3}
- onChange={this.httpChange3}
- filterOption={true}
- onBlur={this.blurChange3}
- onSelect={this.selectAuto3}
- >
- <Input />
- </AutoComplete>
- </FormItem>
- </div>
- <div className="clearfix">
- <FormItem
- className="mid-item"
- {...formItemLayout}
- label={<span>备注巴说明</span>}
- >
- <Input
- type="textarea"
- placeholder="备注说明"
- style={{ width: "250px" }}
- autosize={{ minRows: 3 }}
- value={this.state.remarks}
- onChange={(e) => {
- this.setState({ remarks: e.target.value });
- }}
- />
- </FormItem>
- </div>
- <FormItem wrapperCol={{ span: 12, offset: 8 }}>
- <Button
- type="primary"
- onClick={!!this.props.id ? this.editSubmit : this.addSubmit}
- style={{ marginRight: "50px" }}
- >
- 保存
- </Button>
- <Button
- type="ghost"
- onClick={this.props.handleCancel}>
- 取消
- </Button>
- </FormItem>
- </Form>
- </div>
- </Spin>
- </Modal >
- );
- },
- });
- export default Operation;
|