search.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <view class="container">
  3. <view class="tui-searchbox">
  4. <view class="tui-search-input">
  5. <icon type="search" :size='13' color='#333'></icon>
  6. <input confirm-type="search" @confirm="tosearch" placeholder="关键词" :focus="true" auto-focus
  7. placeholder-class="tui-input-plholder" class="tui-input" v-model.trim="key" @input="inputKey" />
  8. <icon type="clear" :size='13' color='#bcbcbc' @tap="cleanKey" v-show="key"></icon>
  9. </view>
  10. </view>
  11. <view class="tui-search-history" v-show="history.length>0 && !key">
  12. <view class="tui-history-header">
  13. <view class="tui-search-title">搜索推荐</view>
  14. </view>
  15. <view class="tui-history-content">
  16. <block v-for="(item,index) in history" :key="index">
  17. <tui-tag @tap="tohotkey(item)" margin="0 24rpx 24rpx 0" type="gray" shape="circle">{{item}}</tui-tag>
  18. </block>
  19. </view>
  20. </view>
  21. <view v-show="key">
  22. <view class="tui-result-box">
  23. <view class="result-list">
  24. <block v-for="(item,index) in searchList" :key="index">
  25. <navigator :url="'/pages/goodsDetail/goodsDetail?id=' + item.id" class="result-item" hover-class="none">
  26. <image :src="item.image" mode="" class="left-img" mode="aspectFit"></image>
  27. <view class="right-info">
  28. <view class="title">
  29. {{item.name}}
  30. </view>
  31. <view class="sale">
  32. 月销{{item.sale_count}}
  33. </view>
  34. <view class="price">
  35. <text>¥<text class="money">{{item.price}}</text>元</text>
  36. <!--<text class="que-tag">立减20</text>-->
  37. </view>
  38. </view>
  39. </navigator>
  40. </block>
  41. </view>
  42. </view>
  43. </view>
  44. <tui-actionsheet :show="showActionSheet" :tips="tips" @click="itemClick" @cancel="closeActionSheet">
  45. </tui-actionsheet>
  46. </view>
  47. </template>
  48. <script>
  49. const util = require("@/utils/util.js")
  50. export default {
  51. data() {
  52. return {
  53. history: {},
  54. key: "",
  55. showActionSheet: false,
  56. tips: "确认清空搜索历史吗?",
  57. searchList: []
  58. }
  59. },
  60. onShow() {
  61. let _this = this;
  62. _this.$request.post('Config.keyword', {
  63. samkey: (new Date()).valueOf()
  64. }).then(res => {
  65. _this.history = res.data.keyword;
  66. });
  67. },
  68. methods: {
  69. back: function() {
  70. uni.navigateBack();
  71. },
  72. cleanKey: function() {
  73. this.key = ''
  74. },
  75. closeActionSheet: function() {
  76. this.showActionSheet = false
  77. },
  78. itemClick: function(e) {
  79. let index = e.index;
  80. if (index == 0) {
  81. this.showActionSheet = false;
  82. this.history = []
  83. }
  84. },
  85. inputKey: function(e) {
  86. var that = this;
  87. this.key = util.trim(e.detail.value);
  88. if (!this.key) {
  89. this.searchList = [];
  90. return;
  91. }
  92. this.$request.post('goods', {keyword:this.key,showLoading:true}).then(res => {
  93. if (res.errno == 0) {
  94. that.searchList = res.data.data;
  95. }
  96. })
  97. },
  98. tohotkey: function(key) {
  99. this.sam.navigateTo('/pages/goodsList/goodsList?keyword=' + key);
  100. },
  101. tosearch: function(event) {
  102. var inputvalus = event.target.value;
  103. if (inputvalus != '') {
  104. this.sam.navigateTo('/pages/goodsList/goodsList?keyword=' + inputvalus);
  105. } else {
  106. uni.showToast({
  107. title: "请输入搜索内容!",
  108. duration: 1000,
  109. icon: 'none'
  110. });
  111. }
  112. },
  113. }
  114. }
  115. </script>
  116. <style>
  117. page {
  118. color: #333;
  119. background: #fff;
  120. }
  121. .container {
  122. padding: 0 30rpx 30rpx 30rpx;
  123. box-sizing: border-box;
  124. }
  125. .tui-searchbox {
  126. padding: 30rpx 0;
  127. box-sizing: border-box;
  128. display: flex;
  129. align-items: center;
  130. }
  131. .tui-search-input {
  132. width: 100%;
  133. height: 66rpx;
  134. border-radius: 35rpx;
  135. padding: 0 30rpx;
  136. box-sizing: border-box;
  137. background: #f2f2f2;
  138. display: flex;
  139. align-items: center;
  140. flex-wrap: nowrap;
  141. }
  142. .tui-input {
  143. flex: 1;
  144. color: #333;
  145. padding: 0 16rpx;
  146. font-size: 28rpx;
  147. }
  148. .tui-input-plholder {
  149. font-size: 28rpx;
  150. color: #b2b2b2;
  151. }
  152. .tui-cancle {
  153. color: #888;
  154. font-size: 28rpx;
  155. padding-left: 30rpx;
  156. flex-shrink: 0;
  157. }
  158. .tui-history-header {
  159. display: flex;
  160. align-items: center;
  161. justify-content: space-between;
  162. padding: 30rpx 0;
  163. }
  164. .tui-history-content {
  165. display: flex;
  166. align-items: center;
  167. flex-wrap: wrap;
  168. }
  169. .tui-icon-delete {
  170. padding: 10rpx;
  171. }
  172. .tui-search-title {
  173. font-size: 28rpx;
  174. font-weight: bold;
  175. }
  176. .tui-hot-header {
  177. padding: 30rpx 0;
  178. }
  179. .tui-noboredr {
  180. border-left: 0 !important;
  181. }
  182. .tui-result-box {
  183. font-size: 28rpx;
  184. }
  185. .tui-result-item {
  186. line-height: 28rpx;
  187. padding: 28rpx 0;
  188. }
  189. .result-list{
  190. margin: 0 30rpx;
  191. }
  192. .result-list .result-item{
  193. background-color: #fff;
  194. border-radius: 10rpx;
  195. background-color: #FFFFFF;
  196. padding: 30rpx;
  197. margin-bottom: 20rpx;
  198. display: flex;
  199. }
  200. .result-list .result-item .left-img{
  201. width: 260rpx;
  202. height: 186rpx;
  203. border-radius: 10rpx;
  204. margin-right: 30rpx;
  205. }
  206. .result-list .result-item .right-info{
  207. width: 380rpx;
  208. }
  209. .result-list .result-item .title{
  210. font-size: 32rpx;
  211. font-weight: bold;
  212. margin-bottom:60rpx;
  213. overflow: hidden;
  214. white-space: nowrap;
  215. text-overflow: ellipsis;
  216. }
  217. .result-list .result-item .sale{
  218. color: #999999;
  219. font-size: 24rpx;
  220. }
  221. .result-list .result-item .price{
  222. color:#FF3851;
  223. font-size: 24rpx;
  224. display: flex;
  225. align-items: center;
  226. }
  227. .result-list .result-item .money{
  228. font-size: 36rpx;
  229. font-weight: bold;
  230. }
  231. .result-list .result-item .que-tag{
  232. display: inline-block;
  233. border-radius: 2rpx;
  234. height: 32rpx;
  235. line-height: 32rpx;
  236. border: 1px solid #FF3851;
  237. padding: 0 10rpx;
  238. margin-left: 10rpx;
  239. }
  240. </style>