Home2.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. import React, {Component} from 'react';
  2. import {StyleSheet, View, Text, DeviceEventEmitter, ScrollView, TouchableOpacity, Dimensions} from 'react-native';
  3. import {Button} from '@ant-design/react-native';
  4. import ReadUHF from '../../utils/ReadUHF';
  5. import Barcode from 'react-native-barcode-builder';
  6. // import SyncStorage from "sync-storage";
  7. import {SyncStorage} from '../../utils';
  8. let screenW = Dimensions.get('window').width;
  9. let lastBackPressed = 0;
  10. class DesktopHome2 extends Component {
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. data: [],
  15. userData: [],
  16. no_begin: '8',
  17. no_length: '14',
  18. zuhe_temp: '1',
  19. error: 0,
  20. isStart: true,
  21. timerID: [],
  22. };
  23. }
  24. static navigationOptions = {
  25. headerRight: () => (
  26. <Text
  27. onPress={() => DeviceEventEmitter.emit('onSet')}
  28. style={{
  29. fontSize: 18,
  30. color: '#fff',
  31. // marginRight: 5,
  32. }}>设置</Text>
  33. ),
  34. };
  35. async componentDidMount() {
  36. // ReadUHF.changeFlag(0)
  37. DeviceEventEmitter.addListener('onSet', (param) => {
  38. this.props.navigation.navigate("SetPower")
  39. });
  40. DeviceEventEmitter.addListener('MsgFromAndroid', this._addCode);
  41. DeviceEventEmitter.addListener('onKeyDown', this.onKeyDown);
  42. const show_type = await SyncStorage.get('show_type');
  43. if (show_type === undefined) {
  44. SyncStorage.set('show_type', '1');
  45. }
  46. const zuhe_temp = await SyncStorage.get('zuhe_temp');
  47. this.setState({zuhe_temp});
  48. }
  49. _addCode = async (item) => {
  50. const str = JSON.parse(item);
  51. // 防止重复扫描
  52. const show_type = await SyncStorage.get('show_type') ?? '1';
  53. let {data, userData, error} = this.state;
  54. const product_index = userData.indexOf(str['userData']);
  55. console.log(66666666, product_index, show_type, str['error'], str['error_msg'])
  56. if (product_index < 0) {
  57. // 只显示本类别 不显示错误信息
  58. if (show_type == '1') {
  59. // 且没有错误
  60. console.log('000kkk')
  61. if (str['error'] == '0') {
  62. userData.push(str['userData']);
  63. data.unshift(str);
  64. }
  65. } else {
  66. // 全部都显示
  67. console.log('eeerrr')
  68. if (str['error']) {
  69. error += 1;
  70. }
  71. userData.push(str['userData']);
  72. data.unshift(str);
  73. }
  74. console.log(7777777, data)
  75. console.log(8888888, error)
  76. console.log(8888888, userData)
  77. this.setState({data, userData, error});
  78. }
  79. };
  80. _start = async () => {
  81. const no_begin = await SyncStorage.get('no_begin');
  82. const no_length = await SyncStorage.get('no_length');
  83. if (no_begin && no_begin) {
  84. this.setState({no_begin, no_length});
  85. }
  86. let {isStart} = this.state;
  87. ReadUHF.doRead();
  88. this.setState({isStart: !isStart});
  89. };
  90. _clear = () => {
  91. this.setState({userData: [], data: [], error: 0});
  92. };
  93. onKeyDown = async () => {
  94. const no_begin = await SyncStorage.get('no_begin');
  95. const no_length = await SyncStorage.get('no_length');
  96. if (no_begin && no_begin) {
  97. this.setState({no_begin, no_length});
  98. }
  99. let {isStart} = this.state;
  100. this.setState({isStart: !isStart});
  101. };
  102. dianYaRender = (item, index) => {
  103. const assetID = item.assetID.slice(parseInt(this.state.no_begin) - 1, parseInt(this.state.no_begin) + parseInt(this.state.no_length) - 1);
  104. const releaseDates = item.releaseDate.split('-');
  105. const releaseDate = releaseDates[0] + '年' + releaseDates[1] + '月';
  106. let districtText = '';
  107. if (parseInt(item.district) > 10000) {
  108. districtText = item.districtText;
  109. } else {
  110. const len1 = item.districtText.split('-')[1].length;
  111. districtText = '国网' + item.districtText.split('-')[1].slice(0, len1 - 1) + '电力';
  112. }
  113. return (
  114. <View
  115. key={index}
  116. style={styles.mainView}
  117. >
  118. <Text style={styles.textColor}>计量{item.kind}</Text>
  119. <View style={styles.betweenView}>
  120. <Text style={styles.textColor3}>型号:{item.model}</Text>
  121. <View style={styles.centerWidth}>
  122. <Text style={styles.textColor3}>电压等级:{item.voltageLevel}kV</Text>
  123. </View>
  124. <Text style={styles.textColor3}>绕组数量:{item.secondWindingCount}</Text>
  125. </View>
  126. <View style={styles.betweenView}>
  127. <Text style={styles.textColor4}>二次电压</Text>
  128. <View style={styles.centerWidth}>
  129. <Text style={styles.textColor4}>准确等级</Text>
  130. </View>
  131. <View style={styles.rightWidth}>
  132. <Text style={styles.textColor4}>功率因数</Text>
  133. </View>
  134. <Text style={styles.textColor4}>生产日期</Text>
  135. </View>
  136. <View style={styles.betweenView}>
  137. <View style={styles.centerView}>
  138. <Text style={styles.textColor4}>{item.secondVoltage}kV</Text>
  139. </View>
  140. <View style={styles.centerWidth}>
  141. <Text style={styles.textColor4}>{item.accuracy}</Text>
  142. </View>
  143. <View style={styles.rightWidth}>
  144. <Text style={styles.textColor4}>{item.powerFactor}</Text>
  145. </View>
  146. <View style={styles.centerView}>
  147. <Text style={styles.textColor4}>{releaseDate}</Text>
  148. </View>
  149. </View>
  150. <View style={styles.betweenView}>
  151. <Text style={styles.textColor3}>安装场所:{item.place}</Text>
  152. <View style={styles.centerWidth}>
  153. <Text style={styles.textColor3}>额定负荷:{item.ratedLoad}VA</Text>
  154. </View>
  155. <Text style={styles.textColor3}>电压因数:{item.voltageFactor}</Text>
  156. </View>
  157. <View style={styles.betweenView}>
  158. <View style={styles.centerView}>
  159. <Text style={styles.textColor3}>{item.manufacturer}</Text>
  160. </View>
  161. <View style={{
  162. width: (screenW - 10) / 3 * 2,
  163. borderLeftWidth: 0.5,
  164. borderLeftColor: '#7b7b7b',
  165. }}>
  166. <View style={{
  167. flexDirection: 'row',
  168. marginHorizontal: 3,
  169. }}>
  170. <View style={{
  171. flex: 1,
  172. }}>
  173. <Text style={[styles.textColor, {textAlign: 'left'}]}>{districtText}</Text>
  174. </View>
  175. <Text style={[styles.textColor, {textAlign: 'right', paddingRight: 5}]}>NO.{assetID}</Text>
  176. </View>
  177. <View style={{
  178. marginHorizontal: 5,
  179. }}>
  180. <Barcode value={item.assetID} format="CODE128" height={35} width={1.1}/>
  181. <Text style={styles.textColor}>{item.assetID}</Text>
  182. </View>
  183. </View>
  184. </View>
  185. </View>
  186. );
  187. };
  188. dianLiuRender = (item, index) => {
  189. const assetID = item.assetID.slice(parseInt(this.state.no_begin) - 1, parseInt(this.state.no_begin) + parseInt(this.state.no_length) - 1);
  190. const releaseDates = item.releaseDate.split('-');
  191. const releaseDate = releaseDates[0] + '年' + releaseDates[1] + '月';
  192. let districtText = '';
  193. if (parseInt(item.district) > 10000) {
  194. districtText = item.districtText;
  195. } else {
  196. const len1 = item.districtText.split('-')[1].length;
  197. districtText = '国网' + item.districtText.split('-')[1].slice(0, len1 - 1) + '电力';
  198. }
  199. return (
  200. <View
  201. key={index}
  202. style={styles.mainView}
  203. >
  204. <Text style={styles.textColor}>计量{item.kind}</Text>
  205. <View style={styles.betweenView}>
  206. <Text style={styles.textColor3}>型号:{item.model}</Text>
  207. <View style={styles.centerWidth}>
  208. <Text style={styles.textColor3}>电压等级:{item.voltageLevel}kV</Text>
  209. </View>
  210. <Text style={styles.textColor3}>绕组数量:{item.secondWindingCount}</Text>
  211. </View>
  212. <View style={styles.betweenView}>
  213. <Text style={styles.textColor4}>一次电流</Text>
  214. <View style={styles.centerWidth}>
  215. <Text style={styles.textColor4}>二次电流</Text>
  216. </View>
  217. <View style={styles.rightWidth}>
  218. <Text style={styles.textColor4}>功率因数</Text>
  219. </View>
  220. <Text style={styles.textColor4}>生产日期</Text>
  221. </View>
  222. <View style={styles.betweenView}>
  223. <View style={styles.centerView}>
  224. <Text style={styles.textColor4}>{item.firstCurrent}A</Text>
  225. </View>
  226. <View style={styles.centerWidth}>
  227. <Text style={styles.textColor4}>{item.senondCurrent}A</Text>
  228. </View>
  229. <View style={styles.rightWidth}>
  230. <Text style={styles.textColor4}>{item.powerFactor}</Text>
  231. </View>
  232. <View style={styles.centerView}>
  233. <Text style={styles.textColor4}>{releaseDate}</Text>
  234. </View>
  235. </View>
  236. <View style={styles.betweenView}>
  237. <Text style={styles.textColor3}>安装场所:{item.place}</Text>
  238. <View style={styles.centerWidth}>
  239. <Text style={styles.textColor3}>额定负荷:{item.ratedLoad}VA</Text>
  240. </View>
  241. <Text style={styles.textColor3}>准确等级:{item.accuracy}</Text>
  242. </View>
  243. <View style={styles.betweenView}>
  244. <View style={styles.centerView}>
  245. <Text style={styles.textColor3}>{item.manufacturer}</Text>
  246. </View>
  247. <View style={{
  248. width: (screenW - 10) / 3 * 2,
  249. borderLeftWidth: 0.5,
  250. borderLeftColor: '#7b7b7b',
  251. }}>
  252. <View style={{
  253. flexDirection: 'row',
  254. marginHorizontal: 3,
  255. }}>
  256. <View style={{
  257. flex: 1,
  258. }}>
  259. <Text style={[styles.textColor, {textAlign: 'left'}]}>{districtText}</Text>
  260. </View>
  261. <Text style={[styles.textColor, {textAlign: 'right', paddingRight: 5}]}>NO.{assetID}</Text>
  262. </View>
  263. <View style={{
  264. marginHorizontal: 5,
  265. }}>
  266. <Barcode value={item.assetID} format="CODE128" height={35} width={1.1}/>
  267. <Text style={styles.textColor}>{item.assetID}</Text>
  268. </View>
  269. </View>
  270. </View>
  271. </View>
  272. );
  273. };
  274. errorRender = (item, index) => {
  275. return (
  276. <View
  277. key={index}
  278. style={[styles.mainView, {padding: 10}]}
  279. >
  280. <Text style={{color: 'red'}}>{item.error_msg}</Text>
  281. </View>
  282. );
  283. };
  284. render() {
  285. let {isStart, zuhe_temp} = this.state;
  286. const start_text = isStart ? '开始识别' : '停止识别';
  287. return (
  288. <View style={styles.container}>
  289. <ScrollView style={styles.container}>
  290. {
  291. this.state.data.map((item, index) => {
  292. if (item.error) {
  293. return this.errorRender(item, index);
  294. }
  295. else if (item.kind.indexOf('电压') > -1) {
  296. return this.dianYaRender(item, index);
  297. }
  298. else if (item.kind.indexOf('电流') > -1) {
  299. return this.dianLiuRender(item, index);
  300. }
  301. else {
  302. // 组合互感器,没有设置,默认用电压模板
  303. if (zuhe_temp === '2') {
  304. return this.dianLiuRender(item, index);
  305. } else {
  306. return this.dianYaRender(item, index);
  307. }
  308. }
  309. })
  310. }
  311. </ScrollView>
  312. <Text
  313. style={{marginLeft: 10, color: '#f77b22'}}>合计:{this.state.data.length} 失败:{this.state.error}</Text>
  314. <View style={{flexDirection: 'row'}}>
  315. <Button onPress={() => this._start()}
  316. type="primary"
  317. style={[styles.button, {
  318. backgroundColor: isStart ? '#0099FF' : 'red',
  319. width: '65%',
  320. }]}
  321. >
  322. <Text style={{color: '#fff'}}>
  323. {start_text}
  324. </Text>
  325. </Button>
  326. <Button onPress={() => this._clear()}
  327. type="warning"
  328. style={{
  329. width: '25%',
  330. borderRadius: 5,
  331. marginHorizontal: 10,
  332. marginTop: 5,
  333. marginBottom: 2,
  334. borderWidth: 0,
  335. backgroundColor: '#de7642',
  336. }}
  337. >
  338. <Text style={{color: '#fff'}}>
  339. 清除
  340. </Text>
  341. </Button>
  342. </View>
  343. </View>
  344. );
  345. }
  346. }
  347. const styles = StyleSheet.create({
  348. container: {
  349. flex: 1,
  350. },
  351. button: {
  352. borderRadius: 5,
  353. marginHorizontal: 10,
  354. marginBottom: 2,
  355. marginTop: 5,
  356. borderWidth: 0,
  357. backgroundColor: '#2b90ea',
  358. },
  359. textColor: {
  360. color: '#333',
  361. textAlign: 'center',
  362. },
  363. textColor3: {
  364. color: '#333',
  365. textAlign: 'center',
  366. width: (screenW - 9) / 3,
  367. },
  368. textColor4: {
  369. color: '#333',
  370. textAlign: 'center',
  371. width: (screenW - 8) / 4,
  372. },
  373. textColor2: {
  374. color: '#333',
  375. textAlign: 'center',
  376. width: (screenW - 10) / 2,
  377. },
  378. mainView: {
  379. margin: 5,
  380. borderWidth: 0.5,
  381. borderColor: '#7b7b7b',
  382. },
  383. betweenView: {
  384. flexDirection: 'row',
  385. justifyContent: 'space-between',
  386. borderTopWidth: 0.5,
  387. borderTopColor: '#7b7b7b',
  388. },
  389. centerWidth: {
  390. borderLeftWidth: 0.5,
  391. borderRightWidth: 0.5,
  392. borderLeftColor: '#7b7b7b',
  393. borderRightColor: '#7b7b7b',
  394. alignItems: 'center',
  395. flexDirection: 'row',
  396. },
  397. centerView: {
  398. alignItems: 'center',
  399. flexDirection: 'row',
  400. },
  401. rightWidth: {
  402. borderRightWidth: 0.5,
  403. borderRightColor: '#7b7b7b',
  404. alignItems: 'center',
  405. flexDirection: 'row',
  406. },
  407. });
  408. export default DesktopHome2;