assignment.vue 9.0 KB

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