eleChoose.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. <template>
  2. <view class="container">
  3. <view class="search">
  4. <u-row>
  5. <u-col :span="2">
  6. <view class="all-choosed" @click="handleChooseAll">
  7. <image
  8. :src="allChecked?'/static/icon/choosed.png':'/static/icon/nochoose.png'"
  9. class="choosed-image">
  10. </image>
  11. 全选
  12. </view>
  13. </u-col>
  14. <u-col :span="10">
  15. <u-search
  16. v-model="search.text"
  17. placeholder="关键字搜索"
  18. @search="handleSearch"
  19. @custom="handleSearch"
  20. :actionStyle="{
  21. color: '#2979ff'
  22. }"
  23. >
  24. </u-search>
  25. </u-col>
  26. </u-row>
  27. </view>
  28. <view class="last">
  29. <u-button type="primary" :plain="true" :disabled="page==1" @click="handleLast"
  30. :custom-style="{
  31. borderColor: '#FFF',
  32. background: '#F2f2f2',
  33. }"
  34. >
  35. <!-- <u-icon name="arrow-up" color="#2979ff" size="28"></u-icon> -->
  36. <image
  37. :src="'/static/icon/up.png'"
  38. class="option-image">
  39. </image>
  40. </u-button>
  41. </view>
  42. <view class="list">
  43. <template v-for="(item,index) in showList">
  44. <view class="item" :key="index" @click="handleChoose(item)">
  45. <image
  46. :src="item.checked?'/static/icon/choosed.png':'/static/icon/nochoose.png'"
  47. class="choosed-image">
  48. </image>
  49. <image
  50. :src="item.icon"
  51. class="icon-image">
  52. </image>
  53. <view>
  54. <view class="item-value">
  55. {{item.label}}<text v-if="item.workStatusName">({{item.workStatusName}})</text>
  56. </view>
  57. <view class="item-label">
  58. {{item.deptName}}
  59. </view>
  60. </view>
  61. </view>
  62. </template>
  63. <view class="empty" v-if="showList.length==0">{{tips}}</view>
  64. </view>
  65. <view class="next">
  66. <u-button type="primary" :plain="true" :disabled="page==totalPage" @click="handleNext"
  67. :custom-style="{
  68. borderColor: '#FFF',
  69. background: '#F2f2f2',
  70. }"
  71. >
  72. <!-- <u-icon name="arrow-down" color="#2979ff" size="28"></u-icon> -->
  73. <image
  74. :src="'/static/icon/down.png'"
  75. class="option-image">
  76. </image>
  77. </u-button>
  78. </view>
  79. </view>
  80. </template>
  81. <script>
  82. import {isArray,clone,isObject } from 'lodash'
  83. import {realTimeList, realTimeMap} from '@/api/realtimeWatch.js'
  84. import {getImages} from '@/plugins/images'
  85. import {copyProps,clearProps} from '@/utils/gdtq.js'
  86. //资源引入
  87. // 车辆图片
  88. let car_list_online = getImages('/assetsMobile/images/map/icon/vehicle/car_list_online.png') //行驶在线
  89. let car_list_engin = getImages('/assetsMobile/images/map/icon/vehicle/car_list_engin.png') //停驶在线
  90. let car_list_unline = getImages('/assetsMobile/images/map/icon/vehicle/car_list_unline.png') //离线
  91. let car_list_warning = getImages('/assetsMobile/map/icon/vehicle/car_list_warning.png') //报警
  92. let car_online = getImages('/assetsMobile/images/map/icon/vehicle/car_online.png') //行驶在线--地图
  93. let car_engin = getImages('/assetsMobile/images/map/icon/vehicle/car_engin.png') //停驶在线 -- 地图
  94. let car_unline = getImages('/assetsMobile/images/map/icon/vehicle/car_unline.png') //离线 --地图
  95. let car_warning = getImages('/assetsMobile/images/map/icon/vehicle/car_warning.png') //报警 --地图
  96. //人员图片
  97. let people_list_online = getImages('/assetsMobile/images/map/icon/people/people_list_online.png') //在线
  98. let people_list_engin = getImages('/assetsMobile/images/map/icon/people/people_list_engin.png') //停留在线
  99. let people_list_unline = getImages('/assetsMobile/images/map/icon/people/people_list_unline.png') //离线
  100. let people_list_warning = getImages('/assetsMobile/images/map/icon/people/people_list_warning.png') //报警
  101. let people_online = getImages('/assetsMobile/images/map/icon/people/people_online.png') //在线--地图
  102. let people_engin = getImages('/assetsMobile/images/map/icon/people/people_engin.png') //停留在线--地图
  103. let people_unline = getImages('/assetsMobile/images/map/icon/people/people_unline.png') //离线--地图
  104. let people_warning = getImages('/assetsMobile/images/map/icon/people/people_warning.png') //报警--地图
  105. export default {
  106. props: {
  107. size: {
  108. type: Number,
  109. default: 30
  110. },
  111. // 类型 1.人员 2.车辆
  112. queryType: {
  113. type: Number,
  114. default: 2
  115. }
  116. },
  117. data() {
  118. return {
  119. allChecked: false,
  120. page: 1,
  121. total: 0,
  122. totalPage: 0,
  123. search: {
  124. text: ''
  125. },
  126. allData: {},
  127. orginList: [],
  128. resultList: [], //搜索结果集合
  129. showList: [],
  130. checkedKey: [], //选中id
  131. lastTime: null,
  132. tips: '加载中'
  133. }
  134. },
  135. mounted() {
  136. if(this.queryType == 2) {
  137. this.checkedKey = this.$store.state.realtimeWatch.vheicleCheckArr.map(e => e.id)
  138. this.$store.dispatch('getVehIcon').then((res) => {
  139. }).finally(() => {
  140. this.getData()
  141. })
  142. }
  143. if(this.queryType == 1) {
  144. this.checkedKey = this.$store.state.realtimeWatch.peopleCheckArr.map(e => e.id)
  145. this.$store.dispatch('getUserIcon').then((res) => {
  146. }).finally(() => {
  147. this.getData()
  148. })
  149. }
  150. },
  151. methods: {
  152. handleChooseAll() {
  153. this.allChecked = !this.allChecked
  154. this.resultList.map(e => {
  155. e.checked = this.allChecked
  156. })
  157. },
  158. handleChoose(item) {
  159. item.checked=!item.checked
  160. this.computeCheckedData()
  161. },
  162. computeCheckedData() {
  163. let allLength = this.resultList.length
  164. let checedLength = this.resultList.filter((e) => e.checked).length
  165. if(allLength == checedLength) {
  166. this.allChecked = true
  167. } else {
  168. this.allChecked = false
  169. }
  170. },
  171. getChoosed() {
  172. let data = this.orginList.filter((e) => e.checked && !e.disabled)
  173. // console.log(data,'datadtatatdata')
  174. this.$emit('choosed',data)
  175. if(this.queryType == 2) {
  176. this.$store.dispatch('setVheicleCheckArr',data)
  177. } else if (this.queryType == 1) {
  178. this.$store.dispatch('setPeopleCheckArr',data)
  179. }
  180. },
  181. handleSearch() {
  182. this.page = 1
  183. if(this.search.text) {
  184. this.resultList = this.orginList.filter((e) => e.label.includes(this.search.text) || e.deptName.includes(this.search.text))
  185. } else {
  186. this.resultList = clone(this.orginList)
  187. }
  188. this.computeCheckedData()
  189. this.totalPage = Math.ceil(this.resultList.length / this.size)
  190. this.handlePageData()
  191. },
  192. //上一页
  193. handleLast() {
  194. if(this.page != 1) this.page -= 1;
  195. this.handlePageData()
  196. },
  197. //下一页
  198. handleNext() {
  199. if(this.page != this.totalPage) this.page += 1;
  200. this.handlePageData()
  201. },
  202. //处理分页数据
  203. handlePageData() {
  204. let index = (this.page - 1) * this.size
  205. this.showList = clone(this.resultList).splice(index,this.size)
  206. },
  207. getData() {
  208. let that = this;
  209. this.$store.dispatch('setLoading',true)
  210. this.$store.dispatch('setTreeInterVal', {
  211. cb: () => {
  212. that.refreshData();
  213. }
  214. })
  215. realTimeList({
  216. type: this.queryType,
  217. }).then((res) => {
  218. if(isArray(res.data)) {
  219. this.lastTime = res.time
  220. res.data.forEach((item) => {
  221. let disabled = false
  222. if(this.isNull(item.lat)||this.isNull(item.lng)){
  223. disabled=true
  224. }
  225. let iconData = this.getIcons(item)
  226. let obj = {
  227. ...item,
  228. ...iconData,
  229. checked: this.checkedKey.includes(item.id),
  230. disabled
  231. }
  232. this.orginList.push(obj);
  233. this.allData[obj.id] = obj
  234. })
  235. this.handleSearch()
  236. this.$emit('getDataed')
  237. } else {
  238. this.orginList = [];
  239. this.showList = [];
  240. this.allData = {};
  241. this.page = 1
  242. this.totalPage = 0
  243. }
  244. if(Object.prototype.hasOwnProperty.call(res,'extra')) {
  245. this.handleCount(res.extra)
  246. } else {
  247. this.handleCount({})
  248. }
  249. }).finally(() => {
  250. this.$store.dispatch('setLoading',false)
  251. this.tips = '暂无数据'
  252. })
  253. },
  254. refreshData() {
  255. realTimeMap({
  256. type: this.queryType,
  257. time: this.lastTime,
  258. }).then((res) => {
  259. if(res.code == "0") {
  260. this.lastTime = res.time
  261. for(let i in res.data) {
  262. let item = res.data[i]
  263. if(this.allData[i]) {
  264. let iconData = this.getIcons(item)
  265. let disabled = false
  266. if(this.isNull(item.lat)||this.isNull(item.lng)){
  267. disabled=true
  268. }
  269. item.disabled = disabled
  270. if(iconData) {
  271. copyProps(this.allData[i],iconData)
  272. }
  273. // console.log(this.allData[i].speed,'this.allData[i]')
  274. copyProps(this.allData[i],item)
  275. } else {
  276. let disabled = false
  277. if(this.isNull(item.lat)||this.isNull(item.lng)){
  278. disabled=true
  279. }
  280. let iconData = this.getIcons(item)
  281. let obj = {
  282. ...item,
  283. ...iconData,
  284. checked: this.checkedKey.includes(item.id),
  285. disabled
  286. }
  287. this.originList.push(obj);
  288. this.allData[obj.id] = obj
  289. }
  290. }
  291. }
  292. }).finally(() => {
  293. })
  294. },
  295. getIcons(item) {
  296. if(this.queryType == 2) {
  297. return this.getVehIcon(item)
  298. } else if (this.queryType == 1) {
  299. return this.getUserIcon(item)
  300. }
  301. },
  302. getVehIcon(item) {
  303. //列表图标
  304. let listIcon = this.$store.state.icon.vehIcon[2]
  305. //地图图标
  306. let mapIcon = this.$store.state.icon.vehIcon[1]
  307. let icon = ""
  308. let img = ""
  309. let tips = ""
  310. let filterStatus = "" //用筛选
  311. if(item.isAlarm == '1') {
  312. icon = listIcon[4][item.vehType]? getImages(listIcon[4][item.vehType]):car_list_warning
  313. img = mapIcon[4][item.vehType]? getImages(mapIcon[4][item.vehType]):car_warning
  314. tips = '报警'
  315. filterStatus = '0'
  316. } else if (item.online == "1" && item.engineStatus == "1" && item.speed > 0) {
  317. icon = listIcon[1][item.vehType]?getImages(listIcon[1][item.vehType]):car_list_online
  318. img = mapIcon[1][item.vehType]? getImages(mapIcon[1][item.vehType]):car_online
  319. tips = '行驶在线'
  320. filterStatus = '1'
  321. } else if (item.online == "1" && (item.engineStatus == "0" || item.speed == 0)) {
  322. icon = listIcon[2][item.vehType]?getImages(listIcon[2][item.vehType]):car_list_engin
  323. img = mapIcon[2][item.vehType]? getImages(mapIcon[2][item.vehType]):car_engin
  324. tips = '停驶在线'
  325. filterStatus = '2'
  326. } else if (item.online == "0") {
  327. icon = listIcon[3][item.vehType]?getImages(listIcon[3][item.vehType]):car_list_unline
  328. img = mapIcon[3][item.vehType]? getImages(mapIcon[3][item.vehType]):car_unline
  329. tips = '离线'
  330. filterStatus = '3'
  331. } else if (item.online == "2") {
  332. icon = listIcon[3][item.vehType]?getImages(listIcon[3][item.vehType]):car_list_unline
  333. img = mapIcon[3][item.vehType]? getImages(mapIcon[3][item.vehType]):car_unline
  334. tips = '从未上线'
  335. filterStatus = '3'
  336. } else {
  337. icon = listIcon[3][item.vehType]?getImages(listIcon[3][item.vehType]):car_list_unline
  338. img = mapIcon[3][item.vehType]? getImages(mapIcon[3][item.vehType]):car_unline
  339. tips = '离线'
  340. filterStatus = '3'
  341. }
  342. return {
  343. icon,
  344. img,
  345. tips,
  346. filterStatus,
  347. code: 'vehicle',
  348. }
  349. },
  350. //人员图标
  351. getUserIcon(item) {
  352. let listIcon = this.$store.state.icon.userIcon[2]
  353. //地图图标
  354. let mapIcon = this.$store.state.icon.userIcon[1]
  355. let icon = ""
  356. let img = ""
  357. let tips = ""
  358. let filterStatus = "" //用筛选
  359. if(item.isAlarm == '1') {
  360. icon = listIcon[4][item.workType]? getImages(listIcon[4][item.workType]):people_list_warning
  361. img = mapIcon[4][item.workType]? getImages(mapIcon[4][item.workType]):people_warning
  362. tips = '报警'
  363. filterStatus = '0'
  364. } else if (item.online == "1" && item.speed > 0) {
  365. icon = listIcon[1][item.workType]?getImages(listIcon[1][item.workType]):people_list_online
  366. img = mapIcon[1][item.workType]? getImages(mapIcon[1][item.workType]):people_online
  367. tips = '行走在线'
  368. filterStatus = '1'
  369. } else if (item.online == "1" && item.speed == 0) {
  370. icon = listIcon[2][item.workType]?getImages(listIcon[2][item.workType]):people_list_engin
  371. img = mapIcon[2][item.workType]? getImages(mapIcon[2][item.workType]):people_engin
  372. tips = '停留在线'
  373. filterStatus = '2'
  374. } else {
  375. icon = listIcon[3][item.workType]?getImages(listIcon[3][item.workType]):people_list_unline
  376. img = mapIcon[3][item.workType]? getImages(mapIcon[3][item.workType]):people_unline
  377. tips = '离线'
  378. filterStatus = '3'
  379. }
  380. return {
  381. icon,
  382. img,
  383. tips,
  384. filterStatus,
  385. code: 'people',
  386. }
  387. },
  388. //计算在线数量
  389. handleCount(obj) {
  390. let cout = {
  391. alarmNum: 0,
  392. totalNum: 0,
  393. offLine: 0,
  394. onlineNum: 0,
  395. }
  396. if (isObject(obj)) {
  397. for(let i in cout) {
  398. if(obj[i]) {
  399. cout[i] = obj[i]
  400. }
  401. }
  402. }
  403. let countObj = [
  404. { label: "全部", value: cout.totalNum },
  405. {
  406. label: "在线",
  407. value: cout.onlineNum,
  408. },
  409. {
  410. label: "离线",
  411. value: cout.offLine,
  412. },
  413. {
  414. label: "报警",
  415. value: cout.alarmNum,
  416. style: 'color:#D40000;'
  417. },
  418. ];
  419. this.$store.dispatch('setCountInfo',countObj)
  420. },
  421. },
  422. beforeDestroy() {
  423. this.$store.dispatch('clearTreeInterVal')
  424. }
  425. }
  426. </script>
  427. <style lang="scss" scoped>
  428. /* 内容satrt */
  429. .container {
  430. background: #fff;
  431. .search {
  432. padding: 20rpx 40rpx 10rpx 40rpx;
  433. .all-choosed {
  434. display: flex;
  435. justify-content: flex-start;
  436. align-items: center;
  437. font-size: 24rpx;
  438. }
  439. }
  440. .list {
  441. height: calc(85vh - 400rpx);
  442. padding: 0 20rpx;
  443. overflow-y: auto;
  444. .item {
  445. padding: 10rpx 20rpx;
  446. display: flex;
  447. align-items: center;
  448. .item-value {
  449. font-size: 22rpx;
  450. }
  451. .item-label {
  452. font-size: 22rpx;
  453. }
  454. // border-bottom: 2rpx solid #ddd;
  455. }
  456. .empty {
  457. display: flex;
  458. align-items: center;
  459. justify-content: center;
  460. height: calc(100vh - 500rpx);
  461. color: #909193;
  462. min-height: 800rpx;
  463. }
  464. }
  465. .last,.next {
  466. margin: 10rpx 40rpx;
  467. display: flex;
  468. justify-content: center;
  469. align-items: center;
  470. }
  471. }
  472. /* 内容end */
  473. .choosed-image {
  474. width: 32rpx;
  475. height: 32rpx;
  476. margin-right: 10rpx;
  477. }
  478. .icon-image {
  479. width: 32rpx;
  480. height: 32rpx;
  481. margin-right: 10rpx;
  482. }
  483. .option-image {
  484. width: 40rpx;
  485. height: 40rpx;
  486. margin-right: 10rpx;
  487. }
  488. </style>