import React, {Component} from 'react';
import {StyleSheet, View, Text, DeviceEventEmitter, ScrollView, TouchableOpacity, Dimensions} from 'react-native';
import {Button} from '@ant-design/react-native';
import ReadUHF from "../../utils/ReadUHF";
import Barcode from "react-native-barcode-builder";
// import SyncStorage from "sync-storage";
import {SyncStorage} from '../../utils';
let screenW = Dimensions.get('window').width;
class DesktopHome extends Component {
constructor(props) {
super(props);
this.state = {
data: [],
data2: [
{
userData: "453534",
barcode: "4330012800000003232126",
orgType: "国网公司",
model: "YJLSZ-JF-10-630",
connection: "三相三线",
windingCount: "1",
transformer: "线性反应原理",
insulation: "油浸式",
ratedVoltage: "1000kV/√3",
ratedFrequencyAndPlace: "100,户外",
powerFactor: "0.8",
ratedCurrent1: "1000000/5",
ratedCurrent2: "1000000/5",
ratedCurrent3: "1000000/5",
ratedSecondLoadTA: "17.5",
overlightLoadTA: "18.5",
precisionTA: "0.5SS",
voltageChangeRate: "10000/√3/100/√3",
ratedSecondLoadTV: "17.5",
overlightLoadTV: "18.5",
precisionTV: "0.5SS",
flagAndRight: "新,局属",
encodeType: "国标",
securityAndExpansionFactor: "10,1.2",
releaseDate: "2023-07",
assetProperty: "供电企业资产,营销",
manufacturer: "武汉高压研究所新技术公司华电电气技术有限公司",
assetAttribution: "国网天府新区供电公司客户服务中心",
}
],
userData: [], //防止重复扫描
no_begin: '8',
no_length: '14',
error: 0,
isStart: true,
timerID: [],
};
}
static navigationOptions = {
headerRight: () => (
DeviceEventEmitter.emit('onSet')}
style={{
fontSize: 18,
color: '#fff',
// marginRight: 5,
}}>设置
),
};
async componentDidMount() {
// ReadUHF.changeFlag(0)
DeviceEventEmitter.addListener('onSet', (param) => {
this.props.navigation.navigate("SetPower")
});
DeviceEventEmitter.addListener('MsgFromAndroid', this._addCode);
DeviceEventEmitter.addListener('onKeyDown', this.onKeyDown);
const show_type = await SyncStorage.get('show_type')
if (show_type === null) {
SyncStorage.set('show_type', '1')
}
const zuhe_temp = await SyncStorage.get('zuhe_temp');
this.setState({zuhe_temp});
}
_addCode = async (item) => {
const str = JSON.parse(item)
// 防止重复扫描
const show_type = await SyncStorage.get('show_type') // ?? '1'
let {data, userData, error} = this.state;
const product_index = userData.indexOf(str['userData'])
if (product_index < 0) {
// 只显示本类别,不显示错误信息
if (show_type == '1') {
// 且没有错误
if (str['error'] == 0) {
userData.push(str['userData'])
data.unshift(str)
}
} else {
// 全部都显示
if (str['error']) {
error += 1
}
userData.push(str['userData'])
data.unshift(str)
}
this.setState({data, userData, error})
}
}
_start = async () => {
const no_begin = await SyncStorage.get('no_begin')
const no_length = await SyncStorage.get('no_length')
if (no_begin && no_begin) {
this.setState({no_begin, no_length})
}
let {isStart} = this.state;
ReadUHF.doRead()
this.setState({isStart: !isStart})
}
_clear = () => {
this.setState({userData: [], data: [], error: 0})
}
onKeyDown = async () => {
const no_begin = await SyncStorage.get('no_begin')
const no_length = await SyncStorage.get('no_length')
if (no_begin && no_begin) {
this.setState({no_begin, no_length})
}
let {isStart} = this.state;
this.setState({isStart: !isStart})
}
dianLiuRender = (item, index) => {
return (
{item.barcode}
单位类别 {item.orgType}
产品名称 电流电压组合互感器
产品型号 {item.model}
接线方式 {item.connection}
绕组配置 {item.windingCount}
互感器原理 {item.transformer}
绝缘方式 {item.insulation}
{/*绝缘方式 {item.insulation}*/}
额定电压 {item.ratedVoltage}
额定频率(Hz),安装场所 {item.ratedFrequencyAndPlace}
功率因数 {item.powerFactor}
额定电流变比(A)
TA额定二次负荷(VA)
TA轻载负荷(VA)
TA精度
电流变比1 {item.ratedCurrent1}
电流变比2 {item.ratedCurrent2}
{item.ratedSecondLoadTA}
{item.overlightLoadTA}
{item.precisionTA}
电流变比3 {item.ratedCurrent3}
电压比
TV额定二次负荷(VA)
TV轻载负荷(VA)
TV精度
{item.voltageChangeRate}
{item.ratedSecondLoadTV}
{item.overlightLoadTV}
{item.precisionTV}
新旧标志,电能设备计量产权 {item.flagAndRight}
加密方式 {item.encodeType}
仪表保安系数,额定一次电流扩大倍数 {item.securityAndExpansionFactor}
出厂日期 {item.releaseDate}
资产属性,资产归属 {item.assetProperty}
生产厂家 {item.manufacturer}
资产归属地 {item.assetAttribution}
)
}
errorRender = (item, index) => {
return (
{item.error_msg}
)
}
render() {
let {isStart, zuhe_temp} = this.state;
const start_text = isStart ? '开始识别' : '停止识别'
return (
{
this.state.data.map((item, index) => {
if (item.error) {
return this.errorRender(item, index)
}
else {
return this.dianLiuRender(item, index)
}
})
}
合计:{this.state.data.length} 失败:{this.state.error}
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff'
},
button: {
borderRadius: 5,
marginHorizontal: 10,
marginBottom: 2,
marginTop: 5,
borderWidth: 0,
backgroundColor: "#2b90ea"
},
textLeft50: {
color: '#333',
fontSize: 11,
width: '50%',
textAlign: 'left',
},
textColor: {
color: '#333',
fontSize: 11,
textAlign: 'center',
},
textColor1: {
color: '#333',
fontSize: 11,
textAlign: 'center',
borderRightWidth: 0.5,
width: '27%'
},
textColor2: {
color: '#333',
fontSize: 11,
textAlign: 'center',
borderRightWidth: 0.5,
width: '31%'
},
textColor3: {
color: '#333',
fontSize: 11,
textAlign: 'center',
borderRightWidth: 0.5,
width: '26%'
},
textColor4: {
color: '#333',
fontSize: 11,
textAlign: 'center',
width: '16%'
},
textRed: {
color: 'red',
},
mainView: {
margin: 5,
borderWidth: 0.5,
borderColor: '#7b7b7b',
},
betweenView: {
flexDirection: 'row',
justifyContent: 'space-between',
borderTopWidth: 0.5,
borderTopColor: '#7b7b7b',
paddingHorizontal: 5,
},
centerWidth: {
borderLeftWidth: 0.5,
borderRightWidth: 0.5,
borderLeftColor: '#7b7b7b',
borderRightColor: '#7b7b7b',
alignItems: 'center',
flexDirection: 'row',
},
centerView: {
alignItems: 'center',
flexDirection: 'row',
},
rightWidth: {
borderRightWidth: 0.5,
borderRightColor: '#7b7b7b',
alignItems: 'center',
flexDirection: 'row',
},
})
export default DesktopHome;