detail.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="wrapper">
  3. <view v-if="isHistory" class="history-box">
  4. <view v-if="historyList.length > 0">
  5. <view class="history-title">
  6. <text>搜索历史</text>
  7. <text class="uni-icon uni-icon-trash" @click="clearSearch"></text>
  8. </view>
  9. <view class="history-content">
  10. <view class="history-item" v-for="(item, index) in historyList" :key="index">
  11. {{ item.name }}
  12. </view>
  13. </view>
  14. </view>
  15. <view v-else class="no-data">您还没有历史记录</view>
  16. </view>
  17. <view v-else class="history-box">
  18. <view v-if="historyList.length > 0" class="history-list-box">
  19. <view
  20. class="history-list-item"
  21. v-for="(item, index) in historyList"
  22. :key="index"
  23. @click="listTap(item)"
  24. >
  25. <rich-text :nodes="item.nameNodes"></rich-text>
  26. </view>
  27. </view>
  28. <view v-else class="no-data">没有搜索到相关内容</view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import util from '@/components/amap-wx/js/util.js';
  34. export default {
  35. data() {
  36. return {
  37. historyList: [],
  38. isHistory: true,
  39. list: [],
  40. flng: true,
  41. timer: null
  42. };
  43. },
  44. onLoad() {
  45. // 本示例用的是高德 sdk ,请根据具体需求换成自己的服务器接口。
  46. this.amapPlugin = util.mapInit();
  47. this.historyList = uni.getStorageSync('search:history');
  48. },
  49. methods: {
  50. /**
  51. * 列表点击
  52. */
  53. listTap(item) {
  54. item = JSON.parse(JSON.stringify(item));
  55. // 如果当前是历史搜索页面 ,那么点击不储存,直接 跳转
  56. if (this.history) {
  57. return;
  58. } else {
  59. this.isHistory = true;
  60. // 去做一些相关搜索功能 ,这里直接返回到上一个页面
  61. // 点击列表存储搜索数据
  62. util.setHistory(item);
  63. uni.navigateBack();
  64. }
  65. },
  66. /**
  67. * 清理历史搜索数据
  68. */
  69. clearSearch() {
  70. uni.showModal({
  71. title: '提示',
  72. content: '是否清理全部搜索历史?该操作不可逆。',
  73. success: res => {
  74. if (res.confirm) {
  75. this.historyList = util.removeHistory();
  76. }
  77. }
  78. });
  79. },
  80. /**
  81. * 关键字搜索
  82. * 调用高德地图关键字搜索api
  83. */
  84. getInputtips(val) {
  85. let _this = this;
  86. this.amapPlugin.getInputtips({
  87. keywords: val,
  88. city: '北京',
  89. success: data => {
  90. let dataObj = data.tips;
  91. // 处理返回数据文字高亮
  92. dataObj.map(item => {
  93. return util.dataHandle(item, val);
  94. });
  95. //成功回调
  96. _this.historyList = dataObj;
  97. },
  98. fail: info => {
  99. //失败回调
  100. console.log(info);
  101. }
  102. });
  103. }
  104. },
  105. /**
  106. * 当 searchInput 输入时触发
  107. */
  108. onNavigationBarSearchInputChanged(e) {
  109. let text = e.text;
  110. if (!text) {
  111. this.isHistory = true;
  112. this.historyList = [];
  113. this.historyList = uni.getStorageSync('search:history');
  114. return;
  115. } else {
  116. this.isHistory = false;
  117. this.getInputtips(text);
  118. }
  119. },
  120. /**
  121. * 点击软键盘搜索按键触发
  122. */
  123. onNavigationBarSearchInputConfirmed(e) {
  124. let text = e.text;
  125. if (!text) {
  126. this.isHistory = true;
  127. this.historyList = [];
  128. this.historyList = uni.getStorageSync('search:history');
  129. uni.showModal({
  130. title: '提示',
  131. content: '请输入内容。',
  132. success: res => {
  133. if (res.confirm) {
  134. }
  135. }
  136. });
  137. return;
  138. } else {
  139. uni.showModal({
  140. title: '提示',
  141. content: `您输入的内容为"${text}",如果点击确定,将记录到历史搜索,并返回.如果取消不做操作`,
  142. success: res => {
  143. if (res.confirm) {
  144. util.setHistory(text);
  145. uni.navigateBack();
  146. }
  147. }
  148. });
  149. }
  150. },
  151. /**
  152. * 点击导航栏 buttons 时触发
  153. */
  154. onNavigationBarButtonTap() {
  155. uni.showModal({
  156. title: '提示',
  157. content: '点击确定,修改输入框的内容为abc',
  158. success: res => {
  159. if (res.confirm) {
  160. const currentWebview = this.$mp.page.$getAppWebview();
  161. currentWebview.setTitleNViewSearchInputText("abc");
  162. }
  163. }
  164. });
  165. }
  166. };
  167. </script>
  168. <style>
  169. .history-title {
  170. display: flex;
  171. justify-content: space-between;
  172. padding: 20rpx 30rpx;
  173. padding-bottom: 0;
  174. font-size: 34rpx;
  175. color: #333;
  176. }
  177. .history-title .uni-icon {
  178. font-size: 40rpx;
  179. }
  180. .history-content {
  181. display: flex;
  182. flex-wrap: wrap;
  183. padding: 15rpx;
  184. }
  185. .history-item {
  186. padding: 4rpx 35rpx;
  187. border: 1px #f1f1f1 solid;
  188. background: #fff;
  189. border-radius: 50rpx;
  190. margin: 12rpx 10rpx;
  191. color: #999;
  192. }
  193. .history-list-box {
  194. /* margin: 10rpx 0; */
  195. }
  196. .history-list-item {
  197. padding: 30rpx 0;
  198. margin-left: 30rpx;
  199. border-bottom: 1px #EEEEEE solid;
  200. font-size: 28rpx;
  201. }
  202. .no-data {
  203. text-align: center;
  204. color: #999;
  205. margin: 100rpx;
  206. }
  207. </style>