allocation.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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"
  11. 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="请输入设备ID" />
  18. </view>
  19. </view>
  20. <view class="loading" v-if="nonetf">
  21. 暂无可分配设备
  22. </view>
  23. <view class="ass_list">
  24. <checkbox-group class="che_group" @change="checkboxchange">
  25. <label v-for="(items,indexs) in assignments.children" :key="items.id">
  26. <view class="" v-if="items.type_name.search(inputdata)+1" class="equipment">
  27. <view class="equipment_top">
  28. <image
  29. :src="$imageURL+'/bigdata_app/image/fourMoodBase/'+assignments.id+'.png'"
  30. mode="" class="equipment_top_img"></image>
  31. <span class="equipment_top_name">{{assignments.type_name}}</span>
  32. <checkbox :value="String(items.type_name)" :checked="items.check" class="ucheckbox"
  33. 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="$imageURL+'/bigdata_app'+'/image/6209a98f0cb3b5086f2ca36152c9269.png'"
  51. mode=""></image>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. export default {
  57. data() {
  58. return {
  59. search: '',
  60. checken: false,
  61. assignment: [],
  62. assignments: [],
  63. list: [],
  64. current: 0,
  65. assignment_items: [],
  66. images: [{
  67. path: "/image/fourMoodBase/1.png",
  68. id: 3
  69. }, {
  70. path: "/image/fourMoodBase/5.png",
  71. id: 5
  72. }, {
  73. path: "/image/fourMoodBase/2.png",
  74. id: 6
  75. }, {
  76. path: "/image/fourMoodBase/4.png",
  77. id: 7
  78. },
  79. {
  80. path: "/image/fourMoodBase/10.png",
  81. id: 10
  82. }
  83. ],
  84. src: '',
  85. obj: {},
  86. isTop: false,
  87. base_id: "",
  88. baseidarr: "",
  89. inputdata: "",
  90. nonetf: false, //设备列表为空判断
  91. }
  92. },
  93. methods: {
  94. async ybase() { //获取基地已绑定设备
  95. const res = await this.$myRequest({
  96. url: '/api/api_gateway?method=base.bases.base_map_list',
  97. data: {
  98. base_id: this.base_id
  99. }
  100. })
  101. this.baseidarr = res
  102. console.log(res)
  103. var arr = []
  104. for (var i = 0; i < res.length; i++) {
  105. if (arr.indexOf(res[i].type_name) === -1) {
  106. arr.push(res[i].type_name)
  107. }
  108. }
  109. var obj = {}
  110. for (var i = 0; i < arr.length; i++) {
  111. obj[arr[i]] = []
  112. }
  113. for (var i = 0; i < res.length; i++) {
  114. for (var key in obj) {
  115. if (res[i].type_name == key) {
  116. obj[key].push(res[i].device_id)
  117. }
  118. }
  119. }
  120. console.log(obj)
  121. this.obj = obj
  122. this.getFourbase()
  123. },
  124. async getFourbase() { //全部设备列表
  125. const res = await this.$myRequest({
  126. url: '/api/api_gateway?method=base.bases.base_equip',
  127. })
  128. this.assignment = res.data
  129. for (var i = 0; i < this.assignment.length; i++) {
  130. let obj = {}
  131. obj.name = this.assignment[i].type_name
  132. this.list.push(obj)
  133. }
  134. if (this.list.length == 0) {
  135. let obj = {}
  136. obj.name = "全部"
  137. this.list.push(obj)
  138. this.nonetf = true
  139. }
  140. this.assignments = this.assignment[this.current]
  141. for (let i = 0; i < this.assignments.children.length; i++) {
  142. this.assignments.children[i].check = false
  143. for (let j = 0; j < this.baseidarr.length; j++) {
  144. if (this.assignments.children[i].type_name == this.baseidarr[j].device_id) {
  145. this.assignments.children[i].check = true
  146. console.log(this.assignments.children[i].check)
  147. }
  148. }
  149. }
  150. },
  151. forchange(obj) {
  152. for (let i = 0; i < this.assignments.children.length; i++) {
  153. this.assignments.children[i].check = false
  154. for (let key in obj) {
  155. if (key == this.list[this.current].name) {
  156. for (let j = 0; j < obj[key].length; j++) {
  157. if (this.assignments.children[i].type_name == obj[key][j]) {
  158. this.assignments.children[i].check = true
  159. }
  160. }
  161. }
  162. }
  163. }
  164. },
  165. change(index) {
  166. this.current = index
  167. this.assignments = this.assignment[index]
  168. console.log(this.obj)
  169. this.forchange(this.obj)
  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. if (this.base_id) {
  207. this.ybase()
  208. } else {
  209. this.getFourbase()
  210. }
  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: 80px;
  226. z-index: 100;
  227. }
  228. .bases_search {
  229. width: 100%;
  230. position: fixed;
  231. top: 120px;
  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>