index.jsx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. import React from 'react';
  2. import ajax from 'jquery/src/ajax/xhr.js';
  3. import $ from 'jquery/src/ajax';
  4. import moment from 'moment';
  5. import '@/manageCenter/financialManage/distribute/public.less';
  6. import { Button, Input, Spin, Table, Select, message } from 'antd';
  7. import SelContact from './selContact';
  8. import {getPost} from '@/tools';
  9. const Contact = React.createClass({
  10. departmentList() {
  11. this.setState({
  12. loading: true
  13. });
  14. $.ajax({
  15. method: "get",
  16. dataType: "json",
  17. crossDomain: false,
  18. url: globalConfig.context + "/api/admin/organization/selectSuperId",
  19. data: {
  20. },
  21. success: function(data) {
  22. let thedata = data.data;
  23. let theArr=[];
  24. if(!thedata) {
  25. if(data.error && data.error.length) {
  26. message.warning(data.error[0].message);
  27. };
  28. thedata = {};
  29. }else{
  30. thedata.map(function(item,index){
  31. theArr.push({
  32. key:index,
  33. name:item.name,
  34. id:item.id,
  35. })
  36. })
  37. }
  38. this.setState({
  39. departmentArr:theArr,
  40. })
  41. }.bind(this),
  42. }).always(function() {
  43. this.setState({
  44. loading: false
  45. });
  46. }.bind(this));
  47. },
  48. loadData(pageNo) {
  49. this.state.data = [];
  50. this.setState({
  51. selectedRowKeys:[],
  52. selectedRowKey:[],
  53. page:pageNo,
  54. loading: true
  55. });
  56. $.ajax({
  57. method: "get",
  58. dataType: "json",
  59. crossDomain: false,
  60. url: globalConfig.context + "/api/admin/frequentContactsList",
  61. data: {
  62. pageNo: pageNo || 1,
  63. pageSize: this.state.pagination.pageSize,
  64. name: this.state.name,
  65. departmentId:this.state.departmenttList,
  66. },
  67. success: function (data) {
  68. let theArr = [];
  69. if (!data.data || !data.data.list) {
  70. if (data.error && data.error.length) {
  71. message.warning(data.error[0].message);
  72. };
  73. } else {
  74. for (let i = 0; i < data.data.list.length; i++) {
  75. let thisdata = data.data.list[i];
  76. theArr.push({
  77. key: i,
  78. id:thisdata.id,
  79. name: thisdata.name,
  80. departmentName:thisdata.departmentName,
  81. position:thisdata.position,
  82. contactMobile:thisdata.contactMobile
  83. });
  84. };
  85. }
  86. this.state.pagination.current = data.data.pageNo;
  87. this.state.pagination.total = data.data.totalCount;
  88. if(data.data&&data.data.list&&!data.data.list.length){
  89. this.state.pagination.current=0
  90. this.state.pagination.total=0
  91. }
  92. this.setState({
  93. dataSource: theArr,
  94. pagination: this.state.pagination
  95. });
  96. }.bind(this),
  97. }).always(function () {
  98. this.setState({
  99. loading: false
  100. });
  101. }.bind(this));
  102. },
  103. getInitialState() {
  104. return {
  105. searchMore: true,
  106. RowData:{},
  107. selectedRowKeys: [],
  108. selectedRows: [],
  109. loading: false,
  110. pagination: {
  111. defaultCurrent: 1,
  112. defaultPageSize: 10,
  113. showQuickJumper: true,
  114. pageSize: 10,
  115. onChange: function (page) {
  116. this.loadData(page);
  117. }.bind(this),
  118. showTotal: function (total) {
  119. return '共' + total + '条数据';
  120. }
  121. },
  122. columns: [
  123. {
  124. title: '用户姓名',
  125. dataIndex: 'name',
  126. key: 'name'
  127. },{
  128. title: '部门机构',
  129. dataIndex: 'departmentName',
  130. key: 'departmentName'
  131. },{
  132. title: '职务',
  133. dataIndex: 'position',
  134. key: 'position',
  135. render:text=>{
  136. return getPost(text)
  137. }
  138. },{
  139. title: '联系手机',
  140. dataIndex: 'contactMobile',
  141. key: 'contactMobile'
  142. }
  143. ],
  144. dataSource: [],
  145. }
  146. },
  147. componentWillMount() {
  148. this.loadData();
  149. this.departmentList()
  150. },
  151. closeDesc(e, s) {
  152. this.state.RowData={};
  153. this.state.showDesc = e;
  154. if (s) {
  155. this.loadData(this.state.page);
  156. };
  157. },
  158. search() {
  159. this.loadData();
  160. },
  161. reset() {
  162. this.state.name='';
  163. this.state.departmenttList = [];
  164. this.loadData();
  165. },
  166. //删除
  167. del(){
  168. let deletedIds =[];
  169. let rowItem = this.state.selectedRowKeys[0];
  170. let data = this.state.dataSource ||[];
  171. if (data.length) {
  172. deletedIds.push(data[rowItem].id);
  173. }
  174. this.setState({
  175. selectedRowKeys: [],
  176. loading: deletedIds.length > 0
  177. });
  178. $.ajax({
  179. method: "POST",
  180. dataType: "json",
  181. crossDomain: false,
  182. url: globalConfig.context + "/api/admin/deleteFrequentContacts",
  183. data: {
  184. id: deletedIds[0]
  185. }
  186. }).done(function (data) {
  187. if (!data.error.length) {
  188. message.success('删除成功!');
  189. this.loadData();
  190. } else {
  191. message.warning(data.error[0].message);
  192. };
  193. this.setState({
  194. loading: false
  195. });
  196. }.bind(this));
  197. },
  198. //新增
  199. add(){
  200. this.setState({
  201. showDesc:true
  202. });
  203. },
  204. render() {
  205. const rowSelection = {
  206. selectedRowKeys: this.state.selectedRowKeys,
  207. onChange: (selectedRowKeys, selectedRows) => {
  208. this.setState({
  209. selectedRows: selectedRows.slice(-1),
  210. selectedRowKeys: selectedRowKeys.slice(-1)
  211. });
  212. }
  213. };
  214. const hasSelected = this.state.selectedRowKeys.length > 0;
  215. let departmentArr = this.state.departmentArr || [];
  216. return ( <div className="user-content">
  217. <div className="content-title" style={{ marginBottom: 10 }}>
  218. <span style={{ fontWeight: 900, fontSize: 16 }}>常用联系人</span>
  219. </div>
  220. <div className="user-search">
  221. <Input placeholder="联系人姓名"
  222. value={this.state.name}
  223. onChange={(e) => { this.setState({ name: e.target.value }); }} />
  224. <Select placeholder="所属部门"
  225. style={{ width: 150 ,marginRight:'10px',marginLeft:'10px'}}
  226. value={this.state.departmenttList}
  227. onChange={(e) => { this.setState({ departmenttList: e }) }}>
  228. {
  229. departmentArr.map(function (item) {
  230. return <Select.Option key={item.id} >{item.name}</Select.Option>
  231. })
  232. }
  233. </Select>
  234. <Button type="primary" onClick={this.search}>搜索</Button>
  235. <Button onClick={this.reset}>重置</Button>
  236. <Button type="danger" disabled={!hasSelected} onClick={this.del}>删除</Button>
  237. <Button type="primary" onClick={this.add} style={{float:'right'}}>新增常用联系人</Button>
  238. </div>
  239. <div className="patent-table">
  240. <Spin spinning={this.state.loading}>
  241. <Table columns={this.state.columns}
  242. dataSource={this.state.dataSource}
  243. rowSelection={rowSelection}
  244. pagination={this.state.pagination}
  245. />
  246. </Spin>
  247. </div>
  248. <SelContact
  249. departmentArr={departmentArr}
  250. data={this.state.RowData}
  251. showDesc={this.state.showDesc}
  252. closeDesc={this.closeDesc.bind(this)}
  253. />
  254. </div> )
  255. }
  256. })
  257. export default Contact;