tianditu-search.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <view>
  3. <view :style="searchStyle" class="search-zhuozhuo">
  4. <view class="hearderback">
  5. <view class="back" @click="close">关 闭</view>
  6. <view class="confirm" @click="confirm">完 成</view>
  7. </view>
  8. <view class="search" v-show="showSearch">
  9. <view class="search-content">
  10. <view class="search-icon" v-if="searchType === 0" @click="visible = true">{{city.label}}</view>
  11. <input class="search-input" v-model="keyword" placeholder="请输入详细地址" />
  12. <view class="search-btn" @click="searchKeyword">搜索</view>
  13. </view>
  14. </view>
  15. </view>
  16. <tiandituPopupVue :visible="visible" @onClose="visible = false">
  17. <view class="search">
  18. <view class="search-content">
  19. <input class="search-input" v-model="inputCity" placeholder="请输入省\市\区" />
  20. <view class="search-btn" @click="searchCity">搜索</view>
  21. </view>
  22. </view>
  23. <view class="listBox">
  24. <view style="display: flex;justify-content: space-between;align-items: center;">
  25. <h3 style="margin-bottom: 10px;">历史记录</h3>
  26. <view class="clear" @click="clearRcords">清空</view>
  27. </view>
  28. <view class="listBox1">
  29. <view class="tab-card" v-for="(item,index) in records" @click="selectCity(item)" :key="item.value">
  30. {{item.label}}
  31. </view>
  32. </view>
  33. <view data-text="历史记录" class="divider"></view>
  34. <view class="listBoxchild">
  35. <view class="tab-card" v-for="(item,index) in list1" @click="selectCity(item)" :key="item.value">
  36. {{item.label}}
  37. </view>
  38. </view>
  39. </view>
  40. </tiandituPopupVue>
  41. </view>
  42. </template>
  43. <script>
  44. import tiandituPopupVue from './tianditu-popup.vue'
  45. import tools from '../../tools.js'
  46. import dataCityList from '../../cityData.json'
  47. export default {
  48. components: {
  49. tiandituPopupVue
  50. },
  51. data() {
  52. return {
  53. keyword: '',
  54. visible: false,
  55. list1: [],
  56. records: [],
  57. storKey: 'tianditu-records-city',
  58. inputCity: '',
  59. city: {
  60. "label": "德阳市",
  61. "value": "156510600"
  62. },
  63. }
  64. },
  65. props: {
  66. searchType: {
  67. type: Number,
  68. default: 0,
  69. },
  70. searchStyle: {
  71. type: Object || Array,
  72. default: () => ({}),
  73. },
  74. showSearch: {
  75. type: Boolean,
  76. require: true
  77. }
  78. },
  79. created() {
  80. const stor = uni.getStorageSync(this.storKey)
  81. if (stor && stor.length) {
  82. this.records = stor
  83. }
  84. },
  85. methods: {
  86. searchKeyword() {
  87. if (this.keyword) {
  88. let params = {
  89. city: this.city,
  90. keyword: this.keyword
  91. }
  92. if (this.searchType === 1) {
  93. delete params.city
  94. }
  95. this.$emit('onSearch', params)
  96. } else {
  97. tools.createMessage('请输入详细地址')
  98. }
  99. },
  100. selectCity(item) {
  101. if (!this.records.some((zItem) => zItem.value === item.value)) {
  102. const arr = [...this.records, item]
  103. if (arr.length > 10) {
  104. arr.shift()
  105. }
  106. this.records = arr
  107. uni.setStorage({
  108. key: this.storKey,
  109. data: this.records
  110. })
  111. }
  112. this.city = item
  113. this.inputCity = ''
  114. this.visible = false
  115. },
  116. clearRcords() {
  117. this.records = []
  118. uni.setStorage({
  119. key: this.storKey,
  120. data: []
  121. })
  122. },
  123. searchCity() {
  124. if (this.inputCity) {
  125. this.list1 = dataCityList.filter((item) => {
  126. const reg = new RegExp(this.inputCity, 'ig')
  127. if (reg.test(item.label)) {
  128. return true
  129. }
  130. })
  131. } else {
  132. tools.createMessage('请输入省\市\区关键字')
  133. }
  134. },
  135. close() {
  136. this.$emit('onClose')
  137. },
  138. confirm() {
  139. this.$emit('onConfirm')
  140. },
  141. }
  142. }
  143. </script>
  144. <style scoped>
  145. .search-zhuozhuo {
  146. display: flex;
  147. flex-direction: column;
  148. justify-content: end;
  149. /* #ifdef APP */
  150. /* padding-top: 40rpx; */
  151. /* #endif */
  152. }
  153. .hearderback {
  154. display: flex;
  155. justify-content: space-between;
  156. padding: 10px 10px 10px 10px;
  157. }
  158. .back,
  159. .confirm {
  160. width: 48px;
  161. height: 24px;
  162. line-height: 24px;
  163. font-size: 12px;
  164. border: 1px solid #e8e8e8;
  165. text-align: center;
  166. border-radius: 5px;
  167. }
  168. .back:active {
  169. background-color: #f3f4f6;
  170. background-color: #f3f4f6;
  171. }
  172. .confirm {
  173. background-color: #006fff;
  174. border: 1px solid #006fff;
  175. color: #FFFFFF;
  176. }
  177. .confirm:active {
  178. background-color: #f3f4f6;
  179. border: 1px solid #f3f4f6;
  180. color: #333333;
  181. }
  182. .search {
  183. /* position: absolute;
  184. left: 0;
  185. top: 0; */
  186. width: 100%;
  187. height: 40px;
  188. /* z-index: 402; */
  189. display: flex;
  190. justify-content: center;
  191. align-items: flex-start;
  192. background-color: #FFFFFF;
  193. }
  194. .search-content {
  195. width: calc(100% - 24px);
  196. height: 32px;
  197. border-radius: 10px;
  198. padding: 0 5px 0 10px;
  199. background-color: rgb(242, 242, 242);
  200. border-radius: 100px;
  201. font-size: 14px;
  202. display: flex;
  203. justify-content: space-between;
  204. align-items: center;
  205. }
  206. .search-icon {
  207. margin-right: 5px;
  208. border-right: 1px solid #bababa;
  209. padding-right: 5px;
  210. }
  211. .search-icon:active {
  212. color: #666666;
  213. }
  214. .search-input {
  215. flex: 1;
  216. font-size: 14px;
  217. }
  218. .search-btn {
  219. height: 24px;
  220. color: #FFFFFF;
  221. font-size: 14px;
  222. background-color: rgba(148, 170, 41, 0.7);
  223. text-align: center;
  224. line-height: 24px;
  225. border-radius: 25px;
  226. padding: 0 8px;
  227. }
  228. .search-btn:active {
  229. background-color: #e8e8e8;
  230. color: #666666;
  231. }
  232. .listBox {
  233. display: flex;
  234. flex-direction: column;
  235. padding: 12px;
  236. padding-top: 48px;
  237. max-height: 70vh;
  238. }
  239. .listBoxheader {
  240. display: flex;
  241. justify-content: space-between;
  242. align-items: center;
  243. }
  244. .listBox1 {
  245. display: flex;
  246. align-items: flex-start;
  247. flex-wrap: wrap;
  248. }
  249. .listBoxchild {
  250. flex: 1;
  251. overflow-y: scroll;
  252. display: flex;
  253. align-items: flex-start;
  254. flex-wrap: wrap;
  255. }
  256. .tab-card {
  257. background-color: #e8e8e8;
  258. padding: 3px 5px;
  259. font-size: 14px;
  260. color: #666666;
  261. height: 20px;
  262. line-height: 20px;
  263. text-align: center;
  264. margin: 4px 6px 4px 4px;
  265. }
  266. .clear {
  267. font-size: #666666;
  268. font-size: 13px;
  269. }
  270. .divider {
  271. width: 100%;
  272. border: 1px dashed #e8e8e8;
  273. position: relative;
  274. margin: 10px 0;
  275. }
  276. .divider::after {
  277. position: absolute;
  278. top: 50%;
  279. left: 50%;
  280. transform: translate(-50%, -50%);
  281. background-color: #FFFFFF;
  282. padding: 0 10px;
  283. height: 16px;
  284. line-height: 16px;
  285. content: '历史记录';
  286. font-size: 12px;
  287. color: rgb(144, 147, 153);
  288. }
  289. </style>