assignment.vue 8.8 KB

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