allocation.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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="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>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. search: '',
  42. checken: false,
  43. assignment: [],
  44. assignments: [],
  45. list: [],
  46. current: 0,
  47. assignment_items: [],
  48. images: [{
  49. path: "../../static/image/fourMoodBase/1.png",
  50. id: 3
  51. }, {
  52. path: "../../static/image/fourMoodBase/5.png",
  53. id: 5
  54. }, {
  55. path: "../../static/image/fourMoodBase/2.png",
  56. id: 6
  57. }, {
  58. path: "../../static/image/fourMoodBase/4.png",
  59. id: 7
  60. },],
  61. src: '',
  62. obj: {},
  63. addtype: []
  64. }
  65. },
  66. methods: {
  67. async getFourbase() { //基地列表
  68. const res = await this.$myRequest({
  69. url: '/api/api_gateway?method=base.bases.base_equip',
  70. })
  71. this.assignment = res.data
  72. for (var i = 0; i < this.assignment.length; i++) {
  73. let obj = {}
  74. obj.name = this.assignment[i].type_name
  75. this.list.push(obj)
  76. if (this.assignment[i].id == this.images[i].id) {
  77. this.assignment[i].src = this.images[i].path
  78. }
  79. }
  80. this.assignments = this.assignment[this.current]
  81. for (let i = 0; i < this.assignments.children.length; i++) {
  82. this.assignments.children[i].check = false
  83. for (let j = 0; j < this.addtype.length; j++) {
  84. if (this.assignments.children[i].type_name == this.addtype[j]) {
  85. this.assignments.children[i].check = true
  86. console.log(this.assignments.children[i].check)
  87. }
  88. }
  89. }
  90. },
  91. forchange(obj) {
  92. for (let i = 0; i < this.assignments.children.length; i++) {
  93. this.assignments.children[i].check = false
  94. }
  95. for (let i = 0; i < this.assignments.children.length; i++) {
  96. // this.assignments.children[i].check = false
  97. for (let j = 0; j < this.addtype.length; j++) {
  98. if (this.assignments.children[i].type_name == this.addtype[j]) {
  99. this.assignments.children[i].check = true
  100. console.log(this.assignments.children[i].check)
  101. }
  102. }
  103. }
  104. for (let key in obj) {
  105. for (let i = 0; i < key.length; i++) {
  106. for (let j = 0; j < this.assignments.children.length; j++) {
  107. if (Number(obj[key][i]) == this.assignments.children[j].type_name) {
  108. this.assignments.children[j].check = true
  109. }
  110. }
  111. }
  112. }
  113. this.$forceUpdate()
  114. },
  115. change(index) {
  116. this.current = index
  117. this.assignments = this.assignment[index]
  118. this.forchange(this.obj)
  119. console.log(this.obj)
  120. },
  121. checkboxchange(e, items) {
  122. this.obj[this.assignments.type_name] = e.detail.value
  123. this.forchange(this.obj)
  124. },
  125. clickLeft() {
  126. uni.navigateBack({
  127. delta: 1
  128. })
  129. },
  130. cancel() {
  131. this.clickLeft()
  132. },
  133. canfirm() {
  134. uni.setStorage({
  135. key: "id",
  136. data: JSON.stringify(this.obj),
  137. success: () => {
  138. uni.navigateBack({
  139. delta: 1
  140. })
  141. }
  142. })
  143. },
  144. },
  145. onLoad(option) {
  146. console.log(option)
  147. if (option.type) {
  148. this.addtype = option.type.split("#")
  149. console.log(this.addtype)
  150. }
  151. this.getFourbase()
  152. },
  153. }
  154. </script>
  155. <style lang="scss">
  156. .utabs {
  157. width: 100%;
  158. position: fixed;
  159. top: 88px;
  160. z-index: 100;
  161. }
  162. .bases_search {
  163. width: 100%;
  164. position: fixed;
  165. top: 84px;
  166. z-index: 100;
  167. background-color: #FFFFFF;
  168. height: 80rpx;
  169. padding-top: 20rpx;
  170. .bases_search_text {
  171. width: 90%;
  172. margin: 0 auto;
  173. background-color: #F8F8F8;
  174. height: 60rpx;
  175. border-radius: 30rpx;
  176. display: flex;
  177. line-height: 60rpx;
  178. .search {
  179. padding: 0 20rpx;
  180. font-size: 34rpx;
  181. }
  182. input {
  183. width: 80%;
  184. margin-top: 10rpx;
  185. font-size: 28rpx;
  186. }
  187. }
  188. }
  189. .ass_list {
  190. position: absolute;
  191. top: 84px;
  192. width: 100%;
  193. margin-bottom: 40px;
  194. .che_group {
  195. display: flex;
  196. flex-direction: column;
  197. width: 90%;
  198. margin: 0 auto;
  199. }
  200. .equipment {
  201. width: 90%;
  202. margin: 20rpx auto;
  203. box-shadow: 0 0 10rpx #bcb9ca;
  204. padding: 20rpx 30rpx;
  205. .equipment_top {
  206. height: 60rpx;
  207. width: 100%;
  208. border-bottom: 1px solid #dfe5ec;
  209. position: relative;
  210. .equipment_top_img {
  211. width: 40rpx;
  212. height: 40rpx;
  213. position: absolute;
  214. }
  215. .equipment_top_name {
  216. font-size: 24rpx;
  217. margin-left: 60rpx;
  218. }
  219. .ucheckbox {
  220. float: right;
  221. margin: 0rpx -4rpx;
  222. transform: scale(0.7);
  223. }
  224. }
  225. .equipment_bot {
  226. padding: 30rpx 0;
  227. position: relative;
  228. .equipment_bot_id {
  229. font-weight: 700;
  230. font-size: 15px;
  231. margin-bottom: 16rpx;
  232. }
  233. .equipment_bot_name {
  234. font-size: 24rpx;
  235. }
  236. .equipment_state {
  237. position: absolute;
  238. top: 20rpx;
  239. right: 0;
  240. width: 100rpx;
  241. height: 100rpx;
  242. text-align: center;
  243. line-height: 100rpx;
  244. color: #42b983;
  245. }
  246. }
  247. }
  248. }
  249. .allocbtn {
  250. width: 100%;
  251. position: fixed;
  252. bottom: 0;
  253. z-index: 100;
  254. display: flex;
  255. button {
  256. width: 50%;
  257. font-size: 24rpx;
  258. height: 80rpx;
  259. line-height: 80rpx;
  260. border-radius: 0;
  261. }
  262. .cancel {
  263. background-color: #C8C7CC;
  264. color: #555555;
  265. }
  266. .canfirm {
  267. color: white;
  268. background-color: #42b983;
  269. }
  270. }
  271. </style>