qingyiay
2023-04-19 3fd84886a15713ece1ba34954f49fd1e075ef7be
pages/driver-page/driver-index/bill-of-lading-details/weighingDevice/weighingDevice.vue
@@ -12,12 +12,18 @@
               </view>
               <view class="">
                  红外:
                  <u--text :type="infraredStatus ? 'error' : 'success'" :text="infraredStatus ? '异常' : '正常'" size="34"></u--text>
                  <u--text :type="globalinfraredStatus ? 'error' : 'success'" :text="globalinfraredStatus ? '异常' : '正常'" size="34"></u--text>
               </view>
               <!-- <view class="">
                  雷达:
                  <u--text type="success" text="正常" size="34"></u--text>
               </view> -->
            </view>
         </view>
         <view class="bottom" v-if="weighList.orderType == '内购' || weighList.orderType == '转出'">
            <view>
               <view style="font-weight: 600;">原发信息</view>
               <text>皮重{{ primarySkin || '' }}毛重{{ primaryHair || '' }}净重{{ primaryClean || '' }}</text>
            </view>
         </view>
         <view class="bottom"><text>TIP:当前状态为正常时可以称重</text></view>
@@ -40,9 +46,9 @@
         <u-button
            type="primary"
            text="确定称重"
            :disabled="realTimeWeigh == 0 || infraredStatus"
            :disabled="realTimeWeigh == 0 || globalinfraredStatus"
            :loading="isConfirmWeighLoading"
            loadingText="加载中"
            loadingText="确认"
            @click="confirmWeigh"
         ></u-button>
         <u-button type="primary" text="返回加减吨" :disabled="addAndSubtractCoalDisabled" @click="addAndSubtractCoal" class="jiajian"></u-button>
