map-classify.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <view>
  3. <view class="nav-box">
  4. <view class="" :style="{'width': '100%','height':statusBarHeight+'px'}"></view>
  5. <view class="" :style="{'width': '100%','height':navHeight+'px'}"></view>
  6. <!-- :style="{'width':'100%','height':navHeight + 'px'}" -->
  7. <view class="nav-bar" :style="{'top':statusBarHeight+'px','height':navHeight+'px'}">
  8. <view class="nav-bar-back-box" @click.stop="goBack()">
  9. <text class="nav-bar-back iconfont_yige">&#xe65f;</text>
  10. </view>
  11. <view class="search-frame">
  12. <text class="search-icon iconfont_yige">&#xe653;</text>
  13. <!-- <image class="search-icon" src="/static/map/icon_01.png" mode="scaleToFill"></image> -->
  14. <input confirm-type="search" ref="searchInputRef" class="search-input" :auto-blur="true" type="text"
  15. placeholder="请输入关键字" v-model="keyWord" @confirm="getMapList" />
  16. </view>
  17. </view>
  18. </view>
  19. <view class="content-box" v-if="classifyTree && classifyTree.length > 0">
  20. <block v-for="(item , index ) in classifyTree">
  21. <template v-if="item.children && item.children.length > 0">
  22. <view class="classify-label" :key="`label_${index}`">
  23. <image class="classify-label-icon" :src="item.icon" mode="aspectFit"></image>
  24. <text class="classify-label-name">{{item.name}}</text>
  25. </view>
  26. <view class="classify-list">
  27. <view v-for="(cItem , cIndex) in item.children" class="classify-list-item" @click.stop="onOpenMap(cItem)"
  28. :key="`cIndex_${index}_${cIndex}`">{{cItem.name}}</view>
  29. </view>
  30. </template>
  31. </block>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. let app = getApp();
  37. import {
  38. getLocationClassify
  39. } from "@/api/government.js"
  40. export default {
  41. data() {
  42. return {
  43. statusBarHeight: 0,
  44. navHeight: 0,
  45. config: {
  46. back: true,
  47. title: '分类',
  48. color: 'black',
  49. backgroundColor: [1, '#fff'],
  50. statusBarFontColor: 'black'
  51. },
  52. classifyTree: [],
  53. keyWord: '',
  54. oldKeyWord: ''
  55. };
  56. },
  57. onLoad(options) {
  58. const {
  59. statusBarHeight,
  60. navHeight
  61. } = app.globalData;
  62. this.statusBarHeight = statusBarHeight;
  63. this.navHeight = navHeight;
  64. // this.nav_status_Height = statusBarHeight + navHeight;
  65. this.getClassify();
  66. },
  67. methods: {
  68. getClassify() {
  69. getLocationClassify().then(res => {
  70. const data = res.data;
  71. const parentC = [];
  72. data.forEach(el => {
  73. if (!el.parentId) {
  74. parentC.push(el)
  75. }
  76. })
  77. parentC.forEach(el => {
  78. el.children = data.filter(vl => el.id === vl.parentId)
  79. });
  80. this.classifyTree = parentC;
  81. })
  82. },
  83. onOpenMap(item) {
  84. // 获取页面栈
  85. let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
  86. let upRoute = routes[routes.length - 2] // 获取当前页面路由,也就是最后一个打开的页面路由
  87. // console.log('curRoute = ', upRoute)
  88. //
  89. if (upRoute.route === 'pages/government/map') {
  90. // #ifdef APP
  91. upRoute.$vm.onSearch(item);
  92. uni.navigateBack({
  93. delta: 1
  94. })
  95. // #endif
  96. }
  97. },
  98. goBack() {
  99. uni.navigateBack({
  100. delta: 1,
  101. fail: err => {
  102. uni.switchTab({
  103. url: '/pages/home'
  104. })
  105. }
  106. })
  107. },
  108. getMapList(e) {
  109. const kwd = e.detail.value;
  110. if (kwd && kwd !== this.oldKeyWord) {
  111. this.oldKeyWord = kwd;
  112. // 获取页面栈
  113. let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
  114. let upRoute = routes[routes.length - 2] // 获取当前页面路由,也就是最后一个打开的页面路由
  115. // console.log('curRoute = ', upRoute)
  116. if (upRoute.route === 'pages/government/map') {
  117. // #ifdef APP
  118. upRoute.$vm.onSearchKwd(kwd);
  119. uni.navigateBack({
  120. delta: 1
  121. })
  122. // #endif
  123. }
  124. }
  125. }
  126. }
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .nav-box {
  131. .nav-bar {
  132. position: fixed;
  133. left: 0;
  134. right: 0;
  135. padding: 30rpx;
  136. display: flex;
  137. flex-direction: row;
  138. align-items: center;
  139. justify-content: space-between;
  140. .nav-bar-back-box {
  141. width: 80rpx;
  142. text-align: left;
  143. .nav-bar-back {
  144. display: inline-block;
  145. // width:80rpx;
  146. flex-shrink: 0;
  147. color: rgb(102, 102, 102);
  148. font-size: 40rpx;
  149. font-weight: 600;
  150. transform: rotate(-180deg);
  151. text-align: left;
  152. }
  153. }
  154. .search-frame {
  155. flex: 1;
  156. background-color: #fff;
  157. height: 40px;
  158. display: flex;
  159. flex-direction: row;
  160. align-items: center;
  161. padding: 0 20rpx;
  162. background: #f7f7f7;
  163. border: 1rpx solid #d9d9d9;
  164. border-radius: 20rpx;
  165. .search-icon {
  166. font-size: 40rpx;
  167. color: #666666;
  168. width: 40rpx;
  169. height: 40rpx;
  170. transform: rotate(0deg);
  171. }
  172. .search-input {
  173. flex: 1;
  174. font-size: 28rpx;
  175. height: 100%;
  176. margin-left: 10rpx;
  177. }
  178. }
  179. .classify-box {
  180. height: 0;
  181. flex-direction: row;
  182. align-items: center;
  183. justify-content: space-between;
  184. padding: 0 30rpx;
  185. overflow: hidden;
  186. .classify-item {
  187. height: 100rpx;
  188. flex-direction: column;
  189. align-items: center;
  190. justify-content: space-between;
  191. .classify-icon {
  192. width: 64rpx;
  193. height: 64rpx;
  194. }
  195. .classify-text {
  196. font-size: 24rpx;
  197. font-family: PingFang SC, PingFang SC-Bold;
  198. font-weight: 700;
  199. color: #373737;
  200. }
  201. }
  202. // @keyframes identifier {
  203. // to {
  204. // height: 0;
  205. // }
  206. // from {
  207. // height: 179rpx;
  208. // }
  209. // }
  210. }
  211. }
  212. }
  213. .content-box {
  214. width: 100%;
  215. padding: 30rpx 9rpx 30rpx 30rpx;
  216. .classify-label {
  217. width: 100%;
  218. display: flex;
  219. flex-direction: row;
  220. align-items: center;
  221. .classify-label-icon {
  222. width: 40rpx;
  223. height: 40rpx;
  224. }
  225. .classify-label-name {
  226. padding-left: 16rpx;
  227. font-size: 30rpx;
  228. font-family: PingFang SC, PingFang SC-Bold;
  229. font-weight: 700;
  230. color: #1a1a1a;
  231. }
  232. }
  233. .classify-list {
  234. width: 100%;
  235. padding: 40rpx 0 24rpx 20rpx;
  236. display: flex;
  237. flex-direction: row;
  238. align-items: stretch;
  239. flex-wrap: wrap;
  240. .classify-list-item {
  241. font-size: 26rpx;
  242. padding: 0 10rpx;
  243. color: #666;
  244. flex-shrink: 0;
  245. width: 25%;
  246. // min-height: 58rpx;
  247. min-height: 37rpx;
  248. // padding: 10rpx 0;
  249. display: flex;
  250. justify-content: center;
  251. align-items: center;
  252. text-align:center;
  253. // margin: 0 15rpx 36rpx 0;
  254. margin-bottom: 36rpx;
  255. font-family: PingFang SC, PingFang SC-Regular;
  256. border-right: 1rpx solid #cccccc;
  257. &:nth-child(4n) {
  258. // margin-right: 0;
  259. border-right:none;
  260. }
  261. }
  262. }
  263. // <view class="classify-label">
  264. // <image class="classify-label-icon" :src="item.icon" mode="aspectFit"></image>
  265. // <text class="classify-label-name">{{item.name}}</text>
  266. // </view>
  267. }
  268. </style>