invoice_drawer_add_or_edit.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Text,
  5. TextInput,
  6. TouchableOpacity,
  7. SafeAreaView,
  8. } from 'react-native';
  9. import {WingBlank, WhiteSpace} from '@ant-design/react-native';
  10. import public_css from '../../../source/css/public_css';
  11. import {RequestNetwork} from '../../../data/encryption';
  12. import {RetrieveData} from '../../../data/storage';
  13. import {CheckPhoneNumber} from '../../../source/inspect/inspect';
  14. import {ToastShow} from '../../../components/toast/toast';
  15. export default class invoice_drawer_add_or_edit extends Component {
  16. constructor(props) {
  17. super(props);
  18. this.state = {
  19. userName: '',
  20. userPhone: '',
  21. parentCode: '',
  22. entTaxId: null,
  23. shortCode: '',
  24. email: '',
  25. customerMobile: '',
  26. address: '',
  27. contactPhone: '',
  28. bankAccount: '',
  29. bank: '',
  30. remark: '',
  31. mobile: '',
  32. ip: '',
  33. spinner: false,
  34. companyTypes: [
  35. {
  36. label: '个人',
  37. value: '1',
  38. },
  39. {
  40. label: '企业',
  41. value: '2',
  42. },
  43. ],
  44. userType: '1',
  45. categoryBack: 'rgba(42,103,254, 1)',
  46. categoryBackFont: '#ffffff',
  47. categoryBackCompany: 'rgba(42,103,254, 0.07)',
  48. categoryBackCompanyFont: '#2A67FE',
  49. companyKId: '',
  50. companyMId: '',
  51. editStatus: true,
  52. isEdit: false,
  53. };
  54. }
  55. render() {
  56. return (
  57. <SafeAreaView style={public_css.body}>
  58. <View style={{flex: 1}}>
  59. <View style={{height: 40, backgroundColor: '#F7F7F7', justifyContent: 'center', marginLeft: 15}}>
  60. <Text style={{color: '#888888', fontSize: 15}}>基础信息</Text>
  61. </View>
  62. <WingBlank>
  63. <View style={[public_css.view, public_css.lineTopBottom]}>
  64. <Text
  65. style={[
  66. public_css.text,
  67. {color: '#333333'},
  68. ]}>
  69. <Text style={{color: 'red'}}>*</Text> 员工姓名:
  70. </Text>
  71. <TextInput
  72. style={public_css.textInputStyle}
  73. value={this.state.userName}
  74. placeholder="请输入员工姓名"
  75. clearButtonMode="while-editing"
  76. secureTextEntry={false}
  77. onChangeText={(text) => {
  78. this.setState({
  79. userName: text,
  80. });
  81. }}
  82. editable={this.state.editStatus}
  83. />
  84. </View>
  85. <View style={[public_css.view, public_css.lineTopBottom]}>
  86. <Text
  87. style={[
  88. public_css.text,
  89. {color: '#333333'},
  90. ]}>
  91. <Text style={{color: 'red'}}>*</Text> 手机号码:
  92. </Text>
  93. <TextInput
  94. style={public_css.textInputStyle}
  95. value={this.state.userPhone}
  96. placeholder="请输入手机号码"
  97. clearButtonMode="while-editing"
  98. secureTextEntry={false}
  99. onChangeText={(text) => {
  100. this.setState({
  101. userPhone: text,
  102. });
  103. }}
  104. editable={this.state.editStatus}
  105. />
  106. </View>
  107. </WingBlank>
  108. <View style={{height: 40, backgroundColor: '#F7F7F7', justifyContent: 'center'}}>
  109. <Text style={{color: '#888888', fontSize: 15, marginLeft: 15}}>企业权限</Text>
  110. </View>
  111. <View style={{flexDirection: 'row', justifyContent: 'flex-start'}}>
  112. <View>
  113. <TouchableOpacity
  114. onPress={() => {
  115. this.setSelectStatus('1');
  116. }}
  117. style={{
  118. alignItems: 'center',
  119. justifyContent: 'center',
  120. backgroundColor: this.state.categoryBack,
  121. width: 150,
  122. height: 40,
  123. borderRadius: 39,
  124. margin: 10,
  125. }}>
  126. <Text
  127. style={{
  128. color: this.state.categoryBackFont,
  129. fontWeight: 'bold',
  130. fontSize: 16,
  131. }}>
  132. 企业开票主管
  133. </Text>
  134. </TouchableOpacity>
  135. </View>
  136. <View>
  137. <TouchableOpacity
  138. onPress={() => {
  139. this.setSelectStatus('2');
  140. }}
  141. style={{
  142. alignItems: 'center',
  143. justifyContent: 'center',
  144. backgroundColor: this.state.categoryBackCompany,
  145. width: 150,
  146. height: 40,
  147. borderRadius: 39,
  148. margin: 10,
  149. }}>
  150. <Text
  151. style={{
  152. color: this.state.categoryBackCompanyFont,
  153. fontWeight: 'bold',
  154. fontSize: 16,
  155. }}>
  156. 企业开票员
  157. </Text>
  158. </TouchableOpacity>
  159. </View>
  160. </View>
  161. </View>
  162. <WingBlank>
  163. {this.state.isEdit === true ? (
  164. <View style={public_css.bottomStatus}>
  165. <TouchableOpacity
  166. style={{
  167. width: 120,
  168. borderWidth: 1,
  169. borderColor: '#FE2A53',
  170. borderRadius: 8,
  171. justifyContent: 'center',
  172. alignItems: 'center',
  173. marginRight: 10,
  174. }}
  175. onPress={() => this.deleteUser()}>
  176. <Text style={{color: '#FE2A53'}}>删除</Text>
  177. </TouchableOpacity>
  178. <TouchableOpacity
  179. style={[public_css.statusBtn, public_css.statusRBtn]}
  180. onPress={() => this.submitData()}>
  181. <Text style={{color: '#fff'}}>保存</Text>
  182. </TouchableOpacity>
  183. </View>
  184. ) : (
  185. <View style={public_css.bottomStatus}>
  186. <TouchableOpacity
  187. style={[public_css.statusBtn, public_css.statusRBtn]}
  188. onPress={() => this.submitData()}>
  189. <Text style={{color: '#fff'}}>新增</Text>
  190. </TouchableOpacity>
  191. </View>
  192. )}
  193. </WingBlank>
  194. <WhiteSpace />
  195. </SafeAreaView>
  196. );
  197. }
  198. componentDidMount() {
  199. if (this.props.route.params.dataStatus === 1) {
  200. let data = this.props.route.params.data;
  201. let userType = '';
  202. if (data.item.roleMemo === '企业开票主管') {
  203. userType = '1';
  204. } else {
  205. userType = '2';
  206. }
  207. this.setSelectStatus(userType);
  208. this.setState({
  209. userName: data.item.userName,
  210. userPhone: data.item.userMobile,
  211. editStatus: false,
  212. isEdit: true,
  213. });
  214. }
  215. this.getUserRole();
  216. }
  217. //提交数据
  218. submitData = async () => {
  219. let name = this.state.userName;
  220. if (!name) {
  221. ToastShow(1, '员工姓名不可以为空!');
  222. return;
  223. }
  224. let phone = this.state.userPhone;
  225. if (!phone) {
  226. ToastShow(1, '手机号码不可以为空!');
  227. return;
  228. }
  229. let userType = '';
  230. if (this.state.userType === '1') {
  231. userType = this.state.companyMId;
  232. }
  233. if (this.state.userType === '2') {
  234. userType = this.state.companyKId;
  235. }
  236. let { status, msg } = CheckPhoneNumber(`${this.state.userPhone}`);
  237. if (status) {
  238. this.setLoadingStatus(true);
  239. const token = await RetrieveData('token');
  240. const account = await RetrieveData('account');
  241. const company = JSON.parse(await RetrieveData('company'));
  242. if (token && account) {
  243. const url = '/auth/ent/user/saveOnEnt';
  244. let response = await RequestNetwork(
  245. url,
  246. token,
  247. {
  248. entUserMobile: this.state.userPhone,
  249. entUserName: this.state.userName,
  250. mobile: account,
  251. reqChannel: 3,
  252. entTaxId: company.entTaxId,
  253. roleId: userType,
  254. },
  255. false,
  256. 1,
  257. );
  258. if (response) {
  259. console.log(response);
  260. if (response.code === 0) {
  261. this.setLoadingStatus(false);
  262. ToastShow(1, '新增成功!');
  263. this.props.route.params.refresh();
  264. this.props.navigation.goBack();
  265. } else {
  266. this.setLoadingStatus(false);
  267. ToastShow(1, response.msg);
  268. }
  269. }
  270. }
  271. }
  272. else {
  273. ToastShow(1, msg);
  274. }
  275. };
  276. // 企业类型选择
  277. companyTypeChange = (value) => {
  278. let companyType = '';
  279. if (value.length > 0) {
  280. companyType = value[0];
  281. }
  282. this.setState({
  283. companyType: companyType,
  284. });
  285. };
  286. //获取用户角色
  287. getUserRole = async () => {
  288. let token = await RetrieveData('token');
  289. if (token) {
  290. const url = '/auth/ent/role/findCategoryRoles';
  291. let res = await RequestNetwork(
  292. url,
  293. token,
  294. {},
  295. false,
  296. 2,
  297. );
  298. if (res) {
  299. if (res.code === 0) {
  300. res.data.map((item) => {
  301. if (item.name === 'EKPM') {
  302. this.setState({
  303. companyMId: item.id,
  304. });
  305. }
  306. if (item.name === 'EKPP') {
  307. this.setState({
  308. companyKId: item.id,
  309. });
  310. }
  311. });
  312. }
  313. }
  314. }
  315. };
  316. //设置loading层是否显示
  317. setLoadingStatus(isLoading) {
  318. this.setState({
  319. spinner: isLoading,
  320. });
  321. }
  322. // 获取开票类型
  323. setSelectStatus = (invoiceCategory) => {
  324. if (invoiceCategory === '1') {
  325. this.setState({
  326. categoryBack: 'rgba(42,103,254, 1)',
  327. categoryBackCompany: 'rgba(42,103,254, 0.07)',
  328. categoryBackFont: '#ffffff',
  329. categoryBackCompanyFont: '#2A67FE',
  330. userType: invoiceCategory,
  331. });
  332. } else {
  333. this.setState({
  334. categoryBack: 'rgba(42,103,254, 0.07)',
  335. categoryBackCompany: 'rgba(42,103,254, 1)',
  336. categoryBackFont: '#2A67FE',
  337. categoryBackCompanyFont: '#ffffff',
  338. userType: invoiceCategory,
  339. });
  340. }
  341. };
  342. // 删除用户信息
  343. deleteUser = async () => {
  344. let token = await RetrieveData('token');
  345. const account = await RetrieveData('account');
  346. const company = JSON.parse(await RetrieveData('company'));
  347. if (token) {
  348. this.setLoadingStatus(true);
  349. const url = '/auth/ent/user/delOnEnt';
  350. let res = await RequestNetwork(
  351. url,
  352. token,
  353. {
  354. entUserMobile: this.state.userPhone,
  355. entTaxId: company.entTaxId,
  356. mobile: account,
  357. reqChannel: 3,
  358. },
  359. false,
  360. 1,
  361. );
  362. if (res) {
  363. if (res.code === 0) {
  364. this.setLoadingStatus(false);
  365. ToastShow(1, '删除成功!');
  366. this.props.route.params.refresh();
  367. this.props.navigation.goBack();
  368. }
  369. }
  370. }
  371. };
  372. }