ReportCustomerAdd.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Text, StyleSheet, ScrollView, StatusBar, DeviceEventEmitter, KeyboardAvoidingView, Platform,
  5. } from 'react-native';
  6. import {connect} from 'react-redux';
  7. import {
  8. Provider,
  9. Button,
  10. Toast,
  11. List,
  12. Picker,
  13. InputItem,
  14. } from '@ant-design/react-native';
  15. import RadioModal from '../../components/RadioModal';
  16. import ComponentsStyles from '../../components/ComponentsStyles';
  17. import CheckValid from '../../components/CheckValid';
  18. @connect(customer => ({...customer}))
  19. class ReportCustomerAdd extends Component {
  20. // 报备客户
  21. constructor(props) {
  22. super(props);
  23. this.state = {
  24. name: '',
  25. tel: '',
  26. gender: 2,
  27. village: '',
  28. address: '',
  29. source: '',
  30. project: [],
  31. notes: '',
  32. project_text: '请选择',
  33. CUSTOMER_SOURCE: [],
  34. };
  35. }
  36. componentDidMount() {
  37. this._fetchData();
  38. }
  39. _fetchData = () => {
  40. this.props.dispatch({
  41. type: 'customer/fetchReportDict',
  42. callback: (data) => {
  43. let CUSTOMER_SOURCE = [];
  44. data.source.map((item, index) => {
  45. CUSTOMER_SOURCE.push({
  46. value: item.id, label: item.name,
  47. });
  48. });
  49. this.setState({CUSTOMER_SOURCE});
  50. },
  51. });
  52. };
  53. onSave = () => {
  54. if (!this.state.name) {
  55. Toast.info('请填写姓名', 1);
  56. return;
  57. }
  58. if (!this.state.tel) {
  59. Toast.info('请填写手机号', 1);
  60. return;
  61. }
  62. if (!CheckValid(this.state.tel, 'tel')) {
  63. Toast.info('请填写正确的手机号', 1);
  64. return;
  65. }
  66. if (!this.state.village) {
  67. Toast.info('请填写小区', 1);
  68. return;
  69. }
  70. if (!this.state.address) {
  71. Toast.info('请填写地址', 1);
  72. return;
  73. }
  74. if (!this.state.source.length) {
  75. Toast.info('请选择来源', 1);
  76. return;
  77. }
  78. if (!this.state.project.length) {
  79. Toast.info('请选择项目', 1);
  80. return;
  81. }
  82. this.props.dispatch({
  83. type: 'customer/saveReportCustomer',
  84. payload: this.state,
  85. callback: () => {
  86. DeviceEventEmitter.emit('backRefesh');
  87. this.props.navigation.goBack();
  88. },
  89. });
  90. };
  91. onProjectPress = () => {
  92. this.props.navigation.navigate('SearchProject', {
  93. callback: this.setProject,
  94. checked_ids:this.state.project,
  95. checked_names:this.state.project_text,
  96. });
  97. };
  98. setProject = (ids, name) => {
  99. this.setState({project_text: name, project: ids});
  100. };
  101. render() {
  102. const {loading} = this.props.customer;
  103. const isIOS = Platform.OS === 'ios' ? true : false;
  104. return (
  105. <KeyboardAvoidingView behavior={'padding'} enabled={isIOS} style={{backgroundColor: '#fff', flex: 1}}>
  106. <StatusBar backgroundColor={'#fff'} barStyle='dark-content'/>
  107. <Provider>
  108. <ScrollView keyboardShouldPersistTaps={'handled'}>
  109. <List style={styles.listStyle}>
  110. <InputItem
  111. clear
  112. value={this.state.name}
  113. onChange={value => {
  114. this.setState({
  115. name: value,
  116. });
  117. }}
  118. placeholder="请输入客户姓名"
  119. >
  120. <Text style={ComponentsStyles.requiredText}>姓名</Text>
  121. </InputItem>
  122. <View style={ComponentsStyles.genderStyle}>
  123. <Text style={[ComponentsStyles.requiredText, {textAlignVertical: 'center'}]}>性别</Text>
  124. <RadioModal
  125. selectedValue={this.state.gender.toString()}
  126. onValueChange={id => this.setState({type: id})}
  127. style={ComponentsStyles.radioStyle}
  128. innerStyle={{
  129. width: 50,
  130. }}
  131. >
  132. <Text value="1">女</Text>
  133. <Text value="2">男</Text>
  134. </RadioModal>
  135. </View>
  136. <InputItem
  137. clear
  138. type={'number'}
  139. value={this.state.tel}
  140. onChange={value => {
  141. this.setState({
  142. tel: value,
  143. });
  144. }}
  145. placeholder="请输入电话"
  146. >
  147. <Text style={ComponentsStyles.requiredText}>电话</Text>
  148. </InputItem>
  149. <InputItem
  150. clear
  151. value={this.state.village}
  152. onChange={value => {
  153. this.setState({
  154. village: value,
  155. });
  156. }}
  157. placeholder="请输入小区"
  158. >
  159. <Text style={ComponentsStyles.requiredText}>小区</Text>
  160. </InputItem>
  161. <InputItem
  162. clear
  163. value={this.state.address}
  164. onChange={value => {
  165. this.setState({
  166. address: value,
  167. });
  168. }}
  169. placeholder="请输入地址"
  170. >
  171. <Text style={ComponentsStyles.requiredText}>地址</Text>
  172. </InputItem>
  173. <Picker
  174. data={this.state.CUSTOMER_SOURCE}
  175. cols={1}
  176. value={this.state.source}
  177. onChange={text => {
  178. this.setState({
  179. source: text,
  180. });
  181. }}
  182. >
  183. <List.Item arrow="horizontal">
  184. <Text style={ComponentsStyles.requiredText}>来源</Text>
  185. </List.Item>
  186. </Picker>
  187. <List.Item
  188. arrow="horizontal"
  189. extra={
  190. <Text
  191. style={{fontSize: 17, width: 200, textAlign: 'right'}}
  192. onPress={() => this.onProjectPress()}>
  193. {this.state.project_text}
  194. </Text>}
  195. >
  196. <Text style={ComponentsStyles.requiredText}>项目</Text>
  197. </List.Item>
  198. <InputItem
  199. clear
  200. value={this.state.notes}
  201. onChange={value => {
  202. this.setState({
  203. notes: value,
  204. });
  205. }}
  206. placeholder="请输入备注"
  207. >
  208. <Text style={ComponentsStyles.font15}>备注</Text>
  209. </InputItem>
  210. </List>
  211. </ScrollView>
  212. <Button
  213. onPress={this.onSave}
  214. type="primary"
  215. loading={loading}
  216. disabled={loading}
  217. style={ComponentsStyles.button}>保存</Button>
  218. </Provider>
  219. </KeyboardAvoidingView>
  220. );
  221. }
  222. }
  223. const styles = StyleSheet.create({
  224. listStyle: {
  225. marginTop: 5,
  226. },
  227. dateInput: {
  228. borderWidth: 0,
  229. alignItems: 'flex-end',
  230. },
  231. });
  232. export default ReportCustomerAdd;