operation.jsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. import React from "react";
  2. import { Modal, Spin, TreeSelect, Form, Button, Input, Select, message, AutoComplete } from "antd";
  3. import $ from "jquery/src/ajax";
  4. import './index.less'
  5. import { newTreeData } from "@/tools";
  6. const Operation = React.createClass({
  7. getInitialState() {
  8. return {
  9. confirmLoading: false,
  10. levelData: [],
  11. };
  12. },
  13. componentDidMount() {
  14. const { levelData, lev, id } = this.props
  15. !!id && this.getDetails(id)
  16. this.setState({
  17. levelData: newTreeData(levelData, lev),
  18. })
  19. },
  20. // 巴详情接口
  21. getDetails(id) {
  22. this.setState({
  23. confirmLoading: true
  24. })
  25. $.ajax({
  26. method: "get",
  27. dataType: "json",
  28. crossDomain: false,
  29. url: globalConfig.context + "/api/admin/amb/details",
  30. data: { id },
  31. success: function (data) {
  32. this.setState({
  33. confirmLoading: false,
  34. });
  35. let thedata = data.data;
  36. if (data.error.length === 0) {
  37. this.setState({
  38. parentId: thedata.parentId,
  39. name: thedata.name,
  40. leader: thedata.leader,
  41. financeId: thedata.financeId,
  42. accountant: thedata.accountant,
  43. remarks: thedata.remarks,
  44. auto1: thedata.leaderName,
  45. auto2: thedata.financeName,
  46. auto3: thedata.accountantName,
  47. })
  48. } else {
  49. message.warning(data.error[0].message);
  50. }
  51. }.bind(this),
  52. }).always(
  53. function () {
  54. this.setState({
  55. confirmLoading: false
  56. })
  57. }.bind(this)
  58. );
  59. },
  60. // 巴主查询
  61. supervisor(e, role) {
  62. $.ajax({
  63. method: "get",
  64. dataType: "json",
  65. crossDomain: false,
  66. url: globalConfig.context + "/api/admin/customer/listAdminByName",
  67. data: {
  68. adminName: e,
  69. },
  70. success: function (data) {
  71. let thedata = data.data;
  72. if (!thedata) {
  73. if (data.error && data.error.length) {
  74. message.warning(data.error[0].message);
  75. }
  76. thedata = {};
  77. }
  78. if (role == "bz") {
  79. this.setState({
  80. customerArr1: thedata,
  81. });
  82. } else if (role == "cw") {
  83. this.setState({
  84. customerArr2: thedata,
  85. });
  86. } else if (role == "kj") {
  87. this.setState({
  88. customerArr3: thedata,
  89. });
  90. }
  91. }.bind(this),
  92. }).always(
  93. function () {
  94. }.bind(this)
  95. );
  96. },
  97. // 巴主输入触发
  98. httpChange1(e) {
  99. let str = e.trim()
  100. if (str.length >= 1) {
  101. this.supervisor(str, "bz");
  102. }
  103. this.setState({
  104. auto1: str,
  105. });
  106. },
  107. // 巴主选中
  108. selectAuto1(value, options) {
  109. let leaderid = "";
  110. let contactLists = this.state.customerArr1 || [];
  111. if (value) {
  112. contactLists.map(function (item) {
  113. if (item.name == value.toString()) {
  114. leaderid = item.id
  115. }
  116. });
  117. }
  118. this.setState({
  119. auto1: value,
  120. leader: leaderid,
  121. });
  122. },
  123. // 巴主失去焦点时间
  124. blurChange1(e) {
  125. let leaderid = "";
  126. let contactLists = this.state.customerArr1 || [];
  127. if (e) {
  128. contactLists.map(function (item) {
  129. if (item.name == e.toString()) {
  130. leaderid = item.id
  131. }
  132. });
  133. }
  134. this.setState({
  135. leader: leaderid,
  136. });
  137. },
  138. // 财务输入触发
  139. httpChange2(e) {
  140. let str = e.trim()
  141. if (str.length >= 1) {
  142. this.supervisor(str, "cw");
  143. }
  144. this.setState({
  145. auto2: str,
  146. });
  147. },
  148. // 财务选中
  149. selectAuto2(value, options) {
  150. let financeid = "";
  151. let contactLists = this.state.customerArr2 || [];
  152. if (value) {
  153. contactLists.map(function (item) {
  154. if (item.name == value.toString()) {
  155. financeid = item.id
  156. }
  157. });
  158. }
  159. this.setState({
  160. auto2: value,
  161. financeId: financeid,
  162. });
  163. },
  164. // 财务失去焦点时间
  165. blurChange2(e) {
  166. let financeid = "";
  167. let contactLists = this.state.customerArr2 || [];
  168. if (e) {
  169. contactLists.map(function (item) {
  170. if (item.name == e.toString()) {
  171. financeid = item.id
  172. }
  173. });
  174. }
  175. this.setState({
  176. financeId: financeid,
  177. });
  178. },
  179. // 财务输入触发
  180. httpChange3(e) {
  181. let str = e.trim()
  182. if (str.length >= 1) {
  183. this.supervisor(str, "kj");
  184. }
  185. this.setState({
  186. auto3: str,
  187. });
  188. },
  189. // 会计选中
  190. selectAuto3(value, options) {
  191. let accountant = "";
  192. let contactLists = this.state.customerArr3 || [];
  193. if (value) {
  194. contactLists.map(function (item) {
  195. if (item.name == value.toString()) {
  196. accountant = item.id
  197. }
  198. });
  199. }
  200. this.setState({
  201. auto3: value,
  202. accountant: accountant,
  203. });
  204. },
  205. // 会计失去焦点时间
  206. blurChange3(e) {
  207. let accountant = "";
  208. let contactLists = this.state.customerArr3 || [];
  209. if (e) {
  210. contactLists.map(function (item) {
  211. if (item.name == e.toString()) {
  212. accountant = item.id
  213. }
  214. });
  215. }
  216. this.setState({
  217. accountant: accountant,
  218. });
  219. },
  220. // 新建巴
  221. addSubmit() {
  222. if (this.state.parentId === undefined || !this.state.parentId) {
  223. message.warning("请选择上级部门!");
  224. return
  225. }
  226. if (!this.state.name) {
  227. message.warning("请填写巴名称!");
  228. return
  229. }
  230. if (this.state.leader === undefined || !this.state.leader) {
  231. message.warning("请设置巴主!");
  232. return
  233. }
  234. if (this.state.financeId === undefined || !this.state.financeId) {
  235. message.warning("请选择财务负责人!");
  236. return
  237. }
  238. if (this.state.accountant === undefined || !this.state.accountant) {
  239. message.warning("请选择会计负责人!");
  240. return
  241. }
  242. this.setState({
  243. confirmLoading: true
  244. })
  245. let data = {
  246. parentId: this.state.parentId,
  247. name: this.state.name,
  248. leader: this.state.leader,
  249. financeId: this.state.financeId,
  250. accountant: this.state.accountant,
  251. remarks: this.state.remarks,
  252. }
  253. $.ajax({
  254. method: "POST",
  255. dataType: "json",
  256. crossDomain: false,
  257. url: globalConfig.context + "/api/admin/amb/add",
  258. data,
  259. success: function (data) {
  260. if (data.error.length === 0) {
  261. message.success("保存成功!");
  262. this.props.handleCancel();
  263. } else {
  264. message.warning(data.error[0].message);
  265. }
  266. this.setState({
  267. confirmLoading: false,
  268. });
  269. }.bind(this),
  270. }).always(
  271. function () {
  272. this.setState({
  273. confirmLoading: false,
  274. });
  275. }.bind(this)
  276. );
  277. },
  278. // 编辑巴
  279. editSubmit() {
  280. if (this.state.parentId === undefined || !this.state.parentId) {
  281. message.warning("请选择上级部门!");
  282. return
  283. }
  284. if (!this.state.name) {
  285. message.warning("请填写巴名称!");
  286. return
  287. }
  288. if (this.state.leader === undefined || !this.state.leader) {
  289. message.warning("请设置巴主!");
  290. return
  291. }
  292. if (this.state.financeId === undefined || !this.state.financeId) {
  293. message.warning("请选择财务负责人!");
  294. return
  295. }
  296. if (this.state.accountant === undefined || !this.state.accountant) {
  297. message.warning("请选择会计负责人!");
  298. return
  299. }
  300. this.setState({
  301. confirmLoading: true
  302. })
  303. let data = {
  304. id: this.props.id,
  305. parentId: this.state.parentId,
  306. name: this.state.name,
  307. leader: this.state.leader,
  308. financeId: this.state.financeId,
  309. accountant: this.state.accountant,
  310. remarks: this.state.remarks,
  311. }
  312. $.ajax({
  313. method: "POST",
  314. dataType: "json",
  315. crossDomain: false,
  316. url: globalConfig.context + "/api/admin/amb/update",
  317. data,
  318. success: function (data) {
  319. if (data.error.length === 0) {
  320. message.success("保存成功!");
  321. this.props.handleCancel();
  322. } else {
  323. message.warning(data.error[0].message);
  324. }
  325. this.setState({
  326. confirmLoading: false,
  327. });
  328. }.bind(this),
  329. }).always(
  330. function () {
  331. this.setState({
  332. confirmLoading: false,
  333. });
  334. }.bind(this)
  335. );
  336. },
  337. render() {
  338. const { confirmLoading, levelData } = this.state
  339. const { visible, } = this.props;
  340. const FormItem = Form.Item;
  341. const formItemLayout = {
  342. labelCol: { span: 8 },
  343. wrapperCol: { span: 14 },
  344. };
  345. const dataSources1 = this.state.customerArr1 || [];
  346. const options1 = dataSources1.map((group) => (
  347. <Select.Option key={group.id} value={group.name}>
  348. {group.name}
  349. </Select.Option>
  350. ));
  351. const dataSources2 = this.state.customerArr2 || [];
  352. const options2 = dataSources2.map((group) => (
  353. <Select.Option key={group.id} value={group.name}>
  354. {group.name}
  355. </Select.Option>
  356. ));
  357. const dataSources3 = this.state.customerArr3 || [];
  358. const options3 = dataSources3.map((group) => (
  359. <Select.Option key={group.id} value={group.name}>
  360. {group.name}
  361. </Select.Option>
  362. ));
  363. return (
  364. <Modal
  365. maskClosable={false}
  366. width="600px"
  367. title={visible == "add"
  368. ? "新增巴" : visible == "edit"
  369. ? "编辑巴" : ""}
  370. visible={visible != ""}
  371. footer=""
  372. onCancel={this.props.handleCancel}
  373. >
  374. <Spin spinning={confirmLoading}>
  375. <div>
  376. <Form
  377. layout="horizontal"
  378. >
  379. <div className="clearfix">
  380. <FormItem
  381. className="mid-item"
  382. {...formItemLayout}
  383. label={<span><span className="mandatory">*</span>上级部门</span>}
  384. >
  385. <TreeSelect
  386. style={{ width: 250 }}
  387. value={this.state.parentId}
  388. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  389. treeData={levelData}
  390. placeholder="请选择上级部门"
  391. showSearch
  392. treeNodeFilterProp="title"
  393. onChange={(e) => {
  394. this.setState({
  395. parentId: e,
  396. });
  397. }}
  398. />
  399. </FormItem>
  400. </div>
  401. <div className="clearfix">
  402. <FormItem
  403. className="mid-item"
  404. {...formItemLayout}
  405. label={<span><span className="mandatory">*</span>巴名称</span>}
  406. >
  407. <Input
  408. placeholder="请填写巴名称"
  409. style={{ width: "250px" }}
  410. value={this.state.name}
  411. onChange={(e) => {
  412. this.setState({ name: e.target.value });
  413. }}
  414. />
  415. </FormItem>
  416. </div>
  417. <div className="clearfix">
  418. <FormItem
  419. className="mid-item"
  420. {...formItemLayout}
  421. label={<span><span className="mandatory">*</span>巴主</span>}
  422. >
  423. <AutoComplete
  424. className="certain-category-search"
  425. dropdownClassName="certain-category-search-dropdown"
  426. dropdownMatchSelectWidth={false}
  427. style={{ width: "250px" }}
  428. dataSource={options1}
  429. placeholder='输入巴主名称'
  430. value={this.state.auto1}
  431. onChange={this.httpChange1}
  432. filterOption={true}
  433. onBlur={this.blurChange1}
  434. onSelect={this.selectAuto1}
  435. >
  436. <Input />
  437. </AutoComplete>
  438. </FormItem>
  439. </div>
  440. <div className="clearfix">
  441. <FormItem
  442. className="mid-item"
  443. {...formItemLayout}
  444. label={<span><span className="mandatory">*</span>财务负责人</span>}
  445. >
  446. <AutoComplete
  447. className="certain-category-search"
  448. dropdownClassName="certain-category-search-dropdown"
  449. dropdownMatchSelectWidth={false}
  450. style={{ width: "250px" }}
  451. dataSource={options2}
  452. placeholder='输入财务负责人名称'
  453. value={this.state.auto2}
  454. onChange={this.httpChange2}
  455. filterOption={true}
  456. onBlur={this.blurChange2}
  457. onSelect={this.selectAuto2}
  458. >
  459. <Input />
  460. </AutoComplete>
  461. </FormItem>
  462. </div>
  463. <div className="clearfix">
  464. <FormItem
  465. className="mid-item"
  466. {...formItemLayout}
  467. label={<span><span className="mandatory">*</span>会计负责人</span>}
  468. >
  469. <AutoComplete
  470. className="certain-category-search"
  471. dropdownClassName="certain-category-search-dropdown"
  472. dropdownMatchSelectWidth={false}
  473. style={{ width: "250px" }}
  474. dataSource={options3}
  475. placeholder='输入会计负责人名称'
  476. value={this.state.auto3}
  477. onChange={this.httpChange3}
  478. filterOption={true}
  479. onBlur={this.blurChange3}
  480. onSelect={this.selectAuto3}
  481. >
  482. <Input />
  483. </AutoComplete>
  484. </FormItem>
  485. </div>
  486. <div className="clearfix">
  487. <FormItem
  488. className="mid-item"
  489. {...formItemLayout}
  490. label={<span>备注巴说明</span>}
  491. >
  492. <Input
  493. type="textarea"
  494. placeholder="备注说明"
  495. style={{ width: "250px" }}
  496. autosize={{ minRows: 3 }}
  497. value={this.state.remarks}
  498. onChange={(e) => {
  499. this.setState({ remarks: e.target.value });
  500. }}
  501. />
  502. </FormItem>
  503. </div>
  504. <FormItem wrapperCol={{ span: 12, offset: 8 }}>
  505. <Button
  506. type="primary"
  507. onClick={!!this.props.id ? this.editSubmit : this.addSubmit}
  508. style={{ marginRight: "50px" }}
  509. >
  510. 保存
  511. </Button>
  512. <Button
  513. type="ghost"
  514. onClick={this.props.handleCancel}>
  515. 取消
  516. </Button>
  517. </FormItem>
  518. </Form>
  519. </div>
  520. </Spin>
  521. </Modal >
  522. );
  523. },
  524. });
  525. export default Operation;