d-search-log.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <view class="dSLComVue">
  3. <view class="dSLComVueTop">
  4. <view class="dSLComVueTopLeft">
  5. <image class="dSLComVueTopLeftImg" style="width: 30rpx;height: 30rpx;flex: none;" src="@/static/imgs/card/search.png"></image>
  6. <input class="dSLComVueTopLeftInput" v-model="search_input" type="text" :placeholder="placeholder" @blur="onClickInput" />
  7. <view class="dSLComVueTopLeftDel" v-if="search_input" @click="onClickDel">
  8. <!-- <u-icon name="close" size="20"></u-icon> -->
  9. <!-- <image src="/static/icon_img/del.png" class="dSLComVueTopLeftDelImg" style="width: 35rpx;height: 35rpx;flex: none;" ></image> -->
  10. </view>
  11. <image @click='onClickvoice' src="@/static/imgs/card/voice.png" class="dSLComVueTopLeftDelImg" style="width: 30rpx;height: 39rpx;flex: none;" ></image>
  12. </view>
  13. <view class="dSLComVueTopRight">
  14. <view class="dSLComVueTopRightBtn" @click="onClickInput" >{{search_name?search_name:'搜索'}}</view>
  15. </view>
  16. </view>
  17. <view v-if="is_show_more" class="dSLComVue">
  18. <view class="dSLComVueTitle" >
  19. <text>历史搜索</text>
  20. <view style="width: 100rpx;height: 60rpx;display: flex;align-items: center;" @click="onClickDelAll">
  21. <!-- <u-icon name="trash-fill" size="30"></u-icon> -->
  22. <image src="@/static/imgs/card/del.png" style="width: 27rpx;height: 32rpx;margin-right: 35rpx;"></image>
  23. </view>
  24. </view>
  25. <view v-if="search_list_old.length==0" class="mytext">暂无</view>
  26. <view class="dSLComVueLog" v-if="search_list_old.length>0">
  27. <text class="dSLComVueLogBox mytext" v-for="(item,index) in search_list_old" :key="index" @click="onClickInputValue(item)">
  28. {{item?item:'无'}}
  29. </text>
  30. </view>
  31. <view class="dSLComVueTitle" v-if="search_list_hot.length>0" style="margin-top: 20rpx;">
  32. <text>热门搜索</text>
  33. <view style="width: 100rpx;height: 60rpx;display: flex;align-items: center;justify-content: flex-end;" @click="onClickShowHot">
  34. <image :src="is_hot_show?'/static/icon_img/yan_open.png':'/static/icon_img/yan_close.png'" style="width: 30rpx;height: 30rpx;margin-right: 35rpx;"></image>
  35. </view>
  36. </view>
  37. <view class="dSLComVueLog" v-if="search_list_hot.length>0 && is_hot_show">
  38. <text class="dSLComVueLogBox mytext" v-for="(item,index) in search_list_hot" :key="index" @click="onClickInputValue(item)">
  39. {{item?item:'无'}}
  40. </text>
  41. </view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. data() {
  48. return {
  49. search_list_old:[],
  50. search_input:'',
  51. is_hot_show:true,
  52. }
  53. },
  54. created() {
  55. this._init_search()
  56. },
  57. props: {
  58. is_show_more: {
  59. value: Boolean,
  60. default: true
  61. },
  62. search_icon:{
  63. value: String,
  64. default: ''
  65. },
  66. search_list_old_man_num: {
  67. value: Number,
  68. default: 10
  69. },
  70. search_list_hot: {
  71. value: Array,
  72. default: []
  73. },
  74. //HM修改 定义默认搜索关键词(水印文字)
  75. placeholder:{
  76. value: String,
  77. default: '请输入搜索内容'
  78. },
  79. store_key:{
  80. value: String,
  81. default: 'search_list'
  82. },
  83. color_border:{
  84. value: String,
  85. default: ''
  86. },
  87. color_text:{
  88. value: String,
  89. default: '#30c66c'
  90. },
  91. search_name:{
  92. value: String,
  93. default: '搜索'
  94. },
  95. input_text:{
  96. value: String,
  97. default: ''
  98. },
  99. },
  100. watch: {
  101. search_list_hot(newVal) {
  102. if (newVal) {
  103. this.search_list_hot = newVal
  104. }
  105. },
  106. input_text(newVal) {
  107. if (newVal) {
  108. this.search_input = newVal
  109. // this.search_input = search_input.toLowerCase()
  110. this.saveKeyword()
  111. }
  112. },
  113. },
  114. methods:{
  115. onClickInput(){
  116. this.saveKeyword()
  117. },
  118. onClickvoice(){
  119. this.$emit('onSearchvoiceApi', '');
  120. },
  121. onClickInputValue(search_input) {
  122. if (!search_input) {
  123. return false;
  124. }
  125. this.search_input = search_input.toLowerCase()
  126. this.saveKeyword()
  127. },
  128. _init_search() {
  129. var that = this
  130. var store_key = that.store_key
  131. uni.getStorage({
  132. key: store_key,
  133. success: (res) => {
  134. var old_data = JSON.parse(res.data);
  135. that.search_list_old = old_data; //更新历史搜索
  136. // console.log('____________________dev')
  137. // console.log(that.search_list_old)
  138. // console.log('____________________dev')
  139. }
  140. });
  141. },
  142. saveKeyword() {
  143. var that = this
  144. // console.log('搜索的名称为:'+this.search_input)
  145. if (!this.search_input) {
  146. return false;
  147. }
  148. this.search_input = this.search_input.toLowerCase()
  149. var search_input = this.search_input
  150. var store_key = that.store_key
  151. uni.getStorage({
  152. key: store_key,
  153. success: (res) => {
  154. var old_data = JSON.parse(res.data);
  155. var findIndex = old_data.indexOf(search_input);
  156. if (findIndex == -1) {
  157. old_data.unshift(search_input);
  158. } else {
  159. old_data.splice(findIndex, 1);
  160. old_data.unshift(search_input);
  161. }
  162. //最多10个纪录
  163. old_data.length > that.search_list_old_man_num && old_data.pop();
  164. uni.setStorage({
  165. key: store_key,
  166. data: JSON.stringify(old_data)
  167. });
  168. that.search_list_old = old_data; //更新历史搜索
  169. // console.log('____________________dev')
  170. // console.log(that.search_list_old)
  171. // console.log('____________________dev')
  172. },
  173. fail: (e) => {
  174. var old_data = [search_input];
  175. uni.setStorage({
  176. key: store_key,
  177. data: JSON.stringify(old_data)
  178. });
  179. that.search_list_old = old_data; //更新历史搜索
  180. // console.log('____________________dev')
  181. // console.log(that.search_list_old)
  182. // console.log('____________________dev')
  183. }
  184. });
  185. // 向父级发送搜索的事件
  186. that.$emit('onSearchNameApi', this.search_input);
  187. //
  188. },
  189. onClickDel() {
  190. this.search_input = ''
  191. this.$emit('onSearchNameApi', '');
  192. },
  193. onClickDelAll() {
  194. var that = this
  195. console.log('---全部删除-log--')
  196. uni.showModal({
  197. title:'提示',
  198. content:'确定全部删除',
  199. success(res) {
  200. if (res.confirm) {
  201. uni.removeStorageSync(that.store_key)
  202. that.search_list_old = []
  203. // console.log('______清除全部搜索记录______向上级发送事件')
  204. that.$emit('onClickDelAllApi', '');
  205. }
  206. }
  207. })
  208. },
  209. //
  210. onClickShowHot() {
  211. this.is_hot_show = this.is_hot_show==true?false:true
  212. }
  213. }
  214. }
  215. </script>
  216. <style lang="scss">
  217. .myborder {
  218. border: 1rpx solid #60DF9D;
  219. color: #30c66c;
  220. }
  221. .mytext {
  222. color: #8799a3;
  223. }
  224. .dSLComVue {
  225. width: 100%;
  226. display: flex;
  227. flex-direction: column;
  228. align-items: center;
  229. padding: 20rpx;
  230. .dSLComVueTop {
  231. width: 90%;
  232. height: 100rpx;
  233. display: flex;
  234. align-items: center;
  235. justify-content: space-between;
  236. border-radius: 40rpx;
  237. .dSLComVueTopLeft {
  238. flex: 1;
  239. height: 80rpx;
  240. background-color: #F0F0F0;
  241. border-radius: 50rpx;
  242. display: flex;
  243. align-items: center;
  244. justify-content: space-between;
  245. padding: 0 3%;
  246. // background-color: #ccc;
  247. border: 1rpx solid #F0F0F0;
  248. .dSLComVueTopLeftImg {
  249. flex: 1;
  250. height: 80rpx;
  251. }
  252. .dSLComVueTopLeftInput {
  253. flex: 1;
  254. height: 80rpx;
  255. padding: 0 20rpx;
  256. }
  257. .dSLComVueTopLeftDel {
  258. width: 70rpx;
  259. height: 60rpx;
  260. display: flex;
  261. align-items: center;
  262. justify-content: flex-end;
  263. }
  264. }
  265. .dSLComVueTopRight {
  266. width: 100rpx;
  267. margin-left: 10rpx;
  268. height: 60rpx;
  269. display: flex;
  270. align-items: center;
  271. justify-content: flex-end;
  272. .dSLComVueTopRightBtn {
  273. width: 120rpx;
  274. height: 60rpx;
  275. border-radius: 30rpx;
  276. // color: red;
  277. display: flex;
  278. // color: #ff00ff;
  279. // border:1rpx solid #ff00ff;
  280. align-items: center;
  281. justify-content: center;
  282. }
  283. }
  284. }
  285. .dSLComVueTitle {
  286. width: 100%;
  287. height: 80rpx;
  288. display: flex;
  289. font-weight: 600;
  290. font-size: 26rpx;
  291. align-items: center;
  292. // background-color: #30c66c;
  293. align-items: center;
  294. justify-content: space-between;
  295. padding-left: 5%;
  296. }
  297. .dSLComVueTitle text{
  298. position:relative;
  299. font-size:32rpx;
  300. }
  301. .dSLComVueTitle text::before{
  302. content:'';
  303. display:block;
  304. position:absolute;
  305. width: 3px;
  306. height: 16px;
  307. left: -6px;
  308. top: 4px;
  309. background:#4977FC;
  310. }
  311. .dSLComVueLog {
  312. width: 90%;
  313. display: flex;
  314. flex-wrap: wrap;
  315. justify-content: flex-start;
  316. .dSLComVueLogBox {
  317. line-height: 55rpx;
  318. background-color: #e8e8e8;
  319. padding: 0rpx 30rpx;
  320. border-radius: 10rpx;
  321. flex: none;
  322. margin: 10rpx 25rpx 15rpx 0;
  323. // border: 1rpx solid #ccc
  324. }
  325. }
  326. }
  327. </style>