assignment.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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;top:44px;width: 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,index) in assignment" :key="index">
  17. <view class="equipment_top">
  18. <image :src="'http://www.hnyfwlw.com:8006/bigdata_app'+items.src" mode="" class="equipment_top_img"></image>
  19. <span class="equipment_top_name">{{items.device_type_id_name}}</span>
  20. <checkbox :value="String(items.d_id)" :checked="items.device_user==user_info.uid" class="ucheckbox" color="#42b983" />
  21. </view>
  22. <view class="equipment_bot">
  23. <p class="equipment_bot_id">设备ID:{{items.device_id}}</p>
  24. <p class="equipment_bot_name">设备名称:{{items.device_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://www.hnyfwlw.com:8006/bigdata_app'+'/image/6209a98f0cb3b5086f2ca36152c9269.png'" mode=""></image>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. export default {
  42. data() {
  43. return {
  44. user_info: {},
  45. list: [{
  46. name: "全部"
  47. }],
  48. current: 0,
  49. assignment: [],
  50. data: {
  51. devicetypeid: '',
  52. pagesize: 10,
  53. page: 1
  54. },
  55. images: [{
  56. path: "/image/fourMoodBase/scd.png",
  57. id: 2
  58. },
  59. {
  60. path: "/image/fourMoodBase/cbd.png",
  61. id: 3
  62. }, {
  63. path: "/image/fourMoodBase/xycb.png",
  64. id: 4
  65. }, {
  66. path: "/image/fourMoodBase/qxz.png",
  67. id: 5
  68. }, {
  69. path: "/image/fourMoodBase/jk.png",
  70. id: 6
  71. }, {
  72. path: "/image/fourMoodBase/bzy.png",
  73. id: 7
  74. },
  75. {
  76. path: "/image/fourMoodBase/10.png",
  77. id: 10
  78. },
  79. {
  80. path: "/image/fourMoodBase/14.png",
  81. id: 14
  82. },
  83. {
  84. path: "/image/fourMoodBase/15.png",
  85. id: 15
  86. }
  87. ],
  88. allocationvalues: [], //原始数据
  89. allocationvalues2: [], //选项框更改后的数据
  90. allocationvalues3: [], //头部导航栏点击后的数据
  91. allocationvaluesTF: false, //判断选项框是否变动
  92. topbarTF: false ,//判断头部导航栏是否变更
  93. isTop:false
  94. }
  95. },
  96. methods: {
  97. async devicetypelist() { //分配设备
  98. const res = await this.$myRequest({
  99. url: '/api/api_gateway?method=home.homes.user_device_type',
  100. })
  101. console.log(res)
  102. for(var i = 0; i < res.length; i++){
  103. var obj = {
  104. name:res[i].type_name,
  105. id:res[i].id
  106. }
  107. this.list.push(obj)
  108. }
  109. },
  110. deweight(arr) {
  111. var newArr = []
  112. for (var i = 0; i < arr.length; i++) {
  113. if (newArr.indexOf(arr[i]) === -1) {
  114. newArr.push(arr[i])
  115. }
  116. }
  117. return newArr
  118. },
  119. clickLeft() { //返回上一页
  120. uni.navigateTo({
  121. url: './useroperation?item=' + JSON.stringify(this.user_info)
  122. })
  123. },
  124. change(index) { //头部导航栏的点击
  125. this.topbarTF = true //更改导航栏状态
  126. // this.allocationvalues3 = this.deweight(this.allocationvalues3.concat(this.allocationvalues2)) //合并数据
  127. console.log(this.allocationvalues3)
  128. this.current = index
  129. this.data.page = 1
  130. this.data.devicetypeid = ''
  131. uni.pageScrollTo({
  132. scrollTop: 0
  133. });
  134. if (index == 0) {
  135. this.assignment = []
  136. this.getAssign(this.data)
  137. } else {
  138. this.assignment = []
  139. this.data.devicetypeid = this.list[index].id
  140. this.getAssign(this.data)
  141. }
  142. },
  143. async getAssign(data) { //获取设备信息
  144. const res = await this.$myRequest({
  145. url: '/api/api_gateway?method=device.device_manage.user_device_info',
  146. data: {
  147. owner_uid: this.user_info.uid,
  148. device_type_id: data.devicetypeid,
  149. page_size: data.pagesize,
  150. page: data.page
  151. }
  152. })
  153. this.assignment = this.assignment.concat(res.data)
  154. for (var i = 0; i < this.assignment.length; i++) {
  155. if (this.assignment[i].device_user != 0) {
  156. this.allocationvalues.push(this.assignment[i].d_id)
  157. }
  158. for (var j = 0; j < this.images.length; j++) {
  159. if (this.assignment[i].device_type_id == this.images[j].id) {
  160. this.assignment[i].src = this.images[j].path
  161. }
  162. }
  163. for (var j = 0; j < this.list.length; j++) {
  164. if (this.assignment[i].device_type_id == this.list[j].id) {
  165. this.assignment[i].device_type_id_name = this.list[j].name
  166. }
  167. }
  168. }
  169. },
  170. async allocation(data) { //分配设备
  171. const res = await this.$myRequest({
  172. url: '/api/api_gateway?method=device.device_manage.allot_device',
  173. data: {
  174. device_ids: data.device_ids,
  175. uid: data.uid
  176. }
  177. })
  178. },
  179. checkboxchange(e) { //多选框变动时
  180. this.allocationvaluesTF = e._processed
  181. this.allocationvalues2 = e.detail.value
  182. if (this.topbarTF) {
  183. this.allocationvalues3 = this.allocationvalues3.concat(e.detail.value)
  184. console.log(e.detail.value)
  185. }
  186. },
  187. canfirm() { //确定分配
  188. let data = {}
  189. if (this.topbarTF) {
  190. data.device_ids = this.deweight(this.allocationvalues3.concat(this.allocationvalues)).join(',')
  191. } else {
  192. if (this.allocationvaluesTF) {
  193. this.allocationvalues2 = this.deweight(this.allocationvalues2)
  194. data.device_ids = this.allocationvalues2.join(',')
  195. } else {
  196. data.device_ids = this.allocationvalues.join(',')
  197. }
  198. }
  199. data.uid = this.user_info.uid
  200. this.allocation(data)
  201. uni.navigateTo({
  202. url: './useroperation?item=' + JSON.stringify(this.user_info)
  203. })
  204. },
  205. cancel() { //取消分配
  206. uni.navigateTo({
  207. url: './useroperation?item=' + JSON.stringify(this.user_info)
  208. })
  209. },
  210. top() {
  211. uni.pageScrollTo({
  212. scrollTop: 0,
  213. duration: 500
  214. })
  215. }
  216. },
  217. onLoad(option) {
  218. this.user_info = JSON.parse(option.item)
  219. this.devicetypelist()
  220. this.getAssign(this.data)
  221. },
  222. onReachBottom() {
  223. this.data.page++
  224. this.getAssign(this.data)
  225. },
  226. onPageScroll(e) { //nvue暂不支持滚动监听,可用bindingx代替
  227. if (e.scrollTop > 200) { //距离大于200时显示
  228. this.isTop = true
  229. } else { //距离小于200时隐藏
  230. this.isTop = false
  231. }
  232. },
  233. }
  234. </script>
  235. <style lang="scss">
  236. .utabs {
  237. width: 100%;
  238. position: fixed;
  239. top: 88px;
  240. z-index: 100;
  241. }
  242. .ass_list {
  243. margin: 190rpx 0 0;
  244. .che_group {
  245. display: flex;
  246. flex-direction: column;
  247. }
  248. .equipment {
  249. width: 600rpx;
  250. margin: 20rpx auto;
  251. box-shadow: 0 0 10rpx #bcb9ca;
  252. padding: 20rpx 30rpx;
  253. .equipment_top {
  254. height: 60rpx;
  255. width: 100%;
  256. border-bottom: 1px solid #dfe5ec;
  257. position: relative;
  258. .equipment_top_img {
  259. width: 40rpx;
  260. height: 40rpx;
  261. position: absolute;
  262. }
  263. .equipment_top_name {
  264. font-size: 24rpx;
  265. margin-left: 60rpx;
  266. }
  267. .ucheckbox {
  268. float: right;
  269. margin: 0rpx -4rpx;
  270. transform: scale(0.7);
  271. }
  272. }
  273. .equipment_bot {
  274. padding: 30rpx 0;
  275. position: relative;
  276. .equipment_bot_id {
  277. font-weight: 700;
  278. font-size: 15px;
  279. margin-bottom: 16rpx;
  280. }
  281. .equipment_bot_name {
  282. font-size: 10px;
  283. }
  284. .equipment_state {
  285. position: absolute;
  286. top: 20rpx;
  287. right: 0;
  288. width: 100rpx;
  289. height: 100rpx;
  290. text-align: center;
  291. line-height: 100rpx;
  292. color: #42b983;
  293. }
  294. }
  295. }
  296. }
  297. .allocbtn {
  298. width: 100%;
  299. position: fixed;
  300. bottom: 0;
  301. z-index: 100;
  302. display: flex;
  303. button {
  304. width: 50%;
  305. font-size: 24rpx;
  306. height: 80rpx;
  307. line-height: 80rpx;
  308. border-radius: 0;
  309. }
  310. .cancel {
  311. background-color: #C8C7CC;
  312. color: #555555;
  313. }
  314. .canfirm {
  315. color: white;
  316. background-color: #42b983;
  317. }
  318. }
  319. .top {
  320. position: fixed;
  321. right: 30px;
  322. bottom: 100px;
  323. z-index: 100;
  324. image{
  325. width: 100rpx;
  326. height: 100rpx;
  327. }
  328. }
  329. </style>