EditCustomer.js 9.7 KB

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