enterprise_edit.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Image,
  5. Text,
  6. TextInput,
  7. TouchableOpacity,
  8. ScrollView,
  9. DeviceEventEmitter,
  10. SafeAreaView,
  11. } from 'react-native';
  12. import {WingBlank, WhiteSpace, List, Picker} from '@ant-design/react-native';
  13. import login_css from '../../login/login_css';
  14. import public_css from '../../../source/css/public_css';
  15. import loading_css from '../../../source/css/loading_css';
  16. import Spinner from 'react-native-loading-spinner-overlay';
  17. import {RequestNetwork} from '../../../data/encryption';
  18. import {IndividualStorageData, RetrieveData} from '../../../data/storage';
  19. import {ToastShow} from '../../../components/toast/toast';
  20. const Item = List.Item;
  21. export default class enterprise_edit extends Component {
  22. constructor(props) {
  23. super(props);
  24. this.props.navigation.dangerouslyGetParent().setOptions({
  25. tabBarVisible: false,
  26. });
  27. this.state = {
  28. entName: '',
  29. entTaxId: '',
  30. entAddress: '',
  31. entContactPerson: '',
  32. entPhone: '',
  33. bankAccountName: '',
  34. bankAccountNumber: '',
  35. payees: '',
  36. reviewers: '',
  37. drawers: '',
  38. taxRates: '',
  39. spinner: false,
  40. companyTypeList: [
  41. {
  42. label: '一般纳税人',
  43. value: '1',
  44. },
  45. {
  46. label: '小规模纳税人',
  47. value: '2',
  48. },
  49. {
  50. label: '起征点以下纳税人',
  51. value: '3',
  52. },
  53. ],
  54. companyType: '1',
  55. deviceKey: '',
  56. deviceName: '',
  57. };
  58. }
  59. render() {
  60. return (
  61. <SafeAreaView style={public_css.body}>
  62. <Spinner
  63. visible={this.state.spinner}
  64. textContent={'Loading...'}
  65. textStyle={loading_css.spinnerTextStyle}
  66. />
  67. <ScrollView>
  68. <WingBlank>
  69. <View style={[public_css.view, public_css.lineTopBottom]}>
  70. <Text
  71. style={[
  72. public_css.text,
  73. {fontFamily: 'PingFang-SC-Regular', color: '#333333'},
  74. ]}>
  75. 企业名称:
  76. </Text>
  77. <TextInput
  78. style={public_css.textInputStyle}
  79. value={this.state.entName}
  80. clearButtonMode="while-editing"
  81. secureTextEntry={false}
  82. editable={false}
  83. />
  84. </View>
  85. </WingBlank>
  86. <WingBlank>
  87. <View style={[public_css.view, public_css.lineTopBottom]}>
  88. <Text
  89. style={[
  90. public_css.text,
  91. {fontFamily: 'PingFang-SC-Regular', color: '#333333'},
  92. ]}>
  93. 企业税号:
  94. </Text>
  95. <TextInput
  96. style={public_css.textInputStyle}
  97. value={this.state.entTaxId}
  98. clearButtonMode="while-editing"
  99. secureTextEntry={false}
  100. editable={false}
  101. onChangeText={(text) => {
  102. this.setState({
  103. entTaxId: text,
  104. });
  105. }}
  106. />
  107. </View>
  108. </WingBlank>
  109. <Picker
  110. data={this.state.companyTypeList}
  111. cols={1}
  112. value={[this.state.companyType]}
  113. disabled={true}
  114. onChange={(value) => this.companyTypeChange(value)}>
  115. <List.Item arrow="horizontal" onPress={this.onPress}>
  116. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  117. <Text style={{fontSize: 16}}>企业类型:</Text>
  118. </View>
  119. </List.Item>
  120. </Picker>
  121. <List>
  122. <Item
  123. extra={this.state.deviceName}
  124. arrow="horizontal"
  125. onPress={() => {
  126. this.props.navigation.navigate('device_select', {
  127. deviceKey: this.state.deviceKey,
  128. entTaxId: this.state.entTaxId,
  129. getDeviceInfo: (deviceName, deviceKey) => {
  130. this.getDeviceInfo(deviceName, deviceKey);
  131. },
  132. });
  133. }}>
  134. 默认开票设备:
  135. </Item>
  136. </List>
  137. <WingBlank>
  138. <View style={[public_css.view, public_css.lineTopBottom]}>
  139. <Text
  140. style={[
  141. public_css.text,
  142. {fontFamily: 'PingFang-SC-Regular', color: '#333333'},
  143. ]}>
  144. 企业地址:
  145. </Text>
  146. <TextInput
  147. style={public_css.textInputStyle}
  148. value={this.state.entAddress}
  149. placeholder="请输入企业地址"
  150. clearButtonMode="while-editing"
  151. secureTextEntry={false}
  152. onChangeText={(text) => {
  153. this.setState({
  154. entAddress: text,
  155. });
  156. }}
  157. />
  158. </View>
  159. </WingBlank>
  160. <WingBlank>
  161. <View style={[public_css.view, public_css.lineTopBottom]}>
  162. <Text style={public_css.text}>企业电话:</Text>
  163. <TextInput
  164. style={public_css.textInputStyle}
  165. value={this.state.entPhone}
  166. placeholder="请输入企业电话"
  167. clearButtonMode="while-editing"
  168. secureTextEntry={false}
  169. onChangeText={(text) => {
  170. this.setState({
  171. entPhone: text,
  172. });
  173. }}
  174. />
  175. </View>
  176. </WingBlank>
  177. <WingBlank>
  178. <View style={[public_css.view, public_css.lineTopBottom]}>
  179. <Text style={public_css.text}>银行名称:</Text>
  180. <TextInput
  181. style={public_css.textInputStyle}
  182. value={this.state.bankAccountName}
  183. placeholder="请输入开户银行名称"
  184. clearButtonMode="while-editing"
  185. secureTextEntry={false}
  186. onChangeText={(text) => {
  187. this.setState({
  188. bankAccountName: text,
  189. });
  190. }}
  191. />
  192. </View>
  193. </WingBlank>
  194. <WingBlank>
  195. <View style={[public_css.view, public_css.lineTopBottom]}>
  196. <Text style={public_css.text}>银行账号:</Text>
  197. <TextInput
  198. style={public_css.textInputStyle}
  199. value={this.state.bankAccountNumber}
  200. placeholder="请输入开户银行账号"
  201. clearButtonMode="while-editing"
  202. secureTextEntry={false}
  203. onChangeText={(text) => {
  204. this.setState({
  205. bankAccountNumber: text,
  206. });
  207. }}
  208. />
  209. </View>
  210. </WingBlank>
  211. <WingBlank>
  212. <View style={[public_css.view, public_css.lineTopBottom]}>
  213. <Text style={public_css.text}>企业联系人:</Text>
  214. <TextInput
  215. style={public_css.textInputStyle}
  216. value={this.state.entContactPerson}
  217. placeholder="请输入企业联系人"
  218. clearButtonMode="while-editing"
  219. secureTextEntry={false}
  220. onChangeText={(text) => {
  221. this.setState({
  222. entContactPerson: text,
  223. });
  224. }}
  225. />
  226. </View>
  227. </WingBlank>
  228. <WingBlank>
  229. <View
  230. style={[
  231. public_css.view,
  232. public_css.lineTopBottom,
  233. {alignItems: 'center'},
  234. ]}>
  235. <Text style={public_css.text}>收款人:</Text>
  236. <TextInput
  237. style={public_css.textInputStyle}
  238. placeholder="请添加收款人"
  239. clearButtonMode="while-editing"
  240. secureTextEntry={false}
  241. value={this.state.payees}
  242. editable={false}
  243. />
  244. <View style={{marginRight: 20}}>
  245. <TouchableOpacity
  246. onPress={() => {
  247. this.props.navigation.navigate('enterprise_user', {
  248. type: 1,
  249. data: this.state.payees,
  250. getUserInfo: (type, name) => {
  251. this.getUserInfo(type, name);
  252. },
  253. });
  254. }}>
  255. <Image
  256. source={require('../../../source/img/productImg/addIcon.png')}
  257. style={{height: 16, width: 16}}
  258. />
  259. </TouchableOpacity>
  260. </View>
  261. </View>
  262. </WingBlank>
  263. <WingBlank>
  264. <View
  265. style={[
  266. public_css.view,
  267. public_css.lineTopBottom,
  268. {alignItems: 'center'},
  269. ]}>
  270. <Text style={public_css.text}>审核人:</Text>
  271. <TextInput
  272. style={public_css.textInputStyle}
  273. placeholder="请添加审核者"
  274. clearButtonMode="while-editing"
  275. secureTextEntry={false}
  276. value={this.state.reviewers}
  277. editable={false}
  278. />
  279. <View style={{marginRight: 20}}>
  280. <TouchableOpacity
  281. onPress={() => {
  282. this.props.navigation.navigate('enterprise_user', {
  283. type: 2,
  284. data: this.state.reviewers,
  285. getUserInfo: (type, name) => {
  286. this.getUserInfo(type, name);
  287. },
  288. });
  289. }}>
  290. <Image
  291. source={require('../../../source/img/productImg/addIcon.png')}
  292. style={{height: 16, width: 16}}
  293. />
  294. </TouchableOpacity>
  295. </View>
  296. </View>
  297. </WingBlank>
  298. <WingBlank>
  299. <View
  300. style={[
  301. public_css.view,
  302. public_css.lineTopBottom,
  303. {alignItems: 'center'},
  304. ]}>
  305. <Text style={public_css.text}>开票人:</Text>
  306. <TextInput
  307. style={public_css.textInputStyle}
  308. placeholder="请添加审核者"
  309. clearButtonMode="while-editing"
  310. secureTextEntry={false}
  311. value={this.state.drawers}
  312. editable={false}
  313. />
  314. <View style={{marginRight: 20}}>
  315. <TouchableOpacity
  316. onPress={() => {
  317. this.props.navigation.navigate('enterprise_user', {
  318. type: 3,
  319. data: this.state.drawers,
  320. getUserInfo: (type, name) => {
  321. this.getUserInfo(type, name);
  322. },
  323. });
  324. }}>
  325. <Image
  326. source={require('../../../source/img/productImg/addIcon.png')}
  327. style={{height: 16, width: 16}}
  328. />
  329. </TouchableOpacity>
  330. </View>
  331. </View>
  332. </WingBlank>
  333. <WingBlank>
  334. <View
  335. style={[
  336. public_css.view,
  337. public_css.lineTopBottom,
  338. {alignItems: 'center'},
  339. ]}>
  340. <Text style={public_css.text}>可用税率:</Text>
  341. <TextInput
  342. style={[public_css.textInputStyle, {height: 150}]}
  343. placeholder="请添加可用税率"
  344. clearButtonMode="while-editing"
  345. secureTextEntry={false}
  346. value={this.state.taxRates}
  347. editable={false}
  348. multiline={true}
  349. numberOfLines={3}
  350. />
  351. <View>
  352. <TouchableOpacity
  353. style={{
  354. backgroundColor: '#2A67FE',
  355. width: 50,
  356. height: 30,
  357. justifyContent: 'center',
  358. alignItems: 'center',
  359. }}
  360. onPress={() => {
  361. this.getRatesInfo();
  362. // this.props.navigation.navigate('enterprise_tax_rate', {
  363. // data: this.state.taxRates,
  364. // getUserTaxRate: (taxRates) => {
  365. // this.getUserTaxRate(taxRates);
  366. // },
  367. // });
  368. }}>
  369. <Text style={{color: '#fff'}}>同步</Text>
  370. </TouchableOpacity>
  371. </View>
  372. </View>
  373. </WingBlank>
  374. </ScrollView>
  375. <WingBlank>
  376. <View style={public_css.bottomStatus}>
  377. <TouchableOpacity
  378. style={[public_css.statusBtn, public_css.statusRBtn]}
  379. onPress={() => this.submitData()}>
  380. <Text style={{color: '#fff'}}>保存</Text>
  381. </TouchableOpacity>
  382. </View>
  383. </WingBlank>
  384. <WhiteSpace />
  385. </SafeAreaView>
  386. );
  387. }
  388. //加载页面时显示数据
  389. async componentDidMount(): void {
  390. let company = this.props.route.params.enterprise;
  391. this.setState({
  392. entName: company.entName,
  393. entTaxId: company.entTaxId,
  394. entAddress: company.entAddress,
  395. entContactPerson: company.entContactPerson,
  396. entPhone: company.entPhone,
  397. bankAccountName: company.bankAccountName,
  398. bankAccountNumber: company.bankAccountNumber,
  399. payees: company.payees,
  400. reviewers: company.reviewers,
  401. drawers: company.drawers,
  402. taxRates: company.availableTaxes,
  403. companyType: company.entType.toString(),
  404. deviceKey: company.defaultInvoiceDevice,
  405. });
  406. await this.getDeviceName();
  407. }
  408. //提交数据
  409. submitData = async () => {
  410. let company = JSON.parse(await RetrieveData('company'));
  411. let number = this.state.bankAccountNumber;
  412. if (!number) {
  413. ToastShow(1, '企业银行帐号不可以为空!');
  414. return;
  415. }
  416. let payees = this.state.payees;
  417. if (!payees) {
  418. ToastShow(1, '收款人不可以为空!');
  419. return;
  420. }
  421. let entTaxId = this.state.entTaxId;
  422. if (!entTaxId) {
  423. ToastShow(1, '客户税号不可以为空!');
  424. return;
  425. }
  426. this.setLoadingStatus(true);
  427. let token = await RetrieveData('token');
  428. let account = await RetrieveData('account');
  429. if (token && account) {
  430. const url = '/sys/entInfo/updateBriefInfo';
  431. let response = await RequestNetwork(
  432. url,
  433. token,
  434. {
  435. entTaxId: this.state.entTaxId,
  436. entName: this.state.entName,
  437. entType: this.state.companyType,
  438. entAddress: this.state.entAddress,
  439. entContactPerson: this.state.entContactPerson,
  440. entPhone: this.state.entPhone,
  441. bankAccountName: this.state.bankAccountName,
  442. bankAccountNumber: this.state.bankAccountNumber,
  443. payees: this.state.payees,
  444. reviewers: this.state.reviewers,
  445. drawers: this.state.drawers,
  446. availableTaxes: this.state.taxRates,
  447. doConfirm: false,
  448. defaultInvoiceDevice: this.state.deviceKey,
  449. reqChannel: 3,
  450. mobile: account,
  451. },
  452. false,
  453. 1,
  454. );
  455. if (response) {
  456. if (response.code === 0) {
  457. this.setLoadingStatus(false);
  458. company.payees = this.state.payees;
  459. company.reviewers = this.state.reviewers;
  460. company.drawers = this.state.drawers;
  461. company.availableTaxes = this.state.taxRates;
  462. company.entAddress = this.state.entAddress;
  463. company.entContactPerson = this.state.entContactPerson;
  464. company.entPhone = this.state.entPhone;
  465. company.bankName = this.state.bankAccountName;
  466. company.bankAccountNumber = this.state.bankAccountNumber;
  467. await IndividualStorageData('company', JSON.stringify(company));
  468. ToastShow(1, '编辑成功!');
  469. DeviceEventEmitter.emit('updateCompany', null);
  470. DeviceEventEmitter.emit('企业信息刷新', '');
  471. this.props.navigation.goBack();
  472. } else {
  473. this.setLoadingStatus(false);
  474. ToastShow(1, '编辑失败!');
  475. }
  476. } else {
  477. this.setLoadingStatus(false);
  478. ToastShow(1, response.msg);
  479. }
  480. }
  481. };
  482. // 获取收款人、审核人、开票人信息
  483. getUserInfo = (type, name) => {
  484. if (type === 1) {
  485. this.setState({
  486. payees: name,
  487. });
  488. }
  489. if (type === 2) {
  490. this.setState({
  491. reviewers: name,
  492. });
  493. }
  494. if (type === 3) {
  495. this.setState({
  496. drawers: name,
  497. });
  498. }
  499. };
  500. // 获取可用税率信息
  501. getUserTaxRate = (taxRates) => {
  502. this.setState({
  503. taxRates: taxRates,
  504. });
  505. };
  506. //设置loading层是否显示
  507. setLoadingStatus(isLoading) {
  508. this.setState({
  509. spinner: isLoading,
  510. });
  511. };
  512. // 获取设备名称
  513. getDeviceName = async () => {
  514. const token = await RetrieveData('token');
  515. if (token) {
  516. const url = '/sys/entDevice/findDevices';
  517. let response = await RequestNetwork(
  518. url,
  519. token,
  520. {
  521. entTaxId: this.state.entTaxId,
  522. },
  523. false,
  524. 2,
  525. );
  526. if (response) {
  527. if (response.code === 0) {
  528. response.data.map((item) => {
  529. if (this.state.deviceKey === item.deviceKey) {
  530. this.setState({
  531. deviceName: item.deviceLabel,
  532. });
  533. }
  534. });
  535. }
  536. }
  537. }
  538. };
  539. // 获取选择的设备信息
  540. getDeviceInfo = (deviceName, deviceKey) => {
  541. this.setState({
  542. deviceName: deviceName,
  543. deviceKey: deviceKey,
  544. });
  545. };
  546. // 同步税率信息
  547. getRatesInfo = async () => {
  548. const token = await RetrieveData('token');
  549. if (token) {
  550. this.setLoadingStatus(true);
  551. const url = '/sys/entInfo/syncSkRates';
  552. let response = await RequestNetwork(
  553. url,
  554. token,
  555. {
  556. entTaxId: this.state.entTaxId,
  557. reqChannel: 3,
  558. },
  559. false,
  560. 1,
  561. );
  562. if (response) {
  563. console.log(response);
  564. if (response.code === 0) {
  565. this.setLoadingStatus(false);
  566. if (response.data.rates) {
  567. this.setState({
  568. taxRates: response.data.rates,
  569. });
  570. } else {
  571. this.setState({
  572. taxRates: '',
  573. });
  574. }
  575. } else {
  576. this.setLoadingStatus(false);
  577. ToastShow(1, response.msg);
  578. }
  579. }
  580. }
  581. };
  582. }