allocation.vue 7.9 KB

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