home_page.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. import React, {Component} from 'react';
  2. import {
  3. Image,
  4. StyleSheet,
  5. Dimensions,
  6. ImageBackground,
  7. TouchableOpacity,
  8. ScrollView,
  9. Text,
  10. View,
  11. DeviceEventEmitter,
  12. } from 'react-native';
  13. import {GetDataPost} from '../../data/encryption';
  14. import {IndividualStorageData, RetrieveData} from '../../data/storage';
  15. import {ShowToast} from '../../components/rootToast/root_toast';
  16. export default class home_page extends Component {
  17. constructor(props) {
  18. super(props);
  19. this.state = {
  20. name: '',
  21. info: '',
  22. totalAmt: 0.0,
  23. totalTaxes: 0.0,
  24. sumNum: 0.0,
  25. authority: '',
  26. landingStatus: 0, //登录状态,0:表示未登录,1:表示已登录
  27. curCompany: '首页',
  28. };
  29. this.fetchDefaultEnt();
  30. }
  31. componentDidMount() {
  32. this.getAuthority();
  33. // 收到监听
  34. this.listener = DeviceEventEmitter.addListener('updateCurMon', message => {
  35. // 收到监听后想做的事情 // 监听
  36. this.fetchDefaultEnt();
  37. //this.getKPStatsMonth();
  38. });
  39. }
  40. componentWillUnmount() {
  41. // 移除监听
  42. if (this.listener) {
  43. this.listener.remove();
  44. }
  45. this.setState = (state, callback) => {
  46. return;
  47. };
  48. }
  49. render() {
  50. return (
  51. <View>
  52. <ScrollView style={styles.homePageBak}>
  53. <View style={styles.topImgBak}>
  54. <ImageBackground
  55. style={styles.topImg}
  56. source={require('../../source/img/homeImg/topbak.png')}
  57. resizeMode="cover">
  58. <View style={styles.topImgTxt}>
  59. <Text style={styles.ydkpTxt}>移动开票</Text>
  60. <Text style={styles.ydkpTips}>省时省心</Text>
  61. <Text style={styles.ydkpTips}>您身边的开票小能手</Text>
  62. </View>
  63. <View style={styles.whiteSpaces} />
  64. </ImageBackground>
  65. </View>
  66. <View style={styles.taxItemBak}>
  67. <View style={styles.tapBtnBak}>
  68. {this.state.landingStatus === 1 ? (
  69. this.state.authority.includes('sys:invoice:add') ? (
  70. <TouchableOpacity
  71. style={styles.tapBtnBakCol}
  72. onPress={() => {
  73. this.getLandingStatus(1);
  74. }}>
  75. <Image
  76. source={require('../../source/img/homeImg/taxManagement.png')}
  77. style={styles.tapBtnImg}
  78. />
  79. <Text style={styles.tapBtnTips}>发票管理</Text>
  80. </TouchableOpacity>
  81. ) : (
  82. <TouchableOpacity />
  83. )
  84. ) : (
  85. <TouchableOpacity
  86. style={styles.tapBtnBakCol}
  87. onPress={() => {
  88. this.getLandingStatus(1);
  89. }}>
  90. <Image
  91. source={require('../../source/img/homeImg/taxManagement.png')}
  92. style={styles.tapBtnImg}
  93. />
  94. <Text style={styles.tapBtnTips}>发票管理</Text>
  95. </TouchableOpacity>
  96. )}
  97. {this.state.landingStatus === 1 ? (
  98. this.state.authority.includes('sys:product:view') ? (
  99. <TouchableOpacity
  100. style={styles.tapBtnBakCol}
  101. onPress={() => {
  102. this.getLandingStatus(2);
  103. }}>
  104. <Image
  105. source={require('../../source/img/homeImg/productManagement.png')}
  106. style={styles.tapBtnImg}
  107. />
  108. <Text style={styles.tapBtnTips}>商品管理</Text>
  109. </TouchableOpacity>
  110. ) : (
  111. <TouchableOpacity />
  112. )
  113. ) : (
  114. <TouchableOpacity
  115. style={styles.tapBtnBakCol}
  116. onPress={() => {
  117. this.getLandingStatus(2);
  118. }}>
  119. <Image
  120. source={require('../../source/img/homeImg/productManagement.png')}
  121. style={styles.tapBtnImg}
  122. />
  123. <Text style={styles.tapBtnTips}>商品管理</Text>
  124. </TouchableOpacity>
  125. )}
  126. {this.state.landingStatus === 1 ? (
  127. this.state.authority.includes('sys:customer:view') ? (
  128. <TouchableOpacity
  129. style={styles.tapBtnBakCol}
  130. onPress={() => {
  131. this.getLandingStatus(3);
  132. }}>
  133. <Image
  134. source={require('../../source/img/homeImg/userManagement.png')}
  135. style={styles.tapBtnImg}
  136. />
  137. <Text style={styles.tapBtnTips}>客户管理</Text>
  138. </TouchableOpacity>
  139. ) : (
  140. <TouchableOpacity />
  141. )
  142. ) : (
  143. <TouchableOpacity
  144. style={styles.tapBtnBakCol}
  145. onPress={() => {
  146. this.getLandingStatus(3);
  147. }}>
  148. <Image
  149. source={require('../../source/img/homeImg/userManagement.png')}
  150. style={styles.tapBtnImg}
  151. />
  152. <Text style={styles.tapBtnTips}>客户管理</Text>
  153. </TouchableOpacity>
  154. )}
  155. </View>
  156. <View style={styles.userOnlineBak}>
  157. <View style={styles.userOnlineLeft}>
  158. <Image
  159. source={require('../../source/img/homeImg/personNum.png')}
  160. style={{width: 16, height: 16}}
  161. />
  162. <Text style={{marginLeft: 5, color: '#8B7D7B'}}>
  163. 本企业当前在线人数...
  164. </Text>
  165. </View>
  166. <View style={styles.userOnlineRight}>
  167. <Text style={{color: 'blue', alignSelf: 'flex-end'}}>
  168. 999人
  169. </Text>
  170. </View>
  171. </View>
  172. </View>
  173. <View style={styles.yxTopicBak}>
  174. <View style={styles.yxTopicTop}>
  175. <View style={styles.userOnlineLeft}>
  176. <Image
  177. source={require('../../source/img/homeImg/service.png')}
  178. style={{width: 18, height: 18}}
  179. />
  180. <Text
  181. style={{
  182. marginLeft: 10,
  183. fontSize: 16,
  184. color: 'rgba(51, 51, 51, 1)',
  185. }}>
  186. 本月情况
  187. </Text>
  188. </View>
  189. <TouchableOpacity style={styles.userOnlineRight}>
  190. <Text style={{color: 'rgba(153, 153, 153, 1)', marginRight: 5}}>
  191. 查看全部
  192. </Text>
  193. <Image
  194. source={require('../../source/img/homeImg/go.png')}
  195. style={{marginTop: 3, width: 12, height: 12}}
  196. />
  197. </TouchableOpacity>
  198. </View>
  199. <View style={styles.yxTopicBottom}>
  200. <TouchableOpacity
  201. style={[styles.yxTopicItem, styles.yxTopicItem_2]}>
  202. <Text style={styles.yxTopicItemTextA}>开票总数</Text>
  203. {/*<Text style={styles.yxTopicItemTextB}>剩余发票数量</Text>*/}
  204. <Text style={styles.yxTopicItemTextC}>{this.state.sumNum}</Text>
  205. </TouchableOpacity>
  206. <TouchableOpacity
  207. style={[styles.yxTopicItem, styles.yxTopicItem_3]}>
  208. <Text style={styles.yxTopicItemTextA}>开票总额</Text>
  209. {/*<Text style={styles.yxTopicItemTextB}>待勾选发票数</Text>*/}
  210. <Text style={styles.yxTopicItemTextC}>
  211. {this.state.totalAmt}
  212. </Text>
  213. </TouchableOpacity>
  214. <TouchableOpacity
  215. style={[styles.yxTopicItem, styles.yxTopicItem_3]}>
  216. <Text style={styles.yxTopicItemTextA}>税额</Text>
  217. {/*<Text style={styles.yxTopicItemTextB}>待勾选发票数</Text>*/}
  218. <Text style={styles.yxTopicItemTextC}>
  219. {this.state.totalTaxes}
  220. </Text>
  221. </TouchableOpacity>
  222. </View>
  223. </View>
  224. <View style={styles.xpPushBak}>
  225. <View style={styles.xpPushTop}>
  226. <View style={styles.userOnlineLeft}>
  227. <Image
  228. source={require('../../source/img/homeImg/recommend.png')}
  229. style={{width: 18, height: 18}}
  230. />
  231. <Text
  232. style={{
  233. marginLeft: 10,
  234. fontSize: 16,
  235. color: 'rgba(51, 51, 51, 1)',
  236. }}>
  237. 新品推荐
  238. </Text>
  239. </View>
  240. <TouchableOpacity style={styles.userOnlineRight}>
  241. <Text style={{color: 'rgba(153, 153, 153, 1)', marginRight: 5}}>
  242. 查看全部
  243. </Text>
  244. <Image
  245. source={require('../../source/img/homeImg/go.png')}
  246. style={{marginTop: 3, width: 12, height: 12}}
  247. />
  248. </TouchableOpacity>
  249. </View>
  250. <View style={styles.xpPushBottom}>
  251. <View style={styles.xpPushItem}>
  252. <ImageBackground
  253. style={{
  254. height: '100%',
  255. width: '100%',
  256. borderRadius: 10,
  257. resizeMode: 'stretch',
  258. }}
  259. source={require('../../source/img/homeImg/item.png')}
  260. />
  261. </View>
  262. </View>
  263. </View>
  264. </ScrollView>
  265. </View>
  266. );
  267. }
  268. //首页数据获取
  269. getKPStatsMonth = async curEntId => {
  270. const res = await RetrieveData('token');
  271. const account = await RetrieveData('account');
  272. //const curEntId =await RetrieveData('defaultEnt');
  273. if (res && account) {
  274. let token = res.substring(1, res.length - 1);
  275. const url = '/sys/invoiceInfo/getKPStatsMonth';
  276. let response = await GetDataPost(
  277. url,
  278. token,
  279. {
  280. entTaxId: curEntId,
  281. },
  282. false,
  283. 2,
  284. );
  285. if (response.code != 0) {
  286. //console.log(response);
  287. this.setState({
  288. sumNum: 0.0,
  289. totalAmt: 0.0,
  290. totalTaxes: 0.0,
  291. });
  292. } else {
  293. this.setState({
  294. sumNum: response.data.cnt,
  295. totalAmt: response.data.totalAmt,
  296. totalTaxes: response.data.totalTaxes,
  297. });
  298. }
  299. }
  300. };
  301. 获取当前默认绑定企业;
  302. fetchDefaultEnt = async () => {
  303. //const defaultFirm =await RetrieveData('defaultEnt');
  304. //console.log( "default ent:" + JSON.stringify(defaultFirm));
  305. //console.log( "default ent:");
  306. const res = await RetrieveData('token');
  307. const account = await RetrieveData('account');
  308. if (res && account) {
  309. let token = res.substring(1, res.length - 1);
  310. let mobile = account.substring(1, account.length - 1);
  311. const url = '/auth/comm/user/findDefaultChoose';
  312. let response = await GetDataPost(
  313. url,
  314. token,
  315. {
  316. mobile: mobile,
  317. },
  318. false,
  319. 2,
  320. );
  321. if (response.code != 0) {
  322. ShowToast(response.msg);
  323. } else {
  324. this.setState({curCompany: response.data.entName});
  325. //console.log("当前默认绑定企业: "+JSON.stringify(response.data));
  326. await IndividualStorageData(
  327. 'defaultEnt',
  328. JSON.stringify(response.data),
  329. );
  330. await this.getKPStatsMonth(response.data.entTaxId);
  331. this.props.navigation.setOptions({
  332. headerTitleAlign: 'center',
  333. headerTitle: props => {
  334. return (
  335. <View
  336. style={{
  337. flexDirection: 'row',
  338. justifyContent: 'center',
  339. alignItems: 'center',
  340. }}>
  341. <Text style={{color: '#fff', fontSize: 16, fontWeight: '700'}}>
  342. {this.state.curCompany ? this.state.curCompany : '首页'}
  343. </Text>
  344. <TouchableOpacity
  345. onPress={async () => {
  346. const res = await RetrieveData('token');
  347. const account = await RetrieveData('account');
  348. if (res && account) {
  349. this.props.navigation.navigate('enterprise_list');
  350. } else {
  351. ShowToast('请先登录');
  352. }
  353. }}>
  354. <Image
  355. source={require('../../source/img/homeImg/change.png')}
  356. style={{marginLeft: 5, width: 14, height: 14}}
  357. />
  358. </TouchableOpacity>
  359. </View>
  360. );
  361. },
  362. headerStyle: {backgroundColor: '#00A2FE', borderWidth: 0},
  363. });
  364. }
  365. } else {
  366. this.setState({
  367. sumNum: 0.0,
  368. totalAmt: 0.0,
  369. totalTaxes: 0.0,
  370. curCompany: '首页',
  371. });
  372. this.props.navigation.setOptions({
  373. headerTitle: props => {
  374. //console.log("==="+ this.state.curCompany);
  375. return (
  376. <View
  377. style={{
  378. flexDirection: 'row',
  379. justifyContent: 'center',
  380. alignItems: 'flex-end',
  381. }}>
  382. <Text style={{color: '#fff', fontSize: 20, fontWeight: '600'}}>
  383. {this.state.curCompany ? this.state.curCompany : '首页'}
  384. </Text>
  385. </View>
  386. );
  387. },
  388. headerTintColor: '#fff',
  389. });
  390. }
  391. };
  392. //判断是否登录
  393. getLandingStatus = async type => {
  394. const account = await RetrieveData('account');
  395. if (account) {
  396. this.setState({
  397. landingStatus: 1,
  398. });
  399. if (type == 1) {
  400. this.props.navigation.navigate('invoice_product_list');
  401. }
  402. if (type == 2) {
  403. this.props.navigation.navigate('product_infos');
  404. }
  405. if (type == 3) {
  406. this.props.navigation.navigate('customer_information');
  407. }
  408. } else {
  409. this.setState({
  410. landingStatus: 0,
  411. });
  412. this.props.navigation.navigate('login_head');
  413. }
  414. };
  415. //获取权限信息
  416. getAuthority = async () => {
  417. const authority = await RetrieveData('authority');
  418. if (authority) {
  419. this.setState({
  420. authority: authority,
  421. landingStatus: 1,
  422. });
  423. }
  424. };
  425. }
  426. const styles = StyleSheet.create({
  427. homePageBak: {
  428. flexDirection: 'column',
  429. },
  430. topImgBak: {
  431. height: 184,
  432. // backgroundColor: 'blue',
  433. },
  434. topImgTxt: {
  435. flex: 3,
  436. justifyContent: 'center',
  437. marginLeft: 40,
  438. },
  439. ydkpTxt: {
  440. fontSize: 32,
  441. color: '#fff',
  442. },
  443. ydkpTips: {
  444. marginTop: 10,
  445. fontSize: 12,
  446. color: '#fff',
  447. },
  448. topImg: {
  449. flex: 1,
  450. width: '100%',
  451. height: '100%',
  452. flexDirection: 'column',
  453. justifyContent: 'flex-end',
  454. },
  455. whiteSpaces: {
  456. height: 30,
  457. flexDirection: 'row',
  458. borderTopLeftRadius: Dimensions.get('window').width * 0.8,
  459. borderTopRightRadius: Dimensions.get('window').width * 0.8,
  460. backgroundColor: '#fff',
  461. // alignSelf: 'flex-end',
  462. },
  463. taxItemBak: {
  464. height: 145,
  465. backgroundColor: '#fff',
  466. flexDirection: 'column',
  467. // marginTop: 20,
  468. justifyContent: 'center',
  469. },
  470. tapBtnBak: {
  471. flex: 5,
  472. flexDirection: 'row',
  473. justifyContent: 'space-around',
  474. // alignItems: 'center',
  475. },
  476. tapBtnBakCol: {
  477. flexDirection: 'column',
  478. },
  479. tapBtnImg: {
  480. width: 53,
  481. height: 53,
  482. },
  483. userOnlineBak: {
  484. flex: 2,
  485. flexDirection: 'row',
  486. borderTopWidth: 1,
  487. borderTopColor: '#E0EEEE',
  488. alignItems: 'center',
  489. marginLeft: 10,
  490. marginRight: 10,
  491. },
  492. tapBtnTips: {
  493. marginTop: 10,
  494. color: '#000',
  495. },
  496. userOnlineLeft: {
  497. flex: 1,
  498. flexDirection: 'row',
  499. marginLeft: 10,
  500. },
  501. userOnlineRight: {
  502. flex: 1,
  503. marginRight: 10,
  504. flexDirection: 'row',
  505. justifyContent: 'flex-end',
  506. },
  507. yxTopicBak: {
  508. marginTop: 20,
  509. // height: 200,
  510. backgroundColor: '#fff',
  511. flexDirection: 'column',
  512. },
  513. yxTopicTop: {
  514. height: 45,
  515. flexDirection: 'row',
  516. borderBottomWidth: 1,
  517. borderBottomColor: '#E0EEEE',
  518. alignItems: 'center',
  519. marginLeft: 10,
  520. marginRight: 10,
  521. },
  522. yxTopicBottom: {
  523. // height: 260,
  524. flexDirection: 'row',
  525. // justifyContent: 'space-around',
  526. // alignItems: 'center',
  527. flexWrap: 'wrap',
  528. marginLeft: 10,
  529. marginRight: 10,
  530. marginBottom: 10,
  531. },
  532. yxTopicItem: {
  533. width: 120,
  534. height: 120,
  535. marginTop: 10,
  536. marginLeft: 5,
  537. marginRight: 5,
  538. justifyContent: 'center',
  539. alignItems: 'center',
  540. },
  541. yxTopicItem_1: {backgroundColor: 'rgba(116, 211, 255, 0.1)'},
  542. yxTopicItem_2: {backgroundColor: 'rgba(255, 82, 71, 0.1)'},
  543. yxTopicItem_3: {backgroundColor: 'rgba(200, 121, 255, 0.1)'},
  544. yxTopicItemTextA: {
  545. color: 'rgba(51, 51, 51, 1)',
  546. fontWeight: '600',
  547. fontFamily: 'MicrosoftYaHei',
  548. fontSize: 17,
  549. },
  550. yxTopicItemTextB: {
  551. color: 'rgba(102, 102, 102, 1)',
  552. fontFamily: 'MicrosoftYaHei',
  553. fontSize: 12,
  554. marginTop: 5,
  555. },
  556. yxTopicItemTextC: {
  557. color: 'rgba(255, 75, 67, 1)',
  558. fontWeight: '600',
  559. fontFamily: 'MicrosoftYaHei',
  560. fontSize: 24,
  561. marginTop: 11,
  562. },
  563. xpPushBak: {
  564. height: 292,
  565. marginTop: 20,
  566. backgroundColor: '#fff',
  567. flexDirection: 'column',
  568. },
  569. xpPushTop: {
  570. height: 45,
  571. flexDirection: 'row',
  572. borderBottomWidth: 1,
  573. borderBottomColor: '#E0EEEE',
  574. alignItems: 'center',
  575. marginLeft: 10,
  576. marginRight: 10,
  577. },
  578. xpPushBottom: {},
  579. xpPushItem: {
  580. height: 148,
  581. marginTop: 20,
  582. marginRight: 24,
  583. marginLeft: 24,
  584. borderRadius: 10,
  585. backgroundColor: 'red',
  586. },
  587. });