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