123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- import React, {Component} from 'react';
- import {
- View,
- Image,
- Text,
- TextInput,
- TouchableOpacity,
- Dimensions,
- ScrollView,
- KeyboardAvoidingView,
- DeviceEventEmitter,
- } from 'react-native';
- import {List, Picker, Provider} from '@ant-design/react-native';
- import login_css from '../login/login_css';
- import public_css from '../../source/css/public_css';
- import loading_css from '../../source/css/loading_css';
- import Spinner from 'react-native-loading-spinner-overlay';
- import {GetDataPost} from '../../data/encryption';
- import {ShowToast} from '../../components/rootToast/root_toast';
- import {RetrieveData} from '../../data/storage';
- export default class personnel_add extends Component {
- constructor(props) {
- super(props);
- this.props.navigation.dangerouslyGetParent().setOptions({
- tabBarVisible: false,
- });
- this.state = {
- name: '',
- phone: '',
- role_name: '',
- ent_name: '',
- role_list: [],
- ents: [],
- user_type: 1,
- spinner: false,
- };
- }
- render() {
- return (
- <Provider>
- <KeyboardAvoidingView
- enabled
- style={{flex: 1, backgroundColor: '#ffffff'}}>
- <ScrollView>
- <View>
- <Spinner
- visible={this.state.spinner}
- textContent={'Loading...'}
- textStyle={loading_css.spinnerTextStyle}
- />
- <View style={login_css.inputView}>
- <View style={[public_css.view, public_css.lineTopBottom]}>
- <Text
- style={[
- public_css.text,
- {fontFamily: 'PingFang-SC-Regular', color: '#333333'},
- ]}>
- *员工姓名:
- </Text>
- <TextInput
- style={public_css.textInputStyle}
- placeholder="请输入员工姓名"
- value={this.state.name}
- clearButtonMode="while-editing"
- secureTextEntry={false}
- onChangeText={(text) => {
- this.setState({
- name: text,
- });
- }}
- />
- </View>
- <View style={[public_css.view, public_css.lineTopBottom]}>
- <Text
- style={[
- public_css.text,
- {fontFamily: 'PingFang-SC-Regular', color: '#333333'},
- ]}>
- *手机号码:
- </Text>
- <TextInput
- style={public_css.textInputStyle}
- placeholder="请输入手机号码"
- value={this.state.phone}
- clearButtonMode="while-editing"
- secureTextEntry={false}
- onChangeText={(text) => {
- this.setState({
- phone: text,
- });
- }}
- />
- </View>
- <View style={{width: Dimensions.get('window').width}}>
- <Picker
- data={this.state.role_list}
- cols={1}
- value={this.state.role_name}
- onChange={(value) => {
- this.setState({role_name: value});
- }}>
- <List.Item arrow="horizontal">*角色:</List.Item>
- </Picker>
- </View>
- </View>
- </View>
- </ScrollView>
- <View style={public_css.bottomStaus}>
- <TouchableOpacity
- style={[public_css.statusBtn, public_css.statusLBtn]}
- onPress={() => {
- this.setState({
- name: '',
- phone: '',
- role_name: '',
- ent_name: '',
- });
- }}>
- <Image
- source={require('../../source/img/productImg/clear.png')}
- style={{width: 32, height: 32}}
- />
- <Text>全部清除</Text>
- </TouchableOpacity>
- <TouchableOpacity
- style={[public_css.statusBtn, public_css.statusRBtn]}
- onPress={() => this.submitData()}>
- <Image
- source={require('../../source/img/productImg/confirm.png')}
- style={{width: 32, height: 32}}
- />
- <Text style={{color: '#fff'}}>确定</Text>
- </TouchableOpacity>
- </View>
- </KeyboardAvoidingView>
- </Provider>
- );
- }
- //设置loading层是否显示
- setLoadingStatus(isLoading) {
- this.setState({
- spinner: isLoading,
- });
- }
- //加载页面时显示数据
- componentDidMount(): void {
- this.setLoginType();
- }
- //根据登陆帐号类型加载数据
- setLoginType = async () => {
- let userType = await RetrieveData('usertype');
- userType = userType.substring(1, userType.length - 1);
- this.setState({
- user_type: userType,
- });
- //服务商
- if (userType == 2) {
- this.getIspRoleList();
- }
- //运营商
- if (userType == 3) {
- this.getOperRoleList();
- }
- };
- //提交数据
- submitData = () => {
- //服务商
- if (this.state.user_type == 2) {
- this.submitIspData();
- }
- //运营商
- if (this.state.user_type == 3) {
- this.submitOperData();
- }
- };
- //提交运营商新增用户数据
- submitOperData = async () => {
- let name = this.state.name;
- if (!name) {
- ShowToast('员工姓名不可以为空!');
- return;
- }
- let phone = this.state.phone;
- if (!phone) {
- ShowToast('手机号码不可以为空!');
- return;
- }
- this.setLoadingStatus(true);
- let token = await RetrieveData('token');
- let account = await RetrieveData('account');
- if (token && account) {
- token = token.substring(1, token.length - 1);
- account = account.substring(1, account.length - 1);
- const url = 'https://app.taxbk.cn:9443/auth/oper/user/save';
- let response = await GetDataPost(
- url,
- token,
- {
- mobile: this.state.phone,
- name: this.state.name,
- currentUserMobile: account,
- reqChannel: 3,
- roleIds: this.state.role_name,
- },
- false,
- 1,
- );
- if (response) {
- if (response.code == 0) {
- ShowToast('新增成功!');
- this.setLoadingStatus(false);
- this.props.navigation.goBack();
- DeviceEventEmitter.emit('刷新用户列表', '');
- } else {
- ShowToast('新增失败!');
- this.setLoadingStatus(false);
- }
- } else {
- ShowToast(response.msg);
- this.setLoadingStatus(false);
- }
- }
- };
- //提交服务商新增用户数据
- submitIspData = async () => {
- let name = this.state.name;
- if (!name) {
- ShowToast('员工姓名不可以为空!');
- return;
- }
- let phone = this.state.phone;
- if (!phone) {
- ShowToast('手机号码不可以为空!');
- return;
- }
- this.setLoadingStatus(true);
- let token = await RetrieveData('token');
- let account = await RetrieveData('account');
- if (token && account) {
- token = token.substring(1, token.length - 1);
- account = account.substring(1, account.length - 1);
- const url = 'https://app.taxbk.cn:9443/auth/isp/user/save';
- let response = await GetDataPost(
- url,
- token,
- {
- mobile: this.state.phone,
- name: this.state.name,
- currentUserMobile: account,
- reqChannel: 3,
- roleIds: this.state.role_name,
- },
- false,
- 1,
- );
- if (response) {
- if (response.code == 0) {
- ShowToast('新增成功!');
- this.setLoadingStatus(false);
- this.props.navigation.goBack();
- DeviceEventEmitter.emit('刷新用户列表', '');
- } else {
- ShowToast('新增失败!');
- this.setLoadingStatus(false);
- }
- } else {
- ShowToast(response.msg);
- this.setLoadingStatus(false);
- }
- }
- };
- //获取运营商角色列表
- getOperRoleList = async () => {
- let token = await RetrieveData('token');
- if (token) {
- token = token.substring(1, token.length - 1);
- const url = 'https://app.taxbk.cn:9443/auth/oper/role/findCategoryRoles';
- let response = await GetDataPost(url, token, {}, false, 2);
- if (response) {
- if (response.code == 0) {
- let listDatas = response.data.map((_, i) => ({
- label: response.data[i].remark,
- value: response.data[i].id,
- }));
- let list = this.state.role_list.concat(listDatas);
- this.setState({
- role_list: list,
- });
- }
- } else {
- ShowToast(response.msg);
- }
- }
- };
- //获取服务商角色列表
- getIspRoleList = async () => {
- let token = await RetrieveData('token');
- if (token) {
- token = token.substring(1, token.length - 1);
- const url = 'https://app.taxbk.cn:9443/auth/isp/role/findCategoryRoles';
- let response = await GetDataPost(url, token, {}, false, 2);
- if (response) {
- if (response.code == 0) {
- let listDatas = response.data.map((_, i) => ({
- label: response.data[i].remark,
- value: response.data[i].id,
- }));
- let list = this.state.role_list.concat(listDatas);
- this.setState({
- role_list: list,
- });
- }
- } else {
- ShowToast(response.msg);
- }
- }
- };
- }
|