invoice_qrcode_product_list.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Text,
  5. TouchableOpacity,
  6. FlatList,
  7. DeviceEventEmitter,
  8. Image,
  9. } from 'react-native';
  10. import {List, SwipeAction} from '@ant-design/react-native';
  11. import public_css from '../../source/css/public_css';
  12. import {RoundingData} from '../../source/inspect/inspect';
  13. import {ShowToast} from '../../components/rootToast/root_toast';
  14. import invoice_qrcode_css from './invoice_qrcode_css';
  15. export default class invoice_qrcode_product_list extends Component {
  16. constructor(props) {
  17. super(props);
  18. this.props.navigation.dangerouslyGetParent().setOptions({
  19. tabBarVisible: false,
  20. });
  21. this.state = {
  22. listData: [],
  23. product_number_total: 0,
  24. amount_total: 0.0,
  25. tax_rate_total: 0.0,
  26. };
  27. }
  28. render() {
  29. return (
  30. <View style={public_css.body}>
  31. <View style={invoice_qrcode_css.list_view}>
  32. <Text style={invoice_qrcode_css.list_title_text}>产品名称</Text>
  33. <Text style={invoice_qrcode_css.list_title_text}>产品数量</Text>
  34. <Text sstyle={invoice_qrcode_css.list_title_text}>规格型号</Text>
  35. <Text style={invoice_qrcode_css.list_title_text}>单价</Text>
  36. <Text style={invoice_qrcode_css.list_title_text}>税率(%)</Text>
  37. </View>
  38. <View style={{flex: 1}}>
  39. <FlatList
  40. data={this.state.listData}
  41. renderItem={item => this.renderItem(item)}
  42. />
  43. </View>
  44. <View
  45. style={{
  46. flexDirection: 'row',
  47. justifyContent: 'space-around',
  48. alignItems: 'center',
  49. height: 50,
  50. }}>
  51. <Text>共{this.state.product_number_total}个产品</Text>
  52. <Text>
  53. 开票金额:{RoundingData(parseFloat(this.state.amount_total))}元
  54. </Text>
  55. <Text>
  56. 税额:{RoundingData(parseFloat(this.state.tax_rate_total))}
  57. </Text>
  58. </View>
  59. <View style={[public_css.bottomStaus]}>
  60. <TouchableOpacity
  61. style={[public_css.statusBtn, public_css.statusRBtn]}
  62. onPress={() => this.submitData()}>
  63. <Image
  64. source={require('../../source/img/productImg/confirm.png')}
  65. style={{width: 32, height: 32}}
  66. />
  67. <Text style={{color: '#fff'}}>下一步</Text>
  68. </TouchableOpacity>
  69. </View>
  70. </View>
  71. );
  72. }
  73. componentDidMount(): void {
  74. //收到监听
  75. this.listener = DeviceEventEmitter.addListener('扫码开票', data => {
  76. //收到监听后想做的事情
  77. this.setList(data);
  78. });
  79. }
  80. componentWillUnmount() {
  81. //移除监听
  82. if (this.listener) {
  83. this.listener.remove();
  84. }
  85. }
  86. selectProduct = () => {
  87. this.setState({
  88. productVisible: !this.state.productVisible,
  89. });
  90. };
  91. //提交数据到下一步
  92. submitData = () => {
  93. if (this.state.listData.length > 0) {
  94. this.props.navigation.navigate('invoice_qrcode', this.state);
  95. } else {
  96. ShowToast('开票产品信息不能为空!');
  97. }
  98. };
  99. //加载list列表
  100. setList = data => {
  101. let numberTotal =
  102. parseInt(this.state.product_number_total) + parseInt(data.XMSL);
  103. let taxRateTotal = this.state.tax_rate_total + parseFloat(data.SE);
  104. let amountTotal =
  105. this.state.amount_total + parseFloat(data.XMJE) + parseFloat(data.SE);
  106. let list = this.state.listData.concat(data);
  107. this.setState({
  108. listData: list,
  109. amount_total: amountTotal,
  110. tax_rate_total: taxRateTotal,
  111. product_number_total: numberTotal,
  112. });
  113. };
  114. //加载items
  115. renderItem = data => (
  116. <SwipeAction
  117. autoClose
  118. style={{backgroundColor: 'transparent'}}
  119. right={this.right(data)}>
  120. <List.Item>
  121. <View style={{flexDirection: 'row', justifyContent: 'space-around'}}>
  122. <Text>{data.item.XMMC} </Text>
  123. <Text>{data.item.XMSL} </Text>
  124. <Text>{data.item.GGXH}</Text>
  125. <Text>{data.item.XMDJ}</Text>
  126. <Text>{data.item.SL * 100}</Text>
  127. </View>
  128. </List.Item>
  129. </SwipeAction>
  130. );
  131. //左滑删除
  132. right = data => [
  133. {
  134. text: '删除',
  135. onPress: () => {
  136. this.deleteData(data.item);
  137. },
  138. style: {backgroundColor: 'red', color: 'white'},
  139. },
  140. ];
  141. //删除产品信息
  142. deleteData = data => {
  143. let listData = this.state.listData;
  144. let numberTotal =
  145. parseInt(this.state.product_number_total) - parseInt(data.XMSL);
  146. let taxRateTotal =
  147. parseFloat(this.state.tax_rate_total) - parseFloat(data.SE);
  148. let amountTotal =
  149. parseFloat(this.state.amount_total) - data.XMJE - parseFloat(data.SE);
  150. const prevIndex = listData.findIndex(item => item.key === data.SPBM);
  151. listData.splice(prevIndex, 1);
  152. this.setState({
  153. listData: listData,
  154. amount_total: amountTotal,
  155. tax_rate_total: taxRateTotal,
  156. product_number_total: numberTotal,
  157. });
  158. };
  159. }