assignment.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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;top:40px;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 usereqlisttype() { //用户已有的设备类型
  75. const res = await this.$myRequest({
  76. url: '/api/api_gateway?method=home.homes.user_device_type',
  77. })
  78. this.list=[
  79. {
  80. name:"全部",
  81. id:0
  82. }
  83. ]
  84. for (var i = 0; i < res.length; i++) {
  85. var obj = {
  86. name: res[i].type_name,
  87. id: res[i].id
  88. }
  89. this.list.push(obj)
  90. }
  91. },
  92. deweight(arr) {
  93. var newArr = []
  94. for (var i = 0; i < arr.length; i++) {
  95. if (newArr.indexOf(arr[i]) === -1) {
  96. newArr.push(arr[i])
  97. }
  98. }
  99. return newArr
  100. },
  101. clickLeft() { //返回上一页
  102. uni.navigateTo({
  103. url: './useroperation?item=' + JSON.stringify(this.user_info)
  104. })
  105. },
  106. change(index) { //头部导航栏的点击
  107. this.topbarTF = true //更改导航栏状态
  108. // this.allocationvalues3 = this.deweight(this.allocationvalues3.concat(this.allocationvalues2)) //合并数据
  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.type_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. },
  166. canfirm() { //确定分配
  167. let data = {}
  168. if (this.topbarTF) {
  169. data.device_ids = this.deweight(this.allocationvalues3.concat(this.allocationvalues)).join(',')
  170. } else {
  171. if (this.allocationvaluesTF) {
  172. this.allocationvalues2 = this.deweight(this.allocationvalues2)
  173. data.device_ids = this.allocationvalues2.join(',')
  174. } else {
  175. data.device_ids = this.allocationvalues.join(',')
  176. }
  177. }
  178. data.uid = this.user_info.uid
  179. this.allocation(data)
  180. uni.navigateTo({
  181. url: './useroperation?item=' + JSON.stringify(this.user_info)
  182. })
  183. },
  184. cancel() { //取消分配
  185. uni.navigateTo({
  186. url: './useroperation?item=' + JSON.stringify(this.user_info)
  187. })
  188. },
  189. top() {
  190. uni.pageScrollTo({
  191. scrollTop: 0,
  192. duration: 500
  193. })
  194. },
  195. searchs(){
  196. var data = {
  197. pagesize:10,
  198. page:1,
  199. devicetypeid:""
  200. }
  201. if (this.type_id==0) {
  202. this.assignment = []
  203. this.getAssign(data)
  204. } else {
  205. data.devicetypeid = this.type_id
  206. this.assignment = []
  207. this.getAssign(this.data)
  208. }
  209. },
  210. searchinp(){
  211. Debounce(() => {
  212. this.searchs()
  213. }, 1000)()
  214. }
  215. },
  216. onLoad(option) {
  217. this.usereqlisttype()
  218. this.user_info = JSON.parse(option.item)
  219. this.getAssign(this.data)
  220. },
  221. onReachBottom() {
  222. this.data.page++
  223. this.getAssign(this.data)
  224. },
  225. onPageScroll(e) { //nvue暂不支持滚动监听,可用bindingx代替
  226. if (e.scrollTop > 200) { //距离大于200时显示
  227. this.isTop = true
  228. } else { //距离小于200时隐藏
  229. this.isTop = false
  230. }
  231. },
  232. }
  233. </script>
  234. <style lang="scss">
  235. .utabs {
  236. width: 100%;
  237. position: fixed;
  238. top: 84px;
  239. z-index: 100;
  240. }
  241. .ass_list {
  242. margin: 220rpx 0 0;
  243. .che_group {
  244. display: flex;
  245. flex-direction: column;
  246. }
  247. .equipment {
  248. width: 600rpx;
  249. margin: 20rpx auto;
  250. box-shadow: 0 0 10rpx #bcb9ca;
  251. padding: 20rpx 30rpx;
  252. .equipment_top {
  253. height: 60rpx;
  254. width: 100%;
  255. border-bottom: 1px solid #dfe5ec;
  256. position: relative;
  257. .equipment_top_img {
  258. width: 40rpx;
  259. height: 40rpx;
  260. position: absolute;
  261. }
  262. .equipment_top_name {
  263. font-size: 24rpx;
  264. margin-left: 60rpx;
  265. }
  266. .ucheckbox {
  267. float: right;
  268. margin: 0rpx -4rpx;
  269. transform: scale(0.7);
  270. }
  271. }
  272. .equipment_bot {
  273. padding: 30rpx 0;
  274. position: relative;
  275. .equipment_bot_id {
  276. font-weight: 700;
  277. font-size: 15px;
  278. margin-bottom: 16rpx;
  279. }
  280. .equipment_bot_name {
  281. font-size: 10px;
  282. }
  283. .equipment_state {
  284. position: absolute;
  285. top: 20rpx;
  286. right: 0;
  287. width: 100rpx;
  288. height: 100rpx;
  289. text-align: center;
  290. line-height: 100rpx;
  291. color: #42b983;
  292. }
  293. }
  294. }
  295. }
  296. .bases_search {
  297. width: 100%;
  298. position: fixed;
  299. top: 120px;
  300. z-index: 100;
  301. background-color: #FFFFFF;
  302. .bases_search_text {
  303. width: 90%;
  304. margin: 0 auto;
  305. background-color: #F8F8F8;
  306. height: 60rpx;
  307. border-radius: 30rpx;
  308. display: flex;
  309. line-height: 60rpx;
  310. .search {
  311. padding: 0 20rpx;
  312. font-size: 34rpx;
  313. }
  314. input {
  315. width: 80%;
  316. margin-top: 10rpx;
  317. font-size: 28rpx;
  318. }
  319. }
  320. }
  321. .allocbtn {
  322. width: 100%;
  323. position: fixed;
  324. bottom: 0;
  325. z-index: 100;
  326. display: flex;
  327. button {
  328. width: 50%;
  329. font-size: 24rpx;
  330. height: 80rpx;
  331. line-height: 80rpx;
  332. border-radius: 0;
  333. }
  334. .cancel {
  335. background-color: #C8C7CC;
  336. color: #555555;
  337. }
  338. .canfirm {
  339. color: white;
  340. background-color: #42b983;
  341. }
  342. }
  343. .top {
  344. position: fixed;
  345. right: 30px;
  346. bottom: 100px;
  347. z-index: 100;
  348. image{
  349. width: 100rpx;
  350. height: 100rpx;
  351. }
  352. }
  353. </style>