personnel_add.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Image,
  5. Text,
  6. TextInput,
  7. TouchableOpacity,
  8. Dimensions,
  9. ScrollView,
  10. KeyboardAvoidingView,
  11. DeviceEventEmitter,
  12. } from 'react-native';
  13. import {List, Picker, Provider} from '@ant-design/react-native';
  14. import login_css from '../login/login_css';
  15. import public_css from '../../source/css/public_css';
  16. import loading_css from '../../source/css/loading_css';
  17. import Spinner from 'react-native-loading-spinner-overlay';
  18. import {GetDataPost} from '../../data/encryption';
  19. import {ShowToast} from '../../components/rootToast/root_toast';
  20. import {RetrieveData} from '../../data/storage';
  21. export default class personnel_add extends Component {
  22. constructor(props) {
  23. super(props);
  24. this.props.navigation.dangerouslyGetParent().setOptions({
  25. tabBarVisible: false,
  26. });
  27. this.state = {
  28. name: '',
  29. phone: '',
  30. role_name: '',
  31. ent_name: '',
  32. role_list: [],
  33. ents: [],
  34. user_type: 1,
  35. spinner: false,
  36. };
  37. }
  38. render() {
  39. return (
  40. <Provider>
  41. <KeyboardAvoidingView
  42. enabled
  43. style={{flex: 1, backgroundColor: '#ffffff'}}>
  44. <ScrollView>
  45. <View>
  46. <Spinner
  47. visible={this.state.spinner}
  48. textContent={'Loading...'}
  49. textStyle={loading_css.spinnerTextStyle}
  50. />
  51. <View style={login_css.inputView}>
  52. <View style={[public_css.view, public_css.lineTopBottom]}>
  53. <Text
  54. style={[
  55. public_css.text,
  56. {fontFamily: 'PingFang-SC-Regular', color: '#333333'},
  57. ]}>
  58. *员工姓名:
  59. </Text>
  60. <TextInput
  61. style={public_css.textInputStyle}
  62. placeholder="请输入员工姓名"
  63. value={this.state.name}
  64. clearButtonMode="while-editing"
  65. secureTextEntry={false}
  66. onChangeText={(text) => {
  67. this.setState({
  68. name: text,
  69. });
  70. }}
  71. />
  72. </View>
  73. <View style={[public_css.view, public_css.lineTopBottom]}>
  74. <Text
  75. style={[
  76. public_css.text,
  77. {fontFamily: 'PingFang-SC-Regular', color: '#333333'},
  78. ]}>
  79. *手机号码:
  80. </Text>
  81. <TextInput
  82. style={public_css.textInputStyle}
  83. placeholder="请输入手机号码"
  84. value={this.state.phone}
  85. clearButtonMode="while-editing"
  86. secureTextEntry={false}
  87. onChangeText={(text) => {
  88. this.setState({
  89. phone: text,
  90. });
  91. }}
  92. />
  93. </View>
  94. <View style={{width: Dimensions.get('window').width}}>
  95. <Picker
  96. data={this.state.role_list}
  97. cols={1}
  98. value={this.state.role_name}
  99. onChange={(value) => {
  100. this.setState({role_name: value});
  101. }}>
  102. <List.Item arrow="horizontal">*角色:</List.Item>
  103. </Picker>
  104. </View>
  105. </View>
  106. </View>
  107. </ScrollView>
  108. <View style={public_css.bottomStaus}>
  109. <TouchableOpacity
  110. style={[public_css.statusBtn, public_css.statusLBtn]}
  111. onPress={() => {
  112. this.setState({
  113. name: '',
  114. phone: '',
  115. role_name: '',
  116. ent_name: '',
  117. });
  118. }}>
  119. <Image
  120. source={require('../../source/img/productImg/clear.png')}
  121. style={{width: 32, height: 32}}
  122. />
  123. <Text>全部清除</Text>
  124. </TouchableOpacity>
  125. <TouchableOpacity
  126. style={[public_css.statusBtn, public_css.statusRBtn]}
  127. onPress={() => this.submitData()}>
  128. <Image
  129. source={require('../../source/img/productImg/confirm.png')}
  130. style={{width: 32, height: 32}}
  131. />
  132. <Text style={{color: '#fff'}}>确定</Text>
  133. </TouchableOpacity>
  134. </View>
  135. </KeyboardAvoidingView>
  136. </Provider>
  137. );
  138. }
  139. //设置loading层是否显示
  140. setLoadingStatus(isLoading) {
  141. this.setState({
  142. spinner: isLoading,
  143. });
  144. }
  145. //加载页面时显示数据
  146. componentDidMount(): void {
  147. this.setLoginType();
  148. }
  149. //根据登陆帐号类型加载数据
  150. setLoginType = async () => {
  151. let userType = await RetrieveData('usertype');
  152. userType = userType.substring(1, userType.length - 1);
  153. this.setState({
  154. user_type: userType,
  155. });
  156. //服务商
  157. if (userType == 2) {
  158. this.getIspRoleList();
  159. }
  160. //运营商
  161. if (userType == 3) {
  162. this.getOperRoleList();
  163. }
  164. };
  165. //提交数据
  166. submitData = () => {
  167. //服务商
  168. if (this.state.user_type == 2) {
  169. this.submitIspData();
  170. }
  171. //运营商
  172. if (this.state.user_type == 3) {
  173. this.submitOperData();
  174. }
  175. };
  176. //提交运营商新增用户数据
  177. submitOperData = async () => {
  178. let name = this.state.name;
  179. if (!name) {
  180. ShowToast('员工姓名不可以为空!');
  181. return;
  182. }
  183. let phone = this.state.phone;
  184. if (!phone) {
  185. ShowToast('手机号码不可以为空!');
  186. return;
  187. }
  188. this.setLoadingStatus(true);
  189. let token = await RetrieveData('token');
  190. let account = await RetrieveData('account');
  191. if (token && account) {
  192. token = token.substring(1, token.length - 1);
  193. account = account.substring(1, account.length - 1);
  194. const url = 'https://app.taxbk.cn:9443/auth/oper/user/save';
  195. let response = await GetDataPost(
  196. url,
  197. token,
  198. {
  199. mobile: this.state.phone,
  200. name: this.state.name,
  201. currentUserMobile: account,
  202. reqChannel: 3,
  203. roleIds: this.state.role_name,
  204. },
  205. false,
  206. 1,
  207. );
  208. if (response) {
  209. if (response.code == 0) {
  210. ShowToast('新增成功!');
  211. this.setLoadingStatus(false);
  212. this.props.navigation.goBack();
  213. DeviceEventEmitter.emit('刷新用户列表', '');
  214. } else {
  215. ShowToast('新增失败!');
  216. this.setLoadingStatus(false);
  217. }
  218. } else {
  219. ShowToast(response.msg);
  220. this.setLoadingStatus(false);
  221. }
  222. }
  223. };
  224. //提交服务商新增用户数据
  225. submitIspData = async () => {
  226. let name = this.state.name;
  227. if (!name) {
  228. ShowToast('员工姓名不可以为空!');
  229. return;
  230. }
  231. let phone = this.state.phone;
  232. if (!phone) {
  233. ShowToast('手机号码不可以为空!');
  234. return;
  235. }
  236. this.setLoadingStatus(true);
  237. let token = await RetrieveData('token');
  238. let account = await RetrieveData('account');
  239. if (token && account) {
  240. token = token.substring(1, token.length - 1);
  241. account = account.substring(1, account.length - 1);
  242. const url = 'https://app.taxbk.cn:9443/auth/isp/user/save';
  243. let response = await GetDataPost(
  244. url,
  245. token,
  246. {
  247. mobile: this.state.phone,
  248. name: this.state.name,
  249. currentUserMobile: account,
  250. reqChannel: 3,
  251. roleIds: this.state.role_name,
  252. },
  253. false,
  254. 1,
  255. );
  256. if (response) {
  257. if (response.code == 0) {
  258. ShowToast('新增成功!');
  259. this.setLoadingStatus(false);
  260. this.props.navigation.goBack();
  261. DeviceEventEmitter.emit('刷新用户列表', '');
  262. } else {
  263. ShowToast('新增失败!');
  264. this.setLoadingStatus(false);
  265. }
  266. } else {
  267. ShowToast(response.msg);
  268. this.setLoadingStatus(false);
  269. }
  270. }
  271. };
  272. //获取运营商角色列表
  273. getOperRoleList = async () => {
  274. let token = await RetrieveData('token');
  275. if (token) {
  276. token = token.substring(1, token.length - 1);
  277. const url = 'https://app.taxbk.cn:9443/auth/oper/role/findCategoryRoles';
  278. let response = await GetDataPost(url, token, {}, false, 2);
  279. if (response) {
  280. if (response.code == 0) {
  281. let listDatas = response.data.map((_, i) => ({
  282. label: response.data[i].remark,
  283. value: response.data[i].id,
  284. }));
  285. let list = this.state.role_list.concat(listDatas);
  286. this.setState({
  287. role_list: list,
  288. });
  289. }
  290. } else {
  291. ShowToast(response.msg);
  292. }
  293. }
  294. };
  295. //获取服务商角色列表
  296. getIspRoleList = async () => {
  297. let token = await RetrieveData('token');
  298. if (token) {
  299. token = token.substring(1, token.length - 1);
  300. const url = 'https://app.taxbk.cn:9443/auth/isp/role/findCategoryRoles';
  301. let response = await GetDataPost(url, token, {}, false, 2);
  302. if (response) {
  303. if (response.code == 0) {
  304. let listDatas = response.data.map((_, i) => ({
  305. label: response.data[i].remark,
  306. value: response.data[i].id,
  307. }));
  308. let list = this.state.role_list.concat(listDatas);
  309. this.setState({
  310. role_list: list,
  311. });
  312. }
  313. } else {
  314. ShowToast(response.msg);
  315. }
  316. }
  317. };
  318. }