index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <template>
  2. <u-popup :show="isShow" @close="close" :closeOnClickOverlay="true">
  3. <view class="container">
  4. <view class="search">
  5. <u-row>
  6. <u-col :span="2" v-if="multiple">
  7. <view class="all-choosed">
  8. <image
  9. @click="handleChooseAll"
  10. :src="allChecked?'/static/icon/choosed.png':'/static/icon/nochoose.png'"
  11. class="choosed-image">
  12. </image>
  13. 全选
  14. </view>
  15. </u-col>
  16. <u-col :span="!multiple?12:10">
  17. <u-search
  18. v-model="search.text"
  19. placeholder="关键字搜索"
  20. @search="handleSearch"
  21. @custom="handleSearch"
  22. :actionStyle="{
  23. color: '#2979ff'
  24. }"
  25. >
  26. </u-search>
  27. </u-col>
  28. </u-row>
  29. </view>
  30. <view class="last">
  31. <u-button type="primary" :plain="true" :disabled="page==1" @click="handleLast"
  32. :custom-style="{
  33. borderColor: '#FFF',
  34. background: '#F2f2f2',
  35. }"
  36. >
  37. <!-- <u-icon name="arrow-up" color="#2979ff" size="28"></u-icon> -->
  38. <image
  39. :src="'/static/icon/up.png'"
  40. class="option-image">
  41. </image>
  42. </u-button>
  43. </view>
  44. <view class="list">
  45. <template v-for="(item,index) in showList">
  46. <view class="item" :key="index"
  47. @click="handleClick(item)"
  48. >
  49. <image
  50. v-if="multiple"
  51. :src="item.checked?'/static/icon/choosed.png':'/static/icon/nochoose.png'"
  52. class="choosed-image">
  53. </image>
  54. <image
  55. :src="item.icon"
  56. class="icon-image">
  57. </image>
  58. <view>
  59. <view class="item-value">
  60. {{item.label}}<text v-if="item.workStatusName">({{item.workStatusName}})</text>
  61. </view>
  62. <view class="item-label">
  63. {{item.deptName}}
  64. </view>
  65. </view>
  66. </view>
  67. </template>
  68. <view class="empty" v-if="showList.length==0">暂无数据</view>
  69. </view>
  70. <view class="next">
  71. <u-button type="primary" :plain="true" :disabled="page==totalPage" @click="handleNext"
  72. :custom-style="{
  73. borderColor: '#FFF',
  74. background: '#F2f2f2',
  75. }"
  76. >
  77. <!-- <u-icon name="arrow-down" color="#2979ff" size="28"></u-icon> -->
  78. <image
  79. :src="'/static/icon/down.png'"
  80. class="option-image">
  81. </image>
  82. </u-button>
  83. </view>
  84. </view>
  85. </u-popup>
  86. </template>
  87. <script>
  88. import {isArray,clone } from 'lodash'
  89. import {realTimeList} from '@/api/realtimeWatch.js'
  90. import {getImages} from '@/plugins/images'
  91. //资源引入
  92. let car_list_online = getImages('/assetsMobile/images/map/icon/vehicle/car_list_online.png') //行驶在线
  93. let car_list_engin = getImages('/assetsMobile/images/map/icon/vehicle/car_list_engin.png') //停驶在线
  94. let car_list_unline = getImages('/assetsMobile/images/map/icon/vehicle/car_list_unline.png') //离线
  95. let car_online = getImages('/assetsMobile/images/map/icon/vehicle/car_online.png') //行驶在线--地图
  96. let car_engin = getImages('/assetsMobile/images/map/icon/vehicle/car_engin.png') //停驶在线 -- 地图
  97. let car_unline = getImages('/assetsMobile/images/map/icon/vehicle/car_unline.png') //离线 --地图
  98. let people_list_online = getImages('/assetsMobile/images/map/icon/people/people_list_online.png') //在线
  99. let people_list_unline = getImages('/assetsMobile/images/map/icon/people/people_list_unline.png') //离线
  100. let people_online = getImages('/assetsMobile/images/map/icon/people/people_online.png') //在线--地图
  101. let people_unline = getImages('/assetsMobile/images/map/icon/people/people_unline.png') //离线--地图
  102. export default {
  103. props: {
  104. //单页展示数据量
  105. size: {
  106. type: Number,
  107. default: 30
  108. },
  109. // 类型 1.人员 2.车辆
  110. queryType: {
  111. type: Number,
  112. default: 2
  113. },
  114. // 多选
  115. multiple: {
  116. type: Boolean,
  117. default: false
  118. },
  119. // 是否请求图标
  120. isGetIcon: {
  121. type: Boolean,
  122. default: false
  123. }
  124. },
  125. data() {
  126. return {
  127. allChecked: false,
  128. isShow: false,
  129. loadding: false,
  130. page: 1,
  131. total: 0,
  132. totalPage: 0,
  133. search: {
  134. text: ''
  135. },
  136. orginList: [],
  137. resultList: [], //搜索结果集合
  138. showList: [],
  139. }
  140. },
  141. mounted() {
  142. if (this.isGetIcon) {
  143. Promise.all([this.$store.dispatch('getVehIcon'),this.$store.dispatch('getUserIcon')]).then((data) => {
  144. this.getData()
  145. })
  146. } else {
  147. this.getData()
  148. }
  149. },
  150. methods: {
  151. show() {
  152. this.isShow= true;
  153. },
  154. handleChooseAll() {
  155. this.allChecked = !this.allChecked
  156. this.resultList.map(e => {
  157. e.checked = this.allChecked
  158. })
  159. },
  160. computeCheckedData() {
  161. let allLength = this.resultList.length
  162. let checedLength = this.resultList.filter((e) => e.checked).length
  163. if(allLength == checedLength) {
  164. this.allChecked = true
  165. } else {
  166. this.allChecked = false
  167. }
  168. },
  169. getChoosed() {
  170. let data = this.orginList.filter((e) => e.checked)
  171. this.$emit('confirm',data)
  172. },
  173. handleClick(e) {
  174. if(this.multiple) {
  175. e.checked=!e.checked
  176. this.computeCheckedData()
  177. } else {
  178. console.log(e,'e')
  179. this.$emit('confirm',e);
  180. this.isShow = false;
  181. }
  182. },
  183. handleSearch() {
  184. this.page = 1
  185. if(this.search.text) {
  186. this.resultList = this.orginList.filter((e) => e.label.includes(this.search.text) || e.deptName.includes(this.search.text))
  187. } else {
  188. this.resultList = clone(this.orginList)
  189. }
  190. this.computeCheckedData()
  191. this.totalPage = Math.ceil(this.resultList.length / this.size)
  192. this.handlePageData()
  193. },
  194. //上一页
  195. handleLast() {
  196. if(this.page != 1) this.page -= 1;
  197. this.handlePageData()
  198. },
  199. //下一页
  200. handleNext() {
  201. if(this.page != this.totalPage) this.page += 1;
  202. this.handlePageData()
  203. },
  204. //处理分页数据
  205. handlePageData() {
  206. let index = (this.page - 1) * this.size
  207. this.showList = clone(this.resultList).splice(index,this.size)
  208. },
  209. getData() {
  210. let that = this;
  211. this.loadding = true;
  212. realTimeList({
  213. type: this.queryType,
  214. }).then((res) => {
  215. if(isArray(res.data)) {
  216. res.data.forEach((item) => {
  217. let iconData = {}
  218. if (this.isGetIcon) {
  219. if(item.type == 2) {
  220. iconData = this.getVehIcon(item)
  221. } else if (item.type == 1) {
  222. iconData = this.getUserIcon(item)
  223. }
  224. }
  225. let obj = {
  226. ...item,
  227. ...iconData,
  228. checked: false,
  229. }
  230. this.orginList.push(obj);
  231. })
  232. this.$emit('onDataLoad',this.orginList)
  233. this.handleSearch()
  234. } else {
  235. this.orginList = [];
  236. this.showList = [];
  237. this.page = 1
  238. this.totalPage = 0
  239. }
  240. }).finally(() => {
  241. this.loadding = false
  242. })
  243. },
  244. close() {
  245. if(this.multiple) this.getChoosed()
  246. this.isShow = false
  247. },
  248. getVehIcon(item) {
  249. //列表图标
  250. let listIcon = this.$store.state.icon.vehIcon[2]
  251. //地图图标
  252. let mapIcon = this.$store.state.icon.vehIcon[1]
  253. let icon = ""
  254. let img = ""
  255. if (item.online == "1" && item.engineStatus == "1") {
  256. icon = listIcon[1][item.vehType]?getImages(listIcon[1][item.vehType]):car_list_online
  257. img = mapIcon[1][item.vehType]? getImages(mapIcon[1][item.vehType]):car_online
  258. } else if (item.online == "1" && item.engineStatus == "0") {
  259. icon = listIcon[2][item.vehType]?getImages(listIcon[2][item.vehType]):car_list_engin
  260. img = mapIcon[2][item.vehType]? getImages(mapIcon[2][item.vehType]):car_engin
  261. } else if (item.online == "0") {
  262. icon = listIcon[3][item.vehType]?getImages(listIcon[3][item.vehType]):car_list_unline
  263. img = mapIcon[3][item.vehType]?getImages(mapIcon[3][item.vehType]):car_unline
  264. } else {
  265. icon = listIcon[3][item.vehType]?getImages(listIcon[3][item.vehType]):car_list_unline
  266. img = mapIcon[3][item.vehType]?getImages(mapIcon[3][item.vehType]):car_unline
  267. }
  268. return {
  269. icon,
  270. img
  271. }
  272. },
  273. getUserIcon(item) {
  274. let listIcon = this.$store.state.icon.userIcon[2]
  275. //地图图标
  276. let mapIcon = this.$store.state.icon.userIcon[1]
  277. let icon = ""
  278. let img = ""
  279. if (item.online == "1") {
  280. icon = listIcon[1][item.workType]?getImages(listIcon[1][item.workType]):people_list_online
  281. img = mapIcon[1][item.workType]? getImages(mapIcon[1][item.workType]):people_online
  282. } else {
  283. icon = listIcon[3][item.workType]?getImages(listIcon[3][item.workType]):people_list_unline
  284. img = mapIcon[3][item.workType]? getImages(mapIcon[3][item.workType]):people_unline
  285. }
  286. return {
  287. icon,
  288. img
  289. }
  290. },
  291. }
  292. }
  293. </script>
  294. <style lang="scss" scoped>
  295. /* 内容satrt */
  296. .container {
  297. background: #fff;
  298. .search {
  299. padding: 20rpx 40rpx 10rpx 40rpx;
  300. .all-choosed {
  301. display: flex;
  302. justify-content: flex-start;
  303. align-items: center;
  304. font-size: 24rpx;
  305. }
  306. }
  307. .list {
  308. height: calc(85vh - 400rpx);
  309. padding: 0 20rpx;
  310. overflow-y: auto;
  311. .item {
  312. padding: 10rpx 20rpx;
  313. display: flex;
  314. align-items: center;
  315. .item-value {
  316. font-size: 22rpx;
  317. }
  318. .item-label {
  319. font-size: 22rpx;
  320. }
  321. // border-bottom: 2rpx solid #ddd;
  322. }
  323. .empty {
  324. display: flex;
  325. align-items: center;
  326. justify-content: center;
  327. height: calc(100vh - 400rpx);
  328. color: #909193;
  329. min-height: 800rpx;
  330. }
  331. }
  332. .last,.next {
  333. margin: 10rpx 40rpx;
  334. display: flex;
  335. justify-content: center;
  336. align-items: center;
  337. }
  338. }
  339. /* 内容end */
  340. .choosed-image {
  341. width: 30rpx;
  342. height: 30rpx;
  343. margin-right: 10rpx;
  344. }
  345. .icon-image {
  346. width: 30rpx;
  347. height: 30rpx;
  348. margin-right: 10rpx;
  349. }
  350. .option-image {
  351. width: 40rpx;
  352. height: 40rpx;
  353. margin-right: 10rpx;
  354. }
  355. </style>