allocation.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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">
  9. <view style="width: 95%;margin: 0 auto;">
  10. <u-tabs :list="list" :is-scroll="true" :current="current" @change="change" font-size="24" gutter="20"
  11. 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="请输入设备ID"/>
  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 assignments.children" :key="items.id" >
  29. <view class="" v-if="items.type_name.search(inputdata)+1" class="equipment">
  30. <view class="equipment_top">
  31. <image :src="$imageURL+'/bigdata_app/image/fourMoodBase/'+assignments.id+'.png'" mode="" class="equipment_top_img"></image>
  32. <span class="equipment_top_name">{{assignments.type_name}}</span>
  33. <checkbox :value="String(items.type_name)" :checked="items.check" class="ucheckbox" color="#42b983" />
  34. </view>
  35. <view class="equipment_bot">
  36. <!-- <p class="equipment_bot_id">设备ID:{{items.id}}</p> -->
  37. <p class="equipment_bot_name">设备ID:{{items.type_name}}</p>
  38. <!-- <view class="equipment_state">在线</view> -->
  39. </view>
  40. </view>
  41. </label>
  42. </checkbox-group>
  43. </view>
  44. <view class="allocbtn">
  45. <button @click="cancel" class="cancel">取消分配</button>
  46. <button @click="canfirm" class="canfirm">确定分配</button>
  47. </view>
  48. </view>
  49. <view class="top" v-if="isTop" @click="top">
  50. <image :src="$imageURL+ '/bigdata_app'+'/image/6209a98f0cb3b5086f2ca36152c9269.png'" mode=""></image>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. export default {
  56. data() {
  57. return {
  58. search: '',
  59. checken: false,
  60. assignment: [],
  61. assignments: [],
  62. list: [],
  63. current: 0,
  64. assignment_items: [],
  65. src: '',
  66. obj: {},
  67. isTop: false,
  68. base_id: "",
  69. baseidarr: [],
  70. inputdata:"",
  71. loadingtf:false,//loading
  72. nonetf:false,//设备列表为空判断
  73. }
  74. },
  75. methods: {
  76. async ybase() { //获取基地已绑定设备
  77. const res = await this.$myRequest({
  78. url: '/api/api_gateway?method=base.bases.base_map_list',
  79. data: {
  80. type_id:'',
  81. base_id: this.base_id
  82. }
  83. })
  84. this.baseidarr = res
  85. console.log(res)
  86. // var arr = []
  87. // for(var i=0;i<res.length;i++){
  88. // if (arr.indexOf(res[i].type_name) === -1) {
  89. // arr.push(res[i].type_name)
  90. // }
  91. // }
  92. // var obj = {}
  93. // for(var i=0;i<arr.length;i++){
  94. // obj[arr[i]]=[]
  95. // }
  96. // for(var i=0;i<res.length;i++){
  97. // for(var key in obj){
  98. // if(res[i].type_name==key){
  99. // obj[key].push(res[i].device_id)
  100. // }
  101. // }
  102. // }
  103. // console.log(obj)
  104. // this.obj = obj
  105. // this.getFourbase()
  106. },
  107. async getFourbase() { //全部设备列表
  108. this.loadingtf =true
  109. const res = await this.$myRequest({
  110. url: '/api/api_gateway?method=base.bases.base_equip',
  111. data:{
  112. base_id: this.base_id
  113. }
  114. })
  115. this.loadingtf = false
  116. for (var i = 0; i < res.type_info_list.length; i++) {
  117. let obj = {}
  118. obj.name = res.type_info_list[i].type_name
  119. obj.type_id = res.type_info_list[i].type_id
  120. this.list.push(obj)
  121. }
  122. this.change(0)
  123. // if(this.list.length==0){
  124. // let obj = {}
  125. // obj.name = "全部"
  126. // this.list.push(obj)
  127. // this.nonetf = true
  128. // }
  129. // this.assignments = this.assignment[this.current]
  130. // for (let i = 0; i < this.assignments.children.length; i++) {
  131. // this.assignments.children[i].check = false
  132. // for (let j = 0; j < this.baseidarr.length; j++) {
  133. // if (this.assignments.children[i].type_name == this.baseidarr[j].device_id) {
  134. // this.assignments.children[i].check = true
  135. // console.log(this.assignments.children[i].check)
  136. // }
  137. // }
  138. // }
  139. },
  140. forchange(obj) {
  141. for (let i = 0; i < this.assignments.children.length; i++) {
  142. this.assignments.children[i].check = false
  143. for (let key in obj) {
  144. if(key==this.list[this.current].name){
  145. for(let j = 0; j < obj[key].length; j++){
  146. if(this.assignments.children[i].type_name == obj[key][j]){
  147. this.assignments.children[i].check = true
  148. }
  149. }
  150. }
  151. }
  152. }
  153. },
  154. async change(index) {
  155. this.current = index
  156. console.log(this.obj)
  157. // this.forchange(this.obj)
  158. const res = await this.$myRequest({
  159. url: '/api/api_gateway?method=base.bases.base_equip',
  160. data: {
  161. type_id:this.list[this.current].type_id,
  162. base_id: this.base_id
  163. }
  164. })
  165. res.data[0].children = res.data[0].children.map((element)=> {
  166. let result = this.baseidarr.filter((item)=>item.device_id==element.type_name)
  167. return {...element, check: result.length!=0}
  168. });
  169. this.assignments = res.data[0]
  170. },
  171. checkboxchange(e, items) {
  172. this.obj[this.assignments.type_name] = JSON.parse(JSON.stringify(e.detail.value))
  173. console.log(this.obj)
  174. },
  175. clickLeft() {
  176. uni.navigateBack({
  177. delta: 1
  178. })
  179. },
  180. cancel() {
  181. this.clickLeft()
  182. },
  183. canfirm() {
  184. uni.setStorage({
  185. key:"typeid",
  186. data:JSON.stringify(this.obj),
  187. success:()=>{
  188. uni.navigateBack({
  189. delta:1
  190. })
  191. }
  192. })
  193. },
  194. top() {
  195. uni.pageScrollTo({
  196. scrollTop: 0,
  197. duration: 500
  198. })
  199. },
  200. searchs(){
  201. console.log(this.inputdata.search("好"))
  202. },
  203. },
  204. onLoad(option) {
  205. this.base_id = option.base_id
  206. console.log(this.base_id)
  207. if(this.base_id){
  208. this.ybase()
  209. }
  210. this.getFourbase()
  211. },
  212. onPageScroll(e) { //nvue暂不支持滚动监听,可用bindingx代替
  213. if (e.scrollTop > 200) { //距离大于200时显示
  214. this.isTop = true
  215. } else { //距离小于200时隐藏
  216. this.isTop = false
  217. }
  218. },
  219. }
  220. </script>
  221. <style lang="scss">
  222. .utabs {
  223. width: 100%;
  224. position: fixed;
  225. top: 88px;
  226. z-index: 100;
  227. }
  228. .bases_search {
  229. width: 100%;
  230. position: fixed;
  231. top: 128px;
  232. z-index: 100;
  233. background-color: #FFFFFF;
  234. .bases_search_text {
  235. width: 90%;
  236. margin: 0 auto;
  237. background-color: #F8F8F8;
  238. height: 60rpx;
  239. border-radius: 30rpx;
  240. display: flex;
  241. line-height: 60rpx;
  242. .search {
  243. padding: 0 20rpx;
  244. font-size: 34rpx;
  245. }
  246. input {
  247. width: 80%;
  248. margin-top: 10rpx;
  249. font-size: 28rpx;
  250. }
  251. }
  252. }
  253. .loading {
  254. position: fixed;
  255. top: 440px;
  256. width: 95%;
  257. left: 2.5%;
  258. text-align: center;
  259. .img {
  260. width: 300rpx;
  261. height: 40rpx;
  262. }
  263. }
  264. .ass_list {
  265. position: absolute;
  266. top: 115px;
  267. width: 100%;
  268. margin-bottom: 40px;
  269. .che_group {
  270. display: flex;
  271. flex-direction: column;
  272. width: 90%;
  273. margin: 0 auto;
  274. }
  275. .equipment {
  276. width: 90%;
  277. margin: 20rpx auto;
  278. box-shadow: 0 0 10rpx #bcb9ca;
  279. padding: 20rpx 30rpx;
  280. .equipment_top {
  281. height: 60rpx;
  282. width: 100%;
  283. border-bottom: 1px solid #dfe5ec;
  284. position: relative;
  285. .equipment_top_img {
  286. width: 40rpx;
  287. height: 40rpx;
  288. position: absolute;
  289. }
  290. .equipment_top_name {
  291. font-size: 24rpx;
  292. margin-left: 60rpx;
  293. }
  294. .ucheckbox {
  295. float: right;
  296. margin: 0rpx -4rpx;
  297. transform: scale(0.7);
  298. }
  299. }
  300. .equipment_bot {
  301. padding: 30rpx 0;
  302. position: relative;
  303. .equipment_bot_id {
  304. font-weight: 700;
  305. font-size: 15px;
  306. margin-bottom: 16rpx;
  307. }
  308. .equipment_bot_name {
  309. font-size: 24rpx;
  310. }
  311. .equipment_state {
  312. position: absolute;
  313. top: 20rpx;
  314. right: 0;
  315. width: 100rpx;
  316. height: 100rpx;
  317. text-align: center;
  318. line-height: 100rpx;
  319. color: #42b983;
  320. }
  321. }
  322. }
  323. }
  324. .allocbtn {
  325. width: 100%;
  326. position: fixed;
  327. bottom: 0;
  328. z-index: 100;
  329. display: flex;
  330. button {
  331. width: 50%;
  332. font-size: 24rpx;
  333. height: 80rpx;
  334. line-height: 80rpx;
  335. border-radius: 0;
  336. }
  337. .cancel {
  338. background-color: #C8C7CC;
  339. color: #555555;
  340. }
  341. .canfirm {
  342. color: white;
  343. background-color: #42b983;
  344. }
  345. }
  346. .top {
  347. position: fixed;
  348. right: 30px;
  349. bottom: 100px;
  350. z-index: 100;
  351. image {
  352. width: 100rpx;
  353. height: 100rpx;
  354. }
  355. }
  356. </style>