deviceManage.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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/site-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 class="text-grey text-xs">
  28. <image @click="mapLocation(item)" src="../../static/nav-icon.png" style="width:25rpx;height:25rpx;margin-right:26rpx"></image>
  29. </view>
  30. </view>
  31. <view class="move">
  32. <view class="bg-grey" @click.stop="editItem(item)">编辑</view>
  33. <view class="bg-red" @click.stop="deleteItem(item)">删除</view>
  34. </view>
  35. </view>
  36. </view>
  37. <view v-if="!siteList.length&&siteListRes==1" class="text-center margin-top"> 暂无数据</view>
  38. </view>
  39. <!-- 站点列表end -->
  40. <!-- 新增按钮start -->
  41. <view class="plus">
  42. <image src="../../static/plus.png" style="width:125rpx;height:125rpx" @tap="goAddPage()"></image>
  43. </view>
  44. <!-- 新增按钮end -->
  45. </view>
  46. </template>
  47. <script>
  48. export default {
  49. data() {
  50. return {
  51. modalName: null,
  52. listTouchStart: 0,
  53. listTouchDirection: null,
  54. deviceName: '',
  55. siteList: [],
  56. siteListRes: 0,
  57. };
  58. },
  59. onLoad: function(option) {
  60. //站点列表渲染
  61. this.getDeviceList()
  62. },
  63. methods: {
  64. //筛选
  65. searchSiteList() {
  66. this.getDeviceList({
  67. "deviceName": this.deviceName
  68. })
  69. },
  70. //编辑
  71. editItem(item) {
  72. uni.navigateTo({
  73. url: '/pages/deviceAdd/deviceAdd?id=' + item.siteId + '',
  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. // 打开导航
  93. mapLocation(item) {
  94. uni.openLocation({
  95. latitude: parseInt(item.latitude),
  96. longitude: parseInt(item.longitude),
  97. success: function() {
  98. // console.log('success');
  99. }
  100. });
  101. },
  102. async setDelSite(ming = {}) {
  103. const res = await this.$myRequest({
  104. url: 'DeviceManagement/setDelSite',
  105. data: ming
  106. })
  107. if (!res.data.flag) {
  108. uni.showToast({
  109. title: "删除失败",
  110. icon: "none"
  111. });
  112. }else{
  113. uni.showToast({
  114. title: "删除成功",
  115. });
  116. setTimeout(() => {
  117. this.getDeviceList()
  118. }, 1000);
  119. }
  120. },
  121. async getDeviceList(ming = {}) {
  122. const res = await this.$myRequest({
  123. url: 'DeviceManagement/getDeviceList',
  124. showLoading: true,
  125. data: ming
  126. })
  127. this.siteListRes = 1;
  128. this.siteList = res.data.data
  129. console.log(res.data.data);
  130. },
  131. // 新增跳转
  132. goAddPage() {
  133. uni.navigateTo({
  134. url: '/pages/deviceAdd/deviceAdd',
  135. success: res => {},
  136. fail: () => {},
  137. complete: () => {}
  138. });
  139. },
  140. // ListTouch触摸开始
  141. ListTouchStart(e) {
  142. this.listTouchStart = e.touches[0].pageX
  143. },
  144. // ListTouch计算方向
  145. ListTouchMove(e) {
  146. this.listTouchDirection = e.touches[0].pageX - this.listTouchStart < -80 ? 'left' : 'right'
  147. },
  148. // ListTouch计算滚动
  149. ListTouchEnd(e) {
  150. if (this.listTouchDirection == 'left') {
  151. this.modalName = e.currentTarget.dataset.target
  152. } else {
  153. this.modalName = null
  154. }
  155. this.listTouchDirection = null
  156. }
  157. }
  158. }
  159. </script>
  160. <style>
  161. </style>