product_list_info.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Text,
  5. FlatList,
  6. RefreshControl,
  7. Alert,
  8. SafeAreaView,
  9. } from 'react-native';
  10. import {List, 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 {Footer} from '../listPage/pagination';
  15. import {CleanAll} from '../abnormalMessage/abnormal_message';
  16. import {ToastShow} from '../toast/toast';
  17. let pageNo = 1; //当前页码
  18. let totalPage = 5; //总的页数
  19. let pageSize = 10; //每页数量
  20. export default class product_list_info extends Component {
  21. constructor(props) {
  22. super(props);
  23. this.state = {
  24. status: this.props.route.params.status, // 请求页面类型: 1:手工开票页面, 2:购方开票 3:抬头开票
  25. listData: [],
  26. productName: '',
  27. showFoot: 0, // 控制foot, 0:无数据 1:加载中 2 :上拉加载
  28. isLoading: false,
  29. };
  30. }
  31. render() {
  32. return (
  33. <SafeAreaView style={public_css.body}>
  34. <View style={public_css.search}>
  35. <SearchBar
  36. placeholder="搜索"
  37. value={this.state.productName}
  38. onCancel={() => this.searchClear()}
  39. onChange={(value) => this.searchData(value)}
  40. showCancelButton={false}
  41. style={{borderRadius: 15}}
  42. />
  43. </View>
  44. <FlatList
  45. data={this.state.listData}
  46. renderItem={(item) => this.renderItem(item)}
  47. onRefresh={this.initData.bind(this)}
  48. refreshing={this.state.isLoading}
  49. refreshControl={
  50. <RefreshControl
  51. title={'加载中...'}
  52. colors={['#B7B7B7']} //此颜色无效
  53. tintColor={'#B7B7B7'}
  54. titleColor={'#B7B7B7'} //只有ios有效
  55. refreshing={this.state.isLoading}
  56. onRefresh={() => {
  57. this.initData();
  58. }}
  59. />
  60. }
  61. ListFooterComponent={() => Footer(this.state.showFoot)}
  62. onEndReached={() => this.onEndReached()}
  63. onEndReachedThreshold={0.1}
  64. />
  65. </SafeAreaView>
  66. );
  67. }
  68. //页面渲染完成后加载
  69. async componentDidMount(): void {
  70. pageNo = 1;
  71. this.setState({
  72. listData: [],
  73. productName: '',
  74. showFoot: 1,
  75. });
  76. await this.getProductList();
  77. }
  78. //搜索
  79. searchData = async (text) => {
  80. pageNo = 1;
  81. this.setState({
  82. listData: [],
  83. productName: text,
  84. showFoot: 0,
  85. });
  86. await this.getProductList();
  87. };
  88. //初始化数据
  89. initData = async () => {
  90. pageNo = 1;
  91. this.setState({
  92. listData: [],
  93. productName: '',
  94. showFoot: 1,
  95. isLoading: true,
  96. });
  97. await this.getProductList();
  98. };
  99. //清空搜索栏
  100. searchClear = async () => {
  101. await this.initData();
  102. };
  103. //获取产品列表
  104. getProductList = async () => {
  105. let token = await RetrieveData('token');
  106. let account = await RetrieveData('account');
  107. let company = JSON.parse(await RetrieveData('company'));
  108. if (token && account) {
  109. const url = '/sys/product/findPage';
  110. let res = await RequestNetwork(
  111. url,
  112. token,
  113. {
  114. mobile: account,
  115. reqChannel: 3,
  116. entTaxId: company.entTaxId,
  117. pageNum: pageNo,
  118. pageSize: pageSize,
  119. productName: this.state.productName,
  120. },
  121. false,
  122. 2,
  123. );
  124. if (res) {
  125. if (res.code === 0) {
  126. totalPage = res.data.pages;
  127. this.setList(res.data.records);
  128. } else {
  129. this.setState({
  130. showFoot: 0,
  131. });
  132. await this.abnormalMessage(res);
  133. }
  134. }
  135. }
  136. };
  137. //加载产品列表
  138. setList = (data) => {
  139. let listDatas = data.map((_, i) => ({
  140. key: data[i].productId, //产品Id
  141. SPHH: i,
  142. FPHXZ: '0', //发票行性质 0正常行 1折扣行 2被折扣行 必填
  143. SPBM: data[i].taxationCateCode, //商品编码
  144. ZXBM: data[i].productCode, //自行编码
  145. YHZCBS: data[i].preferentialFlag, //优惠政策标识 0不使用 1使用
  146. LSLBS: data[i].zeroRateFlag, //零税率标识
  147. ZZSTSGL: data[i].preferentialType, //增值税特殊管理
  148. XMMC: data[i].productName, //项目名称 必填
  149. DW: data[i].unit, //计量单位
  150. GGXH: data[i].specsModel, //规格型号
  151. XMSL: '', //项目数量
  152. XMDJ: data[i].price, //项目单价
  153. XMJE: '', //项目金额 不含税
  154. SL: data[i].taxRate, //税率 必填
  155. SE: '', //税额 必填
  156. }));
  157. let list = this.state.listData.concat(listDatas);
  158. if (list.length > 0) {
  159. this.setState({
  160. showFoot: 2,
  161. isLoading: false,
  162. listData: list,
  163. });
  164. } else {
  165. this.setState({
  166. showFoot: 0,
  167. isLoading: false,
  168. listData: list,
  169. });
  170. }
  171. };
  172. //加载列表item
  173. renderItem = (data) => (
  174. <List.Item
  175. onPress={() => {
  176. this.props.navigation.navigate('product_confirm', {
  177. data: data.item,
  178. status: this.state.status,
  179. });
  180. }}
  181. style={{display: 'flex', backgroundColor: '#F7F7F7'}}>
  182. <View style={{flex: 1, backgroundColor: '#ffffff'}}>
  183. <View style={{}}>
  184. <Text
  185. style={{
  186. color: '#050505',
  187. fontWeight: 'bold',
  188. fontSize: 18,
  189. marginLeft: 10,
  190. marginTop: 10,
  191. }}>
  192. {data.item.XMMC}
  193. </Text>
  194. <Text
  195. style={{
  196. color: '#B1B2B7',
  197. fontSize: 16,
  198. marginLeft: 10,
  199. marginTop: 10,
  200. }}>
  201. {data.item.SPBM}
  202. </Text>
  203. </View>
  204. <View style={{flexDirection: 'row', marginLeft: 10, marginTop: 10}}>
  205. <View
  206. style={{
  207. flexDirection: 'row',
  208. alignItems: 'center',
  209. backgroundColor: '#F4F5F9',
  210. borderRadius: 24,
  211. height: 25,
  212. margin: 5,
  213. }}>
  214. <View
  215. style={{flexDirection: 'row', alignItems: 'center', padding: 5}}>
  216. <Text style={{color: '#888888'}}>税率:</Text>
  217. <Text style={{color: '#888888'}}>{data.item.SL}</Text>
  218. </View>
  219. </View>
  220. <View
  221. style={{
  222. flexDirection: 'row',
  223. alignItems: 'center',
  224. backgroundColor: '#F4F5F9',
  225. borderRadius: 24,
  226. height: 25,
  227. margin: 5,
  228. }}>
  229. {data.item.GGXH === '' ? (
  230. <View
  231. style={{flexDirection: 'row', alignItems: 'center', padding: 5}}>
  232. <Text style={{color: '#888888'}}>规格:</Text>
  233. <Text style={{color: '#888888'}}>暂无</Text>
  234. </View>
  235. ) : (
  236. <View
  237. style={{flexDirection: 'row', alignItems: 'center', padding: 5}}>
  238. <Text style={{color: '#888888'}}>规格:</Text>
  239. <Text style={{color: '#888888'}}>{data.item.GGXH}</Text>
  240. </View>
  241. )}
  242. </View>
  243. <View
  244. style={{
  245. flexDirection: 'row',
  246. alignItems: 'center',
  247. backgroundColor: '#F4F5F9',
  248. borderRadius: 24,
  249. height: 25,
  250. margin: 5,
  251. }}>
  252. {data.item.DW === '' ? (
  253. <View
  254. style={{flexDirection: 'row', alignItems: 'center', padding: 5}}>
  255. <Text style={{color: '#888888'}}>计量单位:</Text>
  256. <Text style={{color: '#888888'}}>暂无</Text>
  257. </View>
  258. ) : (
  259. <View
  260. style={{flexDirection: 'row', alignItems: 'center', padding: 5}}>
  261. <Text style={{color: '#888888'}}>计量单位:</Text>
  262. <Text style={{color: '#888888'}}>{data.item.DW}</Text>
  263. </View>
  264. )}
  265. </View>
  266. </View>
  267. <View
  268. style={{
  269. borderTopWidth: 1,
  270. borderColor: '#E8E8E8',
  271. marginLeft: 5,
  272. marginRight: 5,
  273. }}
  274. />
  275. <View
  276. style={{
  277. flexDirection: 'row',
  278. justifyContent: 'space-between',
  279. margin: 10,
  280. }}>
  281. <Text style={{color: '#5F5F5F'}}>单价:</Text>
  282. <Text style={{color: '#2A67FE'}}>¥{data.item.XMDJ}</Text>
  283. </View>
  284. </View>
  285. </List.Item>
  286. );
  287. //列表上拉加载
  288. onEndReached = async () => {
  289. if (this.state.showFoot === 2) {
  290. if (pageNo >= totalPage) {
  291. this.setState({showFoot: 0});
  292. return;
  293. } else {
  294. pageNo++;
  295. this.setState({showFoot: 1});
  296. await this.getProductList();
  297. }
  298. }
  299. };
  300. // 处理网络请求数据
  301. abnormalMessage = async (jason) => {
  302. if (jason.code === 401) {
  303. await Alert.alert(
  304. '登录失效',
  305. '登录状态已失效,请重新登录!',
  306. [
  307. {
  308. text: '确定',
  309. onPress: () => {
  310. CleanAll();
  311. this.props.navigation.popToTop();
  312. },
  313. },
  314. ],
  315. {cancelable: false},
  316. );
  317. }
  318. if (jason.code === 403) {
  319. Alert.alert(
  320. '权限',
  321. '暂无权限操作此模块!',
  322. [
  323. {
  324. text: '确定',
  325. onPress: () => {
  326. this.props.navigation.goBack();
  327. },
  328. },
  329. ],
  330. {cancelable: false},
  331. );
  332. }
  333. if (jason.code !== 401 && jason.code !== 403) {
  334. ToastShow(1, jason.msg);
  335. }
  336. };
  337. }