allocation.vue 7.2 KB

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