123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- <template>
- <view class="home">
- <u-sticky bgColor="#f5f7fa" class="main-sticky">
- <view class="data-panel">
- <view class="lane-selector">
- <u-cell-group :border="false" >
- <u-cell
- @click="showPopup('popupLane')"
- :title="currentLane.name"
- value="切换"
- center
- :isLink="true"
- arrowDirection="down"
- ></u-cell>
- </u-cell-group>
- </view>
-
- <view class="status-cards">
- <view class="status-card">
- <view class="label">品种</view>
- <view class="value kind">{{ currentData.materialName || ' ' }}</view>
- </view>
- <view class="status-card">
- <view class="label">预装数</view>
- <view class="value">{{ currentData.number || '0'}}</view>
- </view>
- <view class="status-card">
- <view class="label">已装数</view>
- <view class="value highlight">{{ currentData.hasNum || '0' }}</view>
- </view>
- </view>
- </view>
- </u-sticky>
- <!-- 订单列表区域 -->
- <view class="order-list">
- <view class="section-title">
- <span>包装任务</span>
- <view>
- <u-button style="height:64rpx;padding:0 40rpx" type="primary" shape="circle" @click="toAdd">新增</u-button>
- </view>
- </view>
- <view class="order-cards">
- <view
- v-for="order in orders"
- :key="order.id"
- class="order-card"
- >
- <view class="order-header">
- <span class="lane">{{ order.lane }}车道</span>
- <span class="time">{{ order.roadName }}</span>
- </view>
- <view class="order-content">
- <view class="info-row">
- <span class="label">品种:</span>
- <span class="value">{{ order.materialName }}</span>
- </view>
- <view class="info-row">
- <span class="label">客户:</span>
- <span class="value">{{ order.companyName }}</span>
- </view>
- <view class="info-row">
- <span class="label">车号:</span>
- <span class="value">{{ order.vehicle }}</span>
- </view>
- <view class="info-row">
- <span class="label">装车数量:</span>
- <span class="value highlight">{{ order.number }}吨</span>
- </view>
- <view class="info-row">
- <span class="label">下单时间:</span>
- <span class="value">{{ order.setDate }}</span>
- </view>
- </view>
- </view>
- </view>
- </view>
- <Bars></Bars>
- <PopupSelect ref="popupLane" :option="laneOption" @onConfirm="onConfirm" />
- </view>
- </template>
- <script>
- import PopupSelect from '../../components/popup-select/index.vue'
- import Bars from '../../components/tabBar/tabBar.vue';
- import { getOrder,getLaneList } from '../../api/order'
-
- export default {
- components: {
- Bars,
- PopupSelect
- },
- data() {
- return {
- ws:null,
- wsUrl:'',
- currentData:{},
- orders:[],
- currentLane:{
- name:'',
- id:''
- },
- laneOption:[],
- }
- },
- watch: {
-
- },
- computed: {
-
- },
- onShow() {
- this.getList()
- },
- onLoad(options) {
- uni.hideTabBar()
- this.getLaneList()
- // this.connectSocket()
- },
- beforeUnmount() {
- this.ws.close(); // 组件销毁前关闭连接
- },
- methods: {
- //连接车道ws
- connectSocket(){
- console.log(this.wsUrl);
- if(!this.wsUrl) return
- if(this.ws){
- this.ws.close(); // 组件销毁前关闭连接
- }
- // 创建 WebSocket 连接(替换为你的服务端地址)
- this.ws = new WebSocket(this.wsUrl);
- // 监听连接成功
- this.ws.onopen = () => {
- console.log('WebSocket 连接已建立');
- };
- // 监听消息接收
- this.ws.onmessage = (event) => {
- console.log('1111111111111111',event);
-
- this.currentData = JSON.parse(event.data)
- };
- // 监听错误
- this.ws.onerror = (error) => {
- console.error('WebSocket 错误:', error);
- };
- // 监听连接关闭
- this.ws.onclose = () => {
- console.log('WebSocket 连接已关闭');
- setTimeout(() => this.connectSocket(), 3000); // 3秒后重连
- };
- },
-
- //去新增订单
- toAdd(){
- uni.navigateTo({ url: `/pages/other/addOrder?name=${this.currentLane.name}&id=${this.currentLane.id}` })
- },
- //显示选择
- showPopup(refs) {
- this.$refs[refs].showPicker = true
- },
- //获取车道
- getLaneList(){
- getLaneList().then(res=>{
- if(res.statusCode === 200){
- this.laneOption = res.data.data.map(item=>{
- return {
- text:item.roadName,
- value:item.roadCode,
- ...item
- }
- })
- if(this.laneOption.length){
- this.currentLane.name = this.laneOption[0].text
- this.currentLane.id = this.laneOption[0].value
- this.wsUrl = this.laneOption[0].monitorAddress
- this.connectSocket()
- }
- }
- })
- },
-
- //获取包装任务
- getList(){
- let data = {
- }
- getOrder().then(res=>{
- if(res.statusCode === 200){
- this.orders = res.data.data.records
- }
- })
- },
- //车道确定
- onConfirm(value) {
- console.log(value);
-
- if (value.value && value.value !== this.currentLane.id) {
- this.currentLane.name = value.text
- this.currentLane.id = value.value
- this.wsUrl = value.monitorAddress
- this.connectSocket()
- }
- },
- }
- }
- </script>
- <style scope>
- /* #ifndef APP-NVUE */
- page {
- background-color: #f5f7fa;
- }
- /* #endif */
- </style>
- <style lang="scss" scoped>
- .main-sticky{
- padding: 24rpx;
- }
- .loading-status {
- padding: 32rpx;
- background-color: #f5f7fa;
- min-height: 100vh;
- }
- .data-panel {
- background: white;
- border-radius: 24rpx;
- padding: 32rpx;
- box-shadow: 0 4rpx 24rpx rgba(0, 0, 0, 0.1);
- }
- .lane-selector {
- margin:-32rpx -32rpx 32rpx;
- }
- .lane-selector :deep(.el-select) {
- width: 100%;
- }
- .status-cards {
- display: grid;
- grid-template-columns: repeat(3, 1fr);
- gap: 24rpx;
- }
- .status-card {
- background: #f8f9fb;
- display: flex;
- flex-direction: column;
- border-radius: 16rpx;
- padding: 24rpx;
- text-align: center;
- }
- .status-card .label {
- font-size: 28rpx;
- color: #666;
- margin-bottom: 16rpx;
- }
- .status-card .value {
- font-size: 36rpx;
- font-weight: bold;
- color: #333;
- flex: 1;
- display:flex;
- align-items: center;
- justify-content: center;
- flex-direction: column;
- }
- .status-card .kind{
- font-size: 28rpx;
- }
- .status-card .value.highlight {
- color: #409eff;
- }
- .order-list {
- margin: 24rpx;
- }
- .section-title {
- display: flex;
- justify-content: space-between;
- align-items: center;
- font-size: 32rpx;
- font-weight: bold;
- margin-bottom: 24rpx;
- color: #333;
- }
- .order-cards {
- display: flex;
- flex-direction: column;
- gap: 12px;
- }
- .order-card {
- background: white;
- border-radius: 24rpx;
- padding: 32rpx;
- box-shadow: 0 4rpx 24rpx rgba(0, 0, 0, 0.1);
- }
- .order-header {
- display: flex;
- justify-content: space-between;
- margin-bottom: 24rpx;
- padding-bottom: 16rpx;
- border-bottom: 1px solid #eee;
- }
- .order-header .lane {
- font-weight: bold;
- color: #409eff;
- }
- .order-header .time {
- color: #999;
- }
- .info-row {
- display: flex;
- margin-bottom: 16rpx;
- }
- .info-row .label {
- color: #666;
- width: 160rpx;
- }
- .info-row .value {
- color: #333;
- flex: 1;
- }
- .info-row .value.highlight {
- color: #409eff;
- font-weight: bold;
- }
- </style>
|