assignment.vue 7.9 KB

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