invoice_drawer.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Text,
  5. FlatList,
  6. RefreshControl,
  7. Alert,
  8. SafeAreaView, TouchableOpacity,
  9. } from "react-native";
  10. import { List, SearchBar, SwipeAction } from "@ant-design/react-native";
  11. import {RetrieveData} from '../../../data/storage';
  12. import {RequestNetwork} from '../../../data/encryption';
  13. import public_css from '../../../source/css/public_css';
  14. import {Footer} from '../../../components/listPage/pagination';
  15. import {CleanAll} from '../../../components/abnormalMessage/abnormal_message';
  16. import {ToastShow} from '../../../components/toast/toast';
  17. import LinearGradient from "react-native-linear-gradient";
  18. import Icon from "react-native-vector-icons/Ionicons";
  19. import customer_css from "../customerInformation/customer_css";
  20. import ActionButton from "react-native-action-button";
  21. let pageNo = 1; //当前页码
  22. let totalPage = 5; //总的页数
  23. let pageSize = 10; //每页数量
  24. export default class invoice_drawer extends Component {
  25. constructor(props) {
  26. super(props);
  27. this.props.navigation.dangerouslyGetParent().setOptions({
  28. tabBarVisible: false,
  29. });
  30. this.state = {
  31. listData: [],
  32. productName: '',
  33. showFoot: 0, // 控制foot, 0:无数据 1:加载中 2 :上拉加载
  34. isLoading: false,
  35. };
  36. }
  37. render() {
  38. return (
  39. <SafeAreaView style={public_css.body}>
  40. <View style={public_css.search}>
  41. <SearchBar
  42. placeholder="搜索"
  43. value={this.state.productName}
  44. onCancel={() => this.searchClear()}
  45. onChange={(value) => this.searchData(value)}
  46. showCancelButton={false}
  47. style={{borderRadius: 15}}
  48. />
  49. </View>
  50. <FlatList
  51. data={this.state.listData}
  52. renderItem={(item) => this.renderItem(item)}
  53. onRefresh={this.initData.bind(this)}
  54. refreshing={this.state.isLoading}
  55. refreshControl={
  56. <RefreshControl
  57. title={'加载中...'}
  58. colors={['#B7B7B7']} //此颜色无效
  59. tintColor={'#B7B7B7'}
  60. titleColor={'#B7B7B7'} //只有ios有效
  61. refreshing={this.state.isLoading}
  62. onRefresh={() => {
  63. this.initData();
  64. }}
  65. />
  66. }
  67. ListFooterComponent={() => Footer(this.state.showFoot)}
  68. onEndReached={() => this.onEndReached()}
  69. onEndReachedThreshold={0.1}
  70. />
  71. <ActionButton
  72. buttonColor="rgba(50,100,235,1)"
  73. onPress={() => {
  74. this.props.navigation.navigate('invoice_drawer_add_or_edit', {
  75. dataStatus: 0,
  76. refresh: () => {
  77. this.refresh();
  78. },
  79. });
  80. }}
  81. renderIcon={() => (
  82. <Icon name="md-add-outline" style={customer_css.actionButtonIcon} />
  83. )}
  84. />
  85. </SafeAreaView>
  86. );
  87. }
  88. //页面渲染完成后加载
  89. async componentDidMount(): void {
  90. pageNo = 1;
  91. this.setState({
  92. listData: [],
  93. productName: '',
  94. showFoot: 1,
  95. });
  96. await this.getUserList();
  97. }
  98. //搜索
  99. searchData = async (text) => {
  100. pageNo = 1;
  101. this.setState({
  102. listData: [],
  103. productName: text,
  104. showFoot: 0,
  105. });
  106. await this.getUserList();
  107. };
  108. //初始化数据
  109. initData = async () => {
  110. pageNo = 1;
  111. this.setState({
  112. listData: [],
  113. productName: '',
  114. showFoot: 1,
  115. isLoading: true,
  116. });
  117. await this.getUserList();
  118. };
  119. //清空搜索栏
  120. searchClear = async () => {
  121. await this.initData();
  122. };
  123. //获取产品列表
  124. getUserList = async () => {
  125. let token = await RetrieveData('token');
  126. let account = await RetrieveData('account');
  127. let company = JSON.parse(await RetrieveData('company'));
  128. if (token && account) {
  129. const url = '/auth/ent/user/findEntUserRoleInfo';
  130. let res = await RequestNetwork(
  131. url,
  132. token,
  133. {
  134. mobile: account,
  135. entTaxId: company.entTaxId,
  136. entUserMobile: this.state.productName,
  137. pageNum: pageNo,
  138. pageSize: pageSize,
  139. },
  140. false,
  141. 2,
  142. );
  143. if (res) {
  144. if (res.code === 0) {
  145. totalPage = res.data.pages;
  146. this.setList(res.data.records);
  147. } else {
  148. this.setState({
  149. showFoot: 0,
  150. });
  151. await this.abnormalMessage(res);
  152. }
  153. }
  154. }
  155. };
  156. //加载产品列表
  157. setList = (data) => {
  158. let listDatas = data.map((_, i) => ({
  159. key: data[i].userId, //产品Id
  160. userMobile: data[i].userMobile,
  161. userName: data[i].userName,
  162. userEmail: data[i].userEmail,
  163. defaultChoose: data[i].defaultChoose,
  164. createTime: data[i].createTime,
  165. roleId: data[i].roleId,
  166. roleMemo: data[i].roleMemo,
  167. firstName: data[i].userName.charAt(0),
  168. }));
  169. let list = this.state.listData.concat(listDatas);
  170. if (list.length > 0) {
  171. this.setState({
  172. showFoot: 2,
  173. isLoading: false,
  174. listData: list,
  175. });
  176. } else {
  177. this.setState({
  178. showFoot: 0,
  179. isLoading: false,
  180. listData: list,
  181. });
  182. }
  183. };
  184. //加载列表item
  185. renderItem = (data) => (
  186. <SwipeAction
  187. autoClose
  188. style={{backgroundColor: 'transparent'}}>
  189. <List.Item
  190. onPress={() => {
  191. this.props.navigation.navigate('invoice_drawer_add_or_edit', {
  192. dataStatus: 1,
  193. data: data,
  194. refresh: () => {
  195. this.refresh();
  196. },
  197. });
  198. }}
  199. style={{display: 'flex', backgroundColor: '#F7F7F7'}}>
  200. <View style={{flex: 1, backgroundColor: '#ffffff', flexDirection: 'row', height: 70}}>
  201. <View style={{flex: 1, flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', marginLeft: 10}}>
  202. <View>
  203. <LinearGradient
  204. colors={['#2A67FE', '#4F81FA']}
  205. style={{width: 40, height: 40, justifyContent: 'center', alignItems: 'center', borderRadius: 40}}
  206. start={{x: 0.25, y: 0.25}}
  207. end={{x: 0.7, y: 0.7}}>
  208. <Text style={{color: '#FFFFFF', fontSize: 15}}>{data.item.firstName}</Text>
  209. </LinearGradient>
  210. </View>
  211. <View>
  212. <Text
  213. style={{
  214. color: '#333333',
  215. fontWeight: 'bold',
  216. fontSize: 18,
  217. marginLeft: 10,
  218. }}>
  219. {data.item.userName}
  220. </Text>
  221. <Text
  222. style={{
  223. color: '#838383',
  224. fontSize: 15,
  225. marginLeft: 10,
  226. marginTop: 5,
  227. }}>
  228. {data.item.userMobile}
  229. </Text>
  230. </View>
  231. </View>
  232. <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
  233. <View
  234. style={{
  235. alignItems: 'center',
  236. padding: 5,
  237. backgroundColor: '#E1E9FF',
  238. width: 105,
  239. height: 27,
  240. justifyContent: 'center',
  241. borderRadius: 99,
  242. }}>
  243. <Text style={{color: '#5284FF', fontSize: 14}}>{data.item.roleMemo}</Text>
  244. </View>
  245. </View>
  246. </View>
  247. </List.Item>
  248. </SwipeAction>
  249. );
  250. //列表上拉加载
  251. onEndReached = async () => {
  252. if (this.state.showFoot === 2) {
  253. if (pageNo >= totalPage) {
  254. this.setState({showFoot: 0});
  255. return;
  256. } else {
  257. pageNo++;
  258. this.setState({showFoot: 1});
  259. await this.getUserList();
  260. }
  261. }
  262. };
  263. // 刷新列表
  264. refresh = async () => {
  265. await this.initData();
  266. };
  267. // 处理网络请求数据
  268. abnormalMessage = async (jason) => {
  269. if (jason.code === 401) {
  270. await Alert.alert(
  271. '登录失效',
  272. '登录状态已失效,请重新登录!',
  273. [
  274. {
  275. text: '确定',
  276. onPress: () => {
  277. CleanAll();
  278. this.props.navigation.popToTop();
  279. },
  280. },
  281. ],
  282. {cancelable: false},
  283. );
  284. }
  285. if (jason.code === 403) {
  286. Alert.alert(
  287. '权限',
  288. '暂无权限操作此模块!',
  289. [
  290. {
  291. text: '确定',
  292. onPress: () => {
  293. this.props.navigation.goBack();
  294. },
  295. },
  296. ],
  297. {cancelable: false},
  298. );
  299. }
  300. if (jason.code !== 401 && jason.code !== 403) {
  301. ToastShow(1, jason.msg);
  302. }
  303. };
  304. }