123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- import React from 'react';
- import ajax from 'jquery/src/ajax/xhr.js';
- import $ from 'jquery/src/ajax';
- import moment from 'moment';
- import '@/manageCenter/financialManage/distribute/public.less';
- import { Button, Input, Spin, Table, Select, message } from 'antd';
- import SelContact from './selContact';
- import {getPost} from '@/tools';
- const Contact = React.createClass({
- departmentList() {
- this.setState({
- loading: true
- });
- $.ajax({
- method: "get",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + "/api/admin/organization/selectSuperId",
- data: {
-
- },
- success: function(data) {
- let thedata = data.data;
- let theArr=[];
- if(!thedata) {
- if(data.error && data.error.length) {
- message.warning(data.error[0].message);
- };
- thedata = {};
- }else{
- thedata.map(function(item,index){
- theArr.push({
- key:index,
- name:item.name,
- id:item.id,
- })
- })
- }
- this.setState({
- departmentArr:theArr,
- })
- }.bind(this),
- }).always(function() {
- this.setState({
- loading: false
- });
- }.bind(this));
- },
- loadData(pageNo) {
- this.state.data = [];
- this.setState({
- selectedRowKeys:[],
- selectedRowKey:[],
- page:pageNo,
- loading: true
- });
- $.ajax({
- method: "get",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + "/api/admin/frequentContactsList",
- data: {
- pageNo: pageNo || 1,
- pageSize: this.state.pagination.pageSize,
- name: this.state.name,
- departmentId:this.state.departmenttList,
- },
- success: function (data) {
- let theArr = [];
- if (!data.data || !data.data.list) {
- if (data.error && data.error.length) {
- message.warning(data.error[0].message);
- };
- } else {
- for (let i = 0; i < data.data.list.length; i++) {
- let thisdata = data.data.list[i];
- theArr.push({
- key: i,
- id:thisdata.id,
- name: thisdata.name,
- departmentName:thisdata.departmentName,
- position:thisdata.position,
- contactMobile:thisdata.contactMobile
- });
- };
- }
- this.state.pagination.current = data.data.pageNo;
- this.state.pagination.total = data.data.totalCount;
- if(data.data&&data.data.list&&!data.data.list.length){
- this.state.pagination.current=0
- this.state.pagination.total=0
- }
- this.setState({
- dataSource: theArr,
- pagination: this.state.pagination
- });
- }.bind(this),
- }).always(function () {
- this.setState({
- loading: false
- });
- }.bind(this));
- },
- getInitialState() {
- return {
- searchMore: true,
- RowData:{},
- selectedRowKeys: [],
- selectedRows: [],
- loading: false,
- pagination: {
- defaultCurrent: 1,
- defaultPageSize: 10,
- showQuickJumper: true,
- pageSize: 10,
- onChange: function (page) {
- this.loadData(page);
- }.bind(this),
- showTotal: function (total) {
- return '共' + total + '条数据';
- }
- },
- columns: [
- {
- title: '用户姓名',
- dataIndex: 'name',
- key: 'name'
- },{
- title: '部门机构',
- dataIndex: 'departmentName',
- key: 'departmentName'
- },{
- title: '职务',
- dataIndex: 'position',
- key: 'position',
- render:text=>{
- return getPost(text)
- }
- },{
- title: '联系手机',
- dataIndex: 'contactMobile',
- key: 'contactMobile'
- }
- ],
- dataSource: [],
- }
- },
- componentWillMount() {
- this.loadData();
- this.departmentList()
- },
- closeDesc(e, s) {
- this.state.RowData={};
- this.state.showDesc = e;
- if (s) {
- this.loadData(this.state.page);
- };
- },
- search() {
- this.loadData();
- },
- reset() {
- this.state.name='';
- this.state.departmenttList = [];
- this.loadData();
- },
- //删除
- del(){
- let deletedIds =[];
- let rowItem = this.state.selectedRowKeys[0];
- let data = this.state.dataSource ||[];
- if (data.length) {
- deletedIds.push(data[rowItem].id);
- }
- this.setState({
- selectedRowKeys: [],
- loading: deletedIds.length > 0
- });
- $.ajax({
- method: "POST",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + "/api/admin/deleteFrequentContacts",
- data: {
- id: deletedIds[0]
- }
- }).done(function (data) {
- if (!data.error.length) {
- message.success('删除成功!');
- this.loadData();
- } else {
- message.warning(data.error[0].message);
- };
- this.setState({
- loading: false
- });
- }.bind(this));
- },
- //新增
- add(){
- this.setState({
- showDesc:true
- });
- },
- render() {
- const rowSelection = {
- selectedRowKeys: this.state.selectedRowKeys,
- onChange: (selectedRowKeys, selectedRows) => {
- this.setState({
- selectedRows: selectedRows.slice(-1),
- selectedRowKeys: selectedRowKeys.slice(-1)
- });
- }
- };
- const hasSelected = this.state.selectedRowKeys.length > 0;
- let departmentArr = this.state.departmentArr || [];
- return ( <div className="user-content">
- <div className="content-title">
- <span>常用联系人</span>
- </div>
- <div className="user-search">
- <Input placeholder="联系人姓名"
- value={this.state.name}
- onChange={(e) => { this.setState({ name: e.target.value }); }} />
- <Select placeholder="所属部门"
- style={{ width: 150 ,marginRight:'10px',marginLeft:'10px'}}
- value={this.state.departmenttList}
- onChange={(e) => { this.setState({ departmenttList: e }) }}>
- {
- departmentArr.map(function (item) {
- return <Select.Option key={item.id} >{item.name}</Select.Option>
- })
- }
- </Select>
- <Button type="primary" onClick={this.search}>搜索</Button>
- <Button onClick={this.reset}>重置</Button>
- <Button type="danger" disabled={!hasSelected} onClick={this.del}>删除</Button>
- <Button type="primary" onClick={this.add} style={{float:'right'}}>新增常用联系人</Button>
- </div>
- <div className="patent-table">
- <Spin spinning={this.state.loading}>
- <Table columns={this.state.columns}
- dataSource={this.state.dataSource}
- rowSelection={rowSelection}
- pagination={this.state.pagination}
- />
- </Spin>
- </div>
- <SelContact
- departmentArr={departmentArr}
- data={this.state.RowData}
- showDesc={this.state.showDesc}
- closeDesc={this.closeDesc.bind(this)}
- />
- </div> )
- }
- })
-
- export default Contact;
|