allocation.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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" item-width="140" 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="'http://www.hnyfwlw.com:8006/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">设备名称:{{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="'http://www.hnyfwlw.com:8006/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. base_id: this.base_id
  81. }
  82. })
  83. this.baseidarr = res
  84. console.log(res)
  85. var arr = []
  86. for(var i=0;i<res.length;i++){
  87. if (arr.indexOf(res[i].type_name) === -1) {
  88. arr.push(res[i].type_name)
  89. }
  90. }
  91. var obj = {}
  92. for(var i=0;i<arr.length;i++){
  93. obj[arr[i]]=[]
  94. }
  95. for(var i=0;i<res.length;i++){
  96. for(var key in obj){
  97. if(res[i].type_name==key){
  98. obj[key].push(res[i].device_id)
  99. }
  100. }
  101. }
  102. console.log(obj)
  103. this.obj = obj
  104. this.getFourbase()
  105. },
  106. async getFourbase() { //全部设备列表
  107. this.loadingtf =true
  108. const res = await this.$myRequest({
  109. url: '/api/api_gateway?method=base.bases.base_equip',
  110. data:{
  111. base_id: this.base_id
  112. }
  113. })
  114. this.loadingtf = false
  115. this.assignment = res.data
  116. for (var i = 0; i < this.assignment.length; i++) {
  117. let obj = {}
  118. obj.name = this.assignment[i].type_name
  119. this.list.push(obj)
  120. }
  121. if(this.list.length==0){
  122. let obj = {}
  123. obj.name = "全部"
  124. this.list.push(obj)
  125. this.nonetf = true
  126. }
  127. this.assignments = this.assignment[this.current]
  128. for (let i = 0; i < this.assignments.children.length; i++) {
  129. this.assignments.children[i].check = false
  130. for (let j = 0; j < this.baseidarr.length; j++) {
  131. if (this.assignments.children[i].type_name == this.baseidarr[j].device_id) {
  132. this.assignments.children[i].check = true
  133. console.log(this.assignments.children[i].check)
  134. }
  135. }
  136. }
  137. },
  138. forchange(obj) {
  139. for (let i = 0; i < this.assignments.children.length; i++) {
  140. this.assignments.children[i].check = false
  141. for (let key in obj) {
  142. if(key==this.list[this.current].name){
  143. for(let j = 0; j < obj[key].length; j++){
  144. if(this.assignments.children[i].type_name == obj[key][j]){
  145. this.assignments.children[i].check = true
  146. }
  147. }
  148. }
  149. }
  150. }
  151. },
  152. change(index) {
  153. this.current = index
  154. this.assignments = this.assignment[index]
  155. console.log(this.obj)
  156. this.forchange(this.obj)
  157. },
  158. checkboxchange(e, items) {
  159. this.obj[this.assignments.type_name] = JSON.parse(JSON.stringify(e.detail.value))
  160. console.log(this.obj)
  161. },
  162. clickLeft() {
  163. uni.navigateBack({
  164. delta: 1
  165. })
  166. },
  167. cancel() {
  168. this.clickLeft()
  169. },
  170. canfirm() {
  171. uni.setStorage({
  172. key:"typeid",
  173. data:JSON.stringify(this.obj),
  174. success:()=>{
  175. uni.navigateBack({
  176. delta:1
  177. })
  178. }
  179. })
  180. },
  181. top() {
  182. uni.pageScrollTo({
  183. scrollTop: 0,
  184. duration: 500
  185. })
  186. },
  187. searchs(){
  188. console.log(this.inputdata.search("好"))
  189. },
  190. },
  191. onLoad(option) {
  192. this.base_id = option.base_id
  193. console.log(this.base_id)
  194. if(this.base_id){
  195. this.ybase()
  196. }else{
  197. this.getFourbase()
  198. }
  199. },
  200. onPageScroll(e) { //nvue暂不支持滚动监听,可用bindingx代替
  201. if (e.scrollTop > 200) { //距离大于200时显示
  202. this.isTop = true
  203. } else { //距离小于200时隐藏
  204. this.isTop = false
  205. }
  206. },
  207. }
  208. </script>
  209. <style lang="scss">
  210. .utabs {
  211. width: 100%;
  212. position: fixed;
  213. top: 88px;
  214. z-index: 100;
  215. }
  216. .bases_search {
  217. width: 100%;
  218. position: fixed;
  219. top: 128px;
  220. z-index: 100;
  221. background-color: #FFFFFF;
  222. .bases_search_text {
  223. width: 90%;
  224. margin: 0 auto;
  225. background-color: #F8F8F8;
  226. height: 60rpx;
  227. border-radius: 30rpx;
  228. display: flex;
  229. line-height: 60rpx;
  230. .search {
  231. padding: 0 20rpx;
  232. font-size: 34rpx;
  233. }
  234. input {
  235. width: 80%;
  236. margin-top: 10rpx;
  237. font-size: 28rpx;
  238. }
  239. }
  240. }
  241. .loading {
  242. position: fixed;
  243. top: 440px;
  244. width: 95%;
  245. left: 2.5%;
  246. text-align: center;
  247. .img {
  248. width: 300rpx;
  249. height: 40rpx;
  250. }
  251. }
  252. .ass_list {
  253. position: absolute;
  254. top: 115px;
  255. width: 100%;
  256. margin-bottom: 40px;
  257. .che_group {
  258. display: flex;
  259. flex-direction: column;
  260. width: 90%;
  261. margin: 0 auto;
  262. }
  263. .equipment {
  264. width: 90%;
  265. margin: 20rpx auto;
  266. box-shadow: 0 0 10rpx #bcb9ca;
  267. padding: 20rpx 30rpx;
  268. .equipment_top {
  269. height: 60rpx;
  270. width: 100%;
  271. border-bottom: 1px solid #dfe5ec;
  272. position: relative;
  273. .equipment_top_img {
  274. width: 40rpx;
  275. height: 40rpx;
  276. position: absolute;
  277. }
  278. .equipment_top_name {
  279. font-size: 24rpx;
  280. margin-left: 60rpx;
  281. }
  282. .ucheckbox {
  283. float: right;
  284. margin: 0rpx -4rpx;
  285. transform: scale(0.7);
  286. }
  287. }
  288. .equipment_bot {
  289. padding: 30rpx 0;
  290. position: relative;
  291. .equipment_bot_id {
  292. font-weight: 700;
  293. font-size: 15px;
  294. margin-bottom: 16rpx;
  295. }
  296. .equipment_bot_name {
  297. font-size: 24rpx;
  298. }
  299. .equipment_state {
  300. position: absolute;
  301. top: 20rpx;
  302. right: 0;
  303. width: 100rpx;
  304. height: 100rpx;
  305. text-align: center;
  306. line-height: 100rpx;
  307. color: #42b983;
  308. }
  309. }
  310. }
  311. }
  312. .allocbtn {
  313. width: 100%;
  314. position: fixed;
  315. bottom: 0;
  316. z-index: 100;
  317. display: flex;
  318. button {
  319. width: 50%;
  320. font-size: 24rpx;
  321. height: 80rpx;
  322. line-height: 80rpx;
  323. border-radius: 0;
  324. }
  325. .cancel {
  326. background-color: #C8C7CC;
  327. color: #555555;
  328. }
  329. .canfirm {
  330. color: white;
  331. background-color: #42b983;
  332. }
  333. }
  334. .top {
  335. position: fixed;
  336. right: 30px;
  337. bottom: 100px;
  338. z-index: 100;
  339. image {
  340. width: 100rpx;
  341. height: 100rpx;
  342. }
  343. }
  344. </style>