admin
2024-07-31 dd5d35a6047d6a44d798ef8689a09a49eefec528
提交 | 用户 | 时间
b78728 1 <template>
A 2   <div class="app-container">
3    <el-row :gutter="5">
dd5d35 4      <el-col  :span="7">
A 5        <el-card style="height: 71px" shadow="never">
6          <span style="margin-top: 200px" class="head-font">工位编号 : {{headContent.processesCode}}</span>
b78728 7        </el-card>
A 8      </el-col>
dd5d35 9      <el-col :span="17">
b78728 10        <el-card shadow="never">
dd5d35 11          <span class="head-font">物料编码 : </span>
A 12          <el-input style="width: 50%" v-model="materialCode" @change="handleEnter" placeholder="请扫描物料编码"></el-input>
13          <el-button type="primary" style="float: right" icon="el-icon-search"  @click="serialLink">串口连接</el-button>
14          <el-button @click="clearClick" style="float: right" type="danger" >清除</el-button>
b78728 15        </el-card>
A 16      </el-col>
17
18    </el-row>
19    <el-row :gutter="5" style="margin-top: 5px">
20      <el-col :span="7" >
21        <el-card class="bottom-card">
22          <div slot="header" class="clearfix">
23            <i class="el-icon-tickets"></i>
24            <span style="font-weight: bold">当前工件信息</span>
25          </div>
26          <el-descriptions :column="1" border :content-style="{'min-width': '140px'}">
dd5d35 27            <el-descriptions-item label="产品序列号">
A 28              <span>{{headContent.sfcCode}}</span>
29            </el-descriptions-item>
b78728 30            <el-descriptions-item label="工单编号">
A 31                <span>{{workpieceInformation.workOrderNo}}</span>
32            </el-descriptions-item>
33            <el-descriptions-item label="物料编码">
34              <span>{{workpieceInformation.materialCode}}</span>
35            </el-descriptions-item>
36            <el-descriptions-item label="计划数量">
37              <span>{{workpieceInformation.planQty}}</span>
38            </el-descriptions-item>
39            <el-descriptions-item label="开始时间">
40              <span>{{workpieceInformation.inboundTime}}</span>
41            </el-descriptions-item>
42          </el-descriptions>
43          <el-divider></el-divider>
44          <el-row>
45            <el-col :span="12">
46              <el-button class="circle-button" :class="cakeLamp.plcState ? 'circle-green-animate':'circle-red'" circle></el-button>
47              <span style="display: none">{{cakeLamp.plcState}}</span>
48              <span>&nbsp;PLC状态</span>
49            </el-col>
50            <el-col :span="12">
51              <el-button class="circle-button" :class="cakeLamp.scannerState ? 'circle-green-animate':'circle-red'" circle></el-button>
52              <span style="display: none">{{cakeLamp.scannerState}}</span>
53              <span>&nbsp;扫码枪状态</span>
54            </el-col>
55          </el-row>
56          <el-row style="margin-top: 20px">
57            <el-col :span="12">
58              <el-button class="circle-button" :class="cakeLamp.InPlace ? 'circle-green':'circle-red'" circle></el-button>
59              <span style="display: none">{{cakeLamp.InPlace}}</span>
60              <span>&nbsp;工件到位</span>
61            </el-col>
62            <el-col :span="12">
63              <el-button class="circle-button" :class="cakeLamp.scanFinish ? 'circle-green':'circle-red'" circle></el-button>
64              <span style="display: none">{{cakeLamp.scanFinish}}</span>
65              <span>&nbsp;扫码完成</span>
66            </el-col>
67          </el-row>
68          <el-row style="margin-top: 20px">
69            <el-col :span="12">
70              <el-button class="circle-button" :class="cakeLamp.startWork ? 'circle-green':'circle-red'" circle></el-button>
71              <span style="display: none">{{cakeLamp.startWork}}</span>
72              <span>&nbsp;开始作业</span>
73            </el-col>
74            <el-col :span="12">
75              <el-button class="circle-button" :class="cakeLamp.release ? 'circle-green':'circle-red'" circle></el-button>
76              <span style="display: none">{{cakeLamp.release}}</span>
77              <span>&nbsp;允许放行</span>
78            </el-col>
79          </el-row>
80          <el-row v-show="orderFlag" style="margin-top: 20px">
81            <el-button @click="getWorkOrders" type="warning" size="mini">接收工单</el-button>
82          </el-row>
83        </el-card>
84
85      </el-col>
86      <el-col :span="17">
87        <el-tabs type="border-card"  style="height: 600px" v-model="activeName" @tab-click="changeMenu">
88          <el-tab-pane name="first">
89            <span slot="label"> <a class="el-icon-date"></a>首页</span>
90            <el-col :span="24">
91              <el-table height="500" :cell-style="rowStyle" :data="formulaChildList">
92                <el-table-column label="拧紧步号" width="80" align="center" prop="stepSort">
93                </el-table-column>
94                <el-table-column label="操作内容" align="center" prop="operationSteps">
95                </el-table-column>
96                <el-table-column label="产品编号" width="80" align="center" prop="productCode">
97                </el-table-column>
98                <el-table-column label="物料编码" width="110" align="center" prop="materialCode">
99                </el-table-column>
100                <el-table-column label="采集值" align="center" prop="collectData">
101                </el-table-column>
102                <el-table-column label="结果" width="60" align="center" prop="results">
103                </el-table-column>
104
105              </el-table>
106            </el-col>
107          </el-tab-pane>
108        </el-tabs>
109      </el-col>
110    </el-row>
111     <el-dialog v-dialogpop-up :title="title" :visible.sync="open1" width="1000" append-to-body>
112       <el-row
113         type="flex"
114         class="row-bg"
115         justify="center"
116         v-show="portsList.length === 0"
117       >
118         <el-col :span="7">
119           <div style="margin-top: 400px">
120           <span style="display: block">
121             仅支持Chrome 89+或者Edge 89+浏览器(安全上下文(HTTPS)中可用)
122           </span>
123             <el-button type="primary" @click="obtainAuthorization">授权</el-button>
124           </div>
125         </el-col>
126       </el-row>
127       <el-form
128         v-show="portsList.length > 0"
129         ref="form1"
130         :model="form1"
131         label-width="100px">
132         <el-row>
133           <el-col :span="24"
134           ><div>
135             <el-form-item label="串口">
136               <el-select
137                 v-model="form1.port"
138                 filterable
139                 placeholder="请选择串口"
140                 :disabled="isDisable"
141               >
142                 <el-option
143                   v-for="item in portsList"
144                   :key="item.value"
145                   :label="item.label"
146                   :value="item.value"
147                 >
148                 </el-option>
149               </el-select>
150             </el-form-item>
151             <el-form-item label="波特率">
152               <el-autocomplete
153                 popper-class="my-autocomplete"
154                 v-model="form1.baudRate"
155                 :fetch-suggestions="querySearch"
156                 placeholder="请输入波特率"
157                 :disabled="isDisable"
158               >
159                 <i class="el-icon-edit el-input__icon" slot="suffix"> </i>
160                 <template slot-scope="{ item }">
161                   <div class="name">{{ item.value }}</div>
162                   <span class="addr">{{ item.address }}</span>
163                 </template>
164               </el-autocomplete>
165             </el-form-item>
166             <el-form-item label="数据位">
167               <el-select
168                 v-model="form1.dataBits"
169                 placeholder="请选择数据位"
170                 :disabled="isDisable"
171               >
172                 <el-option label="7" value="7"></el-option>
173                 <el-option label="8" value="8"></el-option>
174               </el-select>
175             </el-form-item>
176             <el-form-item label="停止位">
177               <el-select
178                 v-model="form1.stopBits"
179                 placeholder="请选择停止位"
180                 :disabled="isDisable"
181               >
182                 <el-option label="1" value="1"></el-option>
183                 <el-option label="2" value="2"></el-option>
184               </el-select>
185             </el-form-item>
186
187             <el-form-item label="校验位">
188               <el-select
189                 v-model="form1.parity"
190                 placeholder="请选择校验位"
191                 :disabled="isDisable"
192               >
193                 <el-option label="None" value="none"></el-option>
194                 <el-option label="Even" value="even"></el-option>
195                 <el-option label="Odd" value="odd"></el-option>
196               </el-select>
197             </el-form-item>
198
199             <el-form-item label="流控制">
200               <el-select
201                 v-model="form1.flowControl"
202                 placeholder="请选择流控制"
203                 :disabled="isDisable"
204               >
205                 <el-option label="None" value="none"></el-option>
206                 <el-option label="HardWare" value="hardware"></el-option>
207               </el-select>
208             </el-form-item>
209             <el-form-item label="显示历史">
210               <el-switch
211                 v-model="form1.isShowHistory"
212                 @change="loadHistory"
213               ></el-switch>
214               <el-button
215                 type="danger"
216                 icon="el-icon-delete"
217                 circle
218                 title="清空历史"
219                 @click="clearHistory"
220               ></el-button>
221             </el-form-item>
222             <el-form-item label="发送区设置" v-show="isShowSendArea">
223               <el-form-item label="发送格式">
224                 <el-radio-group v-model="form1.type">
225                   <el-radio label="1">ASCII</el-radio>
226                   <el-radio label="2">HEX</el-radio>
227                 </el-radio-group>
228               </el-form-item>
229               <el-form-item label="发送信息">
230                 <el-input type="textarea" v-model="form1.sendMsg"></el-input>
231               </el-form-item>
232               <el-button type="primary" @click="sendCommon">发送</el-button>
233             </el-form-item>
234
235             <el-form-item>
236               <el-button :type="btnType" @click="connectBtn">{{
237                   btnText
238                 }}</el-button>
239               <el-button type="info" @click="obtainAuthorization"
240               >新增授权</el-button
241               >
242             </el-form-item>
243           </div>
244           </el-col>
245         </el-row>
246       </el-form>
247     </el-dialog>
248   </div>
249 </template>
250 <script>
251 import {listWorkReport} from "@/api/main/om/workReport/workReport";
252 import {listStationConf,getIpv4} from "@/api/main/sc/stationConf";
253 import {
254   clearWorkpieceRelease,
255   fistSetpNumber, initializedData,
256   listFormulaChild,
257   noPageListFormulaChild,
258   releaseCheck, unfinishedProcess,
259   updateResults,
260   updateTighteningFormula,
261   workpieceRelease
262 } from "@/api/main/bs/formulaChild/formulaChild";
263 import MySerialPort from "@/utils/MySerialPort";
264 import USBDevice from "@/utils/usb.json";
265 import {
266   bindYzSfcFlag,
267   checkCarCode, checkYzSfcCode,
268   findBytrolleyYardGetOne,
269   listProductionOrde, mozuReceivingWorkOrders,
270   receivingWorkOrders,
271   trolleyYardBinDing
272 } from "@/api/main/om/productionOrde/productionOrde";
273 import {addPassingStationCollection} from "@/api/main/da/passingStationCollection/passingStationCollection";
274 import {
275   addBasicParameters,
276   addParamCollection,
277   addTighteningParameters,
278   saveCampaignTimeParameters,
279   replaceAssemblyCode, checkRecordDataDone,
280 } from "@/api/main/da/paramCollection/paramCollection";
281 import {addFormula} from "@/api/main/bs/formula/formula";
282
283 export default {
284   name: "stationTerminal",
285   data() {
286     return {
dd5d35 287       materialCode: '', // 物料编码
b78728 288       carCode: '',
A 289       showInput: false,
290       onLineBinDing: false,
291
292       serialPortContent: '',
293       // 查询参数
294       formulaChildParams: {
295         pageNum: 1,
296         pageSize: 10,
297         productCode: null,
298         processesCode: null,
299       },
300       // 配方配置子信息表格数据
301       formulaChildList: [],
302       ipAddress: '',
303       imgSrc: '',
304       headContent: {
305         processesCode: 'OP1010',
306         processesName: '贴标机-贴码',
307         sfcCode: '',
308         yzSfcCode: '',
309         cardCode: '',
310       },
311       workpieceInformation: {
312         workOrderNo: null,
313         productCode: null,
314         productModel: null,
315         productName: null,
316         inboundTime: null,
317         materialCode: null,
318         planQty: null,
319       },
320       // 查询参数
321       queryParams: {
322         pageNum: 1,
323         pageSize: 10,
324         sfcCode: null,
325       },
326       // 查询参数
327       StationConfQueryParams: {
328         pageNum: 1,
329         pageSize: 10,
330         ipAddress: null,
331       },
332       cakeLamp: {
333         plcState: 1, //plc
334         scannerState: 1, //扫码枪
335         InPlace: 0, //工件到位
336         scanFinish: 0,
337         startWork: 0,
338         release: 0 //允许放行
339       },
340       content: '',
341       activeName: 'first',
dd5d35 342       url: "ws://10.103.210.248:8080/websocket/message/",
A 343       // url: "ws://192.168.10.100:8080/websocket/message/",
b78728 344       message: "",
A 345       text_content: "",
346       ws: null,
347       inputValue: '9',
348
349       open1: false,
350       input: "",
351       keepReading: true,
352       form1: {
353         baudRate: "115200",
354         dataBits: "8",
355         stopBits: "1",
356         parity: "none",
357         flowControl: "none",
358         desc: "",
359         type: "1",
360         isShowHistory: false,
361       },
362       btnType: "primary",
363       btnText: "连接串口",
364       restaurants: [],
365       portsList: [],
366       isShowSendArea: false,
367       readType: 1,
368       title: "",
369
370       passingStationForm: {},
371       originalArray: [],
372       yzSfcFlag: 1,
373       endYz: false,
374       orderFlag: true
375     }
376   },
377   beforeDestroy() {
378     this.exit();
379   },
380   created() {
dd5d35 381     document.onkeyup = e => {
A 382       if (e.keyCode === 13) {
383         // 调用登录 验证方法
384         this.submitForm()
385       }
386     }
b78728 387     this.initStation();
A 388     // this.getStationConfList();
389     // setTimeout(() => {
390     //   this.connectWebsocket();
391     // }, 3000);
392   },
393   mounted() {
394     if ("serial" in navigator) {
395       this.myserialport = new MySerialPort();
396       this.getPorts();
397       navigator.serial.addEventListener("connect", (e) => {
398         this.$message.success("设备已连接");
399         this.getPorts();
400       });
401       navigator.serial.addEventListener("disconnect", (e) => {
402         this.$message.error("设备已断开");
403       });
404       this.restaurants = this.loadAll();
405     } else {
406       this.$message.error(
407         "当前为HTTP模式或者浏览器版本过低,不支持网页连接串口"
408       );
409     }
410   },
411   computed: {
412     isDisable() {
413       return this.btnType === "danger";
414     },
415   },
416   methods: {
dd5d35 417     handleEnter() {
A 418       this.serialPortMethod(this.materialCode)
419       this.$message("扫描物料编码"+this.materialCode);
420     },
b78728 421     getWorkOrders(){
A 422       if(this.headContent.sfcCode === '' || this.headContent.sfcCode === null){
423         //接收工单
424         const param = {
425           lineCode: this.headContent.processesCode
426         }
427         mozuReceivingWorkOrders(param).then(response => {
428           this.headContent.sfcCode = response.msg;
429           this.queryParams.productNum = response.msg;
430           this.getList()
431           this.cakeLamp.scanFinish = 1
432           this.cakeLamp.startWork = 1
433           this.cakeLamp.InPlace = 1
434         });
435       }else {
436         this.$message.error("已经有工单了,不能接收!");
437       }
438     },
439     bindcardCode(scanValue){
440       // this.$message('绑定成功!');
441       let param = {
442         productNum: this.headContent.sfcCode,
443         trolleyYard: scanValue,
444       }
445       trolleyYardBinDing(param).then(response => {
446       });
447
448     },
449     serialLink() {
450       this.open1 = true
451     },
452     bindYzSfc(){
453       if(this.headContent.sfcCode!==""&&this.headContent.yzSfcCode!==""){
454         let param = {
455           sfcCode: this.headContent.sfcCode,
456           locationCode: this.headContent.processesCode,
457           yzSfcCode: this.headContent.yzSfcCode
458         }
459         const orderParam = {
460           productNum: this.headContent.sfcCode,
461         }
462         replaceAssemblyCode(param).then(response => {
463           this.$message('绑定成功!');
464           bindYzSfcFlag(orderParam).then(response => {
465             this.yzSfcFlag = 1
466           });
467         });
468       }
469     },
470     Release(){
471       // this.$message('portsList!'+this.portsList.length);
472       if(this.btnType === "danger"){
473         this.$message('连接了!');
474
475       }else {
476         this.$message('mei连接了!');
477
478       }
479     },
480     serialPortMethod(value){
481       let formulaChildParams = {
482         scanBarcode: value,
483         sfcBarcode: this.headContent.sfcCode,
484         workOrderNo: this.workpieceInformation.workOrderNo,
485         productCode: this.workpieceInformation.productCode,
486         locationCode: this.headContent.processesCode,
487         collectionTime: new Date()
488       }
489       updateResults(formulaChildParams).then(response => {
490         console.log(response)
491         if(response.msg === "3"){
492           this.cakeLamp.release= 1 //允许放行
493         }else if(response.msg === "2"){
494           this.$message.error('扫码重复请重新扫码!');
495         }
496         this.getListFormulaChild()
497       });
498     },
499     rowStyle({ row }) {
500       if (row.results === 'OK') {
501         return 'background-color: PaleGreen';
502       } else if (row.results === 'NG') {
503         return 'background-color: LightSalmon';
504       }
505       return '';
506     },
507     /** 查询配方配置子信息列表 */
508     getListFormulaChild() {
509       // this.formulaChildList = []
510       this.formulaChildParams.productCode = this.workpieceInformation.productCode
511       this.formulaChildParams.processesCode = this.headContent.processesCode
512       console.log(this.formulaChildParams)
513       noPageListFormulaChild(this.formulaChildParams).then(response => {
514         this.formulaChildList = response.rows;
515         if (this.formulaChildList.length >0){
516           let pos = 0
517           const tempArr = this.formulaChildList.filter(x=> 'OK' === x.results)
518           if (tempArr.length>0){
519             pos = tempArr.length
520             this.$nextTick(() => {
521               let temp33 = document.getElementsByClassName('el-table__row')
522               console.log('temp33',temp33)
523               console.log('len',temp33.item(pos))
524               if (temp33.length > 0){
525                 console.log('1111111111111111')
526                 let arr = temp33[pos-1]
527                 console.log('srr',arr)
528                 arr.scrollIntoView({ block: 'center' })
529               }
530             })
531           }
532
533         }
534
535       });
536     },
537     endClear(){
538       this.cakeLamp.InPlace= 0 //工件到位
539       this.cakeLamp.scanFinish= 0
540       this.cakeLamp.startWork= 0
541       this.cakeLamp.release= 0 //允许放行
542
543       this.formulaChildList = []
544       this.workpieceInformation.productCode = null;
545       this.workpieceInformation.workOrderNo = null;
546       this.workpieceInformation.productModel = null;
547       this.workpieceInformation.productName = null;
548       this.workpieceInformation.inboundTime = null;
549       this.headContent.sfcCode = '';
550       this.headContent.yzSfcCode = '';
551       this.headContent.cardCode = '';
552     },
553     changeMenu(tab, event) {
554       console.log(tab, event);
555     },
556     clearClick(){
557       const param = {
558         workOrderNo: this.workpieceInformation.workOrderNo,
559         productCode: this.workpieceInformation.productCode,
560         locationCode: this.headContent.processesCode,
561         productBarcode: this.headContent.sfcCode,
562       }
563       this.endClear()
564       clearWorkpieceRelease(param).then(response => {});
565       this.headContent.sfcCode = ''
566       this.$message('清除成功!');
567     },
568     scanCompleted(){
569       this.$message('扫码完成'+this.content);
570       this.headContent.sfcCode = this.content
571       this.queryParams.sfcCode = this.content
572       this.getList()
573       this.getListFormulaChild()
574       this.cakeLamp.scanFinish = 1
575       this.cakeLamp.startWork = 1
576
577     },
578     /** 查询工单列表 */
579     async getList() {
580       await listProductionOrde(this.queryParams).then(response => {
581         let rowsData = response.rows[0];
582         console.log(rowsData)
583         this.workpieceInformation.workOrderNo = rowsData.workOrderNo;
584         this.workpieceInformation.productCode = rowsData.productCode;
585         this.workpieceInformation.materialCode = rowsData.materialCode;
586         this.workpieceInformation.planQty = rowsData.planQty;
587         this.headContent.cardCode = rowsData.trolleyYard;
588       });
589       this.getListFormulaChild()
590       this.workpieceInformation.inboundTime = this.getCurrentTime()
591     },
592
593     initializedData(){
594       const param = {
595         locationCode: this.headContent.processesCode,
596       }
597       initializedData(param).then(response => {
598         if(response.msg !== ''){
599           this.headContent.sfcCode = response.msg;
600           this.queryParams.productNum = response.msg;
601           this.getList()
602           this.cakeLamp.scanFinish = 1
603           this.cakeLamp.startWork = 1
604           this.cakeLamp.InPlace = 1
605         }
606       });
607     },
608
609     getCurrentTime() {
610       const now = new Date();
611       const year = now.getFullYear();
612       const month = this.padTimeUnit(now.getMonth() + 1); // 月份是从0开始的
613       const day = this.padTimeUnit(now.getDate());
614       const hours = this.padTimeUnit(now.getHours());
615       const minutes = this.padTimeUnit(now.getMinutes());
616       const seconds = this.padTimeUnit(now.getSeconds());
617       return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
618     },
619     padTimeUnit(value) {
620       return value.toString().padStart(2, '0');
621     },
622     addBaseData(){
623       addBasicParameters(this.passingStationForm).then(response => {});
624     },
625
626     /** 入站增加过站采集记录 **/
627     addOverStationCollection(){
628       this.passingStationForm = {
629         id: null,
630         workOrderNo: this.workpieceInformation.workOrderNo,
631         productCode: this.workpieceInformation.productCode,
632         locationCode: this.headContent.processesCode,
633         model: this.workpieceInformation.productModel,
634         productBarcode: this.headContent.sfcCode,
635         sfcCode: this.headContent.sfcCode,
636         inboundTime: new Date()
637       }
638       addPassingStationCollection(this.passingStationForm).then(response => {});
639       // addBasicParameters(this.passingStationForm).then(response => {});
640     },
641     exit() {
642       if (this.ws) {
643         this.ws.close();
644         this.ws = null;
645       }
646     },
647     send() {
648       if (this.ws) {
649         this.ws.send(this.message);
650       } else {
651         alert("未连接到服务器");
652       }
653     },
654
655     initStation: async function () {
656       await getIpv4().then(response => {
657         this.StationConfQueryParams.ipAddress = response.msg
658         console.log('查询到本工位IP为' + this.StationConfQueryParams.ipAddress)
659       });
660       await listStationConf(this.StationConfQueryParams).then(response => {
661         let rows = response.rows[0]
662         if (response.rows.length === 0) {
663           this.$message('该工位没有配置IP,请联系管理员配置IP');
664           return
665         }
666         this.headContent.processesName = rows.processesName
667         this.headContent.processesCode = rows.processesCode
668         this.initializedData()
669
670       });
671       this.conCom()
672       console.log('websocket连接工位为' + this.headContent.processesCode)
673       const wsuri = this.url + this.headContent.processesCode;
674       this.ws = new WebSocket(wsuri);
675       const self = this;
676       this.ws.onopen = function (event) {
dd5d35 677         self.$message('websocket连接成功!');
b78728 678       };
A 679
680
681       //socket从后台向前台推送数据
682       this.ws.onmessage = function (event) {
683         if (event.data === "IN") {
684           self.cakeLamp.InPlace = 1;
685           console.log(self.headContent.processesCode);
686           // const param = {
687           //   processesCode: self.headContent.processesCode,
688           // }
689           // fistSetpNumber(param).then(response => {});
690         } else if (event.data === "IN0") {
691           self.cakeLamp.InPlace = 0;
692         } else if (event.data === "OUT") {
693           self.cakeLamp.release = 1;
694         } else if (event.data === "END") {
695
696           const formulaChildIndex = self.formulaChildList.length-1
697
698           const orderParam = {
699             productNum: self.headContent.sfcCode,
700           }
701
702           if(self.headContent.sfcCode=== ''||self.headContent.sfcCode=== null){
703             self.$message('总成码为空,请扫码!')
704             unfinishedProcess({processesCode: self.headContent.processesCode,recordDataDone: 26}).then(response => {});
705             return;
706           }
707
708           if(self.formulaChildList[formulaChildIndex].results !== 'OK'){
709             self.$message('未做完工序禁止放行');
710             unfinishedProcess({processesCode: self.headContent.processesCode,recordDataDone: 25}).then(response => {});
711             return;
712           }
713
714
715           const param = {
716             workOrderNo: self.workpieceInformation.workOrderNo,
717             productCode: self.workpieceInformation.productCode,
718             locationCode: self.headContent.processesCode,
719             productBarcode: self.headContent.sfcCode,
720             inboundTime: self.workpieceInformation.inboundTime,
721             formulaChildEntity: self.formulaChildList[formulaChildIndex]
722           }
723
724           console.log("进入最终方法")
725           self.endSaveData(param)
726
727         } else if (event.data.includes("[")) {
728           let formulaChilds = "";
729           self.formulaChildList.sort((a, b) => a.stepSort - b.stepSort);
730           self.formulaChildList
731             .filter((formulaChild) => formulaChild.operationType === '1');
732           for (let i = 0; i < self.formulaChildList.length; i++) {
733             let formulaChild = self.formulaChildList[i];
734             let results = formulaChild.results;
735
736             if (results === '' || results === null || results === 'NG') {
737               formulaChilds = formulaChild;
738               break;
739             }
740           }
741            if(formulaChilds === ""){
742              self.$message.error('本工位已工作完成!');
743              return;
744            }
745           const param = {
746             id: formulaChilds.id,
747             tightenTheArray: event.data,
748             paramCode: formulaChilds.paramCode,
749             workOrderNo: self.workpieceInformation.workOrderNo,
750             productCode: self.workpieceInformation.productCode,
751             locationCode: self.headContent.processesCode,
752             productBarcode: self.headContent.sfcCode,
753             spareField1: formulaChilds.spareField1,
754             spareField2: formulaChilds.spareField2,
755             spareField3: formulaChilds.spareField3,
756             spareField4: formulaChilds.spareField4,
757             stepSort: formulaChilds.stepSort
758           }
759           if(formulaChilds.paramCode === null||formulaChilds.paramCode ===''){
760             self.$message('未找到参数码,请检查参数码是否正确');
761             return;
762           }
763           if(self.headContent.sfcCode!==null||self.headContent.sfcCode!==''){
764             updateTighteningFormula(param).then(response => {
765               //addTighteningParameters(param).then(response => {});
766               self.getListFormulaChild()
767             }).catch(error =>{
768               self.getListFormulaChild()
769             });
770           }
771         }else if(event.data.includes("productNum")){
772           let productNum = event.data.split(',')[1];
773           self.headContent.sfcCode = productNum;
774           self.queryParams.productNum = productNum;
775           self.getList()
776           self.cakeLamp.scanFinish = 1
777           self.cakeLamp.startWork = 1
778           self.cakeLamp.InPlace = 1
779
780         }
781       };
782     },
783
784     endSaveData(param){
785       saveCampaignTimeParameters(param).then(response => {
786       this.cakeLamp.release = 1;
787       this.endClear()
788       workpieceRelease(param).then(response => {});
789       });
790     },
791
792     //接受数据的回调
793     callBack(value) {
794       if (this.form1.isShowHistory) this.form1.desc = this.readLi().join("");
795       else {
796         const scanValue = this.myserialport.hex2atostr(value).replace(/[\r\n]/g, '');
797         console.log("串口收到数据-------------------"+scanValue)
798         console.log("sfc=--"+this.headContent.sfcCode+"--")
799         if(this.headContent.sfcCode !== '' && this.headContent.sfcCode !== null
800           && this.headContent.sfcCode !== undefined){
801           if(scanValue.includes("0RSP1TE") && this.headContent.processesCode === 'OP240'){
802             this.headContent.cardCode = scanValue
803             this.bindcardCode(scanValue);
804             this.serialPortMethod(scanValue)
805           }else {
806             this.$message('工位终端扫描物料编码'+scanValue);
807             console.log(scanValue)
808             this.serialPortMethod(scanValue)
809           }
810         } else {
811           // if(this.headContent.processesCode === 'OP240'){
812             this.headContent.sfcCode = scanValue;
813             this.queryParams.productNum = scanValue;
814             this.getList()
815             this.cakeLamp.scanFinish = 1
816             this.cakeLamp.startWork = 1
817             this.cakeLamp.InPlace = 1
818           // }else {
819           //   let param = {
820           //     trolleyYard: scanValue
821           //   }
822           //   findBytrolleyYardGetOne(param).then(response => {
823           //     if(response.msg !== '2'){
824           //       this.headContent.sfcCode = response.msg;
825           //       this.queryParams.productNum = response.msg;
826           //       this.$message('扫码识别产品序列号'+scanValue);
827           //       this.getList()
828           //       this.cakeLamp.scanFinish = 1
829           //       this.cakeLamp.startWork = 1
830           //       this.cakeLamp.InPlace = 1
831           //     }else {
832           //       this.$message('没有序列号'+scanValue);
833           //       return
834           //     }
835           //   });
836           // }
837
838         }
839
840       }
841     },
842     clearHistory() {
843       this.form1.desc = "";
844       this.myserialport.state.readValue = [];
845     },
846     loadHistory() {
847       if (this.form1.isShowHistory) this.form1.desc = this.readLi().join("");
848       else {
849         let temp = this.readLi();
850         if (temp.length > 0) this.form1.desc = temp[temp.length - 1].join("");
851       }
852     },
853     readLi() {
854       let readType = this.readType;
855       return this.myserialport.state.readValue.map((items, index) => {
856         const item = items.value;
857         const type = items.type; // 1接收,2发送
858         let body = [];
859         if (item !== undefined) {
860           let strArr = [];
861           for (let hex of Array.from(item)) {
862             strArr.push(hex.toString(16).toLocaleUpperCase());
863           }
864           if (strArr.includes("D") && strArr.includes("A")) {
865             if (strArr.indexOf("A") - strArr.indexOf("D") === 1) {
866               strArr.splice(strArr.indexOf("D"), 1);
867               strArr.splice(strArr.indexOf("A"), 1, <br key={0} />);
868             }
869           }
870           strArr = strArr.map((item) => {
871             if (typeof item === "string") {
872               if (readType === 1) {
873                 return this.myserialport.hex2a(parseInt(item, 16));
874               } else if (readType === 2) {
875                 return item + " ";
876               }
877             }
878             return item;
879           });
880           if (typeof strArr[strArr.length - 1] === "string") {
881             strArr.push("\r\n");
882           }
883           body.push(strArr.join(""));
884         }
885         return body;
886       });
887     },
888     conCom(){
889       try {
890         this.myserialport.state.baudRate = this.form1.baudRate;
891         this.myserialport.state.dataBits = this.form1.dataBits;
892         this.myserialport.state.stopBits = this.form1.stopBits;
893         this.myserialport.state.parity = this.form1.parity;
894         this.myserialport.state.flowControl = this.form1.flowControl;
895         this.myserialport.openPort(0, true, this.callBack);
896         console.log(this.form1.port)
897       } catch (error) {
898         this.$message.error("串口连接失败!请检查串口是否已被占用");
899       }
900       if (this.myserialport.state.isOpen) {
901         this.$message.success("串口连接成功");
902       }
903     },
904     //连接
905     async connectBtn() {
906       if (this.btnType === "primary") {
907         try {
908           this.myserialport.state.baudRate = this.form1.baudRate;
909           this.myserialport.state.dataBits = this.form1.dataBits;
910           this.myserialport.state.stopBits = this.form1.stopBits;
911           this.myserialport.state.parity = this.form1.parity;
912           this.myserialport.state.flowControl = this.form1.flowControl;
913           await this.myserialport.openPort(this.form1.port, true, this.callBack);
914           console.log(this.form1.port)
915         } catch (error) {
916           this.$message.error("串口连接失败!请检查串口是否已被占用");
917         }
918         if (this.myserialport.state.isOpen) {
919           this.$message.success("串口连接成功");
920           this.open1 = false
921           this.btnType = "danger";
922           this.btnText = "关闭串口";
923         }
924       } else {
925         this.myserialport.openPort(this.form1.port, false, this.callBack);
926         this.$message.success("串口关闭成功");
927         this.btnType = "primary";
928         this.btnText = "连接串口";
929       }
930     },
931     //授权
932     async obtainAuthorization() {
933       if ("serial" in navigator) {
934         console.log("The Web Serial API is supported.");
935         if (!this.myserialport) this.myserialport = new MySerialPort();
936         try {
937           await this.myserialport.handleRequestPort();
938           this.$message.success("串口授权成功");
939           this.getPortInfo(this.myserialport.state.ports);
940         } catch (error) {
941           this.$message.warning("未选择新串口授权!");
942         }
943       } else {
944         this.$message.error(
945           "当前为HTTP模式或者浏览器版本过低,不支持网页连接串口"
946         );
947       }
948     },
949     //串口列表初始化
950     getPortInfo(portList) {
951       this.portsList = [];
952       portList.map((port, index) => {
953         const { usbProductId, usbVendorId } = port.getInfo();
954         if (usbProductId === undefined || usbVendorId === undefined) {
955           this.portsList.push({ label: "未知设备" + index, value: index });
956         } else {
957           const usbVendor = USBDevice.filter(
958             (item) => parseInt(item.vendor, 16) === usbVendorId
959           );
960           let usbProduct = [];
961           if (usbVendor.length === 1) {
962             usbProduct = usbVendor[0].devices.filter(
963               (item) => parseInt(item.devid, 16) === usbProductId
964             );
965           }
966           this.portsList.push({ label: usbProduct[0].devname, value: index });
967         }
968       });
969     },
970     // 发送
971     async sendCommon() {
972       if (this.myserialport.state.isOpen) {
973         if (this.form1.sendMsg.length !== 0) {
974           const writeType = this.form1.type;
975           let value = this.form1.sendMsg;
976           let arr = [];
977           if (writeType === 1) {
978             // ASCII
979             for (let i = 0; i < value.length; i++) {
980               arr.push(this.myserialport.a2hex(value[i]));
981             }
982           } else if (writeType === 2) {
983             // HEX
984             if (/^[0-9A-Fa-f]+$/.test(value) && value.length % 2 === 0) {
985               for (let i = 0; i < value.length; i = i + 2) {
986                 arr.push(parseInt(value.substring(i, i + 2), 16));
987               }
988             } else {
989               this.$message.error("格式错误");
990               return;
991             }
992           }
993           this.myserialport.writeText(arr);
994         } else {
995           this.$message.warning("请输入发送的信息");
996         }
997       } else {
998         this.$message.warning("串口处于关闭状态,请连接串口");
999       }
1000     },
1001     async getPorts() {
1002       await this.myserialport.getPorts();
1003       this.getPortInfo(this.myserialport.state.ports);
1004     },
1005     querySearch(queryString, cb) {
1006       var restaurants = this.restaurants;
1007       var results = queryString
1008         ? restaurants.filter(this.createFilter(queryString))
1009         : restaurants;
1010       // 调用 callback 返回建议列表的数据
1011       cb(results);
1012     },
1013     createFilter(queryString) {
1014       return (restaurant) => {
1015         return (
1016           restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) ===
1017           0
1018         );
1019       };
1020     },
1021     loadAll() {
1022       return [
1023         { value: "110" },
1024         { value: "300" },
1025         { value: "600" },
1026         { value: "1200" },
1027         { value: "2400" },
1028         { value: "4800" },
1029         { value: "7200" },
1030         { value: "9600" },
1031         { value: "14400" },
1032         { value: "19200" },
1033         { value: "28800" },
1034         { value: "38400" },
1035         { value: "56000" },
1036         { value: "57600" },
1037         { value: "76800" },
1038         { value: "115200" },
1039         { value: "230400" },
1040         { value: "460800" },
1041       ];
1042     },
1043   }
1044 }
1045
1046 </script>
1047 <style scoped>
1048 .bottom-card{
1049   height: 600px;
1050 }
1051 .circle-button{
1052   height: 30px;
1053   width: 30px;
1054 }
1055 .circle-red {
1056   background-color: #e01a4f;
1057 }
1058 .circle-green {
1059   background-color: green;
1060 }
1061 .circle-green-animate {
1062   background-color: green;
1063   animation: circle-green-animate 2s infinite;
1064 }
1065   @keyframes circle-green-animate {
1066     50% {
1067       opacity: 0.6;
1068     }
1069     0% {
1070       opacity: 0.2;
1071     }
1072   }
1073 .head-font{
1074   /*font-weight: bold;*/
1075   /*font-size: 25px;*/
1076 }
1077 span{
1078   font-size: 15px;
1079 }
1080 .el-table .warning-row {
1081   background: oldlace;
1082 }
1083
1084 .el-table .success-row {
1085   background: #f0f9eb;
1086 }
1087 </style>
1088