index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <u-search shape="square" v-model="value" :show-action="true" action-text="取消" placeholder="想买什么车"
  5. @change="toChange" @custom="toCustom"></u-search>
  6. </view>
  7. <view class="two" v-if="!value&&moreList.length>0">
  8. <view class="two_1">
  9. <view class="left">
  10. 搜索历史
  11. </view>
  12. <view class="right" @tap="toRest">
  13. <u-icon size="18px" name="trash"></u-icon>
  14. </view>
  15. </view>
  16. <view class="two_2">
  17. <view class="title" v-for="(item, index) in moreList" :key="index">
  18. <span @tap="toView(item)">{{item.name}}</span>&nbsp;
  19. <u-icon size="15px" name="close" @tap="toDelete(item)"></u-icon>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="thr" v-else>
  24. <view class="list" v-for="(item, index) in list" :key="index" @tap="toView(item)">
  25. <view class="left">
  26. <image v-if="item.file" class="image" :src="item.file&&item.file.length>0?item.file[0].url:''">
  27. </image>
  28. <u-icon v-else size="16px" name="search"></u-icon>
  29. </view>
  30. <view class="right">
  31. {{item.name}}
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script setup lang="ts">
  38. import { getCurrentInstance, ref } from 'vue';
  39. //该依赖已内置不需要单独安装
  40. import { onShow } from "@dcloudio/uni-app";
  41. // 请求接口
  42. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  43. const value = ref('');
  44. const list = ref([{ name: "本田" }]);
  45. const moreList = ref([{ name: "本田" }]);
  46. onShow(() => {
  47. search();
  48. toCustom();
  49. })
  50. // 查询
  51. const search = async () => {
  52. };
  53. // 搜索
  54. const toChange = async () => {
  55. };
  56. // 取消
  57. const toCustom = async () => {
  58. value.value = ''
  59. };
  60. // 查看详情
  61. const toView = (item) => {
  62. uni.navigateTo({
  63. url: `/pagesHome/search/index?type=${item.type || ''}`
  64. })
  65. };
  66. // 取消
  67. const toRest = async () => {
  68. console.log('重置');
  69. };
  70. // 删除
  71. const toDelete = async () => {
  72. console.log('删除');
  73. };
  74. </script>
  75. <style lang="scss" scoped>
  76. .content {
  77. display: flex;
  78. flex-direction: column;
  79. width: 100vw;
  80. height: 100vh;
  81. .one {
  82. padding: 2vw;
  83. }
  84. .two {
  85. padding: 2vw;
  86. font-size: var(--font14Size);
  87. .two_1 {
  88. margin: 2vw;
  89. display: flex;
  90. justify-content: space-between;
  91. }
  92. .two_2 {
  93. margin: 2vw 0 0 0;
  94. display: flex;
  95. flex-wrap: wrap;
  96. .title {
  97. display: flex;
  98. align-items: center;
  99. padding: 2vw;
  100. margin: 1vw;
  101. background-color: var(--f9Color);
  102. }
  103. }
  104. }
  105. .thr {
  106. .list {
  107. display: flex;
  108. align-items: center;
  109. margin: 1vw 1vw 0 1vw;
  110. padding: 2vw;
  111. border-bottom: 1px solid var(--f9Color);
  112. }
  113. .left {
  114. .image {
  115. width: 40px;
  116. height: 40px;
  117. border-radius: 40px;
  118. }
  119. }
  120. .right {
  121. margin: 0 0 0 2vw;
  122. font-size: var(--font14Size);
  123. }
  124. }
  125. }
  126. </style>