addContact.jsx 8.5 KB

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