index.vue 9.9 KB

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