customer_edit.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Image,
  5. TouchableHighlight,
  6. Text,
  7. StyleSheet,
  8. TextInput,
  9. TouchableOpacity,
  10. Dimensions,
  11. ScrollView,
  12. KeyboardAvoidingView,
  13. DeviceEventEmitter,
  14. } from 'react-native';
  15. import login_css from '../login/login_css';
  16. import public_css from '../../source/css/public_css';
  17. import loading_css from '../../source/css/loading_css';
  18. import Spinner from 'react-native-loading-spinner-overlay';
  19. import {GetDataPost} from '../../data/encryption';
  20. import {ShowToast} from '../../components/rootToast/root_toast';
  21. import {RetrieveData, StorageData} from '../../data/storage';
  22. import {CheckEmail, CheckPhoneNumber} from '../../source/inspect/inspect';
  23. export default class customer_edit extends Component {
  24. constructor(props) {
  25. super(props);
  26. this.props.navigation.dangerouslyGetParent().setOptions({
  27. tabBarVisible: false,
  28. });
  29. this.companyId = this.props.route.params.companyId;
  30. this.state = {
  31. customer_name: '',
  32. customer_code: '',
  33. parent_code: '',
  34. ent_tax_id: '',
  35. short_code: '',
  36. email: '',
  37. customer_mobile: '',
  38. address: '',
  39. contact_phone: '',
  40. bank_account: '',
  41. remark: '',
  42. mobile: '',
  43. req_channel: '',
  44. ip: '',
  45. spinner: false,
  46. };
  47. }
  48. render() {
  49. return (
  50. <KeyboardAvoidingView
  51. enabled
  52. style={{flex: 1, backgroundColor: '#ffffff'}}>
  53. <ScrollView>
  54. <View>
  55. <Spinner
  56. visible={this.state.spinner}
  57. textContent={'Loading...'}
  58. textStyle={loading_css.spinnerTextStyle}
  59. />
  60. <View style={login_css.inputView}>
  61. <View style={[public_css.view, public_css.lineTopBottom]}>
  62. <Text
  63. style={[
  64. public_css.text,
  65. {fontFamily: 'PingFang-SC-Regular', color: '#333333'},
  66. ]}>
  67. *客户姓名:
  68. </Text>
  69. <TextInput
  70. style={public_css.textInputStyle}
  71. value={this.state.customer_name}
  72. placeholder="请输入客户名称"
  73. clearButtonMode="while-editing"
  74. secureTextEntry={false}
  75. onChangeText={text => {
  76. this.setState({
  77. customer_name: text,
  78. });
  79. }}
  80. />
  81. </View>
  82. <View style={[public_css.view, public_css.lineTopBottom]}>
  83. <Text
  84. style={[
  85. public_css.text,
  86. {fontFamily: 'PingFang-SC-Regular', color: '#333333'},
  87. ]}>
  88. *客户企业税号:
  89. </Text>
  90. <TextInput
  91. style={public_css.textInputStyle}
  92. value={this.state.ent_tax_id}
  93. placeholder="请输入客户企业税号"
  94. clearButtonMode="while-editing"
  95. secureTextEntry={false}
  96. onChangeText={text => {
  97. this.setState({
  98. ent_tax_id: text,
  99. });
  100. }}
  101. />
  102. </View>
  103. <View style={[public_css.view, public_css.lineTopBottom]}>
  104. <Text style={public_css.text}>联系电话:</Text>
  105. <TextInput
  106. style={public_css.textInputStyle}
  107. value={this.state.contact_phone}
  108. placeholder="请输入联系电话"
  109. clearButtonMode="while-editing"
  110. secureTextEntry={false}
  111. onChangeText={text => {
  112. this.setState({
  113. contact_phone: text,
  114. });
  115. }}
  116. />
  117. </View>
  118. <View style={[public_css.view, public_css.lineTopBottom]}>
  119. <Text style={public_css.text}>地址:</Text>
  120. <TextInput
  121. style={public_css.textInputStyle}
  122. value={this.state.address}
  123. placeholder="请输入地址"
  124. clearButtonMode="while-editing"
  125. secureTextEntry={false}
  126. onChangeText={text => {
  127. this.setState({
  128. address: text,
  129. });
  130. }}
  131. multiline={true}
  132. numberOfLines={2}
  133. textAlignVertical={'top'}
  134. />
  135. </View>
  136. <View style={[public_css.view, public_css.lineTopBottom]}>
  137. <Text style={public_css.text}>银行账号:</Text>
  138. <TextInput
  139. style={public_css.textInputStyle}
  140. value={this.state.bank_account}
  141. placeholder="请输入银行账号"
  142. clearButtonMode="while-editing"
  143. secureTextEntry={false}
  144. onChangeText={text => {
  145. this.setState({
  146. bank_account: text,
  147. });
  148. }}
  149. multiline={true}
  150. numberOfLines={2}
  151. textAlignVertical={'top'}
  152. />
  153. </View>
  154. <View style={[public_css.view, public_css.lineTopBottom]}>
  155. <Text style={public_css.text}>备注:</Text>
  156. <TextInput
  157. style={public_css.textInputStyle}
  158. value={this.state.remark}
  159. placeholder="请输入备注"
  160. clearButtonMode="while-editing"
  161. secureTextEntry={false}
  162. onChangeText={text => {
  163. this.setState({
  164. remark: text,
  165. });
  166. }}
  167. />
  168. </View>
  169. <View
  170. style={{
  171. backgroundColor: '#F6F6F6',
  172. width: Dimensions.get('window').width * 0.8,
  173. height: 40,
  174. alignItems: 'center',
  175. justifyContent: 'center',
  176. }}>
  177. <Text style={{color: '#A9A9A9', fontSize: 16}}>
  178. 填写联系方式,向你同步电子发票信息
  179. </Text>
  180. </View>
  181. <View style={[public_css.view, public_css.lineTopBottom]}>
  182. <Text style={public_css.text}>*客户手机号:</Text>
  183. <TextInput
  184. style={public_css.textInputStyle}
  185. placeholder="请输入客户手机号"
  186. clearButtonMode="while-editing"
  187. secureTextEntry={false}
  188. value={this.state.customer_mobile}
  189. onChangeText={text => {
  190. this.setState({
  191. customer_mobile: text,
  192. });
  193. }}
  194. />
  195. </View>
  196. <View style={[public_css.view, public_css.lineTopBottom]}>
  197. <Text style={public_css.text}>*邮箱:</Text>
  198. <TextInput
  199. style={public_css.textInputStyle}
  200. placeholder="请输入邮件"
  201. clearButtonMode="while-editing"
  202. secureTextEntry={false}
  203. value={this.state.email}
  204. onChangeText={text => {
  205. this.setState({
  206. email: text,
  207. });
  208. }}
  209. />
  210. </View>
  211. </View>
  212. </View>
  213. </ScrollView>
  214. <View style={public_css.bottomStaus}>
  215. <TouchableOpacity
  216. style={[public_css.statusBtn, public_css.statusLBtn]}
  217. onPress={() => {
  218. this.setState({
  219. customer_name: '',
  220. customer_code: '',
  221. parent_code: '',
  222. ent_tax_id: '',
  223. short_code: '',
  224. email: '',
  225. customer_mobile: '',
  226. address: '',
  227. contact_phone: '',
  228. bank_account: '',
  229. remark: '',
  230. mobile: '',
  231. req_channel: '',
  232. ip: '',
  233. });
  234. }}>
  235. <Image
  236. source={require('../../source/img/productImg/clear.png')}
  237. style={{width: 32, height: 32}}
  238. />
  239. <Text>全部清除</Text>
  240. </TouchableOpacity>
  241. <TouchableOpacity
  242. style={[public_css.statusBtn, public_css.statusRBtn]}
  243. onPress={() => this.submitData()}>
  244. <Image
  245. source={require('../../source/img/productImg/confirm.png')}
  246. style={{width: 32, height: 32}}
  247. />
  248. <Text style={{color: '#fff'}}>确定添加</Text>
  249. </TouchableOpacity>
  250. </View>
  251. </KeyboardAvoidingView>
  252. );
  253. }
  254. //提交数据
  255. submitData = async () => {
  256. let name = this.state.customer_name;
  257. if (!name) {
  258. ShowToast('客户姓名不可以为空!');
  259. return;
  260. }
  261. let entId = this.state.ent_tax_id;
  262. if (!entId) {
  263. ShowToast('客户企业税号不可以为空!');
  264. return;
  265. }
  266. let phone = this.state.customer_mobile;
  267. if (!phone) {
  268. ShowToast('客户手机号不可以为空!');
  269. return;
  270. }
  271. let email = this.state.email;
  272. if (!email) {
  273. ShowToast('客户邮箱不可以为空!');
  274. return;
  275. }
  276. let {status, msg} = CheckPhoneNumber(`${this.state.customer_mobile}`);
  277. if (status) {
  278. let {status, msg} = CheckEmail(`${this.state.email}`);
  279. if (status) {
  280. this.setLoadingStatus(true);
  281. const res = await RetrieveData('token');
  282. const account = await RetrieveData('account');
  283. if (res && account) {
  284. let token = res.substring(1, res.length - 1);
  285. let mobile = account.substring(1, account.length - 1);
  286. const url = '/sys/customer/saveOrUpdate';
  287. let response = await GetDataPost(
  288. url,
  289. token,
  290. {
  291. customerId: this.companyId,
  292. customerName: this.state.customer_name,
  293. customerCode: this.state.customer_code,
  294. parentCode: this.state.parent_code,
  295. entTaxId: this.state.ent_tax_id,
  296. shortCode: this.state.short_code,
  297. email: this.state.email,
  298. customerMobile: this.state.customer_mobile,
  299. address: this.state.address,
  300. contactPhone: this.state.contact_phone,
  301. bankAccount: this.state.bank_account,
  302. remark: this.state.remark,
  303. mobile: mobile,
  304. reqChannel: 3,
  305. ip: this.state.ip,
  306. },
  307. false,
  308. 1,
  309. );
  310. if (response.code != 0) {
  311. ShowToast(response.msg);
  312. this.setLoadingStatus(false);
  313. } else {
  314. ShowToast('编辑成功!');
  315. this.setLoadingStatus(false);
  316. this.props.navigation.goBack();
  317. DeviceEventEmitter.emit('刷新列表', '');
  318. }
  319. }
  320. } else {
  321. ShowToast(msg);
  322. }
  323. } else {
  324. ShowToast(msg);
  325. }
  326. };
  327. //设置loading层是否显示
  328. setLoadingStatus(isLoading) {
  329. this.setState({
  330. spinner: isLoading,
  331. });
  332. }
  333. //加载页面时显示数据
  334. componentDidMount(): void {
  335. this.getCompanyData();
  336. }
  337. //加载数据
  338. getCompanyData = async () => {
  339. const res = await RetrieveData('token');
  340. if (res) {
  341. let token = res.substring(1, res.length - 1);
  342. const url = '/sys/customer/findById';
  343. GetDataPost(
  344. url,
  345. token,
  346. {
  347. customerId: this.companyId,
  348. },
  349. false,
  350. 2,
  351. ).then(res => {
  352. this.setState({
  353. customer_name: res.data.customerName,
  354. customer_code: res.data.customerCode,
  355. parent_code: res.data.parentCode,
  356. ent_tax_id: res.data.entTaxId,
  357. short_code: res.data.shortCode,
  358. email: res.data.email,
  359. address: res.data.address,
  360. contact_phone: res.data.contactPhone,
  361. bank_account: res.data.bankAccount,
  362. remark: res.data.remark,
  363. });
  364. });
  365. }
  366. };
  367. }