enterprise_list.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. FlatList,
  5. Text,
  6. ActivityIndicator,
  7. RefreshControl,
  8. TouchableOpacity,
  9. Image,
  10. Alert,
  11. SafeAreaView,
  12. DeviceEventEmitter,
  13. } from 'react-native';
  14. import {
  15. DatePicker,
  16. List,
  17. Provider,
  18. InputItem,
  19. SwipeAction,
  20. Drawer,
  21. WingBlank,
  22. Radio, SearchBar,
  23. } from "@ant-design/react-native";
  24. import {RetrieveData, IndividualStorageData} from '../../data/storage';
  25. import {RequestNetwork} from '../../data/encryption';
  26. import Spinner from 'react-native-loading-spinner-overlay';
  27. import loading_css from '../../source/css/loading_css';
  28. import {CleanAll} from '../../components/abnormalMessage/abnormal_message';
  29. import {ToastShow} from '../../components/toast/toast';
  30. import public_css from '../../source/css/public_css';
  31. import {Footer} from '../../components/listPage/pagination';
  32. const RadioItem = Radio.RadioItem;
  33. export default class enterprise_list extends Component {
  34. constructor(props) {
  35. super(props);
  36. this.props.navigation.dangerouslyGetParent().setOptions({
  37. tabBarVisible: false,
  38. });
  39. this.state = {
  40. pageNo: 1,
  41. totalPage: 5,
  42. isShowSearch: false,
  43. customerName: '',
  44. customerEntTaxId: '',
  45. entName: '',
  46. listData: [],
  47. status: 0,
  48. showFoot: 0, // 控制foot, 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中
  49. isLoading: false,
  50. entItem: '',
  51. companyGroup: [],
  52. loadingText: 'loading',
  53. entTaxId: '',
  54. companyName: '',
  55. };
  56. }
  57. render() {
  58. return (
  59. <SafeAreaView style={public_css.body}>
  60. <View style={public_css.search}>
  61. <SearchBar
  62. placeholder="搜索"
  63. value={this.state.companyName}
  64. onCancel={() => this.searchClear()}
  65. onChange={(value) => this.searchData(value)}
  66. showCancelButton={false}
  67. style={{borderRadius: 15}}
  68. />
  69. </View>
  70. <FlatList
  71. data={this.state.listData}
  72. renderItem={(item) => this.renderItem(item)}
  73. refreshControl={
  74. <RefreshControl
  75. title={'加载中...'}
  76. colors={['#B7B7B7']} //此颜色无效
  77. tintColor={'#B7B7B7'}
  78. titleColor={'#B7B7B7'} //只有ios有效
  79. refreshing={this.state.isLoading}
  80. onRefresh={() => {
  81. this.initData();
  82. }}
  83. />
  84. }
  85. ListFooterComponent={() => Footer(this.state.showFoot)}
  86. onEndReached={() => this.onEndReached()}
  87. onEndReachedThreshold={0.1}
  88. />
  89. </SafeAreaView>
  90. );
  91. }
  92. //页面加载完成后加载数据
  93. componentDidMount(): void {
  94. this.getCompanyList();
  95. }
  96. //搜索
  97. searchData = async (text) => {
  98. this.setState({
  99. listData: [],
  100. companyName: text,
  101. showFoot: 0,
  102. pageNo: 1,
  103. });
  104. await this.getCompanyList();
  105. };
  106. //数据初始化
  107. initData = () => {
  108. this.setState({
  109. listData: [],
  110. isLoading: false,
  111. showFoot: 0,
  112. status: 0,
  113. pageNo: 1,
  114. companyName: '',
  115. });
  116. this.getCompanyList();
  117. };
  118. //列表上拉加载
  119. onEndReached = async () => {
  120. if (this.state.showFoot === 2) {
  121. if (this.state.pageNo >= this.state.totalPage) {
  122. this.setState({showFoot: 0});
  123. return;
  124. } else {
  125. this.setState({showFoot: 1, pageNo: this.state.pageNo + 1});
  126. await this.getCompanyList();
  127. }
  128. }
  129. };
  130. //获取数据
  131. getCompanyList = async () => {
  132. const entInfo = JSON.parse(await RetrieveData('company'));
  133. this.setState({entItem: entInfo});
  134. const token = await RetrieveData('token');
  135. const account = await RetrieveData('account');
  136. if (token && account) {
  137. const url = '/auth/ent/user/findManageInfoByMobile';
  138. let response = await RequestNetwork(
  139. url,
  140. token,
  141. {
  142. entUserMobile: account,
  143. entName: this.state.companyName,
  144. pageNum: this.state.pageNo,
  145. pageSize: 10,
  146. },
  147. false,
  148. 2,
  149. );
  150. if (response) {
  151. if (response.code === 0) {
  152. this.setState({
  153. totalPage: response.data.pages,
  154. });
  155. this.setList(response.data.records);
  156. } else {
  157. this.setState({
  158. showFoot: 0,
  159. });
  160. await this.abnormalMessage(response);
  161. }
  162. }
  163. }
  164. };
  165. //清空搜索栏
  166. searchClear = async () => {
  167. await this.initData();
  168. };
  169. //设置抬头列表
  170. setList = (data) => {
  171. let listData = data.map((_, i) => ({
  172. userId: data[i].userId,
  173. entTaxId: data[i].entTaxId,
  174. entName: data[i].entName,
  175. roleId: data[i].roleId,
  176. roleMemo: data[i].roleMemo,
  177. }));
  178. let list = this.state.listData.concat(listData);
  179. if (list.length > 0) {
  180. this.setState({
  181. showFoot: 2,
  182. isLoading: false,
  183. listData: list,
  184. });
  185. } else {
  186. this.setState({
  187. showFoot: 0,
  188. isLoading: false,
  189. listData: list,
  190. });
  191. }
  192. };
  193. //切换当前绑定企业
  194. onChange = async (value) => {
  195. this.setState({loadingText: '切换中....'});
  196. this.setLoadingStatus(true);
  197. const token = await RetrieveData('token');
  198. const account = await RetrieveData('account');
  199. if (token && account) {
  200. const url = '/auth/comm/user/setDefaultChoose';
  201. let response = await RequestNetwork(
  202. url,
  203. token,
  204. {
  205. mobile: account,
  206. defaultChoose: value.item.entTaxId,
  207. reqChannel: 3,
  208. },
  209. false,
  210. 1,
  211. );
  212. if (response) {
  213. if (response.code === 0) {
  214. await IndividualStorageData(
  215. 'company',
  216. JSON.stringify(response.data.chooseEntity),
  217. );
  218. await IndividualStorageData('token', response.data.token);
  219. this.setLoadingStatus(false);
  220. this.setState({
  221. entItem: value,
  222. loadingText: 'loading....',
  223. });
  224. DeviceEventEmitter.emit('updateCompany', null);
  225. DeviceEventEmitter.emit('updatePersonal', true);
  226. DeviceEventEmitter.emit('updatePage', null);
  227. // this.props.route.params.getCompanyInfo();
  228. this.props.navigation.goBack();
  229. } else {
  230. this.setLoadingStatus(false);
  231. ToastShow(1, response.msg);
  232. }
  233. }
  234. }
  235. };
  236. //显示发票抬头列表
  237. renderItem = (data) => (
  238. <SwipeAction autoClose style={{backgroundColor: 'transparent'}}>
  239. <RadioItem
  240. key={data.item.entTaxId}
  241. checked={data.item.entTaxId === this.state.entItem.entTaxId}
  242. onChange={(event) => {
  243. if (event.target.checked) {
  244. this.onChange(data);
  245. }
  246. }}>
  247. {data.item.entName}
  248. </RadioItem>
  249. </SwipeAction>
  250. );
  251. // 设置load层是否显示
  252. setLoadingStatus = (isLoading) => {
  253. this.setState({
  254. spinner: isLoading,
  255. });
  256. };
  257. // 处理网络请求数据
  258. abnormalMessage = async (jason) => {
  259. if (jason.code === 401) {
  260. await Alert.alert(
  261. '登录失效',
  262. '登录状态已失效,请重新登录!',
  263. [
  264. {
  265. text: '确定',
  266. onPress: () => {
  267. CleanAll();
  268. this.props.navigation.popToTop();
  269. },
  270. },
  271. ],
  272. {cancelable: false},
  273. );
  274. }
  275. if (jason.code === 403) {
  276. Alert.alert(
  277. '权限',
  278. '暂无权限操作此模块!',
  279. [
  280. {
  281. text: '确定',
  282. onPress: () => {
  283. this.props.navigation.goBack();
  284. },
  285. },
  286. ],
  287. {cancelable: false},
  288. );
  289. }
  290. if (jason.code !== 401 && jason.code !== 403) {
  291. ToastShow(1, jason.msg);
  292. }
  293. };
  294. }