assignment.vue 7.3 KB

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