import React, {Component} from 'react'; import { View, Image, Text, StyleSheet, TextInput, TouchableOpacity, ScrollView, Dimensions, DeviceEventEmitter, } from 'react-native'; import {List, Picker, Provider} from '@ant-design/react-native'; import login_css from '../login/login_css'; import public_css from '../../source/css/public_css'; import loading_css from '../../source/css/loading_css'; import Spinner from 'react-native-loading-spinner-overlay'; import {GetDataPost} from '../../data/encryption'; import {ShowToast} from '../../components/rootToast/root_toast'; import {RetrieveData} from '../../data/storage'; export default class product_edit extends Component { constructor(props) { super(props); this.props.navigation.dangerouslyGetParent().setOptions({ tabBarVisible: false, }); this.state = { productId: this.props.route.params.datas.productId, productName: this.props.route.params.datas.productName, productCode: this.props.route.params.datas.productCode, parentCode: this.props.route.params.datas.parentCode, taxItem: this.props.route.params.datas.taxItem, shortCode: this.props.route.params.datas.shortCode, taxRate: [this.props.route.params.datas.taxRate], specsModel: this.props.route.params.datas.specsModel, price: this.props.route.params.datas.price, unit: this.props.route.params.datas.unit, taxPriceFlag: this.props.route.params.datas.taxPriceFlag, hiddenFlag: this.props.route.params.datas.hiddenFlag, taxationCateCode: this.props.route.params.datas.taxationCateCode, taxationCateName: this.props.route.params.datas.taxationCateName, preferentialFlag: [this.props.route.params.datas.preferentialFlag], preferential_type: this.props.route.params.datas.preferential_type, mobile: this.props.route.params.datas.createBy, reqChannel: this.props.route.params.datas.reqChannel, entTaxIds: '', ip: this.props.route.params.datas.ip, curEntId: '', spinner: false, textColors: '#DCDCDC', zeroRateFlag: [this.props.route.params.datas.zeroRateFlag], taxSpeManage: [this.props.route.params.datas.taxSpeManage], rateData: [ {value: 0, label: 0}, {value: 1, label: 1}, {value: 2, label: 2}, {value: 3, label: 3}, {value: 4, label: 4}, {value: 5, label: 5}, {value: 6, label: 6}, {value: 7, label: 7}, {value: 8, label: 8}, {value: 9, label: 9}, ], //零税标识 zeroTaxRateData: [ {label: '非零税率', value: null}, {label: '普通零税率', value: 3}, {label: '免税', value: 1}, {label: '不征税', value: 2}, ], //优惠政策标识 yhzcData: [{label: '不使用', value: 0}, {label: '使用', value: 1}], specialData: [ {label: '不征税', value: '不征税'}, {label: '征税', value: '征税'}, ], specialFlag: false, }; this._initTaxRate(); } render() { const textStyles = StyleSheet.create({ textStyle: { color: this.state.textColors, }, }); return ( *产品分类: { this.setState({ textColors: '#000', }); }} /> { this.props.navigation.navigate('tax_category_codes', { datas: 'edit', }); }}> 搜索 *产品名称: { this.setState({ productName: text, }); }} /> 简码: { this.setState({ shortCode: text, }); }} /> 规格: { this.setState({ specsModel: text, }); }} /> 计量单位: { this.setState({ unit: text, }); }} /> *单价: { this.setState({ price: text, }); }} /> { this.setState({taxRate: value}); }}> *税率: { if (itemValue === null || itemValue === 3) { this.setState({ preferentialFlag: 0, zeroRateFlag: itemValue, specialFlag: false, // taxSpeManage: '不征税', }); } else { this.setState({ preferentialFlag: 1, zeroRateFlag: itemValue, specialFlag: true, // taxSpeManage: '征税', }); } }}> *零税率标识 { if (itemValue == 1) { this.setState({ preferentialFlag: itemValue, specialFlag: true, // taxSpeManage: '征税', }); } else { this.setState({ preferentialFlag: itemValue, specialFlag: false, // taxSpeManage: '不征税', }); } }}> *优惠政策标识 {this.state.specialFlag ? ( { this.setState({ taxSpeManage: itemValue, }); }}> 增值税特殊管理 ) : null} { this.setState({ productName: this.props.route.params.datas.productName, shortCode: this.props.route.params.datas.shortCode, taxRate: [this.props.route.params.datas.taxRate], specsModel: this.props.route.params.datas.specsModel, price: this.props.route.params.datas.price, unit: this.props.route.params.datas.unit, taxPriceFlag: this.props.route.params.datas.taxPriceFlag, taxationCateCode: this.props.route.params.datas .taxationCateCode, taxationCateName: this.props.route.params.datas .taxationCateName, preferentialFlag: [ this.props.route.params.datas.preferentialFlag, ], textColors: '#DCDCDC', zeroRateFlag: [this.props.route.params.datas.zeroRateFlag], taxSpeManage: [this.props.route.params.datas.taxSpeManage], }); }}> 取消修改 this.signIn()}> 确定修改 ); } componentDidMount() { let zeroRateFlag = this.props.route.params.datas.zeroRateFlag; let preferentialFlag = this.props.route.params.datas.preferentialFlag; if (zeroRateFlag != null || zeroRateFlag != 3) { this.setState({ specialFlag: true, }); } else { this.setState({ specialFlag: false, }); } if (preferentialFlag == 1) { this.setState({ specialFlag: true, }); } else { this.setState({ specialFlag: false, }); } // 收到监听 this.listener = DeviceEventEmitter.addListener( 'getTaxClassCodeEdit', message => { // 收到监听后想做的事情 // 监听 this._initTaxCategoryCode(message); }, ); } componentWillUnmount() { // 移除监听 if (this.listener) { this.listener.remove(); } this.setState = (state, callback) => { return; }; } _initTaxRate = async () => { const entinfos = JSON.parse(await RetrieveData('defaultEnt')); if (!this.emptyString(entinfos.availableTaxes.trim())) { let rates = entinfos.availableTaxes.trim().split(','); this.setState({rateData: rates}); } }; emptyString = str => { return str === '' || str === null ? true : false; }; _initTaxCategoryCode = message => { let obj = JSON.parse(message); if (obj.code === null) { this.setState({ taxationCateCode: '税收分类编码', taxationCateName: '请选择税收分类编码', }); } else { this.setState({ taxationCateCode: obj.code, taxationCateName: obj.name, }); } }; signIn = async () => { this.setLoadingStatus(true); const entInfo = JSON.parse(await RetrieveData('defaultEnt')); this.setState({curEntId: entInfo.entTaxId}); const res = await RetrieveData('token'); const account = await RetrieveData('account'); if (res && account) { let token = res.substring(1, res.length - 1); let mobile = account.substring(1, account.length - 1); const url = '/sys/product/saveOrUpdate'; let response = await GetDataPost( url, token, { productId: this.state.productId, productName: this.state.productName, shortCode: this.state.shortCode, taxRate: this.state.taxRate[0], specsModel: this.state.specsModel, price: this.state.price, unit: this.state.unit, taxPriceFlag: this.state.taxPriceFlag, taxationCateCode: this.state.taxationCateCode, taxationCateName: this.state.taxationCateName, preferentialFlag: this.state.preferentialFlag[0], mobile: mobile, entTaxId: this.state.curEntId, reqChannel: 3, ip: this.state.ip, zeroRateFlag: this.state.zeroRateFlag[0], taxSpeManage: this.state.taxSpeManage[0], }, false, 1, ); if (response) { ShowToast('修改成功!'); this.setLoadingStatus(false); DeviceEventEmitter.emit('updatePage', null); this.props.navigation.goBack(); } else { ShowToast(response.msg); this.setLoadingStatus(false); } } }; setLoadingStatus = isLoading => { this.setState({ spinner: isLoading, }); }; } const styles = StyleSheet.create({ scrollViewStyle: { flexGrow: 1, backgroundColor: '#fff', }, backView: { marginBottom: 30, }, inputView: { flexDirection: 'row', height: 44, alignItems: 'center', width: Dimensions.get('window').width * 0.9, }, dorpDownRow: { marginTop: 20, }, dorpDownRowLeft: { flex: 1, }, dorpDownRowRight: { marginLeft: 20, height: 30, flexDirection: 'row', borderWidth: 1, borderColor: '#DCDCDC', alignItems: 'center', justifyContent: 'center', flex: 2, }, tapToPTCC: { flexDirection: 'row', justifyContent: 'center', alignItems: 'center', marginLeft: 10, marginTop: 5, height: 30, width: 50, borderRadius: 8, backgroundColor: '#99CCFF', }, bottomStaus: { height: 50, flexDirection: 'row', }, statusBtn: { flex: 1, flexDirection: 'row', justifyContent: 'center', alignItems: 'center', }, statusLBtn: { backgroundColor: '#e6e8ea', }, statusRBtn: { backgroundColor: '#1E90FF', }, });