addContact.jsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. import React from 'react';
  2. import { Modal, message, layout, Spin, Input, Button, Form, Row, Col, Radio } from 'antd';
  3. import ajax from 'jquery/src/ajax/xhr.js';
  4. import $ from 'jquery/src/ajax';
  5. const FormItem =Form.Item;
  6. const AddContact = React.createClass({
  7. getInitialState() {
  8. return {
  9. addcontactModul: false,
  10. }
  11. },
  12. addcontactModulOK() {
  13. this.setState({
  14. addcontactModul: false
  15. })
  16. this.props.closeFollow(true, true)
  17. },
  18. addcontactModulcancel() {
  19. this.setState({
  20. addcontactModul: false
  21. })
  22. this.props.closeFollow(false, false)
  23. },
  24. //新增联系人保存函数
  25. submitcontactman(e) {
  26. e.preventDefault();
  27. if (/.*[\u4e00-\u9fa5]+.*$/.test(this.state.newname)) {
  28. } else {
  29. message.error("请填写正确的姓名,且至少包含一个汉字");
  30. return ;
  31. };
  32. if(this.state.newmobile.length!=11){
  33. message.error('请填写正确的手机号码');
  34. return
  35. }
  36. if (/.*[\u4e00-\u9fa5]+.*$/.test(this.state.newdepatrment)) {
  37. } else {
  38. message.error("请填写正确的部门,且至少包含一个汉字");
  39. return;
  40. };
  41. if (/.*[\u4e00-\u9fa5]+.*$/.test(this.state.newposition)) {
  42. } else {
  43. message.error("请填写正确的职位,且至少包含一个汉字");
  44. return;
  45. };
  46. this.setState({
  47. loading: true
  48. })
  49. $.ajax({
  50. method: "post",
  51. dataType: "json",
  52. crossDomain: false,
  53. url: globalConfig.context + "/api/admin/customer/addOneContact",
  54. data: {
  55. uid: this.state.uid,
  56. name: this.state.newname,
  57. mobile: this.state.newmobile,
  58. email: this.state.newemail,
  59. wechat: this.state.newwechat,
  60. depatrment: this.state.newdepatrment,
  61. position: this.state.newposition,
  62. sex: this.state.newsex,
  63. qq: this.state.newqq
  64. },
  65. success: function(data) {
  66. if(!data.error.length) {
  67. this.addcontactModulOK()
  68. this.setState({
  69. loading: false,
  70. })
  71. } else {
  72. message.warning(data.error[0].message);
  73. };
  74. }.bind(this)
  75. });
  76. },
  77. componentWillReceiveProps(nextProps) {
  78. if(nextProps.addcontactModul && nextProps.uids) {
  79. this.setState({
  80. newsex: undefined,
  81. newname: '',
  82. newmobile: '',
  83. newwechat: '',
  84. newqq: '',
  85. newdepatrment: '',
  86. newposition: '',
  87. newemail: '',
  88. addcontactModul: true,
  89. uid: nextProps.uids,
  90. loading:false
  91. })
  92. };
  93. },
  94. render() {
  95. return (
  96. <div>
  97. <Modal
  98. maskClosable={false}
  99. footer=""
  100. width="800px"
  101. title="新增联系人"
  102. visible={this.state.addcontactModul}
  103. onOk={this.addcontactModulOK}
  104. onCancel={this.addcontactModulcancel}
  105. >
  106. <Form
  107. layout="horizontal"
  108. onSubmit={this.submitcontactman}
  109. id="demand-form"
  110. >
  111. <Spin spinning={this.state.loading}>
  112. <Row>
  113. <FormItem
  114. labelCol={{ span: 3 }}
  115. wrapperCol={{ span: 14 }}
  116. label="性别:"
  117. style={{ marginRight: "10px", marginTop: "-15px" }}
  118. >
  119. <Radio.Group
  120. value={this.state.newsex}
  121. onChange={(e) => {
  122. this.setState({ newsex: e.target.value });
  123. }}
  124. >
  125. <Radio value="男">男</Radio>
  126. <Radio value="女">女</Radio>
  127. </Radio.Group>
  128. </FormItem>
  129. </Row>
  130. <Row style={{ paddingLeft: "50px" }}>
  131. <Col span={2}>
  132. <span style={{ color: "red" }}>*</span>姓名:
  133. </Col>
  134. <Col span={8}>
  135. <Input
  136. value={this.state.newname}
  137. required="required"
  138. onChange={(e) => {
  139. this.setState({ newname: e.target.value });
  140. }}
  141. />
  142. </Col>
  143. <Col span={2} style={{ marginLeft: "50px" }}>
  144. <span style={{ color: "red" }}>*</span>手机:
  145. </Col>
  146. <Col span={8}>
  147. <Input
  148. value={this.state.newmobile}
  149. required="required"
  150. onChange={(e) => {
  151. this.setState({ newmobile: e.target.value });
  152. }}
  153. />
  154. </Col>
  155. </Row>
  156. <Row style={{ marginTop: "20px", paddingLeft: "50px" }}>
  157. <Col span={2}>微信:</Col>
  158. <Col span={8}>
  159. <Input
  160. value={this.state.newwechat}
  161. onChange={(e) => {
  162. this.setState({ newwechat: e.target.value });
  163. }}
  164. />
  165. </Col>
  166. <Col span={2} style={{ marginLeft: "50px" }}>
  167. Q Q:
  168. </Col>
  169. <Col span={8}>
  170. <Input
  171. value={this.state.newqq}
  172. onChange={(e) => {
  173. this.setState({ newqq: e.target.value });
  174. }}
  175. />
  176. </Col>
  177. </Row>
  178. <Row style={{ marginTop: "20px", paddingLeft: "50px" }}>
  179. <Col span={2}>
  180. <span style={{ color: "red" }}>*</span>部门:
  181. </Col>
  182. <Col span={8}>
  183. <Input
  184. value={this.state.newdepatrment}
  185. required="required"
  186. onChange={(e) => {
  187. this.setState({ newdepatrment: e.target.value });
  188. }}
  189. />
  190. </Col>
  191. <Col span={2} style={{ marginLeft: "50px" }}>
  192. <span style={{ color: "red" }}>*</span>
  193. 职位:
  194. </Col>
  195. <Col span={8}>
  196. <Input
  197. value={this.state.newposition}
  198. required="required"
  199. onChange={(e) => {
  200. this.setState({ newposition: e.target.value });
  201. }}
  202. />
  203. </Col>
  204. </Row>
  205. <Row style={{ marginTop: "20px", paddingLeft: "50px" }}>
  206. <Col span={2}>邮箱:</Col>
  207. <Col span={8}>
  208. <Input
  209. value={this.state.newemail}
  210. onChange={(e) => {
  211. this.setState({ newemail: e.target.value });
  212. }}
  213. />
  214. </Col>
  215. </Row>
  216. <Row
  217. style={{
  218. marginTop: "20px",
  219. paddingLeft: "50px",
  220. marginBottom: "50px",
  221. }}
  222. >
  223. <Button
  224. className="set-submit"
  225. type="primary"
  226. htmlType="submit"
  227. id="change_keep"
  228. style={{ marginLeft: "60px" }}
  229. >
  230. 保存
  231. </Button>
  232. <Button
  233. className="set-submit"
  234. type="ghost"
  235. onClick={this.addcontactModulcancel}
  236. id="change_rem"
  237. >
  238. 取消
  239. </Button>
  240. </Row>
  241. </Spin>
  242. </Form>
  243. </Modal>
  244. </div>
  245. );
  246. }
  247. })
  248. export default AddContact;