invoice_product_list_add.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Text,
  5. TouchableOpacity,
  6. StyleSheet,
  7. Dimensions,
  8. FlatList,
  9. PixelRatio,
  10. DeviceEventEmitter,
  11. Image,
  12. } from 'react-native';
  13. import {List, SwipeAction} from '@ant-design/react-native';
  14. import public_css from '../../source/css/public_css';
  15. import {RoundingData} from '../../source/inspect/inspect';
  16. import invoice_css from './invoice_css';
  17. import { ToastShow } from "../../components/toast/toast";
  18. export default class invoice_product_list extends Component {
  19. constructor(props) {
  20. super(props);
  21. this.props.navigation.dangerouslyGetParent().setOptions({
  22. tabBarVisible: false,
  23. });
  24. this.state = {
  25. listData: [],
  26. product_number_total: 0,
  27. amount_total: 0.0,
  28. tax_rate_total: 0.0,
  29. };
  30. }
  31. render() {
  32. return (
  33. <View style={public_css.body}>
  34. {/*<View style={invoice_css.list_view}>*/}
  35. {/* <Text style={invoice_css.list_title_text}>产品名称</Text>*/}
  36. {/* <Text style={invoice_css.list_title_text}>产品数量</Text>*/}
  37. {/* <Text sstyle={invoice_css.list_title_text}>规格型号</Text>*/}
  38. {/* <Text style={invoice_css.list_title_text}>单价</Text>*/}
  39. {/* <Text style={invoice_css.list_title_text}>税率(%)</Text>*/}
  40. {/*</View>*/}
  41. <View style={{flex: 1}}>
  42. <FlatList
  43. data={this.state.listData}
  44. renderItem={item => this.renderItem(item)}
  45. />
  46. </View>
  47. <View
  48. style={{
  49. flexDirection: 'row',
  50. justifyContent: 'space-around',
  51. alignItems: 'center',
  52. height: 50,
  53. }}>
  54. <Text>共{this.state.product_number_total}个产品</Text>
  55. <Text>
  56. 开票金额:
  57. {RoundingData(parseFloat(this.state.amount_total)).replace(
  58. /(\d)(?=(\d{3})+(?:\.\d+)?$)/g,
  59. '$1,',
  60. )}
  61. </Text>
  62. <Text>
  63. 税额:{RoundingData(parseFloat(this.state.tax_rate_total))}
  64. </Text>
  65. </View>
  66. <View style={[public_css.bottomStatus]}>
  67. <TouchableOpacity
  68. style={[public_css.statusBtn, public_css.statusRBtn]}
  69. onPress={() => this.submitData()}>
  70. <Image
  71. source={require('../../source/img/productImg/confirm.png')}
  72. style={{width: 32, height: 32}}
  73. />
  74. <Text style={{color: '#fff'}}>下一步</Text>
  75. </TouchableOpacity>
  76. </View>
  77. </View>
  78. );
  79. }
  80. componentDidMount(): void {
  81. //收到监听
  82. this.listener = DeviceEventEmitter.addListener('产品监听', data => {
  83. //收到监听后想做的事情
  84. this.setList(data);
  85. });
  86. }
  87. componentWillUnmount() {
  88. //移除监听
  89. if (this.listener) {
  90. this.listener.remove();
  91. }
  92. }
  93. selectProduct = () => {
  94. this.setState({
  95. productVisible: !this.state.productVisible,
  96. });
  97. };
  98. //提交数据到下一步
  99. submitData = () => {
  100. if (this.state.listData.length > 0) {
  101. this.props.navigation.navigate(
  102. 'invoice_customer_information',
  103. this.state,
  104. );
  105. } else {
  106. ToastShow(1, '编辑成功!');
  107. }
  108. };
  109. //加载list列表
  110. setList = data => {
  111. let numberTotal =
  112. parseInt(this.state.product_number_total) + parseInt(data.XMSL);
  113. let taxRateTotal = this.state.tax_rate_total + parseFloat(data.SE);
  114. let amountTotal =
  115. this.state.amount_total + parseFloat(data.XMJE) + parseFloat(data.SE);
  116. let list = this.state.listData.concat(data);
  117. this.setState({
  118. listData: list,
  119. amount_total: amountTotal,
  120. tax_rate_total: taxRateTotal,
  121. product_number_total: numberTotal,
  122. });
  123. };
  124. //加载items
  125. renderItem = data => (
  126. <SwipeAction
  127. autoClose
  128. style={{backgroundColor: 'transparent'}}
  129. right={this.right(data)}>
  130. <List.Item>
  131. {/*<View style={{flexDirection: 'row', justifyContent: 'space-around'}}>*/}
  132. {/* <Text>{data.item.XMMC} </Text>*/}
  133. {/* <Text>{data.item.XMSL} </Text>*/}
  134. {/* <Text>{data.item.GGXH}</Text>*/}
  135. {/* <Text>{data.item.XMDJ}</Text>*/}
  136. {/* <Text>{data.item.SL * 100}</Text>*/}
  137. {/*</View>*/}
  138. {/*<View style={{flexDirection: 'row', justifyContent: 'space-between', margin: 5}}>*/}
  139. {/* <View style={{flexDirection: 'row'}}>*/}
  140. {/* <Text>金额合计:</Text>*/}
  141. {/* <Text>{data.item.XMSL} </Text>*/}
  142. {/* </View>*/}
  143. {/* <View style={{flexDirection: 'row'}}>*/}
  144. {/* <Text>税额合计:</Text>*/}
  145. {/* <Text>{data.item.XMSL} </Text>*/}
  146. {/* </View>*/}
  147. {/*</View>*/}
  148. <View>
  149. <View>
  150. <Text style={{fontSize: 18, fontWeight: '900'}}>
  151. {data.item.XMMC}
  152. </Text>
  153. </View>
  154. <View
  155. style={{
  156. flexDirection: 'row',
  157. justifyContent: 'space-between',
  158. marginTop: 5,
  159. }}>
  160. <View>
  161. <Text style={{margin: 5}}>规格:{data.item.GGXH}</Text>
  162. <Text style={{margin: 5}}>税率:{data.item.SL * 100}</Text>
  163. <Text style={{margin: 5}}>税额:{data.item.SE}</Text>
  164. </View>
  165. <View>
  166. <Text style={{margin: 5}}>单价:{data.item.XMDJ}</Text>
  167. <Text style={{margin: 5}}>数量:{data.item.XMSL}</Text>
  168. <Text style={{margin: 5}}>
  169. 小计:
  170. {RoundingData(data.item.XMSL * parseFloat(data.item.XMDJ))
  171. .toString()
  172. .replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, '$1,')}
  173. </Text>
  174. </View>
  175. </View>
  176. </View>
  177. </List.Item>
  178. </SwipeAction>
  179. );
  180. //左滑删除
  181. right = data => [
  182. {
  183. text: '删除',
  184. onPress: () => {
  185. this.deleteData(data.item);
  186. },
  187. style: {backgroundColor: 'red', color: 'white'},
  188. },
  189. ];
  190. //删除产品信息
  191. deleteData = data => {
  192. let listData = this.state.listData;
  193. let numberTotal =
  194. parseInt(this.state.product_number_total) - parseInt(data.XMSL);
  195. let taxRateTotal =
  196. parseFloat(this.state.tax_rate_total) - parseFloat(data.SE);
  197. let amountTotal =
  198. parseFloat(this.state.amount_total) - data.XMJE - parseFloat(data.SE);
  199. const prevIndex = listData.findIndex(item => item.key === data.SPBM);
  200. listData.splice(prevIndex, 1);
  201. this.setState({
  202. listData: listData,
  203. amount_total: amountTotal,
  204. tax_rate_total: taxRateTotal,
  205. product_number_total: numberTotal,
  206. });
  207. };
  208. }
  209. const styles = StyleSheet.create({
  210. buttonView: {
  211. alignItems: 'center',
  212. backgroundColor: '#ffffff',
  213. },
  214. //通用按钮样式
  215. button: {
  216. marginTop: 5,
  217. width: Dimensions.get('window').width * 0.8,
  218. height: 34,
  219. borderRadius: 10,
  220. backgroundColor: '#1874CD',
  221. justifyContent: 'center',
  222. alignItems: 'center',
  223. },
  224. //通用按钮样式
  225. buttonText: {
  226. textAlign: 'center',
  227. color: 'white',
  228. },
  229. inputView: {
  230. padding: 5,
  231. backgroundColor: '#fff',
  232. alignItems: 'center',
  233. justifyContent: 'center',
  234. display: 'flex',
  235. },
  236. view: {
  237. flexDirection: 'row',
  238. height: 34,
  239. width: Dimensions.get('window').width * 0.8,
  240. },
  241. //通用textInput样式
  242. text: {
  243. lineHeight: 34,
  244. fontSize: 14,
  245. },
  246. //通用textInput样式
  247. lineTopBottom: {
  248. borderBottomWidth: 3 / PixelRatio.get(),
  249. borderColor: 'rgb(208,208,208)',
  250. },
  251. textInputStyle: {
  252. marginRight: 10,
  253. marginLeft: 20,
  254. fontSize: 14,
  255. marginTop: 4,
  256. },
  257. });