allocation.vue 11 KB

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