customer_add.js 11 KB

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