addContact.jsx 8.3 KB

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