team.jsx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. import React from 'react';
  2. import ReactDom from 'react-dom';
  3. import ajax from 'jquery/src/ajax/xhr.js';
  4. import $ from 'jquery/src/ajax';
  5. import {
  6. Form, Icon, Button, Input, Select, AutoComplete, Spin, Table,
  7. message, DatePicker, Modal, TreeSelect, Popconfirm, Tabs
  8. } from 'antd';
  9. import Newuser from "./newUser.jsx"
  10. import { ShowModal } from "@/tools";
  11. import { ChooseList } from "../../order/orderNew/chooseList";
  12. const { TabPane } = Tabs
  13. const Team = Form.create()(React.createClass({
  14. getInitialState() {
  15. return {
  16. info: {},
  17. searchValues: {}, // 列表筛选条件
  18. loading: false, //加载动画
  19. changeList: undefined, // 更改后的表格显示数据
  20. departmentArr: [], // 部门
  21. dataSource: [], // 列表数据
  22. teamList: [], // 上级
  23. fjlist: [],
  24. pagination: {
  25. defaultCurrent: 1,
  26. defaultPageSize: 10,
  27. showQuickJumper: true,
  28. pageSize: 10,
  29. onChange: function (page) {
  30. this.loadData(page);
  31. }.bind(this),
  32. showTotal: function (total) {
  33. return '共' + total + '条数据';
  34. }
  35. },
  36. columns: [
  37. {
  38. title: '团队名称',
  39. dataIndex: 'name',
  40. key: 'name',
  41. },
  42. {
  43. title: '队长',
  44. dataIndex: 'adminName',
  45. key: 'adminName',
  46. },
  47. {
  48. title: '等级',
  49. dataIndex: 'lvl',
  50. key: 'lvl',
  51. render: (text, record) => {
  52. return (
  53. <div>
  54. {["", "一级", "二级", "三级"][text]}
  55. </div>
  56. )
  57. }
  58. },
  59. {
  60. title: '部门',
  61. dataIndex: 'depName',
  62. key: 'depName',
  63. },
  64. {
  65. title: '上级团队',
  66. dataIndex: 'superName',
  67. key: 'superName',
  68. },
  69. {
  70. title: '状态',
  71. dataIndex: 'status',
  72. key: 'status',
  73. render: (text, record) => {
  74. return (
  75. <div>
  76. {["正常", "解散"][text]}
  77. </div>
  78. )
  79. }
  80. },
  81. ],
  82. visible: "",
  83. };
  84. },
  85. componentWillMount() {
  86. this.loadData();
  87. this.departmentList();
  88. },
  89. // 列表接口
  90. loadData(pageNo) {
  91. const { searchValues, pagination } = this.state;
  92. this.setState({
  93. loading: true,
  94. });
  95. let datas = Object.assign(searchValues, {
  96. pageNo: pageNo || 1,
  97. pageSize: pagination.pageSize,
  98. });
  99. $.ajax({
  100. method: "get",
  101. dataType: "json",
  102. crossDomain: false,
  103. url: globalConfig.context + "/api/admin/salesTeam/pageList",
  104. data: datas,
  105. success: function (data) {
  106. ShowModal(this);
  107. this.setState({
  108. loading: false,
  109. });
  110. let theArr = [];
  111. if (data.error && data.error.length === 0) {
  112. if (data.data) {
  113. pagination.current = data.data.pageNo;
  114. pagination.total = data.data.totalCount;
  115. if (data.data && data.data.list && !data.data.list.length) {
  116. pagination.current = 0
  117. pagination.total = 0
  118. };
  119. this.setState({
  120. dataSource: data.data.list,
  121. pagination: this.state.pagination,
  122. pageNo: data.data.pageNo,
  123. });
  124. }
  125. } else {
  126. message.warning(data.error[0].message);
  127. }
  128. }.bind(this),
  129. }).always(
  130. function () {
  131. this.setState({
  132. loading: false,
  133. });
  134. }.bind(this)
  135. );
  136. },
  137. // 部门
  138. departmentList() {
  139. this.setState({
  140. loading: true
  141. });
  142. $.ajax({
  143. method: "get",
  144. dataType: "json",
  145. crossDomain: false,
  146. url: globalConfig.context + "/api/admin/organization/selectSuperId",
  147. data: {
  148. },
  149. success: function (data) {
  150. let thedata = data.data;
  151. let theArr = [];
  152. if (!thedata) {
  153. if (data.error && data.error.length) {
  154. message.warning(data.error[0].message);
  155. };
  156. thedata = {};
  157. } else {
  158. thedata.map(function (item, index) {
  159. theArr.push({
  160. key: index,
  161. name: item.name,
  162. id: item.id,
  163. depNo: item.depNo
  164. })
  165. })
  166. }
  167. this.setState({
  168. departmentArr: theArr,
  169. })
  170. }.bind(this),
  171. }).always(function () {
  172. this.setState({
  173. loading: false
  174. });
  175. }.bind(this));
  176. },
  177. // 团队
  178. salesTeam(lvl) {
  179. this.setState({
  180. loading: true
  181. });
  182. $.ajax({
  183. method: "get",
  184. dataType: "json",
  185. crossDomain: false,
  186. url: globalConfig.context + "/api/admin/salesTeam/list",
  187. data: {
  188. lvl: lvl - 1
  189. },
  190. success: function (data) {
  191. let thedata = data.data;
  192. let theArr = [];
  193. if (!thedata) {
  194. if (data.error && data.error.length) {
  195. message.warning(data.error[0].message);
  196. };
  197. thedata = {};
  198. } else {
  199. thedata.map(function (item, index) {
  200. theArr.push({
  201. name: item.name,
  202. id: item.id,
  203. })
  204. })
  205. }
  206. this.setState({
  207. teamList: theArr,
  208. })
  209. }.bind(this),
  210. }).always(function () {
  211. this.setState({
  212. loading: false
  213. });
  214. }.bind(this));
  215. },
  216. followUp(e) {
  217. const { info } = this.state;
  218. this.setState({
  219. info: Object.assign(info, {
  220. adminName: e,
  221. }),
  222. });
  223. $.ajax({
  224. method: "get",
  225. dataType: "json",
  226. crossDomain: false,
  227. url: globalConfig.context + "/api/admin/customer/listAdminByName",
  228. data: {
  229. adminName: e,
  230. },
  231. success: function (data) {
  232. let thedata = data.data;
  233. if (!thedata) {
  234. if (data.error && data.error.length) {
  235. message.warning(data.error[0].message);
  236. }
  237. thedata = {};
  238. }
  239. this.setState({
  240. fjlist: thedata,
  241. });
  242. }.bind(this),
  243. }).always(
  244. function () {
  245. this.setState({
  246. loading: false,
  247. });
  248. }.bind(this)
  249. );
  250. },
  251. selectF(value) {
  252. const { info, fjlist } = this.state;
  253. const newdataSources = JSON.stringify(fjlist) == "{}" ? [] : fjlist;
  254. info["aid"] = newdataSources.find((item) => item.name == value).id;
  255. this.setState({
  256. info
  257. });
  258. },
  259. tableRowClick(record, index) {
  260. this.salesTeam(record.lvl)
  261. this.setState({
  262. visible: "edit",
  263. info: record,
  264. })
  265. },
  266. search() {
  267. this.loadData();
  268. },
  269. reset() {
  270. this.setState({
  271. searchValues: {}
  272. }, () => {
  273. this.loadData();
  274. })
  275. },
  276. changeList(arr) {
  277. const newArr = [];
  278. this.state.columns.forEach(item => {
  279. arr.forEach(val => {
  280. if (val === item.title) {
  281. newArr.push(item);
  282. }
  283. });
  284. });
  285. this.setState({
  286. changeList: newArr
  287. });
  288. },
  289. // 保存
  290. handleOk() {
  291. const { info } = this.state
  292. if (!info.name) {
  293. message.warn("团队名称不能为空!")
  294. return
  295. }
  296. if (!info.adminName) {
  297. message.warn("队长姓名不能为空!")
  298. return
  299. }
  300. if (!info.lvl) {
  301. message.warn("请选择等级!")
  302. return
  303. }
  304. if (!info.depId) {
  305. message.warn("请选择部门!")
  306. return
  307. }
  308. // if (!info.superId) {
  309. // message.warn("请选择上级团队!")
  310. // return
  311. // }
  312. if (!info.status && info.status != 0) {
  313. message.warn("请选择状态!")
  314. return
  315. }
  316. let obj = {
  317. id: info.id,
  318. name: info.name,
  319. aid: info.aid,
  320. lvl: info.lvl,
  321. depId: info.depId,
  322. superId: info.superId,
  323. status: info.status,
  324. }
  325. this.setState({
  326. loading: true
  327. });
  328. $.ajax({
  329. method: "POST",
  330. dataType: "json",
  331. crossDomain: false,
  332. url: globalConfig.context + (!info.id ? "/api/admin/salesTeam/add" : "/api/admin/salesTeam/update"),
  333. data: obj
  334. }).done(function (data) {
  335. this.setState({
  336. loading: false
  337. });
  338. if (!data.error.length) {
  339. message.success('保存成功!');
  340. this.handleCancel();
  341. this.loadData();
  342. } else {
  343. message.warning(data.error[0].message);
  344. }
  345. }.bind(this));
  346. },
  347. handleCancel() {
  348. this.setState({
  349. visible: "",
  350. info: {},
  351. })
  352. },
  353. render() {
  354. const { searchValues, departmentArr, teamList, info } = this.state
  355. const FormItem = Form.Item
  356. const formItemLayout = {
  357. labelCol: { span: 8 },
  358. wrapperCol: { span: 14 },
  359. };
  360. const newdataSources = this.state.fjlist || [];
  361. const newoptions = newdataSources.map((group) => (
  362. <Select.Option key={group.id} value={group.name}>
  363. {group.name}
  364. </Select.Option>
  365. ));
  366. return (
  367. <div className="user-content">
  368. <div className="content-title">
  369. <Tabs defaultActiveKey="1" onChange={this.callback} className="test">
  370. <TabPane tab="搜索" key="1">
  371. <div className="user-search" style={{ paddingBottom: 10 }}>
  372. <Input
  373. placeholder="用户姓名"
  374. style={{ width: "180px" }}
  375. value={searchValues["userName"]
  376. ? searchValues["userName"]
  377. : ""}
  378. onChange={e => {
  379. searchValues["userName"] = e.target.value;
  380. this.setState({
  381. searchValues: searchValues,
  382. });
  383. }}
  384. />
  385. <Select
  386. placeholder="部门"
  387. style={{ width: 180 }}
  388. value={searchValues["depId"]
  389. ? searchValues["depId"]
  390. : undefined}
  391. onChange={e => {
  392. searchValues["depId"] = e;
  393. this.setState({
  394. searchValues,
  395. });
  396. }}
  397. >
  398. {departmentArr.map(function (item) {
  399. return (
  400. <Select.Option key={item.id}>{item.name}</Select.Option>
  401. );
  402. })}
  403. </Select>
  404. <Select
  405. placeholder="状态"
  406. style={{ width: 180 }}
  407. value={searchValues["status"]
  408. ? searchValues["status"]
  409. : undefined}
  410. onChange={e => {
  411. searchValues["status"] = e;
  412. this.setState({
  413. searchValues,
  414. });
  415. }}
  416. >
  417. <Select.Option value="0">正常</Select.Option>
  418. <Select.Option value="1">解散</Select.Option>
  419. </Select>
  420. <Button
  421. type="primary"
  422. onClick={this.search}
  423. style={{ margin: "0 10px" }}
  424. >搜索</Button>
  425. <Button onClick={this.reset}>重置</Button>
  426. <Button
  427. type="primary"
  428. style={{
  429. marginBottom: '15px',
  430. position: "absolute",
  431. right: 0,
  432. }}
  433. onClick={() => {
  434. this.setState({
  435. visible: "add"
  436. })
  437. }}
  438. >
  439. 新增团队
  440. </Button>
  441. </div>
  442. </TabPane>
  443. <TabPane tab="更改表格显示数据" key="2">
  444. <div style={{ marginLeft: 10 }}>
  445. <ChooseList
  446. columns={this.state.columns}
  447. changeFn={this.changeList}
  448. changeList={this.state.changeList}
  449. top={55}
  450. margin={11}
  451. />
  452. </div>
  453. </TabPane>
  454. </Tabs>
  455. <div className="patent-table">
  456. <Spin spinning={this.state.loading}>
  457. <Table
  458. bordered
  459. columns={
  460. this.state.changeList
  461. ? this.state.changeList
  462. : this.state.columns
  463. }
  464. style={{
  465. cursor: 'pointer',
  466. }}
  467. dataSource={this.state.dataSource}
  468. pagination={this.state.pagination}
  469. onRowDoubleClick={this.tableRowClick}
  470. />
  471. </Spin>
  472. </div>
  473. <Modal
  474. title={this.state.visible == "add"
  475. ? "新建团队" : this.state.visible == "edit"
  476. ? "编辑团队" : "????"}
  477. width={610}
  478. visible={this.state.visible != ""}
  479. footer={null}
  480. onCancel={this.handleCancel}
  481. >
  482. <Form
  483. layout="horizontal"
  484. >
  485. <Spin spinning={this.state.loading}>
  486. <div className="clearfix">
  487. <FormItem
  488. className="half-middle"
  489. {...formItemLayout}
  490. label="团队名称"
  491. >
  492. <Input
  493. placeholder="团队名称"
  494. value={info["name"] ? info["name"] : undefined}
  495. style={{ width: "230px" }}
  496. onChange={(e) => {
  497. info["name"] = e.target.value;
  498. this.setState({ info });
  499. }}
  500. required="required"
  501. />
  502. </FormItem>
  503. <FormItem
  504. className="half-middle"
  505. {...formItemLayout}
  506. label="队长"
  507. >
  508. <AutoComplete
  509. className="certain-category-search"
  510. dropdownClassName="certain-category-search-dropdown"
  511. dropdownMatchSelectWidth={false}
  512. style={{ width: "230px" }}
  513. dataSource={newoptions}
  514. placeholder="队长姓名"
  515. value={info["adminName"] || undefined}
  516. onChange={this.followUp.bind(this)}
  517. filterOption={true}
  518. onSelect={this.selectF.bind(this)}
  519. >
  520. <Input />
  521. </AutoComplete>
  522. </FormItem>
  523. <FormItem
  524. className="half-middle"
  525. {...formItemLayout}
  526. label="等级"
  527. >
  528. <Select
  529. placeholder="选择等级"
  530. style={{ width: "230px" }}
  531. value={info["lvl"] ? info["lvl"] : undefined}
  532. onChange={(e) => {
  533. info["lvl"] = e;
  534. info["superId"] = null;
  535. this.setState({ info });
  536. this.salesTeam(e)
  537. }}
  538. >
  539. {[
  540. { key: "一级", value: 1 },
  541. { key: "二级", value: 2 },
  542. { key: "三级", value: 3 }].map(function (item) {
  543. return (
  544. <Select.Option key={item.value} value={item.value}>
  545. {item.key}
  546. </Select.Option>
  547. );
  548. })}
  549. </Select>
  550. </FormItem>
  551. <FormItem
  552. className="half-middle"
  553. {...formItemLayout}
  554. label="所属部门"
  555. >
  556. <Select
  557. placeholder="部门"
  558. style={{ width: 230 }}
  559. value={info["depId"]
  560. ? info["depId"]
  561. : undefined}
  562. onChange={e => {
  563. info["depId"] = e;
  564. this.setState({
  565. info,
  566. });
  567. }}
  568. >
  569. {departmentArr.map(function (item) {
  570. return (
  571. <Select.Option key={item.id}>{item.name}</Select.Option>
  572. );
  573. })}
  574. </Select>
  575. </FormItem>
  576. <FormItem
  577. className="half-middle"
  578. {...formItemLayout}
  579. label="上级团队"
  580. >
  581. <Select
  582. placeholder="上级团队"
  583. style={{ width: 230 }}
  584. value={info["superId"]
  585. ? info["superId"]
  586. : undefined}
  587. onChange={e => {
  588. info["superId"] = e;
  589. this.setState({
  590. info,
  591. });
  592. }}
  593. >
  594. {teamList.map(function (item) {
  595. return (
  596. <Select.Option key={item.id} value={item.id}>{item.name}</Select.Option>
  597. );
  598. })}
  599. </Select>
  600. </FormItem>
  601. <FormItem
  602. className="half-middle"
  603. {...formItemLayout}
  604. label="状态"
  605. >
  606. <Select
  607. placeholder="选择状态"
  608. style={{ width: "230px" }}
  609. value={info["status"]}
  610. onChange={(e) => {
  611. info["status"] = e;
  612. this.setState({
  613. info,
  614. });
  615. }}
  616. >
  617. <Select.Option value={0}>正常</Select.Option>
  618. <Select.Option value={1}>解散</Select.Option>
  619. </Select>
  620. </FormItem>
  621. </div>
  622. <FormItem className="half-middle">
  623. <Button
  624. className="set-submit"
  625. type="primary"
  626. style={{ marginLeft: "150px" }}
  627. onClick={this.handleOk}
  628. >
  629. 保存
  630. </Button>
  631. <Button
  632. className="set-submit"
  633. type="ghost"
  634. onClick={this.handleCancel}
  635. >
  636. 取消
  637. </Button>
  638. </FormItem>
  639. </Spin>
  640. </Form>
  641. </Modal>
  642. </div>
  643. </div>
  644. );
  645. }
  646. }));
  647. export default Team;