assignment.vue 7.2 KB

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