list.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div class="battle-warp" style="padding: 10px 15px;height: 100%;">
  3. <div class="list-wrap" style="background-color: #ffffff;padding: 0;border-radius: 4px;height: 100%;">
  4. <van-search v-model="keyword" shape="round" @input="onLoad" placeholder="请输入车牌号或驾驶员姓名"/>
  5. <div v-if="cloneTruckList.length <= 0" class="list-404" style="border-top: 1px solid #dfdfdf;">没有找到"{{ keyword }}"的相关车辆</div>
  6. <div class="list-wrap__item" v-for="(item, index) in cloneTruckList" :key="index" @click="clickTruckEvent(item)" style="border-top: 1px solid #dfdfdf;">
  7. <div class="item-header">
  8. <div class="text-bold">{{ item.carNumber }}<span class="text-normal">({{ item.linked === 1 ? '其他' : '自营' }})</span></div>
  9. <div>今日里程<span class="color-blue">{{ item.mileage || '-' }}</span>公里</div>
  10. </div>
  11. <div class="item-info">
  12. <div class="label item-info__user" style="padding-left: 0" v-if="item.truckDriverList.length > 0">
  13. <div class="driver-wrap">
  14. <div v-for="(driver, driverIndex) in item.truckDriverList" :key="driverIndex" class="driver-list">{{ driver.driverName }}</div>
  15. </div>
  16. <!-- <div>{{ truckToDriverMobile(item.truckDriverList[0].driverName) }}</div>-->
  17. </div>
  18. <div class="label speed">
  19. <span>{{ item.speed || '-' }}</span>公里/小时
  20. <span class="status" :class="'status__' + item.speedStatus">{{ truckStatusList[item.speedStatus] }}</span>
  21. </div>
  22. <div class="label local">{{ item.currAddress || '-' }}</div>
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. </template>
  28. <script>
  29. import 'vue-bmap-gl/dist/style.css'
  30. import axios from 'axios'
  31. import { $gasdataGaugeAll } from '@/service/gasdata'
  32. export default {
  33. name: 'battle',
  34. data() {
  35. return {
  36. truckStatusList: {
  37. 0: '行驶中',
  38. 1: '静止中',
  39. 2: '离线中'
  40. },
  41. keyword: '',
  42. truckList: [],
  43. cloneTruckList: []
  44. }
  45. },
  46. watch: {},
  47. computed: {},
  48. created() {
  49. document.title = 'skkss'
  50. this.dragendPointer()
  51. },
  52. mounted() {},
  53. beforeDestroy() {},
  54. methods: {
  55. onLoad() {
  56. if (this.keyword) {
  57. this.cloneTruckList = this.truckList.filter(item => {
  58. const tmpKeyword = item.tmpKeyword.toLocaleUpperCase()
  59. const inputKeyword = this.keyword.toLocaleUpperCase()
  60. return tmpKeyword.indexOf(inputKeyword) !== -1
  61. })
  62. } else {
  63. this.cloneTruckList = [...this.truckList]
  64. }
  65. },
  66. clickTruckEvent(item) {
  67. this.$router.push({
  68. path: '/truck',
  69. query: {
  70. lat: item.lat,
  71. lng: item.lng,
  72. linked: item.linked,
  73. carNumber: item.carNumber
  74. }
  75. })
  76. },
  77. async queryCurrAddress(location) {
  78. const data = await axios.post(process.env.VUE_APP_BAIDU_URL + '?output=json&ak=BrOh2W3mLGpsn4ML9k48XLfE4hXFAuKK&coordtype=wgs84ll&location=' + location).then(response => {
  79. return response.data
  80. })
  81. if (data.hasOwnProperty('result')) {
  82. return data.result.addressComponent
  83. } else {
  84. return '-'
  85. }
  86. },
  87. truckToDriverUser(driver) {
  88. // 解释司机个人信息
  89. const driverUserInfo = driver.driverName ? driver.driverName.split('/') : []
  90. return driverUserInfo.length >= 1 ? driverUserInfo[0] : '-'
  91. },
  92. truckToDriverMobile(info) {
  93. if (info.indexOf('/') !== -1) {
  94. const userinfo = info.split('/')
  95. return userinfo[1] || '-'
  96. } else {
  97. return '-'
  98. }
  99. },
  100. dragendPointer() {
  101. $gasdataGaugeAll({}).then(response => {
  102. const data = response.carMonitorVos
  103. this.truckList = data
  104. data.forEach(async item => {
  105. // 根据金纬度获取地理位置信息
  106. const addressInfo = await this.queryCurrAddress(item.lat + ',' + item.lng)
  107. const currAddress = addressInfo.province + addressInfo.city + addressInfo.district + addressInfo.street
  108. if (item.hasOwnProperty('currAddress')) {
  109. item.currAddress = currAddress
  110. } else {
  111. this.$set(item, 'currAddress', currAddress)
  112. }
  113. // 解释司机信息
  114. const driverInfo = []
  115. if (item.hasOwnProperty('truckDriverList') && item.truckDriverList.length > 0) {
  116. item.truckDriverList.forEach(driver => {
  117. driverInfo.push(this.truckToDriverUser(driver))
  118. })
  119. }
  120. driverInfo.push(item.carNumber)
  121. if (item.hasOwnProperty('tmpKeyword')) {
  122. item.tmpKeyword = driverInfo.join('')
  123. } else {
  124. this.$set(item, 'tmpKeyword', driverInfo.join(''))
  125. }
  126. })
  127. this.cloneTruckList = [...this.truckList]
  128. })
  129. }
  130. }
  131. }
  132. </script>