付延余
2023-03-23 a20cc4d791acb78db0d7455922c781784d333970
pages/driver-page/driver-index/bill-of-lading-details/weighingDevice/weighingDevice.vue
@@ -2,11 +2,22 @@
   <view class="weighingDevice">
      <view class="one">
         <view class="top">
            <view class="top_left"><text>41.5</text></view>
            <view class="top_left">
               <text>{{ realTimeWeigh }}</text>
            </view>
            <view class="top_right">
               <view class="">称重: <u--text type="success" text="正常" size="34"></u--text></view>
               <view class="">红外: <u--text type="success" text="正常" size="34"></u--text></view>
               <view class="">雷达: <u--text type="success" text="正常" size="34"></u--text></view>
               <view class="">
                  称重:
                  <u--text :type="realTimeWeigh == 0 ? 'error' : 'success'" :text="realTimeWeigh == 0 ? '异常' : '正常'" size="34"></u--text>
               </view>
               <view class="">
                  红外:
                  <u--text :type="infraredStatus ? 'error' : 'success'" :text="infraredStatus ? '异常' : '正常'" size="34"></u--text>
               </view>
               <!-- <view class="">
                  雷达:
                  <u--text type="success" text="正常" size="34"></u--text>
               </view> -->
            </view>
         </view>
         <view class="bottom"><text>TIP:当前状态正常可以称重</text></view>
@@ -14,34 +25,116 @@
      <view class="two">
         <p>订单编号:{{ weighList.code || '' }}</p>
         <p>订单类型:{{ weighList.orderTye || '' }}</p>
         <p>订单余量:{{ weighList.allowance }}</p>
         <p>皮重:{{ weighList.skin || '' }}</p>
         <p>毛重:{{ weighList.hair || '' }}</p>
         <p>净重:{{ weighList.clean || '' }}</p>
         <p>订单余量:{{ weighList.orderSurplus || 0 }}</p>
         <p>皮重:{{ temporaryWeighObj.skin == 0 ? weighList.skin : temporaryWeighObj.skin }}</p>
         <p>毛重:{{ temporaryWeighObj.hair == 0 ? weighList.hair : temporaryWeighObj.hair }}</p>
         <p>净重:{{ temporaryWeighObj.clean == 0 ? weighList.clean : temporaryWeighObj.clean }}</p>
         <p>煤种名称:{{ weighList.coalName || '' }}</p>
         <p>单位名称:{{ weighList.deptName || '' }}</p>
         <p>矿场名称:{{ weighList.filedName || '' }}</p>
      </view>
      <view class="three">
         <!-- 外销订单成皮时,返回加减吨按钮置灰。称毛时可用.外购订单,不出现返回加减吨的按钮 -->
         <u-button type="primary" text="确定称重" @click="confirmWeigh"></u-button>
         <u-button type="primary" text="返回加减吨"></u-button>
         <u-button
            type="primary"
            text="确定称重"
            :disabled="realTimeWeigh == 0 || infraredStatus"
            :loading="isConfirmWeighLoading"
            loadingText="加载中"
            @click="confirmWeigh"
         ></u-button>
         <u-button type="primary" text="返回加减吨" :disabled="addAndSubtractCoalDisabled" v-if="weighList.orderTye == '外销'" @click="addAndSubtractCoal"></u-button>
      </view>
      <view class="four">如您需要调整装载货品吨数,请点击返回加减吨</view>
   </view>
