home.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <template>
  2. <view class="home">
  3. <u-sticky bgColor="#f5f7fa" class="main-sticky">
  4. <view class="data-panel">
  5. <view class="lane-selector">
  6. <u-cell-group :border="false" >
  7. <u-cell
  8. @click="showPopup('popupLane')"
  9. :title="currentLane.name"
  10. value="切换"
  11. center
  12. :isLink="true"
  13. arrowDirection="down"
  14. ></u-cell>
  15. </u-cell-group>
  16. </view>
  17. <view class="status-cards">
  18. <view class="status-card">
  19. <view class="label">品种</view>
  20. <view class="value kind">{{ currentData.materialName || ' ' }}</view>
  21. </view>
  22. <view class="status-card">
  23. <view class="label">预装数</view>
  24. <view class="value">{{ currentData.number || '0'}}</view>
  25. </view>
  26. <view class="status-card">
  27. <view class="label">已装数</view>
  28. <view class="value highlight">{{ currentData.hasNum || '0' }}</view>
  29. </view>
  30. </view>
  31. </view>
  32. </u-sticky>
  33. <!-- 订单列表区域 -->
  34. <view class="order-list">
  35. <view class="section-title">
  36. <span>包装任务</span>
  37. <view>
  38. <u-button style="height:64rpx;padding:0 40rpx" type="primary" shape="circle" @click="toAdd">新增</u-button>
  39. </view>
  40. </view>
  41. <view class="order-cards">
  42. <view
  43. v-for="order in orders"
  44. :key="order.id"
  45. class="order-card"
  46. >
  47. <view class="order-header">
  48. <span class="lane">{{ order.lane }}车道</span>
  49. <span class="time">{{ order.roadName }}</span>
  50. </view>
  51. <view class="order-content">
  52. <view class="info-row">
  53. <span class="label">品种:</span>
  54. <span class="value">{{ order.materialName }}</span>
  55. </view>
  56. <view class="info-row">
  57. <span class="label">客户:</span>
  58. <span class="value">{{ order.companyName }}</span>
  59. </view>
  60. <view class="info-row">
  61. <span class="label">车号:</span>
  62. <span class="value">{{ order.vehicle }}</span>
  63. </view>
  64. <view class="info-row">
  65. <span class="label">装车数量:</span>
  66. <span class="value highlight">{{ order.number }}吨</span>
  67. </view>
  68. <view class="info-row">
  69. <span class="label">下单时间:</span>
  70. <span class="value">{{ order.setDate }}</span>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. <Bars></Bars>
  77. <PopupSelect ref="popupLane" :option="laneOption" @onConfirm="onConfirm" />
  78. </view>
  79. </template>
  80. <script>
  81. import PopupSelect from '../../components/popup-select/index.vue'
  82. import Bars from '../../components/tabBar/tabBar.vue';
  83. import { getOrder,getLaneList } from '../../api/order'
  84. export default {
  85. components: {
  86. Bars,
  87. PopupSelect
  88. },
  89. data() {
  90. return {
  91. ws:null,
  92. wsUrl:'',
  93. currentData:{},
  94. orders:[],
  95. currentLane:{
  96. name:'',
  97. id:''
  98. },
  99. laneOption:[],
  100. }
  101. },
  102. watch: {
  103. },
  104. computed: {
  105. },
  106. onShow() {
  107. this.getList()
  108. },
  109. onLoad(options) {
  110. uni.hideTabBar()
  111. this.getLaneList()
  112. // this.connectSocket()
  113. },
  114. beforeUnmount() {
  115. this.ws.close(); // 组件销毁前关闭连接
  116. },
  117. methods: {
  118. //连接车道ws
  119. connectSocket(){
  120. console.log(this.wsUrl);
  121. if(!this.wsUrl) return
  122. if(this.ws){
  123. this.ws.close(); // 组件销毁前关闭连接
  124. }
  125. // 创建 WebSocket 连接(替换为你的服务端地址)
  126. this.ws = new WebSocket(this.wsUrl);
  127. // 监听连接成功
  128. this.ws.onopen = () => {
  129. console.log('WebSocket 连接已建立');
  130. };
  131. // 监听消息接收
  132. this.ws.onmessage = (event) => {
  133. console.log('1111111111111111',event);
  134. this.currentData = JSON.parse(event.data)
  135. };
  136. // 监听错误
  137. this.ws.onerror = (error) => {
  138. console.error('WebSocket 错误:', error);
  139. };
  140. // 监听连接关闭
  141. this.ws.onclose = () => {
  142. console.log('WebSocket 连接已关闭');
  143. setTimeout(() => this.connectSocket(), 3000); // 3秒后重连
  144. };
  145. },
  146. //去新增订单
  147. toAdd(){
  148. uni.navigateTo({ url: '/pages/other/addOrder' })
  149. },
  150. //显示选择
  151. showPopup(refs) {
  152. this.$refs[refs].showPicker = true
  153. },
  154. //获取车道
  155. getLaneList(){
  156. getLaneList().then(res=>{
  157. if(res.statusCode === 200){
  158. this.laneOption = res.data.data.map(item=>{
  159. return {
  160. text:item.roadName,
  161. value:item.roadCode,
  162. ...item
  163. }
  164. })
  165. if(this.laneOption.length){
  166. this.currentLane.name = this.laneOption[0].text
  167. this.currentLane.id = this.laneOption[0].value
  168. this.wsUrl = this.laneOption[0].monitorAddress
  169. this.connectSocket()
  170. }
  171. }
  172. })
  173. },
  174. //获取包装任务
  175. getList(){
  176. let data = {
  177. }
  178. getOrder().then(res=>{
  179. if(res.statusCode === 200){
  180. this.orders = res.data.data.records
  181. }
  182. })
  183. },
  184. //车道确定
  185. onConfirm(value) {
  186. console.log(value);
  187. if (value.value && value.value !== this.currentLane.id) {
  188. this.currentLane.name = value.text
  189. this.currentLane.id = value.value
  190. this.wsUrl = value.monitorAddress
  191. this.connectSocket()
  192. }
  193. },
  194. }
  195. }
  196. </script>
  197. <style scope>
  198. /* #ifndef APP-NVUE */
  199. page {
  200. background-color: #f5f7fa;
  201. }
  202. /* #endif */
  203. </style>
  204. <style lang="scss" scoped>
  205. .main-sticky{
  206. padding: 24rpx;
  207. }
  208. .loading-status {
  209. padding: 32rpx;
  210. background-color: #f5f7fa;
  211. min-height: 100vh;
  212. }
  213. .data-panel {
  214. background: white;
  215. border-radius: 24rpx;
  216. padding: 32rpx;
  217. box-shadow: 0 4rpx 24rpx rgba(0, 0, 0, 0.1);
  218. }
  219. .lane-selector {
  220. margin:-32rpx -32rpx 32rpx;
  221. }
  222. .lane-selector :deep(.el-select) {
  223. width: 100%;
  224. }
  225. .status-cards {
  226. display: grid;
  227. grid-template-columns: repeat(3, 1fr);
  228. gap: 24rpx;
  229. }
  230. .status-card {
  231. background: #f8f9fb;
  232. display: flex;
  233. flex-direction: column;
  234. border-radius: 16rpx;
  235. padding: 24rpx;
  236. text-align: center;
  237. }
  238. .status-card .label {
  239. font-size: 28rpx;
  240. color: #666;
  241. margin-bottom: 16rpx;
  242. }
  243. .status-card .value {
  244. font-size: 36rpx;
  245. font-weight: bold;
  246. color: #333;
  247. flex: 1;
  248. display:flex;
  249. align-items: center;
  250. justify-content: center;
  251. flex-direction: column;
  252. }
  253. .status-card .kind{
  254. font-size: 28rpx;
  255. }
  256. .status-card .value.highlight {
  257. color: #409eff;
  258. }
  259. .order-list {
  260. margin: 24rpx;
  261. }
  262. .section-title {
  263. display: flex;
  264. justify-content: space-between;
  265. align-items: center;
  266. font-size: 32rpx;
  267. font-weight: bold;
  268. margin-bottom: 24rpx;
  269. color: #333;
  270. }
  271. .order-cards {
  272. display: flex;
  273. flex-direction: column;
  274. gap: 12px;
  275. }
  276. .order-card {
  277. background: white;
  278. border-radius: 24rpx;
  279. padding: 32rpx;
  280. box-shadow: 0 4rpx 24rpx rgba(0, 0, 0, 0.1);
  281. }
  282. .order-header {
  283. display: flex;
  284. justify-content: space-between;
  285. margin-bottom: 24rpx;
  286. padding-bottom: 16rpx;
  287. border-bottom: 1px solid #eee;
  288. }
  289. .order-header .lane {
  290. font-weight: bold;
  291. color: #409eff;
  292. }
  293. .order-header .time {
  294. color: #999;
  295. }
  296. .info-row {
  297. display: flex;
  298. margin-bottom: 16rpx;
  299. }
  300. .info-row .label {
  301. color: #666;
  302. width: 160rpx;
  303. }
  304. .info-row .value {
  305. color: #333;
  306. flex: 1;
  307. }
  308. .info-row .value.highlight {
  309. color: #409eff;
  310. font-weight: bold;
  311. }
  312. </style>