assignment.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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="$imageURL+'/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="$imageURL+'/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. if(res[i].id == 8 ||
  86. res[i].id == 12 ||
  87. res[i].id == 14 ||
  88. res[i].id == 16
  89. ){
  90. continue;
  91. }
  92. var obj = {
  93. name: res[i].type_name,
  94. id: res[i].id
  95. }
  96. this.list.push(obj)
  97. }
  98. },
  99. deweight(arr) {
  100. var newArr = []
  101. for (var i = 0; i < arr.length; i++) {
  102. if (newArr.indexOf(arr[i]) === -1) {
  103. newArr.push(arr[i])
  104. }
  105. }
  106. return newArr
  107. },
  108. clickLeft() { //返回上一页
  109. uni.navigateTo({
  110. url: './useroperation?item=' + JSON.stringify(this.user_info)
  111. })
  112. },
  113. change(index) { //头部导航栏的点击
  114. this.topbarTF = true //更改导航栏状态
  115. // this.allocationvalues3 = this.deweight(this.allocationvalues3.concat(this.allocationvalues2)) //合并数据
  116. console.log(this.allocationvalues3)
  117. this.current = index
  118. this.data.page = 1
  119. this.data.devicetypeid = ''
  120. this.type_id = this.list[index].id
  121. uni.pageScrollTo({
  122. scrollTop: 0
  123. });
  124. if (index == 0) {
  125. this.assignment = []
  126. this.getAssign(this.data)
  127. } else {
  128. this.assignment = []
  129. this.data.devicetypeid = this.type_id
  130. this.getAssign(this.data)
  131. }
  132. },
  133. async getAssign(data) { //获取设备信息
  134. const res = await this.$myRequest({
  135. url: '/api/api_gateway?method=device.device_manage.user_device_info',
  136. data: {
  137. owner_uid: this.user_info.uid,
  138. device_type_id: data.devicetypeid,
  139. page_size: data.pagesize,
  140. page: data.page,
  141. device_id: this.inputdata
  142. }
  143. })
  144. this.assignment = this.assignment.concat(res.data)
  145. for (var i = 0; i < this.assignment.length; i++) {
  146. if (this.assignment[i].device_user != 0) {
  147. this.allocationvalues.push(this.assignment[i].d_id)
  148. }
  149. for (var j = 0; j < this.list.length; j++) {
  150. if (this.assignment[i].device_type_id == this.list[j].id) {
  151. this.assignment[i].device_type_id_name = this.list[j].name
  152. }
  153. }
  154. }
  155. },
  156. async allocation(data) { //分配设备
  157. const res = await this.$myRequest({
  158. url: '/api/api_gateway?method=device.device_manage.allot_device',
  159. data: {
  160. device_ids: data.device_ids,
  161. uid: data.uid
  162. }
  163. })
  164. },
  165. checkboxchange(e) { //多选框变动时
  166. this.allocationvaluesTF = e._processed
  167. this.allocationvalues2 = e.detail.value
  168. if (this.topbarTF) {
  169. this.allocationvalues3 = this.allocationvalues3.concat(e.detail.value)
  170. console.log(e.detail.value)
  171. }
  172. },
  173. canfirm() { //确定分配
  174. let data = {}
  175. if (this.topbarTF) {
  176. data.device_ids = this.deweight(this.allocationvalues3.concat(this.allocationvalues)).join(',')
  177. } else {
  178. if (this.allocationvaluesTF) {
  179. this.allocationvalues2 = this.deweight(this.allocationvalues2)
  180. data.device_ids = this.allocationvalues2.join(',')
  181. } else {
  182. data.device_ids = this.allocationvalues.join(',')
  183. }
  184. }
  185. data.uid = this.user_info.uid
  186. this.allocation(data)
  187. uni.navigateTo({
  188. url: './useroperation?item=' + JSON.stringify(this.user_info)
  189. })
  190. },
  191. cancel() { //取消分配
  192. uni.navigateTo({
  193. url: './useroperation?item=' + JSON.stringify(this.user_info)
  194. })
  195. },
  196. top() {
  197. uni.pageScrollTo({
  198. scrollTop: 0,
  199. duration: 500
  200. })
  201. },
  202. searchs(){
  203. var data = {
  204. pagesize:10,
  205. page:1,
  206. devicetypeid:""
  207. }
  208. if (this.type_id==0) {
  209. this.assignment = []
  210. this.getAssign(data)
  211. } else {
  212. data.devicetypeid = this.type_id
  213. this.assignment = []
  214. this.getAssign(this.data)
  215. }
  216. },
  217. searchinp(){
  218. Debounce(() => {
  219. this.searchs()
  220. }, 1000)()
  221. }
  222. },
  223. onLoad(option) {
  224. this.usereqlisttype()
  225. this.user_info = JSON.parse(option.item)
  226. this.getAssign(this.data)
  227. },
  228. onReachBottom() {
  229. this.data.page++
  230. this.getAssign(this.data)
  231. },
  232. onPageScroll(e) { //nvue暂不支持滚动监听,可用bindingx代替
  233. if (e.scrollTop > 200) { //距离大于200时显示
  234. this.isTop = true
  235. } else { //距离小于200时隐藏
  236. this.isTop = false
  237. }
  238. },
  239. }
  240. </script>
  241. <style lang="scss">
  242. .utabs {
  243. width: 100%;
  244. position: fixed;
  245. top: 84px;
  246. z-index: 100;
  247. }
  248. .ass_list {
  249. margin: 220rpx 0 0;
  250. .che_group {
  251. display: flex;
  252. flex-direction: column;
  253. }
  254. .equipment {
  255. width: 600rpx;
  256. margin: 20rpx auto;
  257. box-shadow: 0 0 10rpx #bcb9ca;
  258. padding: 20rpx 30rpx;
  259. .equipment_top {
  260. height: 60rpx;
  261. width: 100%;
  262. border-bottom: 1px solid #dfe5ec;
  263. position: relative;
  264. .equipment_top_img {
  265. width: 40rpx;
  266. height: 40rpx;
  267. position: absolute;
  268. }
  269. .equipment_top_name {
  270. font-size: 24rpx;
  271. margin-left: 60rpx;
  272. }
  273. .ucheckbox {
  274. float: right;
  275. margin: 0rpx -4rpx;
  276. transform: scale(0.7);
  277. }
  278. }
  279. .equipment_bot {
  280. padding: 30rpx 0;
  281. position: relative;
  282. .equipment_bot_id {
  283. font-weight: 700;
  284. font-size: 15px;
  285. margin-bottom: 16rpx;
  286. }
  287. .equipment_bot_name {
  288. font-size: 10px;
  289. }
  290. .equipment_state {
  291. position: absolute;
  292. top: 20rpx;
  293. right: 0;
  294. width: 100rpx;
  295. height: 100rpx;
  296. text-align: center;
  297. line-height: 100rpx;
  298. color: #42b983;
  299. }
  300. }
  301. }
  302. }
  303. .bases_search {
  304. width: 100%;
  305. position: fixed;
  306. top: 120px;
  307. z-index: 100;
  308. background-color: #FFFFFF;
  309. .bases_search_text {
  310. width: 90%;
  311. margin: 0 auto;
  312. background-color: #F8F8F8;
  313. height: 60rpx;
  314. border-radius: 30rpx;
  315. display: flex;
  316. line-height: 60rpx;
  317. .search {
  318. padding: 0 20rpx;
  319. font-size: 34rpx;
  320. }
  321. input {
  322. width: 80%;
  323. margin-top: 10rpx;
  324. font-size: 28rpx;
  325. }
  326. }
  327. }
  328. .allocbtn {
  329. width: 100%;
  330. position: fixed;
  331. bottom: 0;
  332. z-index: 100;
  333. display: flex;
  334. button {
  335. width: 50%;
  336. font-size: 24rpx;
  337. height: 80rpx;
  338. line-height: 80rpx;
  339. border-radius: 0;
  340. }
  341. .cancel {
  342. background-color: #C8C7CC;
  343. color: #555555;
  344. }
  345. .canfirm {
  346. color: white;
  347. background-color: #42b983;
  348. }
  349. }
  350. .top {
  351. position: fixed;
  352. right: 30px;
  353. bottom: 100px;
  354. z-index: 100;
  355. image{
  356. width: 100rpx;
  357. height: 100rpx;
  358. }
  359. }
  360. </style>