balanceAlert.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <template>
  2. <div class="content">
  3. <!-- <el-radio-group v-if="deptBudgetList.warehouseName=='榆树库'" @change="radiochange" v-model="radio">
  4. <el-radio :label="1">大秤</el-radio>
  5. <el-radio :label="2">小秤</el-radio>
  6. </el-radio-group> -->
  7. <div class="title" v-if="information">{{information}}</div>
  8. <div class="title" v-else></div>
  9. <div class="contentInfo">
  10. <div class="uncertain">浮动重量</div>
  11. <div class="number" v-if="information.indexOf('毛重') > -1">
  12. {{ grossWeightVal }} kg
  13. </div>
  14. <div class="number" v-else>{{ tareVal }} kg</div>
  15. </div>
  16. <div class="contentInfo confirmWeight">
  17. <div class="uncertain titleWeight">确认重量</div>
  18. <div class="number weight" v-if="information.indexOf('毛重') > -1">
  19. {{ grossWeightVal1 }} kg
  20. </div>
  21. <div class="number weight" v-else>{{ tareVal1 }} kg</div>
  22. </div>
  23. <div class="confirmInfo">
  24. <div class="car-type">车牌号</div>
  25. <div class="car-no">{{ deptBudgetList.carNumber }}</div>
  26. </div>
  27. <div class="btn" @click="sendVal">确定</div>
  28. </div>
  29. </template>
  30. <script>
  31. export default {
  32. name: 'balanceAlert',
  33. props: ['deptBudgetList', 'information'],
  34. data() {
  35. return {
  36. param: 9600,
  37. grossWeightVal: '',
  38. tareVal: '',
  39. grossWeightVal1: '',
  40. tareVal1: '',
  41. radio:1,
  42. carNumber:''
  43. }
  44. },
  45. activated() {},
  46. mounted() {
  47. console.log(this.deptBudgetList)
  48. this.openPort()
  49. },
  50. computed: {},
  51. created() {},
  52. methods: {
  53. sendVal() {
  54. if (this.information.indexOf('毛重') > -1) {
  55. this.grossWeightVal1=this.grossWeightVal
  56. }else{
  57. this.tareVal1=this.tareVal
  58. }
  59. console.log(this.grossWeightVal)
  60. console.log(this.tareVal)
  61. console.log(this.deptBudgetList)
  62. if (this.information.indexOf('毛重') > -1) {
  63. this.$emit('balanceListen', this.grossWeightVal)
  64. } else {
  65. this.$emit('balanceListen', this.tareVal)
  66. }
  67. },
  68. radiochange(e){
  69. console.log(e)
  70. localStorage.setItem('balanceStatus',e)
  71. this.openPort()
  72. },
  73. async closePort() {
  74. console.log('closePort')
  75. this.reader.cancel()
  76. },
  77. async openPort() {
  78. console.log(localStorage.getItem('balanceStatus'),this.deptBudgetList.warehouseName)
  79. console.log('openPort', navigator)
  80. if ('serial' in navigator) {
  81. if (!this.$store.state.app.reader) {
  82. if(localStorage.getItem('balanceStatus')){
  83. this.radio=localStorage.getItem('balanceStatus')
  84. }
  85. // The Web Serial API is supported.
  86. console.log('the Web Serial API is supported.')
  87. const port = await navigator.serial.requestPort()
  88. if (
  89. this.deptBudgetList.warehouseName == '白城内陆港' ||
  90. this.deptBudgetList.warehouseName == '肇东金信库'||
  91. this.deptBudgetList.warehouseName == '白城鹏羽库'||
  92. this.deptBudgetList.warehouseName == '洮南胡力吐粮食储备库'||
  93. this.deptBudgetList.warehouseName == '洮南向阳乡金昊'
  94. ) {
  95. this.param = 1200
  96. } else if (this.deptBudgetList.warehouseName == '鲅鱼圈祥腾库') {
  97. this.param = 2400
  98. } else if(this.deptBudgetList.warehouseName == '大庆朝阳沟库' ){
  99. this.param = 4800
  100. }else if(this.deptBudgetList.warehouseName == '榆树库' &&this.radio==2){
  101. this.param = 1200
  102. } else {
  103. this.param = 9600
  104. }
  105. console.log(this.param)
  106. await port.open({
  107. baudRate: this.param
  108. }) // set baud rate
  109. this.reader = port.readable.getReader()
  110. console.log('port ', port)
  111. this.$store.dispatch('app/setReader', this.reader)
  112. console.log('reader ', this.reader)
  113. } else {
  114. console.log('afterport', this.$store.state.app.reader)
  115. this.reader = this.$store.state.app.reader
  116. }
  117. // 监听来自串行设备的数据
  118. while (true) {
  119. const { value, done } = await this.reader.read()
  120. // console.log('value',value);
  121. if (done) {
  122. // 允许稍后关闭串口。
  123. this.reader.releaseLock()
  124. break
  125. }
  126. var result = ''
  127. //2。获取16进制字符串
  128. // var receData = HexConvert.ByteToString(value);
  129. // console.log("receData",receData);
  130. var flag = false
  131. if (
  132. this.deptBudgetList.warehouseName == '克东润津库'&&
  133. value.length < 9
  134. ) {
  135. continue
  136. }
  137. if (value.length > 2) {
  138. if (value.length <= 6) {
  139. // continue
  140. }
  141. if (
  142. (this.deptBudgetList.warehouseName == '肇东金信库' || this.deptBudgetList.warehouseName == '甘南宏旗库') &&
  143. value.length < 10
  144. ) {
  145. var start = new Date().getTime()
  146. while (new Date().getTime() - start < 100) {}
  147. continue
  148. }
  149. if (
  150. this.deptBudgetList.warehouseName == '克东瑞信达'&&
  151. value.length < 10
  152. ) {
  153. var start = new Date().getTime()
  154. while (new Date().getTime() - start < 30) {}
  155. continue
  156. }
  157. var zzz = ''
  158. for (var i = 0; i < value.length; i++) {
  159. zzz += String.fromCharCode(value[i])
  160. }
  161. console.log('value23:', value)
  162. console.log('valuezzz:', zzz)
  163. } else if (
  164. this.deptBudgetList.warehouseName == '白城内陆港' ||
  165. this.deptBudgetList.warehouseName == '洮南胡力吐粮食储备库' ||
  166. this.deptBudgetList.warehouseName == '鲅鱼圈祥腾库'||
  167. this.deptBudgetList.warehouseName == '洮南向阳乡金昊'
  168. ) {
  169. console.log('value:', value)
  170. var start = new Date().getTime()
  171. while (new Date().getTime() - start < 400) {}
  172. continue
  173. }
  174. else if (
  175. this.deptBudgetList.warehouseName == '克东瑞信达'&&
  176. value.length < 10
  177. ) {
  178. var start = new Date().getTime()
  179. while (new Date().getTime() - start < 30) {}
  180. continue
  181. }
  182. var zzz = ''
  183. for (var i = 0; i < value.length; i++) {
  184. zzz += String.fromCharCode(value[i])
  185. }
  186. console.log('value23:', value)
  187. console.log('valuezzz:', zzz)
  188. if (
  189. this.deptBudgetList.warehouseName &&
  190. (this.deptBudgetList.warehouseName == '山东诸城迈饶库' ||
  191. this.deptBudgetList.warehouseName == '山东园丰库' ||
  192. this.deptBudgetList.warehouseName == '克东千红库' ||
  193. this.deptBudgetList.warehouseName == '鲅鱼圈祥腾库' ||
  194. this.deptBudgetList.warehouseName == '哈尔滨依兰库' ||
  195. this.deptBudgetList.warehouseName == '龙江金信库' ||
  196. this.deptBudgetList.warehouseName == '白城内陆港' ||
  197. this.deptBudgetList.warehouseName == '白城鹏羽库' ||
  198. this.deptBudgetList.warehouseName == '洮南胡力吐粮食储备库' ||
  199. this.deptBudgetList.warehouseName == '杜尔伯特家禾库' ||
  200. this.deptBudgetList.warehouseName == '洮南向阳乡金昊' ||
  201. this.deptBudgetList.warehouseName == '洮南光明储备库' ||
  202. this.deptBudgetList.warehouseName == '甘南林峰库' ||
  203. this.deptBudgetList.warehouseName == '肇东金信库' ||
  204. this.deptBudgetList.warehouseName == '呼兰大金仓'||
  205. this.deptBudgetList.warehouseName == '克东润津库'||
  206. this.deptBudgetList.warehouseName == '洮南新友谊兴旺库'||
  207. this.deptBudgetList.warehouseName == '通榆瑞祥源库'||
  208. this.deptBudgetList.warehouseName == '榆树民胜库'||
  209. this.deptBudgetList.warehouseName == '榆树库'||
  210. this.deptBudgetList.warehouseName == '洮南蛟流河烘干塔'||
  211. this.deptBudgetList.warehouseName == '克东瑞信达')
  212. ) {
  213. for (var i = 0; i < value.length; i++) {
  214. var tmp = String.fromCharCode(value[i])
  215. if (tmp == '+') {
  216. flag = true
  217. }
  218. if (flag && result.length < 6 && tmp != '+') {
  219. result += tmp
  220. }
  221. }
  222. if (this.information.indexOf('毛重') > -1) {
  223. if (parseInt(result) || parseInt(result) == 0) {
  224. this.grossWeightVal = parseInt(result)
  225. }
  226. } else {
  227. if (parseInt(result) || parseInt(result) == 0) {
  228. this.tareVal = parseInt(result)
  229. }
  230. }
  231. } else
  232. if (
  233. this.deptBudgetList.warehouseName &&
  234. (this.deptBudgetList.warehouseName == '顺诚粮库' ||
  235. this.deptBudgetList.warehouseName == '鲅鱼圈金信库'|
  236. this.deptBudgetList.warehouseName == '大庆朝阳沟库')
  237. ) {
  238. for (var i = value.length - 1; i >= 0; i--) {
  239. var tmp = String.fromCharCode(value[i])
  240. console.log(tmp)
  241. if (String.fromCharCode(value[0]) == '.') {
  242. flag = true
  243. }
  244. if (flag && result.length < 9 && tmp != '=' && tmp != '.') {
  245. result += tmp
  246. }
  247. }
  248. if (this.information.indexOf('毛重') > -1) {
  249. if (parseInt(result) || parseInt(result) == 0) {
  250. this.grossWeightVal = parseInt(result)
  251. }
  252. } else {
  253. if (parseInt(result) || parseInt(result) == 0) {
  254. this.tareVal = parseInt(result)
  255. }
  256. }
  257. } else{
  258. if (value.length > 10) {
  259. for (var i = 0; i < value.length; i++) {
  260. var tmp = String.fromCharCode(value[i])
  261. // if (value[0] != 49 && value[0] != 2) {
  262. // // if (
  263. // // value[value.length - 1] == 48 &&
  264. // // value[value.length - 2] == 48
  265. // // ) {
  266. // // flag1 = true
  267. // // } else {
  268. // // break
  269. // // }
  270. // // flag1 = true
  271. // if (i == 0) {
  272. // this.result1 = tmp + '0'
  273. // }
  274. // }
  275. // else{
  276. // if (tmp == String.fromCharCode(32)) {
  277. // flag = true
  278. // }
  279. // }
  280. if (tmp == String.fromCharCode(32)) {
  281. flag = true
  282. }
  283. if (
  284. flag &&
  285. result.length < 7 &&
  286. tmp != String.fromCharCode(32)
  287. // &&
  288. // !(
  289. // value[value.length - 1] == 48 && value[value.length - 2] == 48
  290. // )
  291. ) {
  292. if (i > 0 && value[i] == 48 && value[i - 1] == 32 && result) {
  293. break
  294. } else {
  295. result += tmp
  296. }
  297. }
  298. // if (flag1 && tmp != String.fromCharCode(32)) {
  299. // // if (
  300. // // value[value.length - 1] == 48 &&
  301. // // value[value.length - 2] == 48
  302. // // ) {
  303. // // if (i == 0) {
  304. // // this.result1 = tmp + '0'
  305. // // }
  306. // // }
  307. // if (i == 0) {
  308. // this.result1 = tmp + '0'
  309. // }
  310. // }
  311. }
  312. }
  313. if (this.information.indexOf('毛重') > -1) {
  314. if (parseInt(result) || parseInt(result) == 0) {
  315. this.grossWeightVal = parseInt(result + this.result1)
  316. }
  317. } else {
  318. if (parseInt(result) || parseInt(result) == 0) {
  319. this.tareVal = parseInt(result + this.result1)
  320. }
  321. }
  322. }
  323. // else {
  324. // for (var i = 0; i < value.length; i++) {
  325. // var tmp = String.fromCharCode(value[i])
  326. // if (tmp == '+') {
  327. // flag = true
  328. // }
  329. // if (flag && result.length < 6 && tmp != '+') {
  330. // result += tmp
  331. // }
  332. // }
  333. // if (this.information.indexOf('毛重') > -1) {
  334. // if (parseInt(result) || parseInt(result) == 0) {
  335. // this.grossWeightVal = parseInt(result)
  336. // }
  337. // } else {
  338. // if (parseInt(result) || parseInt(result) == 0) {
  339. // this.tareVal = parseInt(result)
  340. // }
  341. // }
  342. // }
  343. // setTimeout(1000)
  344. // value 是一个 Uint8Array
  345. }
  346. await port.close()
  347. } else {
  348. console.log('the Web Serial API is not supported.', navigator)
  349. }
  350. }
  351. }
  352. }
  353. </script>
  354. <style lang="scss" scoped>
  355. /deep/.el-radio-group{
  356. position:absolute;
  357. top:29px;
  358. }
  359. /deep/.el-radio{
  360. color:#fff;
  361. }
  362. /deep/.el-radio__input.is-checked+.el-radio__label{
  363. color:#2aff7c;
  364. }
  365. /deep/.el-radio__input.is-checked .el-radio__inner {
  366. background: #2aff7c !important;
  367. border-color: #2aff7c !important;
  368. }
  369. .content {
  370. height: 350px;
  371. position: relative;
  372. background: black;
  373. color: #2aff7c;
  374. font-size: 32px;
  375. text-align: right;
  376. padding: 20px;
  377. border-radius: 10px;
  378. margin: 0 20px 20px 20px;
  379. .btn {
  380. position: absolute;
  381. bottom: 20px;
  382. right: 20px;
  383. border: 1px solid #2aff7c;
  384. width: 200px;
  385. border-radius: 10px;
  386. display: flex;
  387. align-items: center;
  388. justify-content: center;
  389. }
  390. .contentInfo {
  391. display: flex;
  392. .uncertain {
  393. width: 35%;
  394. text-align: left;
  395. }
  396. .number {
  397. width: 65%;
  398. text-align: right;
  399. }
  400. }
  401. }
  402. .title {
  403. text-align: right;
  404. margin-bottom: 20px;
  405. }
  406. .confirmWeight {
  407. display: flex;
  408. align-items: center;
  409. .titleWeight {
  410. width: 35%;
  411. text-align: left;
  412. line-height: 90px;
  413. color: red;
  414. }
  415. .weight {
  416. width: 65%;
  417. text-align: right;
  418. color: red;
  419. }
  420. }
  421. .confirmInfo {
  422. display: flex;
  423. color: #2aff7c;
  424. .car-type {
  425. text-align: left;
  426. width: 50%;
  427. }
  428. .car-no {
  429. width: 50%;
  430. text-align: right;
  431. }
  432. }
  433. </style>