deviceManage.vue 4.2 KB

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