personnel_edit.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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: this.props.route.params.personnel.name,
  29. phone: this.props.route.params.personnel.mobile,
  30. role_name: this.props.route.params.personnel.role_name,
  31. role_list: [],
  32. ents: [],
  33. user_type: 1,
  34. spinner: false,
  35. };
  36. alert(this.props.route.params.personnel.role_name);
  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.submitEditIspUser();
  170. }
  171. //运营商
  172. if (this.state.user_type == 3) {
  173. this.submitEditOperUser();
  174. }
  175. };
  176. //运营商用户数据编辑
  177. submitEditOperUser = 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/updateManageInfo';
  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. status: true,
  204. roleIds: this.state.role_name,
  205. },
  206. false,
  207. 1,
  208. );
  209. if (response) {
  210. if (response.code == 0) {
  211. ShowToast('编辑成功!');
  212. this.setLoadingStatus(false);
  213. this.props.navigation.goBack();
  214. DeviceEventEmitter.emit('刷新用户列表', '');
  215. } else {
  216. ShowToast('编辑失败!');
  217. this.setLoadingStatus(false);
  218. }
  219. } else {
  220. ShowToast(response.msg);
  221. this.setLoadingStatus(false);
  222. }
  223. }
  224. };
  225. //编辑服务商用户信息
  226. submitEditIspUser = async () => {
  227. let name = this.state.name;
  228. if (!name) {
  229. ShowToast('员工姓名不可以为空!');
  230. return;
  231. }
  232. let phone = this.state.phone;
  233. if (!phone) {
  234. ShowToast('手机号码不可以为空!');
  235. return;
  236. }
  237. this.setLoadingStatus(true);
  238. let token = await RetrieveData('token');
  239. let account = await RetrieveData('account');
  240. if (token && account) {
  241. token = token.substring(1, token.length - 1);
  242. account = account.substring(1, account.length - 1);
  243. const url = 'https://app.taxbk.cn:9443/auth/isp/user/updateManageInfo';
  244. let response = await GetDataPost(
  245. url,
  246. token,
  247. {
  248. mobile: this.state.phone,
  249. name: this.state.name,
  250. currentUserMobile: account,
  251. reqChannel: 3,
  252. status: true,
  253. roleIds: this.state.role_name,
  254. },
  255. false,
  256. 1,
  257. );
  258. if (response) {
  259. if (response.code == 0) {
  260. ShowToast('编辑成功!');
  261. this.setLoadingStatus(false);
  262. this.props.navigation.goBack();
  263. DeviceEventEmitter.emit('刷新用户列表', '');
  264. } else {
  265. ShowToast('编辑失败!');
  266. this.setLoadingStatus(false);
  267. }
  268. } else {
  269. ShowToast(response.msg);
  270. this.setLoadingStatus(false);
  271. }
  272. }
  273. };
  274. //获取运营商角色列表
  275. getOperRoleList = async () => {
  276. let token = await RetrieveData('token');
  277. if (token) {
  278. token = token.substring(1, token.length - 1);
  279. const url = 'https://app.taxbk.cn:9443/auth/oper/role/findCategoryRoles';
  280. let response = await GetDataPost(url, token, {}, false, 2);
  281. if (response) {
  282. if (response.code == 0) {
  283. let listDatas = response.data.map((_, i) => ({
  284. label: response.data[i].remark,
  285. value: response.data[i].id,
  286. }));
  287. let list = this.state.role_list.concat(listDatas);
  288. this.setState({
  289. role_list: list,
  290. });
  291. }
  292. } else {
  293. ShowToast(response.msg);
  294. }
  295. }
  296. };
  297. //获取服务商角色列表
  298. getIspRoleList = async () => {
  299. let token = await RetrieveData('token');
  300. if (token) {
  301. token = token.substring(1, token.length - 1);
  302. const url = 'https://app.taxbk.cn:9443/auth/isp/role/findCategoryRoles';
  303. let response = await GetDataPost(url, token, {}, false, 2);
  304. if (response) {
  305. if (response.code == 0) {
  306. let listDatas = response.data.map((_, i) => ({
  307. label: response.data[i].remark,
  308. value: response.data[i].id,
  309. }));
  310. let list = this.state.role_list.concat(listDatas);
  311. this.setState({
  312. role_list: list,
  313. });
  314. }
  315. } else {
  316. ShowToast(response.msg);
  317. }
  318. }
  319. };
  320. }