POIService.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <dv-border-box-7 ref="container" :color="borderColor" id="container" backgroundColor="rgba(23,65,72,0.5)" class="full">
  3. <div class="full center">
  4. <avue-input style="border-color: transparent;width: 75%" v-model="searchText" placeholder="请输入关键字"></avue-input>
  5. <div style="width: 25%;height: 100%;" class="center">
  6. <el-button @click="handleSearch" size="mini" style="font-size: 10px;background: rgba(255,255,255,0.7);color: #565656" class="click" icon="el-icon-search" ></el-button>
  7. </div>
  8. </div>
  9. <dv-border-box-10 ref="resultBorder" :color="borderColor" backgroundColor="rgba(23,65,72,0.7)" id="resultPanel" v-show="resultPanel" >
  10. <div v-if="resultType==1||resultType==2" style="width: 100%;height: 70px;color: #dddddd;font-size: 14px;font-style: italic;" class="center">
  11. <div class="result full center">
  12. {{resultType==1? '请输入关键字进行搜索 🔍' : '没有搜索到相关内容'}}
  13. <div class="center" style="cursor: pointer;text-decoration-line: underline;width: 70px" @click="resultPanel=false">关闭</div>
  14. </div>
  15. </div>
  16. <div v-if="resultType==3" style="width: 100%;height: 500px;color: white">
  17. <loading v-if="loading"></loading>
  18. <div class="center" style="width: 100%;height: 50px;justify-content: left;text-indent: 20px;">搜索结果 : <div class="center" style="cursor: pointer;text-decoration-line: underline;width: 80%;display: inline-block">{{searchText}}</div></div>
  19. <div class="center" style="width: 100%;height: 400px;">
  20. <table style="width: 95%;height: 100%;border: #dddddd" border="1">
  21. <tr style="height: 50px;color: #dddddd;font-size: 14px">
  22. <th style="width: 25%">名称</th>
  23. <th style="width: 25%">类型</th>
  24. <th style="width: 25%">地址</th>
  25. <th style="width: 25%">联系方式</th>
  26. </tr>
  27. <tr @click="toTarget(item)" class="item-pointer" style="font-size: 14px;cursor: pointer" v-for="(item,index) of data['pois']">
  28. <td>{{item.name}}</td>
  29. <td>{{item.type}}</td>
  30. <td>{{item.address}}</td>
  31. <td>{{item.tel}}</td>
  32. </tr>
  33. </table>
  34. </div>
  35. <div class="center" style="width: 100%;height: 50px">
  36. <div class="center" style="width: 100px">总数:<span style="color: #00f9cf">{{data.count}}</span></div>
  37. <div class="center" style="width: 100px;cursor: pointer;text-decoration-line: underline;" v-if="currentPage!=1" @click="preSearch">上一页</div>
  38. <div class="center" style="width: 50px;color: #00f9cf">{{currentPage}}</div>
  39. <div class="center" style="width: 100px;cursor: pointer;text-decoration-line: underline;" @click="nextSearch" v-if="data.pois.length>=5">下一页</div>
  40. <div class="center" style="cursor: pointer;text-decoration-line: underline;width: 70px" @click="resultPanel=false">关闭</div>
  41. </div>
  42. </div>
  43. </dv-border-box-10>
  44. </dv-border-box-7>
  45. </template>
  46. <script>
  47. import {Message} from "element-ui";
  48. import Loading from "./Loading";
  49. export default {
  50. name: "POIService",
  51. components: {Loading},
  52. props: {
  53. city: {
  54. type: 'String',
  55. default: '全国'
  56. },
  57. borderColor: {
  58. type: 'Array',
  59. default: ['rgba(16,206,250,0.5)','rgba(255,255,255,1)']
  60. }
  61. },
  62. mounted() {
  63. this.placeSearch = new this.$AMap.PlaceSearch(this.option);
  64. },
  65. watch: {
  66. city(){
  67. this.placeSearch.setCity(this.city);
  68. },
  69. resultType(){
  70. this.$refs['resultBorder'].initWH();
  71. },
  72. resultPanel(){
  73. this.$refs['resultBorder'].initWH();
  74. }
  75. },
  76. data(){
  77. return{
  78. loading: {},
  79. data: {},
  80. resultPanel: false,
  81. searchText: '',
  82. resultType: 1,
  83. placeSearch: {},
  84. currentPage: 1,
  85. option: {
  86. pageSize: 5,
  87. pageIndex: 1,
  88. }
  89. }
  90. },
  91. inject: ['screen'],
  92. methods: {
  93. toTarget(item){
  94. this.screen.$refs['map'].removeEntity("placeSearchLabel");
  95. this.screen.$refs['map'].addBillBoard(item.location.lng,item.location.lat,0,'/data/device.png',{
  96. scale: 0.05
  97. },"placeSearchLabel");
  98. this.screen.$refs["map"].flyToPosition(item.location.lng,item.location.lat-0.06, 2000.0,0,-20.0,0.0);
  99. this.resultPanel =false;
  100. },
  101. async preSearch(){
  102. this.currentPage--;
  103. this.placeSearch.setPageIndex(this.currentPage);
  104. this.data =await this.search();
  105. this.loading = false;
  106. },
  107. resize(){
  108. this.$refs['container'].initWH();
  109. },
  110. async nextSearch(){
  111. this.currentPage++;
  112. this.placeSearch.setPageIndex(this.currentPage);
  113. this.data =await this.search();
  114. this.loading = false;
  115. },
  116. async search(){
  117. this.loading = true;
  118. return new Promise((resolve, reject)=> {
  119. this.placeSearch.search(this.searchText, (status, result) => {
  120. if(status=='error'){
  121. reject(result);
  122. }
  123. resolve(result.poiList);
  124. })
  125. })
  126. },
  127. async handleSearch(){
  128. this.currentPage = 1;
  129. this.placeSearch.setPageIndex(1);
  130. if(this.searchText==""){
  131. this.resultType=1;
  132. this.resultPanel = true;
  133. return
  134. }
  135. this.resultPanel = true;
  136. let data = await this.search();
  137. this.loading = false;
  138. if(typeof data == 'undefined' || data['pois'].length==0){
  139. this.resultType=2;
  140. return
  141. }
  142. this.resultType=3;
  143. this.data = data;
  144. }
  145. }
  146. }
  147. </script>
  148. <style scoped>
  149. .full{
  150. width: 100%;
  151. height: 100%;
  152. }
  153. .center{
  154. display: flex;
  155. justify-content: center;
  156. align-items: center;
  157. }
  158. /deep/ .el-input__inner{
  159. border: none;
  160. color: white;
  161. font-size: 16px;
  162. }
  163. #container{
  164. /*background: linear-gradient(to right,rgba(0,0,0,0.5),rgba(0,0,0,0.5));*/
  165. }
  166. .click:hover{
  167. cursor: pointer;
  168. transform: translate(2px,2px);
  169. }
  170. #resultPanel{
  171. position: relative;width: 100%;height: auto;
  172. /*background: rgba(23,65,72,0.8);*/
  173. /*background: linear-gradient(to bottom,rgba(23,65,72,0.5),rgba(23,65,72,0.9));*/
  174. top: 10px;
  175. /*border: 1px solid white;*/
  176. animation: initPanel 0.5s ;
  177. }
  178. .result{
  179. animation: result 0.2s ;
  180. }
  181. @keyframes result {
  182. from{ width: 0 ;height: 0}
  183. to{ width: 100%}
  184. }
  185. @keyframes initPanel {
  186. from{ opacity: 0}
  187. to{ opacity: 1}
  188. }
  189. .item-pointer:hover{
  190. background: rgba(0,0,0,0.5);
  191. }
  192. </style>