product_edit.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Image,
  5. Text,
  6. StyleSheet,
  7. TextInput,
  8. TouchableOpacity,
  9. ScrollView,
  10. Dimensions,
  11. DeviceEventEmitter,
  12. } from 'react-native';
  13. import {List, Picker, Provider} from '@ant-design/react-native';
  14. import login_css from '../login/login_css';
  15. import public_css from '../../source/css/public_css';
  16. import loading_css from '../../source/css/loading_css';
  17. import Spinner from 'react-native-loading-spinner-overlay';
  18. import {GetDataPost} from '../../data/encryption';
  19. import {ShowToast} from '../../components/rootToast/root_toast';
  20. import {RetrieveData} from '../../data/storage';
  21. export default class product_edit extends Component {
  22. constructor(props) {
  23. super(props);
  24. this.props.navigation.dangerouslyGetParent().setOptions({
  25. tabBarVisible: false,
  26. });
  27. this.state = {
  28. productId: this.props.route.params.datas.productId,
  29. productName: this.props.route.params.datas.productName,
  30. productCode: this.props.route.params.datas.productCode,
  31. parentCode: this.props.route.params.datas.parentCode,
  32. taxItem: this.props.route.params.datas.taxItem,
  33. shortCode: this.props.route.params.datas.shortCode,
  34. taxRate: [this.props.route.params.datas.taxRate],
  35. specsModel: this.props.route.params.datas.specsModel,
  36. price: this.props.route.params.datas.price,
  37. unit: this.props.route.params.datas.unit,
  38. taxPriceFlag: this.props.route.params.datas.taxPriceFlag,
  39. hiddenFlag: this.props.route.params.datas.hiddenFlag,
  40. taxationCateCode: this.props.route.params.datas.taxationCateCode,
  41. taxationCateName: this.props.route.params.datas.taxationCateName,
  42. preferentialFlag: [this.props.route.params.datas.preferentialFlag],
  43. preferential_type: this.props.route.params.datas.preferential_type,
  44. mobile: this.props.route.params.datas.createBy,
  45. reqChannel: this.props.route.params.datas.reqChannel,
  46. entTaxIds: '',
  47. ip: this.props.route.params.datas.ip,
  48. curEntId: '',
  49. spinner: false,
  50. textColors: '#DCDCDC',
  51. zeroRateFlag: [this.props.route.params.datas.zeroRateFlag],
  52. taxSpeManage: [this.props.route.params.datas.taxSpeManage],
  53. rateData: [
  54. {value: 0, label: 0},
  55. {value: 1, label: 1},
  56. {value: 2, label: 2},
  57. {value: 3, label: 3},
  58. {value: 4, label: 4},
  59. {value: 5, label: 5},
  60. {value: 6, label: 6},
  61. {value: 7, label: 7},
  62. {value: 8, label: 8},
  63. {value: 9, label: 9},
  64. ],
  65. //零税标识
  66. zeroTaxRateData: [
  67. {label: '非零税率', value: null},
  68. {label: '普通零税率', value: 3},
  69. {label: '免税', value: 1},
  70. {label: '不征税', value: 2},
  71. ],
  72. //优惠政策标识
  73. yhzcData: [{label: '不使用', value: 0}, {label: '使用', value: 1}],
  74. specialData: [
  75. {label: '不征税', value: '不征税'},
  76. {label: '征税', value: '征税'},
  77. ],
  78. specialFlag: false,
  79. };
  80. this._initTaxRate();
  81. }
  82. render() {
  83. const textStyles = StyleSheet.create({
  84. textStyle: {
  85. color: this.state.textColors,
  86. },
  87. });
  88. return (
  89. <Provider>
  90. <View style={{flexDirection: 'column', flex: 1}}>
  91. <Spinner
  92. visible={this.state.spinner}
  93. textContent={'Loading...'}
  94. textStyle={loading_css.spinnerTextStyle}
  95. />
  96. <ScrollView style={styles.scrollViewStyle}>
  97. <View style={[login_css.inputView, styles.backView]}>
  98. <View style={[styles.inputView, public_css.lineTopBottom]}>
  99. <Text style={public_css.text}>*产品分类:</Text>
  100. <TextInput
  101. style={[public_css.textInputStyle, textStyles.textStyle]}
  102. placeholder={this.props.route.params.datas.taxationCateName}
  103. clearButtonMode="while-editing"
  104. editable={false}
  105. value={this.state.taxationCateName}
  106. onChangeText={text => {
  107. this.setState({
  108. textColors: '#000',
  109. });
  110. }}
  111. />
  112. <TouchableOpacity
  113. style={[styles.backRightBtn, styles.backRightBtnLeft]}
  114. onPress={() => {
  115. this.props.navigation.navigate('tax_category_codes', {
  116. datas: 'edit',
  117. });
  118. }}>
  119. <View style={styles.tapToPTCC}>
  120. <Text style={{color: '#fff'}}>搜索</Text>
  121. </View>
  122. </TouchableOpacity>
  123. </View>
  124. <View style={[styles.inputView, public_css.lineTopBottom]}>
  125. <Text style={public_css.text}>*产品名称:</Text>
  126. <TextInput
  127. style={public_css.textInputStyle}
  128. placeholder={this.props.route.params.datas.productName}
  129. clearButtonMode="while-editing"
  130. secureTextEntry={false}
  131. value={this.state.productName}
  132. onChangeText={text => {
  133. this.setState({
  134. productName: text,
  135. });
  136. }}
  137. />
  138. </View>
  139. <View style={[styles.inputView, public_css.lineTopBottom]}>
  140. <Text style={public_css.text}>简码:</Text>
  141. <TextInput
  142. style={public_css.textInputStyle}
  143. placeholder={this.props.route.params.datas.shortCode}
  144. clearButtonMode="while-editing"
  145. value={this.state.shortCode}
  146. secureTextEntry={false}
  147. onChangeText={text => {
  148. this.setState({
  149. shortCode: text,
  150. });
  151. }}
  152. />
  153. </View>
  154. <View style={[styles.inputView, public_css.lineTopBottom]}>
  155. <Text style={public_css.text}>规格:</Text>
  156. <TextInput
  157. style={public_css.textInputStyle}
  158. placeholder={this.props.route.params.datas.specsModel}
  159. clearButtonMode="while-editing"
  160. secureTextEntry={false}
  161. value={this.state.specsModel}
  162. onChangeText={text => {
  163. this.setState({
  164. specsModel: text,
  165. });
  166. }}
  167. />
  168. </View>
  169. <View style={[styles.inputView, public_css.lineTopBottom]}>
  170. <Text style={public_css.text}>计量单位:</Text>
  171. <TextInput
  172. style={public_css.textInputStyle}
  173. placeholder={this.props.route.params.datas.unit}
  174. clearButtonMode="while-editing"
  175. secureTextEntry={false}
  176. value={this.state.unit}
  177. onChangeText={text => {
  178. this.setState({
  179. unit: text,
  180. });
  181. }}
  182. />
  183. </View>
  184. <View style={[styles.inputView, public_css.lineTopBottom]}>
  185. <Text style={public_css.text}>*单价:</Text>
  186. <TextInput
  187. style={public_css.textInputStyle}
  188. keyboardType="number-pad"
  189. placeholder={
  190. this.props.route.params.datas.price == null ||
  191. this.props.route.params.datas.price === ''
  192. ? '0.00'
  193. : this.props.route.params.datas.price.toString()
  194. }
  195. clearButtonMode="while-editing"
  196. secureTextEntry={false}
  197. value={
  198. this.props.route.params.datas.price == null ||
  199. this.props.route.params.datas.price === ''
  200. ? '0.00'
  201. : this.state.price.toString()
  202. }
  203. onChangeText={text => {
  204. this.setState({
  205. price: text,
  206. });
  207. }}
  208. />
  209. </View>
  210. <View style={{width: Dimensions.get('window').width}}>
  211. <Picker
  212. data={this.state.rateData}
  213. cols={1}
  214. value={this.state.taxRate}
  215. onChange={value => {
  216. this.setState({taxRate: value});
  217. }}>
  218. <List.Item arrow="horizontal">*税率:</List.Item>
  219. </Picker>
  220. </View>
  221. <View style={{width: Dimensions.get('window').width}}>
  222. <Picker
  223. data={this.state.zeroTaxRateData}
  224. cols={1}
  225. value={this.state.zeroRateFlag}
  226. onChange={itemValue => {
  227. if (itemValue === null || itemValue === 3) {
  228. this.setState({
  229. preferentialFlag: 0,
  230. zeroRateFlag: itemValue,
  231. specialFlag: false,
  232. // taxSpeManage: '不征税',
  233. });
  234. } else {
  235. this.setState({
  236. preferentialFlag: 1,
  237. zeroRateFlag: itemValue,
  238. specialFlag: true,
  239. // taxSpeManage: '征税',
  240. });
  241. }
  242. }}>
  243. <List.Item arrow="horizontal">*零税率标识</List.Item>
  244. </Picker>
  245. </View>
  246. <View style={{width: Dimensions.get('window').width}}>
  247. <Picker
  248. data={this.state.yhzcData}
  249. cols={1}
  250. value={this.state.preferentialFlag}
  251. onChange={itemValue => {
  252. if (itemValue == 1) {
  253. this.setState({
  254. preferentialFlag: itemValue,
  255. specialFlag: true,
  256. // taxSpeManage: '征税',
  257. });
  258. } else {
  259. this.setState({
  260. preferentialFlag: itemValue,
  261. specialFlag: false,
  262. // taxSpeManage: '不征税',
  263. });
  264. }
  265. }}>
  266. <List.Item arrow="horizontal">*优惠政策标识</List.Item>
  267. </Picker>
  268. {this.state.specialFlag ? (
  269. <View style={{width: Dimensions.get('window').width}}>
  270. <Picker
  271. data={this.state.specialData}
  272. cols={1}
  273. value={this.state.taxSpeManage}
  274. onChange={itemValue => {
  275. this.setState({
  276. taxSpeManage: itemValue,
  277. });
  278. }}>
  279. <List.Item arrow="horizontal">增值税特殊管理</List.Item>
  280. </Picker>
  281. </View>
  282. ) : null}
  283. </View>
  284. </View>
  285. </ScrollView>
  286. <View style={styles.bottomStaus}>
  287. <TouchableOpacity
  288. style={[styles.statusBtn, styles.statusLBtn]}
  289. onPress={() => {
  290. this.setState({
  291. productName: this.props.route.params.datas.productName,
  292. shortCode: this.props.route.params.datas.shortCode,
  293. taxRate: [this.props.route.params.datas.taxRate],
  294. specsModel: this.props.route.params.datas.specsModel,
  295. price: this.props.route.params.datas.price,
  296. unit: this.props.route.params.datas.unit,
  297. taxPriceFlag: this.props.route.params.datas.taxPriceFlag,
  298. taxationCateCode: this.props.route.params.datas
  299. .taxationCateCode,
  300. taxationCateName: this.props.route.params.datas
  301. .taxationCateName,
  302. preferentialFlag: [
  303. this.props.route.params.datas.preferentialFlag,
  304. ],
  305. textColors: '#DCDCDC',
  306. zeroRateFlag: [this.props.route.params.datas.zeroRateFlag],
  307. taxSpeManage: [this.props.route.params.datas.taxSpeManage],
  308. });
  309. }}>
  310. <Image
  311. source={require('../../source/img/productImg/clear.png')}
  312. style={{width: 32, height: 32}}
  313. />
  314. <Text>取消修改</Text>
  315. </TouchableOpacity>
  316. <TouchableOpacity
  317. style={[styles.statusBtn, styles.statusRBtn]}
  318. onPress={() => this.signIn()}>
  319. <Image
  320. source={require('../../source/img/productImg/confirm.png')}
  321. style={{width: 32, height: 32}}
  322. />
  323. <Text style={{color: '#fff'}}>确定修改</Text>
  324. </TouchableOpacity>
  325. </View>
  326. </View>
  327. </Provider>
  328. );
  329. }
  330. componentDidMount() {
  331. let zeroRateFlag = this.props.route.params.datas.zeroRateFlag;
  332. let preferentialFlag = this.props.route.params.datas.preferentialFlag;
  333. if (zeroRateFlag != null || zeroRateFlag != 3) {
  334. this.setState({
  335. specialFlag: true,
  336. });
  337. } else {
  338. this.setState({
  339. specialFlag: false,
  340. });
  341. }
  342. if (preferentialFlag == 1) {
  343. this.setState({
  344. specialFlag: true,
  345. });
  346. } else {
  347. this.setState({
  348. specialFlag: false,
  349. });
  350. }
  351. // 收到监听
  352. this.listener = DeviceEventEmitter.addListener(
  353. 'getTaxClassCodeEdit',
  354. message => {
  355. // 收到监听后想做的事情 // 监听
  356. this._initTaxCategoryCode(message);
  357. },
  358. );
  359. }
  360. componentWillUnmount() {
  361. // 移除监听
  362. if (this.listener) {
  363. this.listener.remove();
  364. }
  365. this.setState = (state, callback) => {
  366. return;
  367. };
  368. }
  369. _initTaxRate = async () => {
  370. const entinfos = JSON.parse(await RetrieveData('defaultEnt'));
  371. if (!this.emptyString(entinfos.availableTaxes.trim())) {
  372. let rates = entinfos.availableTaxes.trim().split(',');
  373. this.setState({rateData: rates});
  374. }
  375. };
  376. emptyString = str => {
  377. return str === '' || str === null ? true : false;
  378. };
  379. _initTaxCategoryCode = message => {
  380. let obj = JSON.parse(message);
  381. if (obj.code === null) {
  382. this.setState({
  383. taxationCateCode: '税收分类编码',
  384. taxationCateName: '请选择税收分类编码',
  385. });
  386. } else {
  387. this.setState({
  388. taxationCateCode: obj.code,
  389. taxationCateName: obj.name,
  390. });
  391. }
  392. };
  393. signIn = async () => {
  394. this.setLoadingStatus(true);
  395. const entInfo = JSON.parse(await RetrieveData('defaultEnt'));
  396. this.setState({curEntId: entInfo.entTaxId});
  397. const res = await RetrieveData('token');
  398. const account = await RetrieveData('account');
  399. if (res && account) {
  400. let token = res.substring(1, res.length - 1);
  401. let mobile = account.substring(1, account.length - 1);
  402. const url = '/sys/product/saveOrUpdate';
  403. let response = await GetDataPost(
  404. url,
  405. token,
  406. {
  407. productId: this.state.productId,
  408. productName: this.state.productName,
  409. shortCode: this.state.shortCode,
  410. taxRate: this.state.taxRate[0],
  411. specsModel: this.state.specsModel,
  412. price: this.state.price,
  413. unit: this.state.unit,
  414. taxPriceFlag: this.state.taxPriceFlag,
  415. taxationCateCode: this.state.taxationCateCode,
  416. taxationCateName: this.state.taxationCateName,
  417. preferentialFlag: this.state.preferentialFlag[0],
  418. mobile: mobile,
  419. entTaxId: this.state.curEntId,
  420. reqChannel: 3,
  421. ip: this.state.ip,
  422. zeroRateFlag: this.state.zeroRateFlag[0],
  423. taxSpeManage: this.state.taxSpeManage[0],
  424. },
  425. false,
  426. 1,
  427. );
  428. if (response) {
  429. ShowToast('修改成功!');
  430. this.setLoadingStatus(false);
  431. DeviceEventEmitter.emit('updatePage', null);
  432. this.props.navigation.goBack();
  433. } else {
  434. ShowToast(response.msg);
  435. this.setLoadingStatus(false);
  436. }
  437. }
  438. };
  439. setLoadingStatus = isLoading => {
  440. this.setState({
  441. spinner: isLoading,
  442. });
  443. };
  444. }
  445. const styles = StyleSheet.create({
  446. scrollViewStyle: {
  447. flexGrow: 1,
  448. backgroundColor: '#fff',
  449. },
  450. backView: {
  451. marginBottom: 30,
  452. },
  453. inputView: {
  454. flexDirection: 'row',
  455. height: 44,
  456. alignItems: 'center',
  457. width: Dimensions.get('window').width * 0.9,
  458. },
  459. dorpDownRow: {
  460. marginTop: 20,
  461. },
  462. dorpDownRowLeft: {
  463. flex: 1,
  464. },
  465. dorpDownRowRight: {
  466. marginLeft: 20,
  467. height: 30,
  468. flexDirection: 'row',
  469. borderWidth: 1,
  470. borderColor: '#DCDCDC',
  471. alignItems: 'center',
  472. justifyContent: 'center',
  473. flex: 2,
  474. },
  475. tapToPTCC: {
  476. flexDirection: 'row',
  477. justifyContent: 'center',
  478. alignItems: 'center',
  479. marginLeft: 10,
  480. marginTop: 5,
  481. height: 30,
  482. width: 50,
  483. borderRadius: 8,
  484. backgroundColor: '#99CCFF',
  485. },
  486. bottomStaus: {
  487. height: 50,
  488. flexDirection: 'row',
  489. },
  490. statusBtn: {
  491. flex: 1,
  492. flexDirection: 'row',
  493. justifyContent: 'center',
  494. alignItems: 'center',
  495. },
  496. statusLBtn: {
  497. backgroundColor: '#e6e8ea',
  498. },
  499. statusRBtn: {
  500. backgroundColor: '#1E90FF',
  501. },
  502. });