product_info.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. import React, {Component} from 'react';
  2. import {
  3. Animated,
  4. View,
  5. Image,
  6. TouchableHighlight,
  7. Text,
  8. StyleSheet,
  9. TextInput,
  10. FlatList,
  11. TouchableOpacity,
  12. ActivityIndicator,
  13. DeviceEventEmitter,
  14. } from 'react-native';
  15. import Spinner from 'react-native-loading-spinner-overlay';
  16. import ListView from '../../components/listView/list_view';
  17. import SearchBar from '../../components/searchBar/search_bar';
  18. import loading_css from '../../source/css/loading_css';
  19. import {GetDataPost} from '../../data/encryption';
  20. import {ShowToast} from '../../components/rootToast/root_toast';
  21. import {RetrieveData, StorageData} from '../../data/storage';
  22. //已废弃
  23. export default class product_info extends Component {
  24. constructor(props) {
  25. super(props);
  26. this.props.navigation.dangerouslyGetParent().setOptions({
  27. tabBarVisible: false,
  28. });
  29. this.state = {
  30. listViewData : [],
  31. productName: '',
  32. productCode: '',
  33. taxItem: '',
  34. specsModel: '',
  35. taxPriceFlag: '',
  36. entTaxIds: '',
  37. taxationCategoryName: '',
  38. preferentialFlag: '',
  39. mobile: '',
  40. reqChannel: 3,
  41. pageNum: 1, //当前页码
  42. pageSize: 10, //每页数量
  43. reflag: false,
  44. showFoot: 0,
  45. spinner: true,
  46. fetctFlag: 0, //是否第一次请求
  47. }
  48. //this._fetchData();
  49. this._fetchData();
  50. }
  51. componentDidMount() {
  52. // 收到监听
  53. this.listener = DeviceEventEmitter.addListener('updatePage', (message) => {
  54. // 收到监听后想做的事情 // 监听
  55. this._fetchData();
  56. });
  57. }
  58. componentWillUnmount() {
  59. // 移除监听
  60. if (this.listener) { this.listener.remove(); }
  61. this.setState = (state,callback)=>{
  62. return;
  63. }
  64. }
  65. //获取数据
  66. _fetchData = async () => {
  67. if (0 === this.state.fetctFlag) {
  68. this.setLoadingStatus(true);
  69. } else {
  70. this.setState({
  71. reflag: true
  72. });
  73. }
  74. const res = await RetrieveData('token');
  75. const account = await RetrieveData('account');
  76. if (res && account) {
  77. let token = res.substring(1, res.length - 1);
  78. let mobile = account.substring(1, account.length - 1);
  79. const url = '/sys/product/findPage';
  80. let response = await GetDataPost(
  81. url,
  82. token,
  83. {
  84. productName: this.state.productName,
  85. productCode: this.state.productCode,
  86. taxItem: this.state.taxItem,
  87. specsModel: this.state.specsModel,
  88. taxationCategoryName: this.state.taxationCategoryName,
  89. mobile: mobile,
  90. entTaxIds: this.state.entTaxIds,
  91. reqChannel: 3,
  92. pageNum: this.state.pageNum,
  93. pageSize: this.state.pageSize,
  94. },
  95. false,
  96. 2,
  97. );
  98. if (response.code != 0) {
  99. ShowToast(response.msg);
  100. this.setState({reflag: false});
  101. this.setLoadingStatus(false);
  102. } else {
  103. this.setState({
  104. listViewData: [].concat(response.data.records)
  105. });
  106. this.setState({reflag: false});
  107. this.setLoadingStatus(false);
  108. }
  109. }
  110. }
  111. //删除数据
  112. _fetchDeleteRow = async (item, index) => {
  113. this.setLoadingStatus(true);
  114. const res = await RetrieveData('token');
  115. const account = await RetrieveData('account');
  116. if (res && account) {
  117. let token = res.substring(1, res.length - 1);
  118. let mobile = account.substring(1, account.length - 1);
  119. let productInfos = {
  120. productId: item.productId,
  121. productCode: item.productCode,
  122. manageUserId: item.manageUserId
  123. };
  124. let list = [productInfos];
  125. //console.log(list);
  126. const url = '/sys/product/delete';
  127. let response = await GetDataPost(
  128. url,
  129. token,
  130. {
  131. delList: list,
  132. mobile: mobile,
  133. reqChannel: 3,
  134. ip: '192.168.1.2',
  135. },
  136. false,
  137. 1,
  138. );
  139. if (response.code != 0) {
  140. console.log(JSON.stringify(response));
  141. ShowToast(response);
  142. this.setLoadingStatus(false);
  143. } else {
  144. //console.log("序列号等于"+index);
  145. let list = this.state.listViewData;
  146. //console.log("删除之前列表数目:" + list.length);
  147. list.splice(index,1);
  148. //console.log("删除之后列表数目:" + list.length);
  149. this.setState({
  150. listViewData: list
  151. });
  152. ShowToast("删除成功!");
  153. this.setLoadingStatus(false);
  154. }
  155. }
  156. }
  157. //搜索数据
  158. _searchData = (text) => {
  159. this.setState({productName: text});
  160. this._fetchData();
  161. }
  162. setLoadingStatus = (isLoading) => {
  163. this.setState({
  164. spinner: isLoading,
  165. });
  166. }
  167. //列表末尾控制,若请求到的数据数据少于一页,则默认没有更多数据了
  168. _onEndReached() {
  169. if (10 >= this.state.listViewData.length) {
  170. this.setState({
  171. showFoot: 1,
  172. fetchFlag: 1
  173. });
  174. } else {
  175. this.setState({showFoot: 2});
  176. }
  177. }
  178. //每项列表分割线
  179. _itemSeparatorComponent() {
  180. return (<View style={{height:1,backgroundColor:'#696969'}}></View>);
  181. }
  182. //列表末尾控件
  183. _renderFooter(){
  184. if (this.state.showFoot === 1) {
  185. return (
  186. <View style={{height:30,alignItems:'center',justifyContent:'center',}}>
  187. <Text style={{color:'#999999',fontSize:14,marginTop:5,marginBottom:5,}}>
  188. 没有更多数据了
  189. </Text>
  190. </View>
  191. );
  192. } else if(this.state.showFoot === 2) {
  193. return (
  194. <View style={styles.footer}>
  195. <ActivityIndicator />
  196. <Text>正在加载...</Text>
  197. </View>
  198. );
  199. } else if(this.state.showFoot === 0){
  200. return (
  201. <View style={styles.footer}>
  202. <Text></Text>
  203. </View>
  204. );
  205. }
  206. }
  207. render() {
  208. return (
  209. <View>
  210. <Spinner
  211. visible={this.state.spinner}
  212. textContent={'Loading...'}
  213. textStyle={loading_css.spinnerTextStyle}
  214. />
  215. <View style={{flexDirection: 'column', display: 'flex', marginTop: 20, marginBottom: 100}}>
  216. <View>
  217. <SearchBar _searchData={this._searchData.bind(this)}/>
  218. </View>
  219. <View style={styles.cardList}>
  220. <FlatList
  221. data={this.state.listViewData}
  222. renderItem={({item, index}) => (
  223. <View style={styles.productCard}>
  224. <View style={styles.productCardItem1}>
  225. <Text style={styles.topTag}><Text style={styles.topTagName}>名称:</Text><Text>{item.productName}</Text></Text>
  226. <View style={styles.optIcons}>
  227. <TouchableOpacity
  228. style={[styles.backRightBtn, styles.backRightBtnLeft]}
  229. onPress={() => {
  230. this.props.navigation.navigate('product_edit', {
  231. datas: item,
  232. });
  233. }}>
  234. <Image source={require('../../source/img/productImg/edit1.png')} style={styles.trash}/>
  235. </TouchableOpacity>
  236. <TouchableOpacity
  237. onPress={this._fetchDeleteRow.bind(this, item, index)}
  238. >
  239. <Image source={require('../../source/img/productImg/delete.png')} style={styles.trash} />
  240. </TouchableOpacity>
  241. </View>
  242. </View>
  243. <View style={styles.productCardItem2}>
  244. <Text style={styles.centerTag} style={styles.tagLeft}><Text style={styles.topTagName}>单价:</Text>{item.price}</Text>
  245. <Text style={styles.centerTag} style={styles.tagRight}><Text style={styles.topTagName}>税率:</Text>{item.taxRate}</Text>
  246. </View>
  247. <View style={styles.productCardItem3}>
  248. <Text style={styles.centerTag} style={styles.tagLeft}><Text style={styles.topTagName}>规格:</Text>{item.specsModel}</Text>
  249. <Text style={styles.centerTag} style={styles.tagRight}><Text style={styles.topTagName}>计量单位:</Text>{item.unit}</Text>
  250. </View>
  251. <View style={styles.productCardItem4}>
  252. <Text style={styles.bottomTag}><Text style={styles.bottomTagName}>税收分类编码:</Text><Text style={styles.bottomBM}>{item.taxationCategoryCode}</Text></Text>
  253. </View>
  254. </View>
  255. )}
  256. onRefresh={this._fetchData}
  257. refreshing={this.state.reflag}
  258. ItemSeparatorComponent={this._itemSeparatorComponent}
  259. ListFooterComponent={this._renderFooter.bind(this)}
  260. onEndReached={this._onEndReached.bind(this)}
  261. onEndReachedThreshold={0.1}
  262. ></FlatList>
  263. </View>
  264. </View>
  265. </View>
  266. );
  267. }
  268. //刷新数据
  269. // _fetchRefreshData = async () => {
  270. // this._fetchData;
  271. // }
  272. }
  273. const styles = StyleSheet.create({
  274. container: {
  275. backgroundColor: 'white',
  276. flex: 1,
  277. },
  278. backTextWhite: {
  279. color: '#FFF',
  280. },
  281. cardList: {
  282. marginTop: 20
  283. },
  284. productCard: {
  285. flexDirection: 'column',
  286. height: 120,
  287. backgroundColor: '#ffffff',
  288. margin : 0,
  289. // borderRadius: 10,
  290. // borderWidth: 1,
  291. justifyContent: 'space-around'
  292. },
  293. productCardItem1: {
  294. flexDirection: 'row',
  295. marginTop: 8,
  296. marginLeft: 30,
  297. marginRight: 30,
  298. marginBottom: 15,
  299. // flex: 3,
  300. },
  301. productCardItem2: {
  302. flexDirection: 'row',
  303. marginLeft: 40,
  304. // justifyContent: 'space-around'
  305. // flex: 2,
  306. },
  307. productCardItem3: {
  308. flexDirection: 'row',
  309. marginLeft: 40,
  310. // justifyContent: 'space-around'
  311. // flex: 2,
  312. },
  313. productCardItem4: {
  314. flexDirection: 'row',
  315. justifyContent: 'flex-end',
  316. marginRight: 20,
  317. marginTop: 5,
  318. marginBottom: 5
  319. // flex: 1,
  320. },
  321. topTag: {
  322. flex: 1,
  323. fontSize: 16,
  324. fontWeight: "600"
  325. },
  326. centerTag: {
  327. fontSize: 12
  328. },
  329. bottomTag: {
  330. fontSize: 11,
  331. },
  332. tagLeft: {
  333. flex: 1,
  334. justifyContent: 'flex-start',
  335. },
  336. tagRight: {
  337. flex: 1,
  338. justifyContent: 'flex-start',
  339. },
  340. optIcons: {
  341. flex: 1,
  342. flexDirection: 'row',
  343. justifyContent: 'flex-end',
  344. },
  345. trash: {
  346. width: 24,
  347. height: 24,
  348. marginLeft: 5
  349. },
  350. topTagName: {
  351. fontSize: 14,
  352. color: '#1E90FF',
  353. },
  354. bottomTagName: {
  355. fontSize: 12,
  356. color: '#696969',
  357. },
  358. bottomBM: {
  359. color: '#000000',
  360. fontWeight: '800'
  361. }
  362. // trashSep: {
  363. // // marginRight: 10
  364. // }
  365. });