customer_add_or_edit.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Text,
  5. TextInput,
  6. TouchableOpacity,
  7. ScrollView,
  8. SafeAreaView,
  9. } from 'react-native';
  10. import {List, Picker, WingBlank, WhiteSpace} from '@ant-design/react-native';
  11. import public_css from '../../../source/css/public_css';
  12. import loading_css from '../../../source/css/loading_css';
  13. import Spinner from 'react-native-loading-spinner-overlay';
  14. import {RequestNetwork} from '../../../data/encryption';
  15. import {RetrieveData} from '../../../data/storage';
  16. import {CheckEmail, CheckPhoneNumber} from '../../../source/inspect/inspect';
  17. import {ToastShow} from '../../../components/toast/toast';
  18. export default class customer_add_or_edit extends Component {
  19. constructor(props) {
  20. super(props);
  21. this.state = {
  22. customerName: '',
  23. entTaxId: '',
  24. email: '',
  25. customerMobile: '',
  26. address: '',
  27. contactPhone: '',
  28. bank: '',
  29. bankAccount: '',
  30. remark: '',
  31. mobile: '',
  32. spinner: false,
  33. companyTypes: [
  34. {
  35. label: '个人',
  36. value: '1',
  37. },
  38. {
  39. label: '企业',
  40. value: '2',
  41. },
  42. ],
  43. companyType: '1',
  44. isEdit: false,
  45. customerId: '',
  46. };
  47. }
  48. render() {
  49. return (
  50. <SafeAreaView style={public_css.body}>
  51. <ScrollView>
  52. <View>
  53. <Spinner
  54. visible={this.state.spinner}
  55. textContent={'Loading...'}
  56. textStyle={loading_css.spinnerTextStyle}
  57. />
  58. <View
  59. style={{
  60. backgroundColor: '#F6F6F6',
  61. height: 36,
  62. justifyContent: 'center',
  63. marginLeft: 14,
  64. }}>
  65. <Text style={{color: '#A9A9A9', fontSize: 16}}>基础信息</Text>
  66. </View>
  67. <Picker
  68. data={this.state.companyTypes}
  69. cols={1}
  70. value={[this.state.companyType]}
  71. onChange={(value) => this.companyTypeChange(value)}>
  72. <List.Item arrow="horizontal" onPress={this.onPress}>
  73. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  74. <Text style={{color: 'red', marginRight: 5}}>*</Text>
  75. <Text style={{fontSize: 16}}>客户抬头类型:</Text>
  76. </View>
  77. </List.Item>
  78. </Picker>
  79. <WingBlank>
  80. <View style={[public_css.view, public_css.lineTopBottom]}>
  81. <Text
  82. style={[
  83. public_css.text,
  84. {fontFamily: 'PingFang-SC-Regular', color: '#333333'},
  85. ]}>
  86. <Text style={{color: 'red'}}>*</Text>客户姓名:
  87. </Text>
  88. <TextInput
  89. style={public_css.textInputStyle}
  90. value={this.state.customerName}
  91. placeholder="请输入客户名称"
  92. clearButtonMode="while-editing"
  93. secureTextEntry={false}
  94. onChangeText={(text) => {
  95. this.setState({
  96. customerName: text,
  97. });
  98. }}
  99. />
  100. </View>
  101. </WingBlank>
  102. <WingBlank>
  103. {this.state.companyType === '1' ? (
  104. <View style={[public_css.view, public_css.lineTopBottom]}>
  105. <Text
  106. style={[
  107. public_css.text,
  108. {fontFamily: 'PingFang-SC-Regular', color: '#333333'},
  109. ]}>
  110. 客户企业税号:
  111. </Text>
  112. <TextInput
  113. style={public_css.textInputStyle}
  114. value={this.state.entTaxId}
  115. placeholder="请输入客户企业税号"
  116. clearButtonMode="while-editing"
  117. secureTextEntry={false}
  118. onChangeText={(text) => {
  119. this.setState({
  120. entTaxId: text,
  121. });
  122. }}
  123. />
  124. </View>
  125. ) : (
  126. <View style={[public_css.view, public_css.lineTopBottom]}>
  127. <Text
  128. style={[
  129. public_css.text,
  130. {fontFamily: 'PingFang-SC-Regular', color: '#333333'},
  131. ]}>
  132. <Text style={{color: 'red'}}>*</Text> 客户企业税号:
  133. </Text>
  134. <TextInput
  135. style={public_css.textInputStyle}
  136. value={this.state.entTaxId}
  137. placeholder="请输入客户企业税号"
  138. clearButtonMode="while-editing"
  139. secureTextEntry={false}
  140. onChangeText={(text) => {
  141. this.setState({
  142. entTaxId: text,
  143. });
  144. }}
  145. />
  146. </View>
  147. )}
  148. </WingBlank>
  149. <WingBlank>
  150. <View style={[public_css.view, public_css.lineTopBottom]}>
  151. <Text style={public_css.text}>地址:</Text>
  152. <TextInput
  153. style={public_css.textInputStyle}
  154. value={this.state.address}
  155. placeholder="请输入地址"
  156. clearButtonMode="while-editing"
  157. secureTextEntry={false}
  158. onChangeText={(text) => {
  159. this.setState({
  160. address: text,
  161. });
  162. }}
  163. multiline={true}
  164. numberOfLines={2}
  165. textAlignVertical={'top'}
  166. />
  167. </View>
  168. </WingBlank>
  169. <WingBlank>
  170. <View style={[public_css.view, public_css.lineTopBottom]}>
  171. <Text style={public_css.text}>联系电话:</Text>
  172. <TextInput
  173. style={public_css.textInputStyle}
  174. value={this.state.contactPhone}
  175. placeholder="请输入联系电话"
  176. clearButtonMode="while-editing"
  177. secureTextEntry={false}
  178. onChangeText={(text) => {
  179. this.setState({
  180. contactPhone: text,
  181. });
  182. }}
  183. />
  184. </View>
  185. </WingBlank>
  186. <WingBlank>
  187. <View style={[public_css.view, public_css.lineTopBottom]}>
  188. <Text style={public_css.text}>开户行:</Text>
  189. <TextInput
  190. style={public_css.textInputStyle}
  191. value={this.state.bank}
  192. placeholder="请输入地址"
  193. clearButtonMode="while-editing"
  194. secureTextEntry={false}
  195. onChangeText={(text) => {
  196. this.setState({
  197. bank: text,
  198. });
  199. }}
  200. />
  201. </View>
  202. </WingBlank>
  203. <WingBlank>
  204. <View style={[public_css.view, public_css.lineTopBottom]}>
  205. <Text style={public_css.text}>银行账号:</Text>
  206. <TextInput
  207. style={public_css.textInputStyle}
  208. value={this.state.bankAccount}
  209. placeholder="请输入银行账号"
  210. clearButtonMode="while-editing"
  211. secureTextEntry={false}
  212. onChangeText={(text) => {
  213. this.setState({
  214. bankAccount: text,
  215. });
  216. }}
  217. multiline={true}
  218. numberOfLines={2}
  219. textAlignVertical={'top'}
  220. />
  221. </View>
  222. </WingBlank>
  223. <WingBlank>
  224. <View style={[public_css.view, public_css.lineTopBottom]}>
  225. <Text style={public_css.text}>备注:</Text>
  226. <TextInput
  227. style={public_css.textInputStyle}
  228. value={this.state.remark}
  229. placeholder="请输入备注"
  230. clearButtonMode="while-editing"
  231. secureTextEntry={false}
  232. onChangeText={(text) => {
  233. this.setState({
  234. remark: text,
  235. });
  236. }}
  237. />
  238. </View>
  239. </WingBlank>
  240. <View
  241. style={{
  242. backgroundColor: '#F6F6F6',
  243. height: 40,
  244. marginLeft: 14,
  245. justifyContent: 'center',
  246. }}>
  247. <Text style={{color: '#A9A9A9', fontSize: 16}}>
  248. 填写联系方式,向您同步电子发票信息
  249. </Text>
  250. </View>
  251. <WingBlank>
  252. <View style={[public_css.view, public_css.lineTopBottom]}>
  253. <Text style={public_css.text}>
  254. <Text style={{color: 'red'}}>*</Text> 客户手机号:
  255. </Text>
  256. <TextInput
  257. style={public_css.textInputStyle}
  258. placeholder="请输入客户手机号"
  259. clearButtonMode="while-editing"
  260. secureTextEntry={false}
  261. value={this.state.customerMobile}
  262. onChangeText={(text) => {
  263. this.setState({
  264. customerMobile: text,
  265. });
  266. }}
  267. />
  268. </View>
  269. </WingBlank>
  270. <WingBlank>
  271. <View style={[public_css.view, public_css.lineTopBottom]}>
  272. <Text style={public_css.text}>
  273. <Text style={{color: 'red'}}>*</Text> 邮箱:
  274. </Text>
  275. <TextInput
  276. style={public_css.textInputStyle}
  277. placeholder="请输入邮件"
  278. clearButtonMode="while-editing"
  279. secureTextEntry={false}
  280. value={this.state.email}
  281. onChangeText={(text) => {
  282. this.setState({
  283. email: text,
  284. });
  285. }}
  286. />
  287. </View>
  288. </WingBlank>
  289. </View>
  290. </ScrollView>
  291. <WingBlank>
  292. {this.state.isEdit === true ? (
  293. <View style={public_css.bottomStatus}>
  294. <TouchableOpacity
  295. style={{
  296. width: 120,
  297. borderWidth: 1,
  298. borderColor: '#FE2A53',
  299. borderRadius: 8,
  300. justifyContent: 'center',
  301. alignItems: 'center',
  302. marginRight: 10,
  303. }}
  304. onPress={() => this.deleteCustomer()}>
  305. <Text style={{color: '#FE2A53'}}>删除</Text>
  306. </TouchableOpacity>
  307. <TouchableOpacity
  308. style={[public_css.statusBtn, public_css.statusRBtn]}
  309. onPress={() => this.submitData()}>
  310. <Text style={{color: '#fff'}}>保存</Text>
  311. </TouchableOpacity>
  312. </View>
  313. ) : (
  314. <View style={public_css.bottomStatus}>
  315. <TouchableOpacity
  316. style={[public_css.statusBtn, public_css.statusRBtn]}
  317. onPress={() => this.submitData()}>
  318. <Text style={{color: '#fff'}}>新增</Text>
  319. </TouchableOpacity>
  320. </View>
  321. )}
  322. </WingBlank>
  323. <WhiteSpace />
  324. </SafeAreaView>
  325. );
  326. }
  327. //加载页面时显示数据
  328. componentDidMount(): void {
  329. let customerId = this.props.route.params.companyId;
  330. if (customerId) {
  331. this.setState({
  332. isEdit: true,
  333. customerId: customerId,
  334. });
  335. this.getCompanyData();
  336. }
  337. }
  338. //提交数据
  339. submitData = async () => {
  340. let name = this.state.customerName;
  341. if (!name) {
  342. ToastShow(1, '客户姓名不可以为空!');
  343. return;
  344. }
  345. if (this.state.companyType === '2') {
  346. let entId = this.state.entTaxId;
  347. if (!entId) {
  348. ToastShow(1, '客户企业税号不可以为空!');
  349. return;
  350. }
  351. }
  352. let phone = this.state.customerMobile;
  353. if (!phone) {
  354. ToastShow(1, '客户手机号不可以为空!');
  355. return;
  356. }
  357. let email = this.state.email;
  358. if (!email) {
  359. ToastShow(1, '客户邮箱不可以为空!');
  360. return;
  361. }
  362. let {status, msg} = CheckPhoneNumber(`${this.state.customerMobile}`);
  363. if (status) {
  364. let {status, msg} = CheckEmail(`${this.state.email}`);
  365. if (status) {
  366. this.setLoadingStatus(true);
  367. const token = await RetrieveData('token');
  368. const account = await RetrieveData('account');
  369. const company = JSON.parse(await RetrieveData('company'));
  370. if (token && account) {
  371. const url = '/sys/customer/save';
  372. let response = await RequestNetwork(
  373. url,
  374. token,
  375. {
  376. customerId: this.state.customerId,
  377. customerName: this.state.customerName,
  378. customerType: this.state.companyType,
  379. customerEntTaxId: this.state.entTaxId,
  380. email: this.state.email,
  381. customerMobile: this.state.customerMobile,
  382. address: this.state.address,
  383. contactPhone: this.state.contactPhone,
  384. bankName: this.state.bank,
  385. bankAccountNumber: this.state.bankAccount,
  386. remark: this.state.remark,
  387. entTaxId: company.entTaxId,
  388. mobile: account,
  389. reqChannel: 3,
  390. },
  391. false,
  392. 1,
  393. );
  394. if (response) {
  395. console.log(response);
  396. if (response.code === 0) {
  397. this.setLoadingStatus(false);
  398. ToastShow(1, '保存成功!');
  399. this.props.route.params.refresh();
  400. this.props.navigation.goBack();
  401. } else {
  402. this.setLoadingStatus(false);
  403. ToastShow(1, response.msg);
  404. }
  405. }
  406. }
  407. } else {
  408. ToastShow(1, msg);
  409. }
  410. } else {
  411. ToastShow(1, msg);
  412. }
  413. };
  414. //设置loading层是否显示
  415. setLoadingStatus(isLoading) {
  416. this.setState({
  417. spinner: isLoading,
  418. });
  419. }
  420. // 企业类型选择
  421. companyTypeChange = (value) => {
  422. let companyType = '';
  423. if (value.length > 0) {
  424. companyType = value[0];
  425. }
  426. this.setState({
  427. companyType: companyType,
  428. });
  429. };
  430. //加载数据
  431. getCompanyData = async () => {
  432. const token = await RetrieveData('token');
  433. if (token) {
  434. const url = '/sys/customer/findById';
  435. let res = await RequestNetwork(
  436. url,
  437. token,
  438. {
  439. customerId: this.state.customerId,
  440. },
  441. false,
  442. 2,
  443. );
  444. if (res) {
  445. if (res.code === 0) {
  446. this.setState({
  447. customerName: res.data.customerName,
  448. entTaxId: res.data.customerEntTaxId,
  449. email: res.data.email,
  450. address: res.data.address,
  451. contactPhone: res.data.contactPhone,
  452. customerMobile: res.data.customerMobile,
  453. bank: res.data.bankName,
  454. bankAccount: res.data.bankAccountNumber,
  455. remark: res.data.remark,
  456. companyType: res.data.customerType.toString(),
  457. });
  458. }
  459. }
  460. }
  461. };
  462. //删除客户数据
  463. deleteCustomer = async () => {
  464. let account = await RetrieveData('account');
  465. let token = await RetrieveData('token');
  466. const company = JSON.parse(await RetrieveData('company'));
  467. if (account && token) {
  468. const url = '/sys/customer/delete';
  469. let res = await RequestNetwork(
  470. url,
  471. token,
  472. {
  473. mobile: account,
  474. reqChannel: 3,
  475. delList: [
  476. {
  477. customerId: this.state.customerId,
  478. entTaxId: company.entTaxId,
  479. },
  480. ],
  481. },
  482. false,
  483. 1,
  484. );
  485. if (res) {
  486. if (res.code === 0) {
  487. ToastShow(1, '删除成功!');
  488. this.props.route.params.refresh();
  489. this.props.navigation.goBack();
  490. } else {
  491. ToastShow(1, '删除失败!');
  492. }
  493. } else {
  494. ToastShow(1, '删除失败!');
  495. }
  496. }
  497. };
  498. }