deviceManage.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <view class="site-wrapper">
  3. <!-- 筛选框start -->
  4. <view style="height:90rpx"></view>
  5. <view class="ding">
  6. <view class="cu-bar search bg-gray filter-section">
  7. <view class="search-form round bg-white">
  8. <text class="cuIcon-search"></text>
  9. <input class="" type="text" placeholder="请输入设备名称"
  10. confirm-type="search" v-model="deviceName"></input>
  11. </view>
  12. <view class="action">
  13. <button class="cu-btn bg-blue round" @click="searchSiteList">查询</button>
  14. </view>
  15. </view>
  16. </view>
  17. <!-- 筛选框end -->
  18. <!-- 站点列表start -->
  19. <view class="site-items" style="margin-top:0;height: calc(100vh - 286rpx);">
  20. <view class="cu-list menu-avatar">
  21. <view class="cu-item" :class="modalName=='move-box-'+ index?'move-cur':''" v-for="(item,index) in siteList" :key="index"
  22. @touchstart="ListTouchStart" @touchmove="ListTouchMove" @touchend="ListTouchEnd" :data-target="'move-box-' + index">
  23. <view class="cu-avatar round lg" style="background-image: url(/static/device-icon.png);"></view>
  24. <view class="content">
  25. <view class="text-grey site-tit">{{item.deviceName}}</view>
  26. </view>
  27. <view class="nav-right num">
  28. </view>
  29. <view class="move">
  30. <view class="bg-grey" @click.stop="editItem(item)">编辑</view>
  31. <view class="bg-red" @click.stop="deleteItem(item)">删除</view>
  32. </view>
  33. </view>
  34. </view>
  35. <view v-if="!siteList.length&&siteListRes==1" class="text-center margin-top"> 暂无数据</view>
  36. </view>
  37. <!-- 站点列表end -->
  38. <!-- 新增按钮start -->
  39. <view class="plus">
  40. <image src="../../static/plus.png" style="width:100rpx;height:100rpx" @tap="goAddPage()"></image>
  41. </view>
  42. <!-- 新增按钮end -->
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. data() {
  48. return {
  49. modalName: null,
  50. listTouchStart: 0,
  51. listTouchDirection: null,
  52. deviceName: '',
  53. siteList: [],
  54. siteListRes: 0,
  55. siteId:''
  56. };
  57. },
  58. onLoad: function(option) {
  59. this.siteId=option.siteId;
  60. //设备列表渲染
  61. this.getDeviceList({"siteId":option.siteId})
  62. },
  63. methods: {
  64. //筛选
  65. searchSiteList() {
  66. this.getDeviceList({
  67. "deviceName": this.deviceName,"siteId":this.siteId
  68. })
  69. },
  70. //编辑
  71. editItem(item) {
  72. uni.navigateTo({
  73. url: '/pages/deviceAdd/deviceAdd?id=' + item.siteId + '&deviceCode=' + item.deviceCode + '',
  74. });
  75. },
  76. //删除
  77. deleteItem(item) {
  78. uni.showModal({
  79. title: '确认删除吗?',
  80. content: '',
  81. success: function(result) {
  82. if (result.confirm) {
  83. this.setDelSite({
  84. "id": item.id
  85. })
  86. } else if (result.cancel) {
  87. // console.log('用户点击取消');
  88. }
  89. }.bind(this)
  90. });
  91. },
  92. async setDelSite(ming = {}) {
  93. const res = await this.$myRequest({
  94. url: 'DeviceManagement/setDelSite',
  95. data: ming
  96. })
  97. if (!res.data.flag) {
  98. uni.showToast({
  99. title: "删除失败",
  100. icon: "none"
  101. });
  102. }else{
  103. uni.showToast({
  104. title: "删除成功",
  105. });
  106. setTimeout(() => {
  107. this.getDeviceList({"siteId":this.siteId})
  108. }, 1000);
  109. }
  110. },
  111. async getDeviceList(ming = {}) {
  112. const res = await this.$myRequest({
  113. url: 'DeviceManagement/getDeviceList',
  114. showLoading: true,
  115. data: ming
  116. })
  117. this.siteListRes = 1;
  118. this.siteList = res.data.data
  119. console.log(res.data.data);
  120. },
  121. // 新增跳转
  122. goAddPage() {
  123. uni.navigateTo({
  124. url: '/pages/deviceAdd/deviceAdd?id=' + this.siteId + '',
  125. success: res => {},
  126. fail: () => {},
  127. complete: () => {}
  128. });
  129. },
  130. // ListTouch触摸开始
  131. ListTouchStart(e) {
  132. this.listTouchStart = e.touches[0].pageX
  133. },
  134. // ListTouch计算方向
  135. ListTouchMove(e) {
  136. this.listTouchDirection = e.touches[0].pageX - this.listTouchStart < -80 ? 'left' : 'right'
  137. },
  138. // ListTouch计算滚动
  139. ListTouchEnd(e) {
  140. if (this.listTouchDirection == 'left') {
  141. this.modalName = e.currentTarget.dataset.target
  142. } else {
  143. this.modalName = null
  144. }
  145. this.listTouchDirection = null
  146. }
  147. }
  148. }
  149. </script>
  150. <style>
  151. </style>