assignment.vue 7.2 KB

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