@@ -65,14 +71,19 @@
<script>
let socket = null;
import { webSocketUrl } from '@/api/request.js';
import { mapState, mapMutations } from 'vuex';
export default {
   onLoad(params) {
      console.log(params, '第二次放空参数');
      this.takeCoalId = params.takeCoalId;
      this.weighData.sceneId = params.sceneId;
      this.weighData.gateCameraId = params.gateCameraId;
      this.weighData.equipmentCode = params.gateCameraCode;
      this.weighData.sceneInOut = params.sceneInOut;
      this.weighHouseCode = params.weighHouseCode;
      this.primarySkin = params.primarySkin;
      this.primaryHair = params.primaryHair;
      this.primaryClean = params.primaryClean;
      this.changeweighHouseCode(params.weighHouseCode);
   },
   data() {
      return {
@@ -85,7 +96,8 @@
            gateCameraId: '',
            equipmentCode: '',
            weigh: 0,
            tmCode: ''
            tmCode: '',
            sceneInOut: ''
         },
         takeCoalId: null,
         weighHouseCode: '',
@@ -113,12 +125,16 @@
         // 放空控制
         evacuationModalShow: false,
         evacuationTitle: '放空确认',
         evacuationContent: '是否确认放空'
         evacuationContent: '是否确认放空',
         // 获取原发信息
         primarySkin: null,
         primaryHair: null,
         primaryClean: null
      };
   },
   watch: {
      realTimeWeigh(newV, oldV) {
         if (this.weighList.orderType == '外销' || this.weighList.orderType == '内销') {
         if (this.weighList.orderType == '外销' || this.weighList.orderType == '内销' || this.weighList.orderType == '转出') {
            if (this.weighList.skin == 0) {
               // this.temporaryWeighObj.skin = this.realTimeWeigh;
               this.temporaryWeighObj.skin = newV;
@@ -127,7 +143,7 @@
               this.temporaryWeighObj.hair = newV;
               this.temporaryWeighObj.clean = (this.temporaryWeighObj.hair - this.weighList.skin).toFixed(2);
            }
         } else if (this.weighList.orderType == '外购' || this.weighList.orderType == '转出') {
         } else if (this.weighList.orderType == '外购' || this.weighList.orderType == '内购' || this.weighList.orderType == '转入') {
            if (this.weighList.hair == 0) {
               // this.temporaryWeighObj.hair = this.realTimeWeigh;
               this.temporaryWeighObj.hair = newV;
@@ -137,13 +153,23 @@
               this.temporaryWeighObj.clean = (this.weighList.hair - this.temporaryWeighObj.skin).toFixed(2);
            }
         }
      },
      // 监听重量变化
      globalweigh: {
         handler(v) {
            this.weighData.weigh = this.realTimeWeigh = v;
            console.log(this.realTimeWeigh, '真实重量改变了');
         },
         immediate: true,
         deep: true
      }
   },
   onShow() {
      this.init();
      this.initWebSocket();
      // this.initWebSocket();
   },
   computed: {
      ...mapState(['globalweigh', 'globalinfraredStatus']),
      token() {
         return uni.getStorageSync('token');
      },
@@ -167,6 +193,7 @@
      }
   },
   methods: {
      ...mapMutations(['changeweighHouseCode']),
      init() {
         // 获取称重信息
         this.$reqGet('weighList', { id: this.takeCoalId }).then(res => {
@@ -216,6 +243,8 @@
                     });
                     this.isConfirmWeighLoading = false;
                  }, 1000);
               } else {
                  this.$u.toast('称重失败,请稍后重试');
               }
            })
            .catch(err => {
@@ -241,46 +270,44 @@
      /**
       * 初始化 weoSocket
       */
      initWebSocket() {
         let wsUrl = `${webSocketUrl}?access_token=${uni.getStorageSync('token')}`;
         let socket = uni.connectSocket({
            url: wsUrl,
            header: {
               CLIENT_TOC: 'Y'
            },
            complete: res => {
               console.log(res, 'socket结果');
            }
         });
         socket.onOpen(() => {
            console.log('onOpen');
         });
         // 获取服务器传来的数据,做相应处理
         socket.onMessage(res => {
            console.log('socketWeigh', res);
            let nowWeighObj = JSON.parse(res.data.slice(7));
            console.log(nowWeighObj);
            // 一开始是weighHouseCode
            if (nowWeighObj.eqCode == this.weighHouseCode) {
               if (nowWeighObj.eqInfraredStatus) {
                  this.infraredStatus = true;
                  this.weighData.weigh = this.realTimeWeigh = nowWeighObj.weigh;
               } else {
                  this.infraredStatus = false;
                  this.weighData.weigh = this.realTimeWeigh = nowWeighObj.weigh;
               }
            }
         });
         socket.onClose(() => {
            uni.closeSocket();
            console.log('webSocketClose');
            this.$u.toast('磅房已关闭');
         });
         socket.onError(err => {
            console.log('socket报错', err);
            this.$u.toast('磅房暂时不能使用,请重新进入该页面,重试!!');
         });
      },
      // initWebSocket() {
      //    let wsUrl = `${webSocketUrl}?access_token=${uni.getStorageSync('token')}`;
      //    let socket = uni.connectSocket({
      //       url: wsUrl,
      //       header: {
      //          CLIENT_TOC: 'Y'
      //       },
      //       complete: res => {
      //          console.log(res, 'socket结果');
      //       }
      //    });
      //    socket.onOpen(() => {
      //       console.log('onOpen');
      //    });
      //    // 获取服务器传来的数据,做相应处理
      //    socket.onMessage(res => {
      //       console.log('socketWeigh', res);
      //       let nowWeighObj = JSON.parse(res.data.slice(7));
      //       if (nowWeighObj.eqCode == this.weighHouseCode) {
      //          if (nowWeighObj.eqInfraredStatus) {
      //             this.infraredStatus = true;
      //             this.weighData.weigh = this.realTimeWeigh = nowWeighObj.weigh;
      //          } else {
      //             this.infraredStatus = false;
      //             this.weighData.weigh = this.realTimeWeigh = nowWeighObj.weigh;
      //          }
      //       }
      //    });
      //    socket.onClose(() => {
      //       uni.closeSocket();
      //       console.log('webSocketClose');
      //       this.$u.toast('磅房已关闭');
      //    });
      //    socket.onError(err => {
      //       console.log('socket报错', err);
      //       this.$u.toast('磅房暂时不能使用,请重新进入该页面,重试!!');
      //    });
      // },
      // 放空
      evacuation() {
         this.evacuationModalShow = true;
@@ -333,6 +360,8 @@
      }
      .bottom {
         text-align: center;
         position: relative;
         top: vww(-30);
      }
   }
   .two {