</template>
<script>
let socket = null;
import { webSocketUrl } from '@/api/request.js';
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.weighHouseCode = params.weighHouseCode;
   },
   data() {
      return {
         weighData: {
            //确认称重接口参数
            deptId: '',
            tmId: '',
            sceneId: '',
            carNo: '',
            gateCameraId: '',
            equipmentCode: '',
            weigh: 0,
            tmCode: ''
         },
         takeCoalId: null,
         weighList: {}
         weighHouseCode: '',
         isConfirmWeighLoading: false, //确定称重按钮
         realTimeWeigh: '',
         weighList: {},
         webSocket: null, // webSocket实例
         // lockReconnect: false, // 重连锁,避免多次重连
         // maxReconnect: 6, // 最大重连次数, -1 标识无限重连
         // reconnectTime: 0, // 重连尝试次数
         // heartbeat: {
         //    interval: 30 * 1000, // 心跳间隔时间
         //    timeout: 10 * 1000, // 响应超时时间
         //    pingTimeoutObj: null, // 延时发送心跳的定时器
         //    pongTimeoutObj: null, // 接收心跳响应的定时器
         //    pingMessage: JSON.stringify({ type: 'ping' }) // 心跳请求信息
         // }
         // 临时称重对象
         temporaryWeighObj:{
            skin:0,
            hair:0,
            clean:0
         },
         infraredStatus:false// 红外状态
      };
   },
   watch:{
      realTimeWeigh(newV,oldV){
         if(this.weighList.orderTye == '外销'){
            if(this.weighList.skin == 0){
               this.temporaryWeighObj.skin = this.realTimeWeigh
            } else {
               this.temporaryWeighObj.hair = this.realTimeWeigh
               this.temporaryWeighObj.clean = this.temporaryWeighObj.hair - this.weighList.skin
            }
         } else if(this.weighList.orderTye == '外购'){
            if(this.weighList.hair == 0){
               this.temporaryWeighObj.hair = this.realTimeWeigh
            } else {
               this.temporaryWeighObj.skin = this.realTimeWeigh
               this.temporaryWeighObj = this.weighList.hair - this.temporaryWeighObj.skin
            }
         }
      }
   },
   onShow() {
      this.init();
      this.initWebSocket();
   },
   computed: {
      token() {
         return uni.getStorageSync('token');
      },
      // 加减煤按钮禁用与否
      addAndSubtractCoalDisabled() {
         if (this.weighList.orderTye == '外销') {
            if (this.weighList.skin == 0) {
               return true;
            } else if (this.weighList.skin != 0) {
               return false;
            }
         }
      },
   },
   methods: {
      init() {
@@ -50,16 +143,109 @@
            console.log(res, '获取称重信息');
            if (res.code == 0) {
               this.weighList = res.data;
               this.weighData.deptId = res.data.deptId;
               this.weighData.tmId = res.data.id;
               this.weighData.carNo = res.data.carNo;
               this.weighData.tmCode = res.data.code;
            }
         });
      },
      /**
       * @确认称重等待后端提供实时称重接口,获取皮重,毛重
       */
      confirmWeigh(){
         // this.$reqPost('saveWeigh',{id:this.takeCoalId,skin:'',hair:''}).then(res=>{
         //    console.log(res,"确认称重");
         // })
       */
      confirmWeigh() {
         if (this.isConfirmWeighLoading == false) {
            this.isConfirmWeighLoading = true;
            if (this.weighData.weigh != 0) {
               if (this.weighList.orderTye == '外销') {
                  if (this.weighList.skin ? (this.weighList.skin < this.realTimeWeigh ? true : false) : true) {
                     this.saveWeigh();
                  } else {
                     this.$u.toast('毛重不能小于皮重');
                     this.isConfirmWeighLoading = false;
                  }
               } else {
                  this.saveWeigh();
               }
            } else {
               this.$u.toast('未能获取地磅重量');
               this.isConfirmWeighLoading = false;
            }
         }
      },
      // 确认称重接口
      saveWeigh() {
         this.$reqPost('saveWeigh', this.weighData, 'json')
            .then(res => {
               if (res.code == 0) {
                  this.$u.toast('称重成功');
                  setTimeout(() => {
                     uni.navigateBack({
                        delta: 1
                     });
                     this.isConfirmWeighLoading = false;
                  }, 1000);
               }
            })
            .catch(err => {
               this.isConfirmWeighLoading = false;
               console.log(err);
            });
      },
      // 加减煤
      addAndSubtractCoal() {
         this.$reqPost('addAndSubtractCoal', { deptId: this.weighData.deptId, sceneId: this.weighData.sceneId, carNo: this.weighData.carNo }, 'json').then(res => {
            if (res.code == 0) {
               this.$u.toast('操作成功,即将返回上一页');
               setTimeout(() => {
                  uni.navigateBack({
                     delta: 1
                  });
                  this.isConfirmWeighLoading = false;
               }, 1000);
               console.log(res, '加减煤');
            }
         });
      },
      /**
       * 初始化 weoSocket
       */
      initWebSocket() {
         let wsUrl = `${webSocketUrl}?access_token=${uni.getStorageSync('token')}`;
         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(() => {
            console.log('webSocketClose');
            this.$u.toast('磅房接口终端');
         });
         socket.onError(err => {
            console.log('socket报错', err);
            this.$u.toast('磅房接口暂时不能使用,请重新进入该页面,重试!!');
         });
      }
   }
};
@@ -82,16 +268,16 @@
         .top_left {
            flex: 3;
            font-size: vww(50);
            display:flex;
            display: flex;
            align-items: center;
            justify-content: center;
         }
         .top_right {
            display:flex;
            display: flex;
            flex-direction: column;
            justify-content: center;
            flex: 2;
            view{
            view {
               display: flex;
            }
         }