assignment.vue 9.1 KB

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