siteManage.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <view class="site-wrapper">
  3. <!-- 筛选框start -->
  4. <view style="height:200rpx"></view>
  5. <view class="ding">
  6. <view class="cu-bar search bg-gray filter-section" style="padding-top:10rpx">
  7. <view class="search-form round bg-white" style="position:relative;overflow:auto">
  8. <input name="siteName" v-model="formMess.siteName" @click="toggleShow" @focus="focusfns"
  9. @input="handleInput()" placeholder="请输入或选择所属线路"></input>
  10. </view>
  11. </view>
  12. <view class="cu-bar search bg-gray filter-section">
  13. <view class="search-form round bg-white">
  14. <text class="cuIcon-search"></text>
  15. <input class="" type="text" placeholder="请输入站点名称" v-model="siteName"></input>
  16. </view>
  17. <view class="action">
  18. <button class="cu-btn bg-blue round" @click="searchSiteList">查询</button>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="siteItems" v-if="isShow" style="max-height:60vh;overflow:auto;position:absolute;z-index:999; margin: 0 32rpx;
  23. width: calc(100% - 64rpx);top:100rpx">
  24. <view class=" site-item" v-if="!siteItemData.length">暂无结果</view>
  25. <view class="site-item" v-for="(item,index) in siteItemData" @click="changeModel(item,index)" :key="index" style="padding:16rpx 22rpx">
  26. {{item.route_name}}
  27. </view>
  28. </view>
  29. <!-- 筛选框end -->
  30. <!-- 站点列表start -->
  31. <view class="site-items" style="margin-top:0;height: calc(100vh - 380rpx)">
  32. <view class="cu-list menu-avatar">
  33. <view class="cu-item" :class="modalName=='move-box-'+ index?'move-cur':''"
  34. v-for="(item,index) in siteList" :key="index" @touchstart="ListTouchStart"
  35. @touchmove="ListTouchMove" @touchend="ListTouchEnd" :data-target="'move-box-' + index">
  36. <view class="cu-avatar round lg" style="background-image: url(../../static/site-icon.png);"></view>
  37. <view class="content" @tap="goDeviceManage(item)">
  38. <view class="text-grey site-tit inOneLine" style="display:block">{{item.siteName}}</view>
  39. </view>
  40. <view class="nav-right num">
  41. <view class="text-grey text-xs">
  42. <image @click="mapLocation(item)" src="../../static/nav-icon.png"
  43. style="width:25rpx;height:25rpx;margin-right:26rpx"></image>
  44. </view>
  45. </view>
  46. <view class="move">
  47. <view class="bg-grey" @click.stop="editItem(item)">编辑</view>
  48. <view class="bg-red" @click.stop="deleteItem(item)">删除</view>
  49. </view>
  50. </view>
  51. </view>
  52. <view v-if="!siteList.length&&siteListRes==1" class="text-center margin-top"> 暂无数据</view>
  53. <view v-show="isLoadMore&&this.currentPage>1" style="padding-bottom:60px">
  54. <uni-load-more :status="loadStatus"></uni-load-more>
  55. </view>
  56. </view>
  57. <!-- 站点列表end -->
  58. <!-- 新增按钮start -->
  59. <view style="width: 100%;
  60. position: fixed;
  61. bottom: 0px;
  62. right: 0px;
  63. height: 64px;
  64. background: #fff;">
  65. <view class="plus">
  66. <image src="../../static/plus.png" style="width:100rpx;height:100rpx" @tap="goAddPage()"></image>
  67. </view>
  68. </view>
  69. <!-- 新增按钮end -->
  70. </view>
  71. </template>
  72. <!-- <script src="https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script> -->
  73. <script>
  74. </script>
  75. <script>
  76. //引入js sdk的封装
  77. import * as jwx from '../../util/jssdk.js'
  78. export default {
  79. data() {
  80. return {
  81. modalName: null,
  82. listTouchStart: 0,
  83. listTouchDirection: null,
  84. siteName: '',
  85. siteList: [],
  86. siteListRes: 0,
  87. router_id: 0,
  88. routeListData: [],
  89. route_name: '',
  90. isShow: false,
  91. formMess: {
  92. "siteName": "",
  93. },
  94. siteItemDataOrigin: [],
  95. siteItemData: [],
  96. currentPage: 1,
  97. size: 10,
  98. loadStatus: 'loading', //加载样式:more-加载前样式,loading-加载中样式,nomore-没有数据样式
  99. isLoadMore: false, //是否加载中
  100. };
  101. },
  102. onReachBottom() { //上拉触底函数
  103. if (!this.isLoadMore) { //此处判断,上锁,防止重复请求
  104. this.isLoadMore = true
  105. this.currentPage += 1;
  106. this.loadData()
  107. }
  108. },
  109. onLoad: function(option) {
  110. //站点列表渲染
  111. this.loadData()
  112. this.getRoutrBox()
  113. },
  114. methods: {
  115. //筛选
  116. searchSiteList() {
  117. this.siteList=[];
  118. this.currentPage = 1;
  119. this.siteListRes = 0;
  120. this.loadData()
  121. },
  122. loadData(){
  123. this.getSiteList({
  124. "siteName": this.siteName,
  125. "route_name": this.formMess.siteName,
  126. currentPage: this.currentPage,
  127. size: this.size,
  128. })
  129. },
  130. //线路名称下拉数据请求
  131. async getRoutrBox(params = {}) {
  132. const res = await this.$myRequest({
  133. url: 'Archives/getRoutrBox',
  134. showLoading: true,
  135. data: params
  136. })
  137. // this.routeListData = res.data.data;
  138. // console.log(this.routeListData)
  139. this.siteItemData = res.data.data;
  140. this.siteItemDataOrigin = res.data.data;
  141. this.siteItemData = this.siteItemDataOrigin;
  142. },
  143. //选中下拉选项,隐藏框,赋值
  144. changeModel: function(item, index) {
  145. this.isShow = false;
  146. this.formMess.siteName = item.route_name;
  147. },
  148. // 输入框点击 显示隐藏下拉框
  149. toggleShow: function() {
  150. this.isShow = !this.isShow;
  151. },
  152. //点击下拉筛选
  153. handleInput() {
  154. //将元素根据搜索内容过滤出来 这里改变了siteItemData
  155. this.siteItemData = this.siteItemDataOrigin;
  156. this.siteItemData = this.siteItemData.filter(item => item.route_name.indexOf(this.formMess.siteName) > -1);
  157. },
  158. focusfns: function(e) {
  159. //将元素根据搜索内容过滤出来 这里改变了siteItemData
  160. this.siteItemData = this.siteItemDataOrigin;
  161. this.siteItemData = this.siteItemData.filter(item => item.route_name.indexOf(this.formMess.siteName) >
  162. -1);
  163. },
  164. //编辑
  165. editItem(item) {
  166. uni.navigateTo({
  167. url: '/pages/siteAdd/siteAdd?id=' + item.id + '',
  168. });
  169. },
  170. //删除
  171. deleteItem(item) {
  172. uni.showModal({
  173. title: '确认删除吗?',
  174. content: '',
  175. success: function(result) {
  176. if (result.confirm) {
  177. this.setDelSite({
  178. "id": item.id
  179. })
  180. } else if (result.cancel) {
  181. // console.log('用户点击取消');
  182. }
  183. }.bind(this)
  184. });
  185. },
  186. // 打开导航
  187. mapLocation(item) {
  188. //h5 地图导航
  189. // window.location.href = 'http://apis.map.qq.com/uri/v1/marker?marker=coord:'+parseFloat(item.latitude)+','+parseFloat(item.longitude)+''
  190. //app导航
  191. // uni.openLocation({
  192. // latitude: parseFloat(item.latitude),
  193. // longitude: parseFloat(item.longitude),
  194. // success: function() {
  195. // // console.log('success');
  196. // }
  197. // });
  198. // 微信公众号导航
  199. jwx.configWeiXin(jweixin => {
  200. let shareInfo = {
  201. latitude: parseFloat(item.latitude), // 纬度,浮点数,范围为90 ~ -90
  202. longitude: parseFloat(item.longitude), // 经度,浮点数,范围为180 ~ -180。
  203. name: item.siteName, // 位置名
  204. address: item.address, // 地址详情说明
  205. scale: 15, // 地图缩放级别,整型值,范围从1~28。默认为最大
  206. };
  207. jweixin.openLocation(shareInfo);
  208. });
  209. },
  210. async setDelSite(ming = {}) {
  211. const res = await this.$myRequest({
  212. url: 'SiteManagement/setDelSite',
  213. data: ming
  214. })
  215. if (!res.data.flag) {
  216. uni.showToast({
  217. title: "删除失败",
  218. icon: "none"
  219. });
  220. } else {
  221. uni.showToast({
  222. title: "删除成功",
  223. });
  224. setTimeout(() => {
  225. this.getSiteList()
  226. }, 1000);
  227. }
  228. },
  229. async getSiteList(ming = {}) {
  230. const res = await this.$myRequest({
  231. url: 'SiteManagement/getSiteList',
  232. showLoading: true,
  233. data: ming
  234. })
  235. this.siteListRes = 1;
  236. if (res.data.total) {
  237. this.siteList = this.siteList.concat(res.data.data)
  238. if (res.data.data.length < this.size) { //判断接口返回数据量小于请求数据量,则表示此为最后一页
  239. this.isLoadMore = true
  240. this.loadStatus = 'nomore'
  241. } else {
  242. this.isLoadMore = false
  243. }
  244. } else {
  245. this.isLoadMore = true
  246. this.loadStatus = 'nomore'
  247. }
  248. },
  249. // 新增跳转
  250. goAddPage() {
  251. uni.navigateTo({
  252. url: '/pages/siteAdd/siteAdd',
  253. success: res => {},
  254. fail: () => {},
  255. complete: () => {}
  256. });
  257. },
  258. //跳转到设备管理页面
  259. goDeviceManage(item) {
  260. uni.navigateTo({
  261. url: '/pages/deviceManage/deviceManage?siteId=' + item.id + '',
  262. success: res => {},
  263. fail: () => {},
  264. complete: () => {}
  265. });
  266. },
  267. // ListTouch触摸开始
  268. ListTouchStart(e) {
  269. this.listTouchStart = e.touches[0].pageX
  270. },
  271. // ListTouch计算方向
  272. ListTouchMove(e) {
  273. this.listTouchDirection = e.touches[0].pageX - this.listTouchStart < -80 ? 'left' : 'right'
  274. },
  275. // ListTouch计算滚动
  276. ListTouchEnd(e) {
  277. if (this.listTouchDirection == 'left') {
  278. this.modalName = e.currentTarget.dataset.target
  279. } else {
  280. this.modalName = null
  281. }
  282. this.listTouchDirection = null
  283. }
  284. }
  285. }
  286. </script>
  287. <style>
  288. </style>