admin
2 天以前 4e91ae3c1ff41d0bf9f65d444c90c2583e69cdb7
提交 | 用户 | 时间
b78728 1 <template>
A 2   <div class="app-container">
3     <el-row :gutter="5">
4       <el-col :span="7">
5         <el-card shadow="never">
4e91ae 6           <span class="head-font">工位编号:{{headContent.processesCode}}</span>
b78728 7         </el-card>
A 8       </el-col>
9       <el-col :span="7">
10         <el-card shadow="never">
4e91ae 11           <span class="head-font">工位名称:{{headContent.processesName}}</span>
b78728 12         </el-card>
A 13       </el-col>
14       <el-col :span="10">
4e91ae 15         <el-card shadow="never" body-style="padding: 10px;">
A 16           <span class="head-font">产品序列号:</span>
22260b 17           <el-input style="width: 50%;" v-model="headContent.sfcCode" placeholder="请输入内容"></el-input>
A 18 <!--          <el-button type="primary" id="print" v-print="'#printMe'">打印</el-button>-->
d3541f 19           <el-button type="primary" id="print" v-print="'#printMe'" style="display: none;">打印</el-button>
22260b 20 <!--          <el-button id="print" @click="print1" type="primary">打印</el-button>-->
d3541f 21           <el-button type="primary" @click="printBefore">打印</el-button>
22260b 22           <el-button @click="clearClick" type="danger">清除</el-button>
b78728 23         </el-card>
A 24       </el-col>
25
26     </el-row>
27     <el-row :gutter="5" style="margin-top: 5px">
22260b 28       <el-col :span="24">
b78728 29         <el-tabs type="border-card"  style="height: 600px" v-model="activeName" @tab-click="changeMenu">
A 30           <el-tab-pane name="first">
31             <span slot="label"> <a class="el-icon-date"></a>首页</span>
32             <el-col :span="24">
33               <div>
4e91ae 34                 <div id="printMe">
22260b 35                   <offline-qualification-report :printParam="printParam"></offline-qualification-report>
b78728 36                 </div>
A 37               </div>
38             </el-col>
39           </el-tab-pane>
40         </el-tabs>
41       </el-col>
42     </el-row>
43   </div>
44 </template>
45 <script>
46 import {getIpv4, listStationConf} from "@/api/main/sc/stationConf";
47 import {
48   noPageListFormulaChild,
49   workpieceRelease,
50   yzUpdateResults,
51   yzUpdateTighteningFormula
52 } from "@/api/main/bs/formulaChild/formulaChild";
53 import MySerialPort from "@/utils/MySerialPort";
54 import USBDevice from "@/utils/usb.json";
55 import {addPassingStationCollection} from "@/api/main/da/passingStationCollection/passingStationCollection";
56 import {
4e91ae 57   addTighteningParameters, enterWeighing, getPrintOfflineReportInfo, listParamCollection,
b78728 58   replaceAssemblyCode,
A 59   saveCampaignTimeParameters,
60   yzAddBasicParameters,
61 } from "@/api/main/da/paramCollection/paramCollection";
62 import QRCode from "qrcodejs2";
2dd455 63 import OfflineQualificationReport from "@/views/components/offlineQualificationReport.vue";
4e91ae 64 import {listProductionOrde} from "@/api/main/om/productionOrde/productionOrde";
b78728 65
A 66 export default {
67   name: "stationTerminal",
2dd455 68   components: {OfflineQualificationReport},
b78728 69   data() {
A 70     return {
22260b 71       printParam: {
4e91ae 72
22260b 73       },
b78728 74       weightValue: '',
A 75       showInput: true,
76       serialPortContent: '',
77       // 查询参数
78       formulaChildParams: {
79         pageNum: 1,
80         pageSize: 10,
81         productCode: null,
82         processesCode: null,
83       },
84       // 配方配置子信息表格数据
85       formulaChildList: [],
86       ipAddress: '',
87       imgSrc: '',
88       headContent: {
89         processesCode: 'OP520',
90         processesName: '成品下线',
91         sfcCode: '',
92         yzSfcCode: '',
93       },
94       workpieceInformation: {
95         workOrderNo: null,
96         productCode: null,
97         productModel: null,
98         productName: null,
99         beat: null,
100       },
101       // 查询参数
102       queryParams: {
103         pageNum: 1,
104         pageSize: 10,
105         sfcCode: null,
106       },
107       // 查询参数
108       StationConfQueryParams: {
109         pageNum: 1,
110         pageSize: 10,
111         ipAddress: null,
112       },
113       cakeLamp: {
114         plcState: 1, //plc
115         scannerState: 1, //扫码枪
116         InPlace: 0, //工件到位
117         scanFinish: 0,
118         startWork: 0,
119         release: 0 //允许放行
120       },
121       content: '',
122       activeName: 'first',
d5a701 123       url: "ws://192.168.20.250:8080/websocket/message/",
b78728 124       message: "",
A 125       text_content: "",
126       ws: null,
127       inputValue: '9',
128
129       open1: false,
130       input: "",
131       keepReading: true,
132       form1: {
133         baudRate: "115200",
134         dataBits: "8",
135         stopBits: "1",
136         parity: "none",
137         flowControl: "none",
138         desc: "",
139         type: "1",
140         isShowHistory: false,
141       },
142       btnType: "primary",
143       btnText: "连接串口",
144       restaurants: [],
145       portsList: [],
146       isShowSendArea: false,
147       readType: 1,
148       title: "",
149
150       passingStationForm: {},
151       originalArray: [],
152       text1: '',
153     }
154   },
155   created() {
156     this.initStation();
157     // this.getStationConfList();
158     // setTimeout(() => {
159     //   this.connectWebsocket();
160     // }, 3000);
161   },
162   methods: {
163     serialLink() {
164       this.open1 = true
165     },
166     bindYzSfc(){
167       if(this.headContent.sfcCode!==""&&this.headContent.yzSfcCode!==""){
168         let param = {
169           sfcCode: this.headContent.sfcCode,
170           locationCode: this.headContent.processesCode,
171           yzSfcCode: this.headContent.yzSfcCode
172         }
173         this.$message('可以绑定!');
174         replaceAssemblyCode(param).then(response => {
175
176         });
177       }
178     },
179
180     serialPortMethod(value){
181       let formulaChildParams = {
182         scanBarcode: value,
183         sfcBarcode: this.headContent.sfcCode,
184         workOrderNo: this.workpieceInformation.workOrderNo,
185         productCode: "1P102S",
186         locationCode: this.headContent.processesCode,
187         collectionTime: new Date()
188       }
189       yzUpdateResults(formulaChildParams).then(response => {
190         this.getListFormulaChild()
191       });
192     },
193     rowStyle({ row }) {
194       if (row.results === 'OK') {
195         return 'background-color: PaleGreen';
196       } else if (row.results === 'NG') {
197         return 'background-color: LightSalmon';
198       }
199       return '';
200     },
201     /** 查询配方配置子信息列表 */
202     getListFormulaChild() {
203       this.formulaChildParams.productCode = "1P102S"
204       this.formulaChildParams.processesCode = this.headContent.processesCode
205       console.log(this.formulaChildParams)
206       noPageListFormulaChild(this.formulaChildParams).then(response => {
207         this.formulaChildList = response.rows;
208         if (this.formulaChildList.length >0){
209           let pos = 0
210           const tempArr = this.formulaChildList.filter(x=> 'OK' === x.results)
211           if (tempArr.length>0){
212             pos = tempArr.length
213             this.$nextTick(() => {
214               let temp33 = document.getElementsByClassName('el-table__row')
215               console.log('temp33',temp33)
216               console.log('len',temp33.item(pos))
217               if (temp33.length > 0){
218                 console.log('1111111111111111')
219                 let arr = temp33[pos-1]
220                 console.log('srr',arr)
221                 arr.scrollIntoView({ block: 'center' })
222               }
223             })
224           }
225
226         }
227       });
228     },
229     endClear(){
230
231     },
232     changeMenu(tab, event) {
233       console.log(tab, event);
234     },
235     clearClick(){
236       this.$message('这是一条清除消息提示');
237       this.headContent.sfcCode = null
238     },
239     scanCompleted(){
240       this.$message('扫码完成'+this.content);
241       this.headContent.sfcCode = this.content
242       this.queryParams.sfcCode = this.content
243       this.getList()
244       this.getListFormulaChild()
245       this.cakeLamp.scanFinish = 1
246       this.cakeLamp.startWork = 1
247
248     },
249     /** 查询工单列表 */
250     async getList() {
251       // this.getListFormulaChild()
252       // this.addOverStationCollection()
253       this.print1()
254     },
22260b 255     printBefore() {
A 256       if (this.headContent.sfcCode !== '') {
4e91ae 257         listProductionOrde({productNum: this.headContent.sfcCode}).then(response => {
A 258           let rowsData = response.rows[0];
259           if(rowsData){
260             getPrintOfflineReportInfo({productNum: this.headContent.sfcCode}).then(response => {
261               this.printParam = response.data
262               document.getElementById('print').click();
263             });
264           }else {
265             this.$message.error('系统没有此工单,请重新扫码!');
266           }
267         });
22260b 268       } else {
4e91ae 269         this.$message.error('请先扫码!');
b78728 270       }
A 271     },
4e91ae 272
22260b 273     // print1() {
A 274     //   if(this.headContent.sfcCode !== ''){
275     //     // 新开页面打印
276     //     const value = 'Hello, Parent!';
277     //     this.$emit('value-sent', value);
278     //     let newStr = document.getElementById('printMe').innerHTML;
279     //     let newWin = window.open('', '_blank');
280     //     newWin.document.body.innerHTML = newStr;
281     //     newWin.print();
282     //     return;
283     //   }else {
284     //     this.$message.error('请先扫码');
285     //   }
286     // },
b78728 287     /** 入站增加过站采集记录 **/
A 288     addOverStationCollection(){
289       this.passingStationForm = {
290         id: null,
291         // workOrderNo: this.workpieceInformation.workOrderNo,
292         productCode: "1P102S",
293         locationCode: this.headContent.processesCode,
294         // model: this.workpieceInformation.productModel,
295         productBarcode: this.headContent.sfcCode,
296         sfcCode: this.headContent.sfcCode,
297         inboundTime: new Date()
298       }
299       addPassingStationCollection(this.passingStationForm).then(response => {});
300       yzAddBasicParameters(this.passingStationForm).then(response => {});
301     },
302     initStation: async function () {
303       await getIpv4().then(response => {
304         this.StationConfQueryParams.ipAddress = response.msg
305         console.log('查询到本工位IP为' + this.StationConfQueryParams.ipAddress)
306       });
307       await listStationConf(this.StationConfQueryParams).then(response => {
308         let rows = response.rows[0]
309         if (response.rows.length === 0) {
310           // this.$message('该工位没有配置IP,请联系管理员配置IP');
311           return
312         }
313         this.headContent.processesName = rows.processesName
314         this.headContent.processesCode = rows.processesCode
315         console.log('设置工位编码' + this.headContent.processesCode)
316
317       });
318       this.conCom()
319       console.log('websocket连接工位为' + this.headContent.processesCode)
320       const wsuri = this.url + this.headContent.processesCode;
321       this.ws = new WebSocket(wsuri);
322       const self = this;
323       this.ws.onopen = function (event) {
324         this.$message('websocket连接成功!');
325       };
326       this.ws.onmessage = function (event) {
4280d7 327         if (event.data === "print") {
A 328           self.$message('postman调用打印方法打印!');
329           // self.print1()
330           document.getElementById('print').click();
331         }else if (event.data === "IN") {
b78728 332           self.cakeLamp.InPlace = 1;
A 333         } else if (event.data === "IN0") {
334           self.cakeLamp.InPlace = 0;
335         } else if (event.data === "OUT") {
336           console.log("out")
337
338           const param = {
339             workOrderNo: self.workpieceInformation.workOrderNo,
340             productCode: "1P102S",
341             locationCode: self.headContent.processesCode,
342             productBarcode: self.headContent.sfcCode,
343           }
344           // saveCampaignTimeParameters(param).then(response => {});
345           // self.cakeLamp.release = 1;
346           workpieceRelease(param).then(response => {});
347           self.formulaChildList = [];
348           self.headContent.sfcCode = '';
349           console.log(self.formulaChildList)
350         } else if (event.data === "END") {
351           // const param = {
352           //   workOrderNo: self.workpieceInformation.workOrderNo,
353           //   productCode: self.workpieceInformation.productCode,
354           //   locationCode: self.headContent.processesCode,
355           //   productBarcode: self.headContent.sfcCode,
356           // }
357           // saveCampaignTimeParameters(param).then(response => {});
358           // self.endClear()
359           // workpieceRelease(param).then(response => {});
360         } else if (event.data.includes("[")) {
361           let formulaChilds = "";
362           self.formulaChildList.sort((a, b) => a.stepSort - b.stepSort);
363           self.formulaChildList
364             .filter((formulaChild) => formulaChild.operationType === '1');
365           for (let i = 0; i < self.formulaChildList.length; i++) {
366             let formulaChild = self.formulaChildList[i];
367             let results = formulaChild.results;
368             if (results === '' || results === null || results === 'NG') {
369               formulaChilds = formulaChild;
370               break;
371             }
372           }
373           const param = {
374             tightenTheArray: event.data,
375             paramCode: formulaChilds.paramCode,
376             // workOrderNo: self.workpieceInformation.workOrderNo,
377             productCode: "1P102S",
378             locationCode: self.headContent.processesCode,
379             productBarcode: self.headContent.sfcCode,
380           }
381           addTighteningParameters(param).then(response => {});
382           yzUpdateTighteningFormula(param).then(response => {
383             console.log(response.msg)
384             if(response.msg === "1"){
385               self.getListFormulaChild()
386
387             }else {
388               const param = {
389                 workOrderNo: self.workpieceInformation.workOrderNo,
390                 productCode: "1P102S",
391                 locationCode: self.headContent.processesCode,
392                 productBarcode: self.headContent.sfcCode,
393               }
394               saveCampaignTimeParameters(param).then(response => {});
395               workpieceRelease(param).then(response => {});
396               self.formulaChildList = [];
397               self.headContent.sfcCode = '';
398             }
399           });
400         }
401       };
402     },
403
404
405
406     //接受数据的回调
407     callBack(value) {
408       if (this.form1.isShowHistory) this.form1.desc = this.readLi().join("");
409       else {
410         const scanValue = this.myserialport.hex2atostr(value).replace(/[\r\n]/g, '');
411         console.log("串口收到数据-------------------"+scanValue)
412         this.test1()
413         this.test2()
414         this.text1 = scanValue
415         this.headContent.sfcCode = scanValue
416         // this.print1()
417         // setTimeout(() => {
418         //   this.print()
419         // },50)
420         // this.getList()
421
422       }
423     },
424     clearHistory() {
425       this.form1.desc = "";
426       this.myserialport.state.readValue = [];
427     },
428     loadHistory() {
429       if (this.form1.isShowHistory) this.form1.desc = this.readLi().join("");
430       else {
431         let temp = this.readLi();
432         if (temp.length > 0) this.form1.desc = temp[temp.length - 1].join("");
433       }
434     },
435     readLi() {
436       let readType = this.readType;
437       return this.myserialport.state.readValue.map((items, index) => {
438         const item = items.value;
439         const type = items.type; // 1接收,2发送
440         let body = [];
441         if (item !== undefined) {
442           let strArr = [];
443           for (let hex of Array.from(item)) {
444             strArr.push(hex.toString(16).toLocaleUpperCase());
445           }
446           if (strArr.includes("D") && strArr.includes("A")) {
447             if (strArr.indexOf("A") - strArr.indexOf("D") === 1) {
448               strArr.splice(strArr.indexOf("D"), 1);
449               strArr.splice(strArr.indexOf("A"), 1, <br key={0} />);
450             }
451           }
452           strArr = strArr.map((item) => {
453             if (typeof item === "string") {
454               if (readType === 1) {
455                 return this.myserialport.hex2a(parseInt(item, 16));
456               } else if (readType === 2) {
457                 return item + " ";
458               }
459             }
460             return item;
461           });
462           if (typeof strArr[strArr.length - 1] === "string") {
463             strArr.push("\r\n");
464           }
465           body.push(strArr.join(""));
466         }
467         return body;
468       });
469     },
470     conCom(){
471       try {
472         this.myserialport.state.baudRate = this.form1.baudRate;
473         this.myserialport.state.dataBits = this.form1.dataBits;
474         this.myserialport.state.stopBits = this.form1.stopBits;
475         this.myserialport.state.parity = this.form1.parity;
476         this.myserialport.state.flowControl = this.form1.flowControl;
477         this.myserialport.openPort(0, true, this.callBack);
478         console.log(this.form1.port)
479       } catch (error) {
480         this.$message.error("串口连接失败!请检查串口是否已被占用");
481       }
482       if (this.myserialport.state.isOpen) {
483         this.$message.success("串口连接成功");
484       }
485     },
486     //连接
487     async connectBtn() {
488       if (this.btnType === "primary") {
489         try {
490           this.myserialport.state.baudRate = this.form1.baudRate;
491           this.myserialport.state.dataBits = this.form1.dataBits;
492           this.myserialport.state.stopBits = this.form1.stopBits;
493           this.myserialport.state.parity = this.form1.parity;
494           this.myserialport.state.flowControl = this.form1.flowControl;
495           await this.myserialport.openPort(this.form1.port, true, this.callBack);
496           console.log(this.form1.port)
497         } catch (error) {
498           this.$message.error("串口连接失败!请检查串口是否已被占用");
499         }
500         if (this.myserialport.state.isOpen) {
501           this.$message.success("串口连接成功");
502           this.open1 = false
503           this.btnType = "danger";
504           this.btnText = "关闭串口";
505         }
506       } else {
507         this.myserialport.openPort(this.form1.port, false, this.callBack);
508         this.$message.success("串口关闭成功");
509         this.btnType = "primary";
510         this.btnText = "连接串口";
511       }
512     },
513     //授权
514     async obtainAuthorization() {
515       if ("serial" in navigator) {
516         console.log("The Web Serial API is supported.");
517         if (!this.myserialport) this.myserialport = new MySerialPort();
518         try {
519           await this.myserialport.handleRequestPort();
520           this.$message.success("串口授权成功");
521           this.getPortInfo(this.myserialport.state.ports);
522         } catch (error) {
523           this.$message.warning("未选择新串口授权!");
524         }
525       } else {
526         this.$message.error(
527           "当前为HTTP模式或者浏览器版本过低,不支持网页连接串口"
528         );
529       }
530     },
531     //串口列表初始化
532     getPortInfo(portList) {
533       this.portsList = [];
534       portList.map((port, index) => {
535         const { usbProductId, usbVendorId } = port.getInfo();
536         if (usbProductId === undefined || usbVendorId === undefined) {
537           this.portsList.push({ label: "未知设备" + index, value: index });
538         } else {
539           const usbVendor = USBDevice.filter(
540             (item) => parseInt(item.vendor, 16) === usbVendorId
541           );
542           let usbProduct = [];
543           if (usbVendor.length === 1) {
544             usbProduct = usbVendor[0].devices.filter(
545               (item) => parseInt(item.devid, 16) === usbProductId
546             );
547           }
548           this.portsList.push({ label: usbProduct[0].devname, value: index });
549         }
550       });
551     },
552     // 发送
553     async sendCommon() {
554       if (this.myserialport.state.isOpen) {
555         if (this.form1.sendMsg.length !== 0) {
556           const writeType = this.form1.type;
557           let value = this.form1.sendMsg;
558           let arr = [];
559           if (writeType === 1) {
560             // ASCII
561             for (let i = 0; i < value.length; i++) {
562               arr.push(this.myserialport.a2hex(value[i]));
563             }
564           } else if (writeType === 2) {
565             // HEX
566             if (/^[0-9A-Fa-f]+$/.test(value) && value.length % 2 === 0) {
567               for (let i = 0; i < value.length; i = i + 2) {
568                 arr.push(parseInt(value.substring(i, i + 2), 16));
569               }
570             } else {
571               this.$message.error("格式错误");
572               return;
573             }
574           }
575           this.myserialport.writeText(arr);
576         } else {
577           this.$message.warning("请输入发送的信息");
578         }
579       } else {
580         this.$message.warning("串口处于关闭状态,请连接串口");
581       }
582     },
583     async getPorts() {
584       await this.myserialport.getPorts();
585       this.getPortInfo(this.myserialport.state.ports);
586     },
587     querySearch(queryString, cb) {
588       var restaurants = this.restaurants;
589       var results = queryString
590         ? restaurants.filter(this.createFilter(queryString))
591         : restaurants;
592       // 调用 callback 返回建议列表的数据
593       cb(results);
594     },
595     createFilter(queryString) {
596       return (restaurant) => {
597         return (
598           restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) ===
599           0
600         );
601       };
602     },
603     loadAll() {
604       return [
605         { value: "110" },
606         { value: "300" },
607         { value: "600" },
608         { value: "1200" },
609         { value: "2400" },
610         { value: "4800" },
611         { value: "7200" },
612         { value: "9600" },
613         { value: "14400" },
614         { value: "19200" },
615         { value: "28800" },
616         { value: "38400" },
617         { value: "56000" },
618         { value: "57600" },
619         { value: "76800" },
620         { value: "115200" },
621         { value: "230400" },
622         { value: "460800" },
623       ];
624     },
625   }
626 }
627
628 </script>
22260b 629
b78728 630 <style scoped>
359f3b 631 .div1, .div2 {
A 632   flex: 1; /* 两个div平分容器宽度 */
633 }
3dca2f 634 .span{
A 635   font-family: 'Microsoft YaHei', sans-serif;
636 }
359f3b 637 .div2{
A 638   margin-left: 30px;
639 }
b78728 640 .bottom-card{
A 641   height: 600px;
642 }
643 .circle-button{
644   height: 30px;
645   width: 30px;
646 }
647 .circle-red {
648   background-color: #e01a4f;
649 }
650 .circle-green {
651   background-color: green;
652 }
653 .circle-green-animate {
654   background-color: green;
655   animation: circle-green-animate 2s infinite;
656 }
657 @keyframes circle-green-animate {
658   50% {
659     opacity: 0.6;
660   }
661   0% {
662     opacity: 0.2;
663   }
664 }
665 .head-font{
666   /*font-weight: bold;*/
667   /*font-size: 25px;*/
668 }
669 span{
670   font-size: 15px;
671 }
672 .el-table .warning-row {
673   background: oldlace;
674 }
675
676 .el-table .success-row {
677   background: #f0f9eb;
678 }
4e91ae 679
A 680 /*隐藏打印区域*/
681 /*#printMe {*/
682 /*  display: none;*/
683 /*}*/
684 /*!*打印时显示打印区域*!*/
685 /*@media print {*/
686 /*  #printMe {*/
687 /*    display: block;*/
688 /*  }*/
689 /*}*/
b78728 690 </style>
A 691