barList.jsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. import React, { Component } from "react";
  2. import { Button, Modal, Form, AutoComplete, TreeSelect, Input, message, Spin, Select, Tabs, Table, } from "antd";
  3. import $ from "jquery/src/ajax";
  4. import { ShowModal, getBarLevel } from "@/tools";
  5. import './index.less'
  6. import ShowModalDiv from "@/showModal.jsx";
  7. import { ChooseList } from "../../order/orderNew/chooseList";
  8. import Operation from "./operation"
  9. const { TabPane } = Tabs;
  10. const FormItem = Form.Item;
  11. const confirm = Modal.confirm;
  12. class Source extends Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. visible: '', // 弹窗控制
  17. level1Data: [], // 体系数据
  18. searchValues: {}, // 列表筛选条件
  19. lvl: 5, // 层级
  20. pagination: {
  21. defaultCurrent: 1,
  22. defaultPageSize: 10,
  23. showQuickJumper: true,
  24. pageSize: 10,
  25. onChange: function (page) {
  26. this.loadData(page);
  27. }.bind(this),
  28. showTotal: function (total) {
  29. return "共" + total + "条数据";
  30. },
  31. },
  32. loading: false, //加载动画
  33. changeList: undefined, // 更改后的表格显示数据
  34. dataSource: [], // 列表数据
  35. selectedRowKeys: [], // 选中列表数据
  36. selectedRows: [], // 选中列表数据
  37. columns: [
  38. {
  39. title: "名称",
  40. dataIndex: "name",
  41. key: "name",
  42. width: "8%",
  43. render: (text, record) =>
  44. <span>
  45. {text + (getBarLevel(record.ancestorsNames)[4] != "" ? ("(" + getBarLevel(record.ancestorsNames)[4] + ")") : "")}
  46. </span>
  47. },
  48. {
  49. title: "巴主",
  50. dataIndex: "leaderName",
  51. key: "leaderName",
  52. width: "8%",
  53. },
  54. {
  55. title: "各战区&区事业部",
  56. dataIndex: "name4",
  57. key: "name4",
  58. width: "8%",
  59. render: (text, record) =>
  60. <span >
  61. {getBarLevel(record.ancestorsNames)[3]}
  62. </span>
  63. },
  64. {
  65. title: "各事业部&区经管开综",
  66. dataIndex: "name3",
  67. key: "name3",
  68. width: "8%",
  69. render: (text, record) =>
  70. <span >
  71. {getBarLevel(record.ancestorsNames)[2]}
  72. </span>
  73. },
  74. {
  75. title: "各大区管理中心&集团经开综",
  76. dataIndex: "name2",
  77. key: "name2",
  78. render: (text, record) =>
  79. <span >
  80. {getBarLevel(record.ancestorsNames)[1]}
  81. </span>
  82. },
  83. {
  84. title: "管理中心",
  85. dataIndex: "name1",
  86. key: "name1",
  87. width: "8%",
  88. render: (text, record) =>
  89. <span >
  90. {getBarLevel(record.ancestorsNames)[0]}
  91. </span>
  92. },
  93. {
  94. title: "财务",
  95. dataIndex: "financeName",
  96. key: "financeName",
  97. width: "8%",
  98. },
  99. {
  100. title: "会计",
  101. dataIndex: "accountantName",
  102. key: "accountantName",
  103. width: "8%",
  104. },
  105. {
  106. title: "状态",
  107. dataIndex: "status",
  108. key: "status",
  109. render: (text) =>
  110. <span style={{ color: ["green", "red"][text] }}>
  111. {text == 0
  112. ? "正常" : text == 1
  113. ? "停用" : "-"}
  114. </span>
  115. },
  116. {
  117. title: "创建时间",
  118. dataIndex: "createTimes",
  119. key: "createTimes",
  120. },
  121. {
  122. title: "操作",
  123. dataIndex: "opt",
  124. key: "opt",
  125. render: (text, record) =>
  126. <div>
  127. <Button
  128. type="primary"
  129. style={{ marginRight: "10px" }}
  130. onClick={() => {
  131. this.setState({
  132. visible: "edit",
  133. id: record.id
  134. })
  135. }}
  136. >
  137. 编辑
  138. </Button>
  139. <Button
  140. type="danger"
  141. style={{ marginRight: "10px" }}
  142. onClick={() => {
  143. let _this = this
  144. confirm({
  145. title: '提醒',
  146. content: '确定要删除吗?',
  147. onOk() {
  148. _this.delete(record.id)
  149. }
  150. })
  151. }}
  152. >
  153. 删除
  154. </Button>
  155. <Button
  156. type="primary"
  157. onClick={() => {
  158. this.editStatus(record.id, record.status == 0 ? 1 : 0)
  159. }}
  160. >
  161. {record.status == 0 ? "停用" : "启用"}
  162. </Button>
  163. </div>
  164. },
  165. ],
  166. };
  167. this.supervisor = this.supervisor.bind(this);
  168. this.httpChange = this.httpChange.bind(this);
  169. this.blurChange = this.blurChange.bind(this);
  170. this.selectAuto = this.selectAuto.bind(this);
  171. this.handleCancel = this.handleCancel.bind(this);
  172. this.handleCancel = this.handleCancel.bind(this);
  173. }
  174. // 修改状态
  175. editStatus(id, num) {
  176. this.setState({
  177. loading: true
  178. })
  179. let data = {
  180. id,
  181. status: num
  182. }
  183. $.ajax({
  184. method: "POST",
  185. dataType: "json",
  186. crossDomain: false,
  187. url: globalConfig.context + "/api/admin/amb/update",
  188. data,
  189. success: function (data) {
  190. if (data.error.length === 0) {
  191. message.success("操作成功!");
  192. this.loadData();
  193. } else {
  194. message.warning(data.error[0].message);
  195. }
  196. this.setState({
  197. loading: false,
  198. });
  199. }.bind(this),
  200. }).always(
  201. function () {
  202. this.setState({
  203. loading: false,
  204. });
  205. }.bind(this)
  206. );
  207. }
  208. // 根据id获取子集
  209. getSubset(id, list, key = "id", valus = "list") {
  210. let newList = [];
  211. if (!list) {
  212. return newList
  213. }
  214. list.forEach((item) => {
  215. if (item[key] == id) {
  216. newList = item[valus]
  217. }
  218. })
  219. return newList
  220. }
  221. // 筛选数据
  222. getList() {
  223. this.setState({
  224. loading: true,
  225. });
  226. $.ajax({
  227. method: "get",
  228. dataType: "json",
  229. crossDomain: false,
  230. url: globalConfig.context + "/api/admin/amb/selectAll",
  231. success: function (data) {
  232. this.setState({
  233. loading: false,
  234. });
  235. if (data.error && data.error.length === 0) {
  236. let menuList = data.data
  237. this.setState({
  238. level1Data: menuList ? this.handleTreeData(menuList) : []
  239. });
  240. } else {
  241. message.warning(data.error[0].message);
  242. }
  243. }.bind(this),
  244. }).always(
  245. function () {
  246. this.setState({
  247. loading: false,
  248. });
  249. }.bind(this)
  250. );
  251. }
  252. // 树状默认数据处理
  253. handleTreeData(treeData) {
  254. let nodeDta = [];
  255. treeData.map(item => {
  256. let treeObj = {};
  257. treeObj.key = item.id
  258. treeObj.id = item.id
  259. treeObj.value = item.id
  260. treeObj.label = item.name
  261. treeObj.title = item.name
  262. treeObj.lvl = item.lvl
  263. treeObj.parentId = item.parentId
  264. item.list ? treeObj.children = this.handleTreeData(item.list) : null;
  265. nodeDta.push(treeObj)
  266. })
  267. return nodeDta
  268. }
  269. // 更改表格显示数据
  270. changeList(arr) {
  271. const newArr = [];
  272. this.state.columns.forEach((item) => {
  273. arr.forEach((val) => {
  274. if (val === item.title) {
  275. newArr.push(item);
  276. }
  277. });
  278. });
  279. this.setState({
  280. changeList: newArr,
  281. });
  282. }
  283. // 重置
  284. resetAll() {
  285. this.setState(
  286. {
  287. auto: "",
  288. searchValues: JSON.parse(JSON.stringify({})),
  289. lvl: 5,
  290. selectedRowKeys: [],
  291. selectedRows: [],
  292. },
  293. () => {
  294. this.loadData();
  295. }
  296. );
  297. }
  298. // 搜索
  299. submit() {
  300. this.setState({
  301. params: this.state.searchValues
  302. })
  303. this.loadData()
  304. }
  305. // 列表接口
  306. loadData(pageNo) {
  307. const { searchValues, pagination, lvl } = this.state;
  308. this.setState({
  309. loading: true,
  310. });
  311. let datas = Object.assign(searchValues, {
  312. pageNo: pageNo || 1,
  313. pageSize: pagination.pageSize,
  314. lvl,
  315. });
  316. $.ajax({
  317. method: "get",
  318. dataType: "json",
  319. crossDomain: false,
  320. url: globalConfig.context + "/api/admin/amb/select",
  321. data: datas,
  322. success: function (data) {
  323. ShowModal(this);
  324. this.setState({
  325. loading: false,
  326. });
  327. if (data.error && data.error.length === 0) {
  328. if (data.data.list) {
  329. pagination.current = data.data.pageNo;
  330. pagination.total = data.data.totalCount;
  331. if (data.data && data.data.list && !data.data.list.length) {
  332. pagination.current = 0;
  333. pagination.total = 0;
  334. }
  335. this.setState({
  336. dataSource: data.data.list,
  337. pagination: this.state.pagination,
  338. pageNo: data.data.pageNo,
  339. });
  340. } else {
  341. this.setState({
  342. dataSource: data.data,
  343. pagination: false,
  344. });
  345. }
  346. } else {
  347. message.warning(data.error[0].message);
  348. }
  349. }.bind(this),
  350. }).always(
  351. function () {
  352. this.setState({
  353. loading: false,
  354. });
  355. }.bind(this)
  356. );
  357. }
  358. // 查询用户
  359. supervisor(e) {
  360. $.ajax({
  361. method: "get",
  362. dataType: "json",
  363. crossDomain: false,
  364. url: globalConfig.context + "/api/admin/customer/listAdminByName",
  365. data: {
  366. adminName: e,
  367. },
  368. success: function (data) {
  369. let thedata = data.data;
  370. if (!thedata) {
  371. if (data.error && data.error.length) {
  372. message.warning(data.error[0].message);
  373. }
  374. thedata = {};
  375. }
  376. this.setState({
  377. customerArr: thedata,
  378. });
  379. }.bind(this),
  380. }).always(
  381. function () {
  382. }.bind(this)
  383. );
  384. }
  385. // 输入触发
  386. httpChange(e) {
  387. if (e.length >= 1) {
  388. this.supervisor(e);
  389. }
  390. this.setState({
  391. auto: e,
  392. });
  393. }
  394. // 选中
  395. selectAuto(value, options) {
  396. const { searchValues } = this.state
  397. let contactLists = this.state.customerArr || [];
  398. if (value) {
  399. contactLists.map(function (item) {
  400. if (item.name == value.toString()) {
  401. searchValues["leader"] = item.id;
  402. }
  403. });
  404. }
  405. this.setState({
  406. auto: value,
  407. searchValues: searchValues,
  408. });
  409. }
  410. // 失去焦点
  411. blurChange(e) {
  412. const { searchValues } = this.state
  413. let contactLists = this.state.customerArr || [];
  414. if (e) {
  415. contactLists.map(function (item) {
  416. if (item.name == e.toString()) {
  417. searchValues["leader"] = item.id;
  418. }
  419. });
  420. }
  421. this.setState({
  422. searchValues: searchValues,
  423. });
  424. }
  425. // 选择行
  426. onSelectChange(selectedRowKeys, selectedRows) {
  427. this.setState({ selectedRowKeys, selectedRows });
  428. }
  429. // 删除巴
  430. delete(id) {
  431. this.setState({
  432. loading: true,
  433. })
  434. $.ajax({
  435. method: "post",
  436. dataType: "json",
  437. crossDomain: false,
  438. url: globalConfig.context + "/api/admin/amb/delete",
  439. data: { id },
  440. success: function (data) {
  441. if (data.error.length) {
  442. if (data.error && data.error.length) {
  443. message.warning(data.error[0].message)
  444. }
  445. } else {
  446. message.success('删除成功');
  447. this.getList();
  448. this.loadData();
  449. this.setState({
  450. selectedRowKeys: [],
  451. selectedRows: [],
  452. });
  453. }
  454. }.bind(this),
  455. }).always(
  456. function () {
  457. this.setState({
  458. loading: false,
  459. })
  460. }.bind(this)
  461. );
  462. }
  463. // 关闭弹窗
  464. handleCancel() {
  465. this.setState({
  466. visible: "",
  467. id: "",
  468. }, () => {
  469. this.getList();
  470. this.loadData();
  471. })
  472. }
  473. componentWillMount() {
  474. this.getList();
  475. this.loadData();
  476. }
  477. render() {
  478. const { searchValues, columns, selectedRowKeys, selectedRows, changeList, level1Data } = this.state;
  479. const rowSelection = {
  480. selectedRowKeys,
  481. onChange: this.onSelectChange.bind(this),
  482. hideDefaultSelections: true,
  483. type: "radio",
  484. };
  485. const dataSources = this.state.customerArr || [];
  486. const options = dataSources.map((group) => (
  487. <Select.Option key={group.id} value={group.name}>
  488. {group.name}
  489. </Select.Option>
  490. ));
  491. return (
  492. <div className="user-content">
  493. <ShowModalDiv ShowModal={this.state.showModal} onClose={() => { this.setState({ showModal: false }) }} />
  494. <div className="content-title" style={{ marginBottom: 10 }}>
  495. <span style={{ fontWeight: 900, fontSize: 16, }}>阿米巴管理</span>
  496. </div>
  497. <Tabs defaultActiveKey="1" onChange={() => { }}>
  498. <TabPane tab="搜索" key="1">
  499. <div style={{ padding: "0 10px" }}>
  500. <Form layout="inline">
  501. <FormItem>
  502. <Input
  503. placeholder="输入巴名称"
  504. value={searchValues["name"]
  505. ? searchValues["name"]
  506. : ""}
  507. onChange={(e) => {
  508. searchValues["name"] = e.target.value;
  509. this.setState({
  510. searchValues: searchValues,
  511. });
  512. }}
  513. />
  514. </FormItem>
  515. <FormItem>
  516. <AutoComplete
  517. className="certain-category-search"
  518. dropdownClassName="certain-category-search-dropdown"
  519. dropdownMatchSelectWidth={false}
  520. style={{ width: 150 }}
  521. dataSource={options}
  522. placeholder='输入巴主名称'
  523. value={this.state.auto}
  524. onChange={this.httpChange}
  525. filterOption={true}
  526. onBlur={this.blurChange}
  527. onSelect={this.selectAuto}
  528. >
  529. <Input />
  530. </AutoComplete>
  531. </FormItem>
  532. <FormItem>
  533. <Select
  534. placeholder="层级"
  535. style={{ width: 150 }}
  536. value={this.state.lvl}
  537. onChange={(e) => {
  538. this.setState({ lvl: e })
  539. }}
  540. >
  541. <Select.Option value={1}>管理中心</Select.Option>
  542. <Select.Option value={2}>各大区管理中心&集团经开综</Select.Option>
  543. <Select.Option value={3}>各事业部&区经管开综</Select.Option>
  544. <Select.Option value={4}>各战区&区事业部</Select.Option>
  545. <Select.Option value={5}>各巴&小巴</Select.Option>
  546. </Select>
  547. </FormItem>
  548. <FormItem>
  549. <TreeSelect
  550. style={{ width: 300 }}
  551. value={searchValues["ancestors"]
  552. ? searchValues["ancestors"]
  553. : undefined}
  554. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  555. treeData={level1Data}
  556. placeholder="请选择"
  557. showSearch
  558. treeNodeFilterProp="title"
  559. onChange={(e) => {
  560. searchValues["ancestors"] = e;
  561. this.setState({
  562. searchValues: searchValues,
  563. });
  564. }}
  565. />
  566. </FormItem>
  567. <Button
  568. type="primary"
  569. onClick={() => { this.submit() }}
  570. style={{ marginRight: "10px" }}
  571. >
  572. 搜索
  573. </Button>
  574. <Button
  575. onClick={() => { this.resetAll() }}
  576. style={{ marginRight: "10px" }}
  577. >
  578. 重置
  579. </Button>
  580. <Button
  581. type="primary"
  582. onClick={() => { this.setState({ visible: "add" }) }}
  583. style={{ float: "right" }}
  584. >
  585. 新增阿米巴架构
  586. </Button>
  587. </Form>
  588. </div>
  589. </TabPane>
  590. {/* <TabPane tab="操作" key="2">
  591. <div style={{ marginLeft: 10 }}>
  592. </div>
  593. </TabPane> */}
  594. <TabPane tab="更改表格显示数据" key="2">
  595. <div style={{ marginLeft: 10 }}>
  596. <ChooseList
  597. columns={columns}
  598. changeFn={this.changeList.bind(this)}
  599. changeList={changeList}
  600. top={55}
  601. />
  602. </div>
  603. </TabPane>
  604. </Tabs>
  605. <div className="patent-table">
  606. <Spin spinning={this.state.loading}>
  607. <Table
  608. bordered
  609. size="middle"
  610. columns={changeList ? changeList : columns}
  611. dataSource={this.state.dataSource}
  612. pagination={this.state.pagination}
  613. rowSelection={rowSelection}
  614. />
  615. </Spin>
  616. </div>
  617. {
  618. // 新建/编辑巴
  619. this.state.visible != "" &&
  620. <Operation
  621. visible={this.state.visible}
  622. handleCancel={this.handleCancel}
  623. levelData={this.state.level1Data}
  624. id={this.state.id}
  625. lev={5}
  626. />
  627. }
  628. </div>
  629. );
  630. }
  631. }
  632. export default Source;