invoice_product_list_add.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Text,
  5. Dimensions,
  6. FlatList,
  7. ActivityIndicator,
  8. RefreshControl,
  9. Alert,
  10. } from 'react-native';
  11. import {List, SearchBar, SwipeAction} from '@ant-design/react-native';
  12. import {RetrieveData} from '../../data/storage';
  13. import {GetDataPost} from '../../data/encryption';
  14. import public_css from '../../source/css/public_css';
  15. import invoice_css from './invoice_css';
  16. let pageNo = 1; //当前页码
  17. let totalPage = 5; //总的页数
  18. let pageSize = 10; //每页数量
  19. export default class invoice_product_list_add extends Component {
  20. constructor(props) {
  21. super(props);
  22. this.state = {
  23. listData: [],
  24. productName: '',
  25. showFoot: 0, // 控制foot, 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中
  26. isLoading: false,
  27. };
  28. }
  29. render() {
  30. return (
  31. <View style={public_css.body}>
  32. <View
  33. style={{
  34. width: Dimensions.get('window').width,
  35. alignItems: 'center',
  36. justifyContent: 'center',
  37. backgroundColor: '#ffffff',
  38. height: 50,
  39. }}>
  40. <SearchBar
  41. placeholder="搜索"
  42. value={this.state.productName}
  43. onCancel={() => this.searchClear()}
  44. onChange={value => this.searchData(value)}
  45. showCancelButton={false}
  46. style={{borderRadius: 15}}
  47. />
  48. </View>
  49. <View style={invoice_css.list_view}>
  50. <Text style={invoice_css.list_title_text}>产品名称</Text>
  51. <Text sstyle={invoice_css.list_title_text}>规格型号</Text>
  52. <Text style={invoice_css.list_title_text}>单价</Text>
  53. <Text style={invoice_css.list_title_text}>税率(%)</Text>
  54. </View>
  55. <View style={{height: Dimensions.get('window').height}}>
  56. <FlatList
  57. data={this.state.listData}
  58. renderItem={item => this.renderItem(item)}
  59. refreshControl={
  60. <RefreshControl
  61. title={'加载中...'}
  62. colors={['#B7B7B7']} //此颜色无效
  63. tintColor={'#B7B7B7'}
  64. titleColor={'#B7B7B7'} //只有ios有效
  65. refreshing={this.state.isLoading}
  66. onRefresh={() => {
  67. this.initData();
  68. }}
  69. />
  70. }
  71. ListFooterComponent={this._renderFooter.bind(this)}
  72. onEndReached={this._onEndReached.bind(this)}
  73. onEndReachedThreshold={0.1}
  74. />
  75. </View>
  76. </View>
  77. );
  78. }
  79. //页面渲染完成后加载
  80. componentDidMount(): void {
  81. pageNo = 1;
  82. this.setState({
  83. listData: [],
  84. productName: '',
  85. showFoot: 0,
  86. });
  87. this.getProductList();
  88. }
  89. //搜索
  90. searchData = text => {
  91. pageNo = 1;
  92. this.setState({
  93. listData: [],
  94. productName: text,
  95. showFoot: 0,
  96. });
  97. this.getProductList();
  98. };
  99. //初始化数据
  100. initData = () => {
  101. pageNo = 1;
  102. this.setState({
  103. listData: [],
  104. productName: '',
  105. showFoot: 0,
  106. isLoading: false,
  107. });
  108. this.getProductList();
  109. };
  110. //清空搜索栏
  111. searchClear = () => {
  112. this.initData();
  113. };
  114. //获取当前账户下企业税号
  115. getProductList = async () => {
  116. let token = await RetrieveData('token');
  117. let account = await RetrieveData('account');
  118. let ents = await RetrieveData('defaultEnt');
  119. if (token && account && ents) {
  120. token = token.substring(1, token.length - 1);
  121. account = account.substring(1, account.length - 1);
  122. let ent = JSON.parse(ents);
  123. const url = '/sys/product/findPage';
  124. GetDataPost(
  125. url,
  126. token,
  127. {
  128. mobile: account,
  129. reqChannel: 3,
  130. entTaxIds: ent.entTaxId,
  131. pageNum: pageNo,
  132. pageSize: pageSize,
  133. productName: this.state.productName,
  134. },
  135. false,
  136. 2,
  137. ).then(res => {
  138. if (res) {
  139. totalPage = res.data.pages;
  140. this.setList(res.data.records);
  141. if (res.data.records.length == 0 || res.data == null) {
  142. Alert.alert(
  143. '商品信息为空',
  144. '请先在【商品管理】中添加商品信息,再进行开票操作!',
  145. [
  146. {
  147. text: '取消',
  148. onPress: () => console.log('Cancel Pressed'),
  149. style: 'cancel',
  150. },
  151. {text: '确定', onPress: () => console.log('submit')},
  152. ],
  153. {cancelable: false},
  154. );
  155. }
  156. }
  157. });
  158. }
  159. };
  160. //加载产品列表
  161. setList = data => {
  162. let listDatas = data.map((_, i) => ({
  163. key: data[i].productId, //产品Id
  164. FPHXZ: '0', //发票行性质 0正常行 1折扣行 2被折扣行 必填
  165. SPBM: data[i].taxationCateCode, //商品编码
  166. ZXBM: data[i].productCode, //自行编码
  167. YHZCBS: '', //优惠政策标识 0不使用 1使用
  168. LSLBS: '', //零税率标识
  169. ZZSTSGL: '', //增值税特殊管理
  170. XMMC: data[i].productName, //项目名称 必填
  171. DW: data[i].unit, //计量单位
  172. GGXH: data[i].specsModel, //规格型号
  173. XMSL: '', //项目数量
  174. XMDJ: data[i].price, //项目单价
  175. XMJE: '', //项目金额 不含税
  176. SL: data[i].taxRate, //税率 必填
  177. SE: '', //税额 必填
  178. }));
  179. let list = this.state.listData.concat(listDatas);
  180. this.setState({
  181. showFoot: 0,
  182. listData: list,
  183. });
  184. };
  185. //加载列表item
  186. renderItem = data => (
  187. <SwipeAction
  188. autoClose
  189. style={{
  190. backgroundColor: 'transparent',
  191. width: Dimensions.get('window').width,
  192. }}>
  193. <List.Item
  194. onPress={() => {
  195. this.props.navigation.navigate('invoice_product_number', data.item);
  196. }}
  197. style={{display: 'flex'}}>
  198. <View style={{flexDirection: 'row', justifyContent: 'space-around'}}>
  199. <Text
  200. style={invoice_css.list_item_text}
  201. ellipsizeMode={'tail'}
  202. numberOfLines={2}>
  203. {data.item.XMMC}{' '}
  204. </Text>
  205. <Text style={invoice_css.list_item_text}>{data.item.GGXH}</Text>
  206. <Text style={invoice_css.list_item_text}>{data.item.XMDJ}</Text>
  207. <Text style={invoice_css.list_item_text}>{data.item.SL}</Text>
  208. </View>
  209. </List.Item>
  210. </SwipeAction>
  211. );
  212. //加载列表尾部
  213. _renderFooter() {
  214. if (this.state.showFoot === 1) {
  215. return (
  216. <View
  217. style={{
  218. height: 30,
  219. alignItems: 'center',
  220. justifyContent: 'flex-start',
  221. }}>
  222. <Text
  223. style={{
  224. color: '#999999',
  225. fontSize: 14,
  226. marginTop: 5,
  227. marginBottom: 5,
  228. }}>
  229. 没有更多数据了
  230. </Text>
  231. </View>
  232. );
  233. } else if (this.state.showFoot === 2) {
  234. return (
  235. <View style={invoice_css.footer}>
  236. <ActivityIndicator />
  237. <Text>正在加载更多数据...</Text>
  238. </View>
  239. );
  240. } else if (this.state.showFoot === 0) {
  241. return (
  242. <View style={invoice_css.footer}>
  243. <Text />
  244. </View>
  245. );
  246. }
  247. }
  248. //列表上拉加载
  249. _onEndReached() {
  250. if (this.state.showFoot == 0) {
  251. if (pageNo >= totalPage) {
  252. this.setState({showFoot: 1});
  253. return;
  254. } else {
  255. pageNo++;
  256. this.setState({showFoot: 2});
  257. this.getProductList();
  258. }
  259. }
  260. }
  261. }