allocation.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 44px;">
  5. <view style="position: fixed;z-index: 100;">
  6. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="设备分配"></uni-nav-bar>
  7. </view>
  8. <view class="utabs" v-if="typeList.length">
  9. <view style="width: 95%;margin: 0 auto;">
  10. <u-tabs :list="typeList" keyName="type_name" :is-scroll="true" :current="current" @change="change"
  11. item-width="140" font-size="24" gutter="20" bar-width="60" active-color="#42b983"></u-tabs>
  12. </view>
  13. </view>
  14. <view class="bases_search">
  15. <view class="bases_search_text">
  16. <u-icon name="search" class="search" @click="searchs"></u-icon>
  17. <input type="text" v-model="inputdata" placeholder="请输入设备编号" @change="handleSearch" @confirm="handleSearch" />
  18. </view>
  19. </view>
  20. <view class="loading" v-if="loadingtf">
  21. <image src="../../static/images/ajax-loader.gif" mode="" class="img"></image>
  22. </view>
  23. <view class="loading" v-if="nonetf">
  24. 暂无可分配设备
  25. </view>
  26. <view class="ass_list">
  27. <checkbox-group class="che_group" @change="checkboxchange">
  28. <label v-for="(items,indexs) in equipmentList" :key="items.id">
  29. <view class="" class="equipment">
  30. <view class="equipment_top">
  31. <image
  32. :src="'http://www.hnyfwlw.com:8006/bigdata_app/image/fourMoodBase/'+currentType.type_id+'.png'"
  33. mode="" class="equipment_top_img"></image>
  34. <span class="equipment_top_name">{{currentType.type_name}}</span>
  35. <checkbox :value="String(items.type_name)" :checked="items.check" class="ucheckbox"
  36. color="#42b983" />
  37. </view>
  38. <view class="equipment_bot">
  39. <p class="equipment_bot_id">设备ID:{{items.id}}</p>
  40. <p class="equipment_bot_name">设备编号:{{items.type_name}}</p>
  41. <view class="equipment_state">在线</view>
  42. </view>
  43. </view>
  44. </label>
  45. </checkbox-group>
  46. </view>
  47. <view class="allocbtn">
  48. <button @click="cancel" class="cancel">取消分配</button>
  49. <button @click="canfirm" class="canfirm">确定分配</button>
  50. </view>
  51. </view>
  52. <view class="top" v-if="isTop" @click="top">
  53. <image :src="'http://www.hnyfwlw.com:8006/bigdata_app'+'/image/6209a98f0cb3b5086f2ca36152c9269.png'"
  54. mode=""></image>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import {
  60. map,
  61. assign,
  62. concat,
  63. zipObject,
  64. groupBy,
  65. uniqBy,
  66. values,
  67. keys
  68. } from 'lodash-es';
  69. export default {
  70. data() {
  71. return {
  72. search: '',
  73. checken: false,
  74. assignment: [],
  75. assignments: [],
  76. list: [],
  77. current: 0,
  78. assignment_items: [],
  79. src: '',
  80. obj: {},
  81. isTop: false,
  82. base_id: "",
  83. baseidarr: "",
  84. inputdata: "",
  85. loadingtf: false, //loading
  86. nonetf: false, //设备列表为空判断
  87. currentTypeID: 3,
  88. pageSize: 10,
  89. page: 1,
  90. equipmentList: [],
  91. typeList: [{
  92. "type_name": "测报灯",
  93. "type_id": 3
  94. }],
  95. selectedDataSource: {},
  96. selectedGroupByNameIDs: {}
  97. }
  98. },
  99. computed: {
  100. currentType() {
  101. return this.typeList[this.current]
  102. }
  103. },
  104. methods: {
  105. async ybase() { //获取基地已绑定设备
  106. const res = await this.$myRequest({
  107. url: '/api/api_gateway?method=base.bases.base_map_list',
  108. data: {
  109. base_id: this.base_id
  110. }
  111. })
  112. this.baseidarr = res;
  113. this.selectedDataSource = zipObject(map(res, 'device_id'), res);
  114. this.selectedGroupByNameIDs = groupBy(res, item => item.type_name);
  115. console.log(res, this.selectedDataSource)
  116. var arr = []
  117. for (var i = 0; i < res.length; i++) {
  118. if (arr.indexOf(res[i].type_name) === -1) {
  119. arr.push(res[i].type_name)
  120. }
  121. }
  122. var obj = {}
  123. for (var i = 0; i < arr.length; i++) {
  124. obj[arr[i]] = []
  125. }
  126. for (var i = 0; i < res.length; i++) {
  127. for (var key in obj) {
  128. if (res[i].type_name == key) {
  129. obj[key].push(res[i].device_id)
  130. }
  131. }
  132. }
  133. console.log(obj)
  134. this.obj = obj
  135. this.getFourbase()
  136. },
  137. async getFourbase() { //全部设备列表
  138. this.loadingtf = true
  139. const res = await this.$myRequest({
  140. url: '/api/api_gateway?method=base.bases.base_equip',
  141. data: {
  142. base_id: this.base_id,
  143. type_id: this.currentTypeID,
  144. device_id: this.inputdata,
  145. page_size: this.pageSize,
  146. page: this.page
  147. }
  148. })
  149. this.typeList = res.type_info_list.map(item => {
  150. return {
  151. name: item.type_name,
  152. type_name: item.type_name,
  153. type_id: item.type_id
  154. }
  155. });
  156. console.log(res, 'get four base', this.typeList)
  157. this.loadingtf = false
  158. this.assignment = res.data
  159. for (var i = 0; i < this.assignment.length; i++) {
  160. let obj = {}
  161. obj.name = this.assignment[i].type_name
  162. this.list.push(obj)
  163. }
  164. if (this.list.length == 0) {
  165. let obj = {}
  166. obj.name = "全部"
  167. this.list.push(obj)
  168. this.nonetf = true
  169. }
  170. console.warn(this.assignment, '--------------- equipment list', this.page)
  171. this.assignments = this.assignment[0]
  172. const dataList = res.data[0] && map(res.data[0].children, item => {
  173. return assign({}, item, {
  174. check: !!this.selectedDataSource[item.type_name]
  175. })
  176. });
  177. this.equipmentList = this.page === 1 ? dataList : concat(this.equipmentList, dataList);
  178. console.warn(this.equipmentList, 'get equip list ', this.equipmentList.length)
  179. // for (let i = 0; i < this.assignments.children.length; i++) {
  180. // this.assignments.children[i].check = false
  181. // for (let j = 0; j < this.baseidarr.length; j++) {
  182. // if (this.assignments.children[i].type_name == this.baseidarr[j].device_id) {
  183. // this.assignments.children[i].check = true
  184. // console.log(this.assignments.children[i].check)
  185. // }
  186. // }
  187. // }
  188. },
  189. forchange(obj) {
  190. for (let i = 0; i < this.assignments.children.length; i++) {
  191. this.assignments.children[i].check = false
  192. for (let key in obj) {
  193. if (key == this.list[this.current].name) {
  194. for (let j = 0; j < obj[key].length; j++) {
  195. if (this.assignments.children[i].type_name == obj[key][j]) {
  196. this.assignments.children[i].check = true
  197. }
  198. }
  199. }
  200. }
  201. }
  202. },
  203. change(index, item) {
  204. this.current = index
  205. this.page = 1;
  206. this.equipmentList = []
  207. this.currentTypeID = this.typeList[index] && this.typeList[index].type_id || ''
  208. this.getFourbase();
  209. console.log(this.obj)
  210. // this.forchange(this.obj)
  211. },
  212. checkboxchange(e, items) {
  213. console.log(e.detail, 'checkbox ', typeof e.detail.value)
  214. this.obj[this.assignments.type_name] = JSON.parse(JSON.stringify(e.detail.value))
  215. const originCurrentTypeIDList = this.selectedGroupByNameIDs[this.currentType.type_name] || []
  216. this.selectedGroupByNameIDs[this.currentType.type_name] = uniqBy(concat(originCurrentTypeIDList, map(e
  217. .detail.value, id => ({
  218. device_id: id
  219. }), 'device_id')))
  220. if (!this.selectedDataSource[e.detail.value]) {
  221. this.selectedDataSource[e.detail.value] = {
  222. "type_name": this.currentType.type_name,
  223. "device_id": e.detail.value
  224. }
  225. }
  226. },
  227. clickLeft() {
  228. uni.navigateBack({
  229. delta: 1
  230. })
  231. },
  232. cancel() {
  233. this.clickLeft()
  234. },
  235. canfirm() {
  236. const data = zipObject(keys(this.selectedGroupByNameIDs), map(values(this.selectedGroupByNameIDs),
  237. items => map(items, 'device_id')))
  238. console.log(data, 'confrim ')
  239. uni.setStorage({
  240. key: "typeid",
  241. data: JSON.stringify(data),
  242. success: () => {
  243. uni.navigateBack({
  244. delta: 1
  245. })
  246. }
  247. })
  248. },
  249. top() {
  250. uni.pageScrollTo({
  251. scrollTop: 0,
  252. duration: 500
  253. })
  254. },
  255. searchs() {
  256. console.log(this.inputdata.search("好"))
  257. },
  258. handleSearch() {
  259. console.log('handle search 00000000000000')
  260. this.page = 1;
  261. this.equipmentList = [];
  262. this.getFourbase();
  263. }
  264. },
  265. onLoad(option) {
  266. this.base_id = option.base_id
  267. console.log(this.base_id)
  268. if (this.base_id) {
  269. this.ybase()
  270. } else {
  271. this.getFourbase()
  272. }
  273. },
  274. onPageScroll(e) { //nvue暂不支持滚动监听,可用bindingx代替
  275. if (e.scrollTop > 200) { //距离大于200时显示
  276. this.isTop = true
  277. } else { //距离小于200时隐藏
  278. this.isTop = false
  279. }
  280. },
  281. onReachBottom() {
  282. this.page++;
  283. this.getFourbase();
  284. }
  285. }
  286. </script>
  287. <style lang="scss">
  288. .utabs {
  289. width: 100%;
  290. position: fixed;
  291. top: 88px;
  292. z-index: 100;
  293. }
  294. .bases_search {
  295. width: 100%;
  296. position: fixed;
  297. top: 128px;
  298. z-index: 100;
  299. background-color: #FFFFFF;
  300. .bases_search_text {
  301. width: 90%;
  302. margin: 0 auto;
  303. background-color: #F8F8F8;
  304. height: 60rpx;
  305. border-radius: 30rpx;
  306. display: flex;
  307. line-height: 60rpx;
  308. .search {
  309. padding: 0 20rpx;
  310. font-size: 34rpx;
  311. }
  312. input {
  313. width: 80%;
  314. margin-top: 10rpx;
  315. font-size: 28rpx;
  316. }
  317. }
  318. }
  319. .loading {
  320. position: fixed;
  321. top: 440px;
  322. width: 95%;
  323. left: 2.5%;
  324. text-align: center;
  325. .img {
  326. width: 300rpx;
  327. height: 40rpx;
  328. }
  329. }
  330. .ass_list {
  331. position: absolute;
  332. top: 115px;
  333. width: 100%;
  334. margin-bottom: 40px;
  335. .che_group {
  336. display: flex;
  337. flex-direction: column;
  338. width: 90%;
  339. margin: 0 auto;
  340. }
  341. .equipment {
  342. width: 90%;
  343. margin: 20rpx auto;
  344. box-shadow: 0 0 10rpx #bcb9ca;
  345. padding: 20rpx 30rpx;
  346. .equipment_top {
  347. height: 60rpx;
  348. width: 100%;
  349. border-bottom: 1px solid #dfe5ec;
  350. position: relative;
  351. .equipment_top_img {
  352. width: 40rpx;
  353. height: 40rpx;
  354. position: absolute;
  355. }
  356. .equipment_top_name {
  357. font-size: 24rpx;
  358. margin-left: 60rpx;
  359. }
  360. .ucheckbox {
  361. float: right;
  362. margin: 0rpx -4rpx;
  363. transform: scale(0.7);
  364. }
  365. }
  366. .equipment_bot {
  367. padding: 30rpx 0;
  368. position: relative;
  369. .equipment_bot_id {
  370. font-weight: 700;
  371. font-size: 15px;
  372. margin-bottom: 16rpx;
  373. }
  374. .equipment_bot_name {
  375. font-size: 24rpx;
  376. }
  377. .equipment_state {
  378. position: absolute;
  379. top: 20rpx;
  380. right: 0;
  381. width: 100rpx;
  382. height: 100rpx;
  383. text-align: center;
  384. line-height: 100rpx;
  385. color: #42b983;
  386. }
  387. }
  388. }
  389. }
  390. .allocbtn {
  391. width: 100%;
  392. position: fixed;
  393. bottom: 0;
  394. z-index: 100;
  395. display: flex;
  396. button {
  397. width: 50%;
  398. font-size: 24rpx;
  399. height: 80rpx;
  400. line-height: 80rpx;
  401. border-radius: 0;
  402. }
  403. .cancel {
  404. background-color: #C8C7CC;
  405. color: #555555;
  406. }
  407. .canfirm {
  408. color: white;
  409. background-color: #42b983;
  410. }
  411. }
  412. .top {
  413. position: fixed;
  414. right: 30px;
  415. bottom: 100px;
  416. z-index: 100;
  417. image {
  418. width: 100rpx;
  419. height: 100rpx;
  420. }
  421. }
  422. </style>