product_confirm.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Text,
  5. TextInput,
  6. TouchableOpacity,
  7. DeviceEventEmitter,
  8. Image,
  9. ScrollView,
  10. SafeAreaView,
  11. } from 'react-native';
  12. import {
  13. List,
  14. Picker,
  15. Provider,
  16. WingBlank,
  17. WhiteSpace,
  18. } from '@ant-design/react-native';
  19. import {NumberTwoDecimal, NumberTenDecimal} from '../../source/inspect/inspect';
  20. import {RetrieveData} from '../../data/storage';
  21. import {ToastShow} from '../toast/toast';
  22. import public_css from '../../source/css/public_css';
  23. export default class product_confirm extends Component {
  24. constructor(props) {
  25. super(props);
  26. this.props.navigation.dangerouslyGetParent().setOptions({
  27. tabBarVisible: false,
  28. });
  29. this.state = {
  30. status: this.props.route.params.status,
  31. key: '',
  32. productName: '',
  33. specsModel: '',
  34. unit: '',
  35. number: '',
  36. price: '',
  37. taxRate: '',
  38. companyTypes: [
  39. {
  40. label: '个人',
  41. value: '1',
  42. },
  43. {
  44. label: '企业',
  45. value: '2',
  46. },
  47. ],
  48. rateData: '',
  49. amount: '',
  50. taxAmount: '',
  51. };
  52. }
  53. render() {
  54. return (
  55. <Provider>
  56. <SafeAreaView style={public_css.body}>
  57. <ScrollView>
  58. <View style={public_css.body}>
  59. <List>
  60. <WingBlank>
  61. <View style={[public_css.view, public_css.lineTopBottom]}>
  62. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  63. <Text style={{color: 'red', marginRight: 5}}>*</Text>
  64. <Text style={{fontSize: 16}}>产品名称:</Text>
  65. </View>
  66. <TextInput
  67. style={public_css.textInputStyle}
  68. placeholder="请输入产品名称"
  69. clearButtonMode="while-editing"
  70. secureTextEntry={false}
  71. value={this.state.productName}
  72. onChangeText={(text) => {
  73. this.setState({
  74. productName: text,
  75. });
  76. }}
  77. />
  78. </View>
  79. </WingBlank>
  80. <WingBlank>
  81. <View style={[public_css.view, public_css.lineTopBottom]}>
  82. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  83. <Text style={{fontSize: 16}}>规格型号:</Text>
  84. </View>
  85. <TextInput
  86. style={public_css.textInputStyle}
  87. placeholder="请输入规格型号"
  88. clearButtonMode="while-editing"
  89. secureTextEntry={false}
  90. value={this.state.specsModel}
  91. onChangeText={(text) => {
  92. this.setState({
  93. specsModel: text,
  94. });
  95. }}
  96. />
  97. </View>
  98. </WingBlank>
  99. <WingBlank>
  100. <View style={[public_css.view, public_css.lineTopBottom]}>
  101. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  102. <Text style={{fontSize: 16}}>单位:</Text>
  103. </View>
  104. <TextInput
  105. style={public_css.textInputStyle}
  106. placeholder="请输入规格型号"
  107. clearButtonMode="while-editing"
  108. secureTextEntry={false}
  109. value={this.state.unit}
  110. onChangeText={(text) => {
  111. this.setState({
  112. unit: text,
  113. });
  114. }}
  115. />
  116. </View>
  117. </WingBlank>
  118. <WingBlank>
  119. <View style={[public_css.view, public_css.lineTopBottom]}>
  120. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  121. <Text style={{fontSize: 16}}>数量:</Text>
  122. </View>
  123. <TextInput
  124. style={public_css.textInputStyle}
  125. placeholder="请输入产品数量"
  126. clearButtonMode="while-editing"
  127. secureTextEntry={false}
  128. keyboardType={'numeric'}
  129. value={this.state.number}
  130. onChangeText={(text) => {
  131. this.numberChange(text);
  132. }}
  133. />
  134. </View>
  135. </WingBlank>
  136. <WingBlank>
  137. <View style={[public_css.view, public_css.lineTopBottom]}>
  138. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  139. <Text style={{fontSize: 16}}>单价:</Text>
  140. </View>
  141. <TextInput
  142. style={public_css.textInputStyle}
  143. placeholder="请输入单价"
  144. clearButtonMode="while-editing"
  145. secureTextEntry={false}
  146. keyboardType={'numeric'}
  147. value={this.state.price}
  148. onChangeText={(text) => {
  149. this.priceChange(text);
  150. }}
  151. />
  152. </View>
  153. </WingBlank>
  154. <WingBlank>
  155. <View style={[public_css.view, public_css.lineTopBottom]}>
  156. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  157. <Text style={{color: 'red', marginRight: 5}}>*</Text>
  158. <Text style={{fontSize: 16}}>合计:</Text>
  159. </View>
  160. <TextInput
  161. style={public_css.textInputStyle}
  162. placeholder="请输入合计金额"
  163. clearButtonMode="while-editing"
  164. secureTextEntry={false}
  165. value={this.state.amount}
  166. onChangeText={(text) => {
  167. this.amountChange(text);
  168. }}
  169. />
  170. </View>
  171. </WingBlank>
  172. <Picker
  173. data={this.state.rateData}
  174. cols={1}
  175. value={[this.state.taxRate]}
  176. onChange={(value) => {
  177. this.taxRateChange(value);
  178. }}>
  179. <List.Item arrow="horizontal" onPress={this.onPress}>
  180. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  181. <Text style={{color: 'red', marginRight: 5}}>*</Text>
  182. <Text style={{fontSize: 16}}>税率(%):</Text>
  183. </View>
  184. </List.Item>
  185. </Picker>
  186. <WingBlank>
  187. <View style={[public_css.view, public_css.lineTopBottom]}>
  188. <View style={{flexDirection: 'row', alignItems: 'center'}}>
  189. <Text style={{color: 'red', marginRight: 5}}>*</Text>
  190. <Text style={{fontSize: 16}}>税额:</Text>
  191. </View>
  192. <TextInput
  193. style={public_css.textInputStyle}
  194. editable={false}
  195. value={this.state.taxAmount}
  196. />
  197. </View>
  198. </WingBlank>
  199. </List>
  200. </View>
  201. </ScrollView>
  202. <WingBlank>
  203. <View style={public_css.bottomStatus}>
  204. <TouchableOpacity
  205. style={[public_css.statusBtn, public_css.statusRBtn]}
  206. onPress={() => this.submitData()}>
  207. {/*<Image*/}
  208. {/* source={require('../../source/img/productImg/confirm.png')}*/}
  209. {/* style={{width: 32, height: 32}}*/}
  210. {/*/>*/}
  211. <Text style={{color: '#fff'}}>确定添加</Text>
  212. </TouchableOpacity>
  213. </View>
  214. </WingBlank>
  215. <WhiteSpace />
  216. </SafeAreaView>
  217. </Provider>
  218. );
  219. }
  220. // render加载完后调用
  221. async componentDidMount() {
  222. this.getProductInfo();
  223. await this.getTaxRate();
  224. }
  225. // 页面加载完成后获取传递的数据
  226. getProductInfo = () => {
  227. let price = this.props.route.params.data.XMDJ;
  228. if (price) {
  229. price = price.toString();
  230. }
  231. let number = this.props.route.params.data.XMSL;
  232. if (number) {
  233. number = number.toString();
  234. }
  235. let taxRate = this.props.route.params.data.SL;
  236. if (taxRate) {
  237. taxRate = taxRate.toString();
  238. }
  239. this.setState({
  240. key: this.props.route.params.data.key,
  241. productName: this.props.route.params.data.XMMC,
  242. specsModel: this.props.route.params.data.GGXH,
  243. unit: this.props.route.params.data.DW,
  244. price: price,
  245. number: number,
  246. taxRate: taxRate,
  247. });
  248. };
  249. //提交数据添加到产品列表中
  250. submitData = () => {
  251. if (this.state.productName === '') {
  252. ToastShow(1, '产品名称不能为空!');
  253. return;
  254. }
  255. // if (this.state.price === '') {
  256. // ToastShow(1, '单价不能为空!');
  257. // return;
  258. // }
  259. // if (this.state.number === '') {
  260. // ToastShow(1, '产品数量不能为空!');
  261. // return;
  262. // }
  263. if (this.state.amount === '') {
  264. ToastShow(1, '合计金额不能为空!');
  265. return;
  266. }
  267. if (this.state.taxRate.length === 0) {
  268. ToastShow(1, '税率不能为空!');
  269. return;
  270. }
  271. if (this.state.taxAmount === '') {
  272. ToastShow(1, '税额不能为空!');
  273. return;
  274. }
  275. let number = '';
  276. if (this.state.number !== 0 && this.state.number !== '') {
  277. number = this.state.number;
  278. }
  279. let price = '';
  280. let priceTax = '';
  281. if (this.state.price !== 0 && this.state.price !== '') {
  282. price = NumberTenDecimal(
  283. parseFloat(this.state.price) / (1 + parseFloat(this.state.taxRate)),
  284. );
  285. priceTax = this.state.price;
  286. }
  287. let data = {
  288. FPHXZ: this.props.route.params.data.FPHXZ, //发票行性质 0正常行 1折扣行 2被折扣行 必填
  289. SPBM: this.props.route.params.data.SPBM, //商品编码
  290. ZXBM: this.props.route.params.data.ZXBM, //自行编码
  291. YHZCBS: this.props.route.params.data.YHZCBS, //优惠政策标识 0不使用 1使用
  292. LSLBS: this.props.route.params.data.LSLBS, //零税率标识
  293. ZZSTSGL: this.props.route.params.data.ZZSTSGL, //增值税特殊管理
  294. XMMC: this.state.productName, //项目名称 必填
  295. DW: this.state.unit, //计量单位
  296. GGXH: this.state.specsModel, //规格型号
  297. XMSL: number, //项目数量
  298. XMDJ: price, //项目单价
  299. XMJE: NumberTwoDecimal(
  300. parseFloat(this.state.amount) -
  301. (parseFloat(this.state.amount) /
  302. (1 + parseFloat(this.state.taxRate))) *
  303. parseFloat(this.state.taxRate),
  304. ), //项目金额 不含税
  305. SL: this.state.taxRate, //税率 必填
  306. SE:
  307. (parseFloat(this.state.amount) / (1 + parseFloat(this.state.taxRate))) *
  308. this.state.taxRate, //税额 必填
  309. price: priceTax,
  310. amount: this.state.amount,
  311. taxAmount: this.state.taxAmount,
  312. };
  313. if (this.state.status === 1) {
  314. DeviceEventEmitter.emit('productInfo', data);
  315. this.props.navigation.navigate('invoice');
  316. }
  317. if (this.state.status === 2) {
  318. DeviceEventEmitter.emit('buyerInvoice', data);
  319. this.props.navigation.navigate('buyer_invoice');
  320. }
  321. if (this.state.status === 3) {
  322. DeviceEventEmitter.emit('headInvoice', data);
  323. this.props.navigation.navigate('invoice_head');
  324. }
  325. };
  326. // 加载可用税率
  327. getTaxRate = async () => {
  328. let companyInfo = JSON.parse(await RetrieveData('company'));
  329. if (!this.emptyString(companyInfo.availableTaxes.trim())) {
  330. let rates = companyInfo.availableTaxes.trim().split(',');
  331. let data = [];
  332. rates.map((tax) => {
  333. let status = data.some((item) => item.value === tax);
  334. if (!status) {
  335. data.push({
  336. value: tax,
  337. label: tax * 100 + '%',
  338. });
  339. }
  340. });
  341. this.setState({rateData: data});
  342. }
  343. };
  344. // 判断可用税率是否为空
  345. emptyString = (str) => {
  346. return str === '' || str === null ? true : false;
  347. };
  348. // 单价变化计算
  349. priceChange = (value) => {
  350. this.setState({
  351. price: value,
  352. });
  353. if (value === '') {
  354. this.setState({
  355. amount: '',
  356. taxAmount: '',
  357. });
  358. return;
  359. }
  360. let number = this.state.number;
  361. if (number !== '' || number > 0) {
  362. let amount = parseFloat(value) * parseInt(number);
  363. this.setState({
  364. amount: NumberTwoDecimal(amount).toString(),
  365. });
  366. let taxRate = this.state.taxRate;
  367. if (taxRate !== '' || taxRate !== null) {
  368. let taxAmount = amount * parseFloat(taxRate);
  369. this.setState({
  370. taxAmount: NumberTwoDecimal(taxAmount).toString(),
  371. });
  372. }
  373. }
  374. };
  375. // 数量变化计算
  376. numberChange = (value) => {
  377. this.setState({
  378. number: value,
  379. });
  380. if (value === '') {
  381. this.setState({
  382. amount: '',
  383. taxAmount: '',
  384. });
  385. return;
  386. }
  387. let price = this.state.price;
  388. if (price !== '' || price > 0) {
  389. let amount = parseFloat(price) * parseInt(value);
  390. this.setState({
  391. amount: NumberTwoDecimal(amount).toString(),
  392. });
  393. let taxRate = this.state.taxRate;
  394. if (taxRate !== '' || taxRate !== null) {
  395. let taxAmount = amount * parseFloat(taxRate);
  396. this.setState({
  397. taxAmount: NumberTwoDecimal(taxAmount).toString(),
  398. });
  399. }
  400. } else {
  401. let amount = this.state.amount;
  402. if (amount !== '' || amount > 0) {
  403. let price = parseFloat(amount) / parseFloat(value);
  404. this.setState({
  405. price: NumberTenDecimal(price).toString(),
  406. });
  407. }
  408. }
  409. };
  410. // 合计金额变化计算
  411. amountChange = (value) => {
  412. this.setState({
  413. amount: value,
  414. });
  415. if (value === '') {
  416. this.setState({
  417. price: '',
  418. taxAmount: '',
  419. });
  420. return;
  421. }
  422. let number = this.state.number;
  423. let price = this.state.price;
  424. if (number === 0 || number === '') {
  425. if (price === 0 || price === '') {
  426. let taxRate = this.state.taxRate;
  427. if (taxRate !== '' || taxRate !== null) {
  428. let taxAmount = parseFloat(value) * parseFloat(taxRate);
  429. this.setState({
  430. taxAmount: NumberTwoDecimal(taxAmount).toString(),
  431. });
  432. }
  433. }
  434. } else {
  435. let price = parseFloat(value) / parseFloat(number);
  436. this.setState({
  437. price: NumberTenDecimal(price).toString(),
  438. });
  439. let taxRate = this.state.taxRate;
  440. if (taxRate !== '' || taxRate !== null) {
  441. let taxAmount = parseFloat(value) * parseFloat(taxRate);
  442. this.setState({
  443. taxAmount: NumberTwoDecimal(taxAmount).toString(),
  444. });
  445. }
  446. }
  447. };
  448. // 税率变化计算
  449. taxRateChange = (value) => {
  450. let taxRate = '';
  451. if (value.length > 0) {
  452. taxRate = value[0];
  453. }
  454. this.setState({
  455. taxRate: taxRate,
  456. });
  457. let amount = this.state.amount;
  458. // if (amount === '') {
  459. // this.setState({
  460. // taxRate: '',
  461. // });
  462. // return;
  463. // }
  464. if (taxRate !== '' || taxRate !== null) {
  465. let taxAmount = parseFloat(amount) * parseFloat(taxRate);
  466. this.setState({
  467. taxAmount: NumberTwoDecimal(taxAmount).toString(),
  468. });
  469. }
  470. };
  471. }