invoice_head_product_add.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 {GetDataPost} 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. token = token.substring(1, token.length - 1);
  120. account = account.substring(1, account.length - 1);
  121. let ent = JSON.parse(ents);
  122. const url = '/sys/product/findPage';
  123. GetDataPost(
  124. url,
  125. token,
  126. {
  127. mobile: account,
  128. reqChannel: 3,
  129. entTaxIds: ent.entTaxId,
  130. pageNum: pageNo,
  131. pageSize: pageSize,
  132. productName: this.state.productName,
  133. },
  134. false,
  135. 2,
  136. ).then(res => {
  137. if (res) {
  138. totalPage = res.data.pages;
  139. this.setList(res.data.records);
  140. }
  141. });
  142. }
  143. };
  144. //加载产品列表
  145. setList = data => {
  146. let listDatas = data.map((_, i) => ({
  147. key: data[i].productId, //产品Id
  148. FPHXZ: '0', //发票行性质 0正常行 1折扣行 2被折扣行 必填
  149. SPBM: data[i].taxationCateCode, //商品编码
  150. ZXBM: '', //自行编码
  151. YHZCBS: '', //优惠政策标识 0不使用 1使用
  152. LSLBS: '', //零税率标识
  153. ZZSTSGL: '', //增值税特殊管理
  154. XMMC: data[i].productName, //项目名称 必填
  155. DW: data[i].unit, //计量单位
  156. GGXH: data[i].specsModel, //规格型号
  157. XMSL: '', //项目数量
  158. XMDJ: data[i].price, //项目单价
  159. XMJE: '', //项目金额 不含税
  160. SL: data[i].taxRate, //税率 必填
  161. SE: '', //税额 必填
  162. BY1: '', //备用字段1
  163. BY2: '', //备用字段2
  164. BY3: '', //备用字段3
  165. BY4: '', //备用字段4
  166. BY5: '', //备用字段5
  167. }));
  168. let list = this.state.listData.concat(listDatas);
  169. this.setState({
  170. showFoot: 0,
  171. listData: list,
  172. });
  173. };
  174. //加载列表item
  175. renderItem = data => (
  176. <SwipeAction
  177. autoClose
  178. style={{
  179. backgroundColor: 'transparent',
  180. width: Dimensions.get('window').width,
  181. }}>
  182. <List.Item
  183. onPress={() => {
  184. this.props.navigation.navigate(
  185. 'invoice_head_product_number',
  186. data.item,
  187. );
  188. }}
  189. style={{display: 'flex'}}>
  190. <View style={{flexDirection: 'row', justifyContent: 'space-around'}}>
  191. <Text
  192. style={invoice_head_css.list_item_text}
  193. ellipsizeMode={'tail'}
  194. numberOfLines={2}>
  195. {data.item.XMMC}{' '}
  196. </Text>
  197. <Text style={invoice_head_css.list_item_text}>{data.item.GGXH}</Text>
  198. <Text style={invoice_head_css.list_item_text}>{data.item.XMDJ}</Text>
  199. <Text style={invoice_head_css.list_item_text}>{data.item.SL}</Text>
  200. </View>
  201. </List.Item>
  202. </SwipeAction>
  203. );
  204. //加载列表尾部
  205. _renderFooter() {
  206. if (this.state.showFoot === 1) {
  207. return (
  208. <View
  209. style={{
  210. height: 30,
  211. alignItems: 'center',
  212. justifyContent: 'flex-start',
  213. }}>
  214. <Text
  215. style={{
  216. color: '#999999',
  217. fontSize: 14,
  218. marginTop: 5,
  219. marginBottom: 5,
  220. }}>
  221. 没有更多数据了
  222. </Text>
  223. </View>
  224. );
  225. } else if (this.state.showFoot === 2) {
  226. return (
  227. <View style={invoice_head_css.footer}>
  228. <ActivityIndicator />
  229. <Text>正在加载更多数据...</Text>
  230. </View>
  231. );
  232. } else if (this.state.showFoot === 0) {
  233. return (
  234. <View style={invoice_head_css.footer}>
  235. <Text />
  236. </View>
  237. );
  238. }
  239. }
  240. //列表上拉加载
  241. _onEndReached() {
  242. if (this.state.showFoot === 0) {
  243. if (pageNo >= totalPage) {
  244. this.setState({showFoot: 1});
  245. return;
  246. } else {
  247. pageNo++;
  248. this.setState({showFoot: 2});
  249. this.getProductList();
  250. }
  251. }
  252. }
  253. }