invoice_head_product_add.js 7.0 KB

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