admin
6 天以前 768498719683f85e5ed19c73eb3d14cdbf420df4
提交 | 用户 | 时间
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>
768498 127                <el-table-column label="物料编码" width="110" 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',
768498 394       url: "ws://10.103.210.248:8080/websocket/message/",
A 395       // url: "ws://192.168.2.76:8080/websocket/message/",
e57a89 396       message: "",
397       text_content: "",
398       ws: null,
c2944a 399       inputValue: '9',
400
401       open1: false,
402       input: "",
403       keepReading: true,
404       form1: {
b5fcd8 405         baudRate: "115200",
c2944a 406         dataBits: "8",
407         stopBits: "1",
408         parity: "none",
409         flowControl: "none",
410         desc: "",
411         type: "1",
412         isShowHistory: false,
413       },
414       btnType: "primary",
415       btnText: "连接串口",
416       restaurants: [],
417       portsList: [],
418       isShowSendArea: false,
419       readType: 1,
420       title: "",
b64ed2 421
422       passingStationForm: {},
49c784 423       originalArray: [],
237733 424       yzSfcFlag: 1,
768498 425       endYz: false,
e57a89 426     }
427   },
428   beforeDestroy() {
429     this.exit();
430   },
431   created() {
432     this.initStation();
433     // this.getStationConfList();
434     // setTimeout(() => {
435     //   this.connectWebsocket();
436     // }, 3000);
437   },
438   mounted() {
c2944a 439     if ("serial" in navigator) {
440       this.myserialport = new MySerialPort();
441       this.getPorts();
442       navigator.serial.addEventListener("connect", (e) => {
443         this.$message.success("设备已连接");
444         this.getPorts();
445       });
446       navigator.serial.addEventListener("disconnect", (e) => {
447         this.$message.error("设备已断开");
448       });
449       this.restaurants = this.loadAll();
450     } else {
451       this.$message.error(
452         "当前为HTTP模式或者浏览器版本过低,不支持网页连接串口"
453       );
454     }
455   },
456   computed: {
457     isDisable() {
458       return this.btnType === "danger";
459     },
e57a89 460   },
461   methods: {
768498 462     bindcardCode(scanValue){
A 463       // this.$message('绑定成功!');
a75d86 464       let param = {
A 465         productNum: this.headContent.sfcCode,
768498 466         trolleyYard: scanValue,
a75d86 467       }
A 468       trolleyYardBinDing(param).then(response => {
469       });
470
471     },
c2944a 472     serialLink() {
473       this.open1 = true
ddb300 474     },
A 475     bindYzSfc(){
476       if(this.headContent.sfcCode!==""&&this.headContent.yzSfcCode!==""){
477         let param = {
478           sfcCode: this.headContent.sfcCode,
479           locationCode: this.headContent.processesCode,
480           yzSfcCode: this.headContent.yzSfcCode
481         }
237733 482         const orderParam = {
A 483           productNum: this.headContent.sfcCode,
484         }
ddb300 485         replaceAssemblyCode(param).then(response => {
68f0c8 486           this.$message('绑定成功!');
237733 487           bindYzSfcFlag(orderParam).then(response => {
A 488             this.yzSfcFlag = 1
489           });
ddb300 490         });
A 491       }
c2944a 492     },
e57a89 493     Release(){
93feb8 494       // this.$message('portsList!'+this.portsList.length);
495       if(this.btnType === "danger"){
496         this.$message('连接了!');
497
498       }else {
499         this.$message('mei连接了!');
500
e57a89 501       }
502     },
c2944a 503     serialPortMethod(value){
b77303 504       let formulaChildParams = {
505         scanBarcode: value,
506         sfcBarcode: this.headContent.sfcCode,
507         workOrderNo: this.workpieceInformation.workOrderNo,
508         productCode: this.workpieceInformation.productCode,
509         locationCode: this.headContent.processesCode,
510         collectionTime: new Date()
511       }
512       updateResults(formulaChildParams).then(response => {
c5e9c5 513         console.log(response)
514         if(response.msg === "3"){
515           this.cakeLamp.release= 1 //允许放行
2fbce7 516         }else if(response.msg === "2"){
A 517           this.$message.error('扫码重复请重新扫码!');
c5e9c5 518         }
b77303 519         this.getListFormulaChild()
520       });
e57a89 521     },
522     rowStyle({ row }) {
523       if (row.results === 'OK') {
524         return 'background-color: PaleGreen';
525       } else if (row.results === 'NG') {
526         return 'background-color: LightSalmon';
527       }
528       return '';
529     },
530     /** 查询配方配置子信息列表 */
531     getListFormulaChild() {
11cc36 532       // this.formulaChildList = []
e57a89 533       this.formulaChildParams.productCode = this.workpieceInformation.productCode
534       this.formulaChildParams.processesCode = this.headContent.processesCode
054a69 535       console.log(this.formulaChildParams)
0caf87 536       noPageListFormulaChild(this.formulaChildParams).then(response => {
e57a89 537         this.formulaChildList = response.rows;
6a462f 538         if (this.formulaChildList.length >0){
W 539           let pos = 0
540           const tempArr = this.formulaChildList.filter(x=> 'OK' === x.results)
541           if (tempArr.length>0){
542             pos = tempArr.length
543             this.$nextTick(() => {
544               let temp33 = document.getElementsByClassName('el-table__row')
545               console.log('temp33',temp33)
546               console.log('len',temp33.item(pos))
547               if (temp33.length > 0){
548                 console.log('1111111111111111')
549                 let arr = temp33[pos-1]
550                 console.log('srr',arr)
551                 arr.scrollIntoView({ block: 'center' })
552               }
553             })
554           }
555
556         }
557
e57a89 558       });
559     },
1df825 560     endClear(){
561       this.cakeLamp.InPlace= 0 //工件到位
562       this.cakeLamp.scanFinish= 0
563       this.cakeLamp.startWork= 0
564       this.cakeLamp.release= 0 //允许放行
b77c7b 565
1df825 566       this.formulaChildList = []
c5e9c5 567       this.workpieceInformation.productCode = null;
568       this.workpieceInformation.workOrderNo = null;
569       this.workpieceInformation.productModel = null;
570       this.workpieceInformation.productName = null;
768498 571       this.workpieceInformation.inboundTime = null;
5316c5 572       this.headContent.sfcCode = '';
288790 573       this.headContent.yzSfcCode = '';
A 574       this.headContent.cardCode = '';
1df825 575     },
e57a89 576     changeMenu(tab, event) {
577       console.log(tab, event);
578     },
579     clearClick(){
8cfe20 580       const param = {
A 581         workOrderNo: this.workpieceInformation.workOrderNo,
582         productCode: this.workpieceInformation.productCode,
583         locationCode: this.headContent.processesCode,
584         productBarcode: this.headContent.sfcCode,
585       }
586       this.endClear()
587       clearWorkpieceRelease(param).then(response => {});
588       this.headContent.sfcCode = ''
bdb404 589       this.$message('清除成功!');
e57a89 590     },
591     scanCompleted(){
592       this.$message('扫码完成'+this.content);
593       this.headContent.sfcCode = this.content
594       this.queryParams.sfcCode = this.content
595       this.getList()
596       this.getListFormulaChild()
597       this.cakeLamp.scanFinish = 1
598       this.cakeLamp.startWork = 1
599
600     },
b64ed2 601     /** 查询工单列表 */
e57a89 602     async getList() {
b64ed2 603       await listProductionOrde(this.queryParams).then(response => {
e57a89 604         let rowsData = response.rows[0];
605         console.log(rowsData)
b64ed2 606         this.workpieceInformation.workOrderNo = rowsData.workOrderNo;
e57a89 607         this.workpieceInformation.productCode = rowsData.productCode;
608         this.workpieceInformation.productModel = rowsData.productModel;
609         this.workpieceInformation.productName = rowsData.productName;
768498 610         this.headContent.cardCode = rowsData.trolleyYard;
e57a89 611       });
612       this.getListFormulaChild()
768498 613       // this.addOverStationCollection()
A 614       this.workpieceInformation.inboundTime = this.getCurrentTime()
bdb404 615       const param = {
A 616         processesCode: this.headContent.processesCode,
617       }
618       fistSetpNumber(param).then(response => {
619         console.log("fistSetpNumber------"+response.msg)
620       });
b64ed2 621     },
622
768498 623     getCurrentTime() {
A 624       const now = new Date();
625       const year = now.getFullYear();
626       const month = this.padTimeUnit(now.getMonth() + 1); // 月份是从0开始的
627       const day = this.padTimeUnit(now.getDate());
628       const hours = this.padTimeUnit(now.getHours());
629       const minutes = this.padTimeUnit(now.getMinutes());
630       const seconds = this.padTimeUnit(now.getSeconds());
631       return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
632     },
633     padTimeUnit(value) {
634       return value.toString().padStart(2, '0');
635     },
8cfe20 636     addBaseData(){
A 637       addBasicParameters(this.passingStationForm).then(response => {});
638     },
639
b64ed2 640     /** 入站增加过站采集记录 **/
641     addOverStationCollection(){
642       this.passingStationForm = {
643         id: null,
644         workOrderNo: this.workpieceInformation.workOrderNo,
645         productCode: this.workpieceInformation.productCode,
646         locationCode: this.headContent.processesCode,
647         model: this.workpieceInformation.productModel,
648         productBarcode: this.headContent.sfcCode,
32483a 649         sfcCode: this.headContent.sfcCode,
b64ed2 650         inboundTime: new Date()
651       }
b77c7b 652       addPassingStationCollection(this.passingStationForm).then(response => {});
4a5f2a 653       // addBasicParameters(this.passingStationForm).then(response => {});
e57a89 654     },
655     exit() {
656       if (this.ws) {
657         this.ws.close();
658         this.ws = null;
659       }
660     },
661     send() {
662       if (this.ws) {
663         this.ws.send(this.message);
664       } else {
665         alert("未连接到服务器");
666       }
667     },
1df825 668
49c784 669     initStation: async function () {
e57a89 670       await getIpv4().then(response => {
671         this.StationConfQueryParams.ipAddress = response.msg
49c784 672         console.log('查询到本工位IP为' + this.StationConfQueryParams.ipAddress)
e57a89 673       });
674       await listStationConf(this.StationConfQueryParams).then(response => {
675         let rows = response.rows[0]
49c784 676         if (response.rows.length === 0) {
e57a89 677           this.$message('该工位没有配置IP,请联系管理员配置IP');
678           return
679         }
680         this.headContent.processesName = rows.processesName
681         this.headContent.processesCode = rows.processesCode
a75d86 682         if(this.headContent.processesCode === 'OP240'){
A 683           this.onLineBinDing = true
684         }
4a5f2a 685         if(this.headContent.processesCode === 'OP260'){
768498 686           // this.showInput = true
a75d86 687         }
e57a89 688
a75d86 689         console.log('设置工位编码' + this.headContent.processesCode)
a320dc 690
e57a89 691       });
f17d8c 692       this.conCom()
49c784 693       console.log('websocket连接工位为' + this.headContent.processesCode)
e57a89 694       const wsuri = this.url + this.headContent.processesCode;
695       this.ws = new WebSocket(wsuri);
696       const self = this;
697       this.ws.onopen = function (event) {
698         this.$message('websocket连接成功!');
a320dc 699
e57a89 700       };
701       this.ws.onmessage = function (event) {
49c784 702         if (event.data === "IN") {
703           self.cakeLamp.InPlace = 1;
a320dc 704           console.log(self.headContent.processesCode);
bdb404 705           // const param = {
A 706           //   processesCode: self.headContent.processesCode,
707           // }
708           // fistSetpNumber(param).then(response => {});
49c784 709         } else if (event.data === "IN0") {
710           self.cakeLamp.InPlace = 0;
711         } else if (event.data === "OUT") {
712           self.cakeLamp.release = 1;
32483a 713         } else if (event.data === "END") {
768498 714
A 715           const formulaChildIndex = self.formulaChildList.length-1
237733 716
A 717           const orderParam = {
718             productNum: self.headContent.sfcCode,
719           }
16714e 720
A 721           if(self.headContent.sfcCode=== ''||self.headContent.sfcCode=== null){
2fbce7 722             self.$message('总成码为空,请扫码!')
768498 723             return;
16714e 724           }
A 725
768498 726           // if(self.headContent.cardCode === null || self.headContent.cardCode === ''){
A 727           //   self.$alert('<strong style="color: red;font-size: 30px">未扫描小车码禁止放行</strong>', '提示', {
728           //     dangerouslyUseHTMLString: true
729           //   });
730           //   return;
731           // }
732
733           if(self.formulaChildList[formulaChildIndex].results !== 'OK'){
734             self.$message('未做完工序禁止放行');
735             return;
736           }
737
738
739           const param = {
740             workOrderNo: self.workpieceInformation.workOrderNo,
741             productCode: self.workpieceInformation.productCode,
742             locationCode: self.headContent.processesCode,
743             productBarcode: self.headContent.sfcCode,
744             inboundTime: self.workpieceInformation.inboundTime,
745             formulaChildEntity: self.formulaChildList[formulaChildIndex]
746           }
747
748           console.log("进入最终方法")
749           self.endSaveData(param)
750
751
752           // if(self.headContent.processesCode === "OP260"){
753           //   checkYzSfcCode(orderParam).then(response => {
754           //     if(response.data === 0){
755           //       self.$message('未绑定总成码禁止放行');
756           //       return;
757           //     }else {
758           //       self.endSaveData(param)
759           //       // saveCampaignTimeParameters(param).then(response => {
760           //       //   self.cakeLamp.release = 1;
761           //       //   self.endClear()
762           //       //   workpieceRelease(param).then(response => {});});
763           //     }
764           //   })
765           // }else {
766           //   self.endSaveData(param)
767           //   // saveCampaignTimeParameters(param).then(response => {
768           //   //   self.cakeLamp.release = 1;
769           //   //   self.endClear()
770           //   //   workpieceRelease(param).then(response => {});
771           //   // });
772           // }
773
774           // checkCarCode(orderParam).then(response => {
775           //   console.log(response.data)
776           //   if(response.data === 1){
777           //     if(self.headContent.processesCode === "OP260"){
778           //       checkYzSfcCode(orderParam).then(response => {
779           //         if(response.data === 1){
780           //           saveCampaignTimeParameters(param).then(response => {
781           //             checkRecordDataDone(param).then(response => {
782           //               if(response.msg === "21"){
783           //                 self.cakeLamp.release = 1;
784           //                 self.endClear()
785           //                 workpieceRelease(param).then(response => {});
786           //               }else {
787           //                 self.$message('未做完工序禁止放行');
788           //               }
789           //             });
790           //           });
791           //         }else {
792           //           self.$message('请先绑定预装总成');
793           //         }
794           //       });
795           //     }else {
796           //       saveCampaignTimeParameters(param).then(response => {
797           //         checkRecordDataDone(param).then(response => {
798           //           if(response.msg === "21"){
799           //             self.cakeLamp.release = 1;
800           //             self.endClear()
801           //             workpieceRelease(param).then(response => {});
802           //           }else {
803           //             self.$message('未做完工序禁止放行');
804           //           }
805           //         });
806           //       });
807           //     }
808           //   }else {
809           //     self.$alert('<strong style="color: red;font-size: 30px">未扫描小车码禁止放行</strong>', '提示', {
810           //       dangerouslyUseHTMLString: true
811           //     });
812           //   }
813           // });
49c784 814         } else if (event.data.includes("[")) {
b77c7b 815           let formulaChilds = "";
3c2299 816           self.formulaChildList.sort((a, b) => a.stepSort - b.stepSort);
817           self.formulaChildList
818             .filter((formulaChild) => formulaChild.operationType === '1');
819           for (let i = 0; i < self.formulaChildList.length; i++) {
820             let formulaChild = self.formulaChildList[i];
b77c7b 821             let results = formulaChild.results;
2fbce7 822
3c2299 823             if (results === '' || results === null || results === 'NG') {
b77303 824               formulaChilds = formulaChild;
3c2299 825               break;
b77c7b 826             }
3c2299 827           }
2fbce7 828            if(formulaChilds === ""){
A 829              self.$message.error('本工位已工作完成!');
830              return;
831            }
49c784 832           const param = {
2fbce7 833             id: formulaChilds.id,
49c784 834             tightenTheArray: event.data,
b77c7b 835             paramCode: formulaChilds.paramCode,
49c784 836             workOrderNo: self.workpieceInformation.workOrderNo,
837             productCode: self.workpieceInformation.productCode,
838             locationCode: self.headContent.processesCode,
839             productBarcode: self.headContent.sfcCode,
2fbce7 840             spareField1: formulaChilds.spareField1,
A 841             spareField2: formulaChilds.spareField2,
842             spareField3: formulaChilds.spareField3,
843             spareField4: formulaChilds.spareField4,
844             stepSort: formulaChilds.stepSort
49c784 845           }
16714e 846           if(formulaChilds.paramCode === null||formulaChilds.paramCode ===''){
A 847             self.$message('未找到参数码,请检查参数码是否正确');
848             return;
849           }
850           if(self.headContent.sfcCode!==null||self.headContent.sfcCode!==''){
851             updateTighteningFormula(param).then(response => {
2fbce7 852               //addTighteningParameters(param).then(response => {});
16714e 853               self.getListFormulaChild()
A 854             }).catch(error =>{
855               self.getListFormulaChild()
856             });
857           }
e57a89 858         }
859       };
860     },
c2944a 861
768498 862     endSaveData(param){
A 863       saveCampaignTimeParameters(param).then(response => {
864       this.cakeLamp.release = 1;
865       this.endClear()
866       workpieceRelease(param).then(response => {});
867       });
868     },
1df825 869
c2944a 870     //接受数据的回调
871     callBack(value) {
872       if (this.form1.isShowHistory) this.form1.desc = this.readLi().join("");
873       else {
874         const scanValue = this.myserialport.hex2atostr(value).replace(/[\r\n]/g, '');
11cc36 875         console.log("串口收到数据-------------------"+scanValue)
2fbce7 876         console.log("sfc=--"+this.headContent.sfcCode+"--")
bdb404 877         if(this.headContent.sfcCode !== '' && this.headContent.sfcCode !== null
A 878           && this.headContent.sfcCode !== undefined){
768498 879           // if(scanValue.includes("P9900173252")){
A 880           //   this.headContent.yzSfcCode = scanValue
881           //   this.bindYzSfc();
882           // }else
883           if(scanValue.includes("0RSP1TE") && this.headContent.processesCode === 'OP240'){
a75d86 884             this.headContent.cardCode = scanValue
768498 885             this.bindcardCode(scanValue);
A 886             this.serialPortMethod(scanValue)
ddb300 887           }else {
a52d08 888             this.$message('工位终端扫描物料编码'+scanValue);
3c2299 889             console.log(scanValue)
890             this.serialPortMethod(scanValue)
891           }
ddb300 892         } else {
a75d86 893           if(this.headContent.processesCode === 'OP240'){
A 894             this.headContent.sfcCode = scanValue;
895             this.queryParams.productNum = scanValue;
4a5f2a 896             this.getList()
A 897             this.cakeLamp.scanFinish = 1
898             this.cakeLamp.startWork = 1
a75d86 899           }else {
A 900             let param = {
901               trolleyYard: scanValue
902             }
903             findBytrolleyYardGetOne(param).then(response => {
4a5f2a 904               if(response.msg !== '2'){
A 905                 this.headContent.sfcCode = response.msg;
906                 this.queryParams.productNum = response.msg;
907                 this.$message('扫码识别产品序列号'+scanValue);
908                 // this.headContent.sfcCode = scanValue;
909                 // this.queryParams.productNum = scanValue;
910                 this.getList()
911                 this.cakeLamp.scanFinish = 1
912                 this.cakeLamp.startWork = 1
913               }else {
914                 this.$message('没有序列号'+scanValue);
915                 return
916               }
a75d86 917             });
A 918           }
4a5f2a 919
ddb300 920         }
A 921
e57a89 922       }
c2944a 923     },
924     clearHistory() {
925       this.form1.desc = "";
926       this.myserialport.state.readValue = [];
927     },
928     loadHistory() {
929       if (this.form1.isShowHistory) this.form1.desc = this.readLi().join("");
930       else {
931         let temp = this.readLi();
932         if (temp.length > 0) this.form1.desc = temp[temp.length - 1].join("");
933       }
934     },
935     readLi() {
936       let readType = this.readType;
937       return this.myserialport.state.readValue.map((items, index) => {
938         const item = items.value;
939         const type = items.type; // 1接收,2发送
940         let body = [];
941         if (item !== undefined) {
942           let strArr = [];
943           for (let hex of Array.from(item)) {
944             strArr.push(hex.toString(16).toLocaleUpperCase());
945           }
946           if (strArr.includes("D") && strArr.includes("A")) {
947             if (strArr.indexOf("A") - strArr.indexOf("D") === 1) {
948               strArr.splice(strArr.indexOf("D"), 1);
949               strArr.splice(strArr.indexOf("A"), 1, <br key={0} />);
950             }
951           }
952           strArr = strArr.map((item) => {
953             if (typeof item === "string") {
954               if (readType === 1) {
955                 return this.myserialport.hex2a(parseInt(item, 16));
956               } else if (readType === 2) {
957                 return item + " ";
958               }
959             }
960             return item;
961           });
962           if (typeof strArr[strArr.length - 1] === "string") {
963             strArr.push("\r\n");
964           }
965           body.push(strArr.join(""));
966         }
967         return body;
968       });
969     },
640ff8 970     conCom(){
971       try {
972         this.myserialport.state.baudRate = this.form1.baudRate;
973         this.myserialport.state.dataBits = this.form1.dataBits;
974         this.myserialport.state.stopBits = this.form1.stopBits;
975         this.myserialport.state.parity = this.form1.parity;
976         this.myserialport.state.flowControl = this.form1.flowControl;
977         this.myserialport.openPort(0, true, this.callBack);
978         console.log(this.form1.port)
979       } catch (error) {
980         this.$message.error("串口连接失败!请检查串口是否已被占用");
981       }
982       if (this.myserialport.state.isOpen) {
983         this.$message.success("串口连接成功");
984       }
985     },
c2944a 986     //连接
987     async connectBtn() {
988       if (this.btnType === "primary") {
989         try {
990           this.myserialport.state.baudRate = this.form1.baudRate;
991           this.myserialport.state.dataBits = this.form1.dataBits;
992           this.myserialport.state.stopBits = this.form1.stopBits;
993           this.myserialport.state.parity = this.form1.parity;
994           this.myserialport.state.flowControl = this.form1.flowControl;
995           await this.myserialport.openPort(this.form1.port, true, this.callBack);
11cc36 996           console.log(this.form1.port)
c2944a 997         } catch (error) {
998           this.$message.error("串口连接失败!请检查串口是否已被占用");
999         }
1000         if (this.myserialport.state.isOpen) {
1001           this.$message.success("串口连接成功");
1002           this.open1 = false
1003           this.btnType = "danger";
1004           this.btnText = "关闭串口";
1005         }
1006       } else {
1007         this.myserialport.openPort(this.form1.port, false, this.callBack);
1008         this.$message.success("串口关闭成功");
1009         this.btnType = "primary";
1010         this.btnText = "连接串口";
1011       }
1012     },
1013     //授权
1014     async obtainAuthorization() {
1015       if ("serial" in navigator) {
1016         console.log("The Web Serial API is supported.");
1017         if (!this.myserialport) this.myserialport = new MySerialPort();
1018         try {
1019           await this.myserialport.handleRequestPort();
1020           this.$message.success("串口授权成功");
1021           this.getPortInfo(this.myserialport.state.ports);
1022         } catch (error) {
1023           this.$message.warning("未选择新串口授权!");
1024         }
1025       } else {
1026         this.$message.error(
1027           "当前为HTTP模式或者浏览器版本过低,不支持网页连接串口"
1028         );
1029       }
1030     },
1031     //串口列表初始化
1032     getPortInfo(portList) {
1033       this.portsList = [];
1034       portList.map((port, index) => {
1035         const { usbProductId, usbVendorId } = port.getInfo();
1036         if (usbProductId === undefined || usbVendorId === undefined) {
1037           this.portsList.push({ label: "未知设备" + index, value: index });
1038         } else {
1039           const usbVendor = USBDevice.filter(
1040             (item) => parseInt(item.vendor, 16) === usbVendorId
1041           );
1042           let usbProduct = [];
1043           if (usbVendor.length === 1) {
1044             usbProduct = usbVendor[0].devices.filter(
1045               (item) => parseInt(item.devid, 16) === usbProductId
1046             );
1047           }
1048           this.portsList.push({ label: usbProduct[0].devname, value: index });
1049         }
1050       });
1051     },
1052     // 发送
1053     async sendCommon() {
1054       if (this.myserialport.state.isOpen) {
1055         if (this.form1.sendMsg.length !== 0) {
1056           const writeType = this.form1.type;
1057           let value = this.form1.sendMsg;
1058           let arr = [];
1059           if (writeType === 1) {
1060             // ASCII
1061             for (let i = 0; i < value.length; i++) {
1062               arr.push(this.myserialport.a2hex(value[i]));
1063             }
1064           } else if (writeType === 2) {
1065             // HEX
1066             if (/^[0-9A-Fa-f]+$/.test(value) && value.length % 2 === 0) {
1067               for (let i = 0; i < value.length; i = i + 2) {
1068                 arr.push(parseInt(value.substring(i, i + 2), 16));
1069               }
1070             } else {
1071               this.$message.error("格式错误");
1072               return;
1073             }
1074           }
1075           this.myserialport.writeText(arr);
1076         } else {
1077           this.$message.warning("请输入发送的信息");
1078         }
1079       } else {
1080         this.$message.warning("串口处于关闭状态,请连接串口");
1081       }
1082     },
1083     async getPorts() {
1084       await this.myserialport.getPorts();
1085       this.getPortInfo(this.myserialport.state.ports);
1086     },
1087     querySearch(queryString, cb) {
1088       var restaurants = this.restaurants;
1089       var results = queryString
1090         ? restaurants.filter(this.createFilter(queryString))
1091         : restaurants;
1092       // 调用 callback 返回建议列表的数据
1093       cb(results);
1094     },
1095     createFilter(queryString) {
1096       return (restaurant) => {
1097         return (
1098           restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) ===
1099           0
1100         );
1101       };
1102     },
1103     loadAll() {
1104       return [
1105         { value: "110" },
1106         { value: "300" },
1107         { value: "600" },
1108         { value: "1200" },
1109         { value: "2400" },
1110         { value: "4800" },
1111         { value: "7200" },
1112         { value: "9600" },
1113         { value: "14400" },
1114         { value: "19200" },
1115         { value: "28800" },
1116         { value: "38400" },
1117         { value: "56000" },
1118         { value: "57600" },
1119         { value: "76800" },
1120         { value: "115200" },
1121         { value: "230400" },
1122         { value: "460800" },
1123       ];
1124     },
e57a89 1125   }
1126 }
1127
1128 </script>
1129 <style scoped>
1130 .bottom-card{
1131   height: 600px;
1132 }
1133 .circle-button{
1134   height: 30px;
1135   width: 30px;
1136 }
1137 .circle-red {
1138   background-color: #e01a4f;
1139 }
1140 .circle-green {
1141   background-color: green;
1142 }
1143 .circle-green-animate {
1144   background-color: green;
1145   animation: circle-green-animate 2s infinite;
1146 }
1147   @keyframes circle-green-animate {
1148     50% {
1149       opacity: 0.6;
1150     }
1151     0% {
1152       opacity: 0.2;
1153     }
1154   }
1155 .head-font{
c2944a 1156   /*font-weight: bold;*/
1157   /*font-size: 25px;*/
e57a89 1158 }
1159 span{
1160   font-size: 15px;
1161 }
1162 .el-table .warning-row {
1163   background: oldlace;
1164 }
1165
1166 .el-table .success-row {
1167   background: #f0f9eb;
1168 }
1169 </style>
1170