d-search-log.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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 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. onClickInputValue(search_input) {
  119. if (!search_input) {
  120. return false;
  121. }
  122. this.search_input = search_input.toLowerCase()
  123. this.saveKeyword()
  124. },
  125. _init_search() {
  126. var that = this
  127. var store_key = that.store_key
  128. uni.getStorage({
  129. key: store_key,
  130. success: (res) => {
  131. var old_data = JSON.parse(res.data);
  132. that.search_list_old = old_data; //更新历史搜索
  133. // console.log('____________________dev')
  134. // console.log(that.search_list_old)
  135. // console.log('____________________dev')
  136. }
  137. });
  138. },
  139. saveKeyword() {
  140. var that = this
  141. // console.log('搜索的名称为:'+this.search_input)
  142. if (!this.search_input) {
  143. return false;
  144. }
  145. this.search_input = this.search_input.toLowerCase()
  146. var search_input = this.search_input
  147. var store_key = that.store_key
  148. uni.getStorage({
  149. key: store_key,
  150. success: (res) => {
  151. var old_data = JSON.parse(res.data);
  152. var findIndex = old_data.indexOf(search_input);
  153. if (findIndex == -1) {
  154. old_data.unshift(search_input);
  155. } else {
  156. old_data.splice(findIndex, 1);
  157. old_data.unshift(search_input);
  158. }
  159. //最多10个纪录
  160. old_data.length > that.search_list_old_man_num && old_data.pop();
  161. uni.setStorage({
  162. key: store_key,
  163. data: JSON.stringify(old_data)
  164. });
  165. that.search_list_old = old_data; //更新历史搜索
  166. // console.log('____________________dev')
  167. // console.log(that.search_list_old)
  168. // console.log('____________________dev')
  169. },
  170. fail: (e) => {
  171. var old_data = [search_input];
  172. uni.setStorage({
  173. key: store_key,
  174. data: JSON.stringify(old_data)
  175. });
  176. that.search_list_old = old_data; //更新历史搜索
  177. // console.log('____________________dev')
  178. // console.log(that.search_list_old)
  179. // console.log('____________________dev')
  180. }
  181. });
  182. // 向父级发送搜索的事件
  183. that.$emit('onSearchNameApi', this.search_input);
  184. //
  185. },
  186. onClickDel() {
  187. this.search_input = ''
  188. this.$emit('onSearchNameApi', '');
  189. },
  190. onClickDelAll() {
  191. var that = this
  192. console.log('---全部删除-log--')
  193. uni.showModal({
  194. title:'提示',
  195. content:'确定全部删除',
  196. success(res) {
  197. if (res.confirm) {
  198. uni.removeStorageSync(that.store_key)
  199. that.search_list_old = []
  200. // console.log('______清除全部搜索记录______向上级发送事件')
  201. that.$emit('onClickDelAllApi', '');
  202. }
  203. }
  204. })
  205. },
  206. //
  207. onClickShowHot() {
  208. this.is_hot_show = this.is_hot_show==true?false:true
  209. }
  210. }
  211. }
  212. </script>
  213. <style lang="scss">
  214. .myborder {
  215. border: 1rpx solid #60DF9D;
  216. color: #30c66c;
  217. }
  218. .mytext {
  219. color: #8799a3;
  220. }
  221. .dSLComVue {
  222. width: 100%;
  223. display: flex;
  224. flex-direction: column;
  225. align-items: center;
  226. padding: 10rpx 0;
  227. .dSLComVueTop {
  228. width: 90%;
  229. height: 100rpx;
  230. display: flex;
  231. align-items: center;
  232. justify-content: space-between;
  233. border-radius: 40rpx;
  234. .dSLComVueTopLeft {
  235. flex: 1;
  236. height: 80rpx;
  237. background-color: #F0F0F0;
  238. border-radius: 50rpx;
  239. display: flex;
  240. align-items: center;
  241. justify-content: space-between;
  242. padding: 0 3%;
  243. // background-color: #ccc;
  244. border: 1rpx solid #F0F0F0;
  245. .dSLComVueTopLeftImg {
  246. flex: 1;
  247. height: 80rpx;
  248. }
  249. .dSLComVueTopLeftInput {
  250. flex: 1;
  251. height: 80rpx;
  252. padding: 0 20rpx;
  253. }
  254. .dSLComVueTopLeftDel {
  255. width: 70rpx;
  256. height: 60rpx;
  257. display: flex;
  258. align-items: center;
  259. justify-content: flex-end;
  260. }
  261. }
  262. .dSLComVueTopRight {
  263. width: 100rpx;
  264. margin-left: 10rpx;
  265. height: 60rpx;
  266. display: flex;
  267. align-items: center;
  268. justify-content: flex-end;
  269. .dSLComVueTopRightBtn {
  270. width: 120rpx;
  271. height: 60rpx;
  272. border-radius: 30rpx;
  273. // color: red;
  274. display: flex;
  275. // color: #ff00ff;
  276. // border:1rpx solid #ff00ff;
  277. align-items: center;
  278. justify-content: center;
  279. }
  280. }
  281. }
  282. .dSLComVueTitle {
  283. width: 100%;
  284. height: 80rpx;
  285. display: flex;
  286. font-weight: 600;
  287. font-size: 26rpx;
  288. align-items: center;
  289. // background-color: #30c66c;
  290. align-items: center;
  291. justify-content: space-between;
  292. padding-left: 5%;
  293. }
  294. .dSLComVueTitle text{
  295. position:relative;
  296. font-size:32rpx;
  297. }
  298. .dSLComVueTitle text::before{
  299. content:'';
  300. display:block;
  301. position:absolute;
  302. width: 3px;
  303. height: 16px;
  304. left: -6px;
  305. top: 4px;
  306. background:#4977FC;
  307. }
  308. .dSLComVueLog {
  309. width: 90%;
  310. display: flex;
  311. flex-wrap: wrap;
  312. justify-content: flex-start;
  313. .dSLComVueLogBox {
  314. line-height: 55rpx;
  315. background-color: #e8e8e8;
  316. padding: 0rpx 30rpx;
  317. border-radius: 10rpx;
  318. flex: none;
  319. margin: 10rpx 25rpx 15rpx 0;
  320. // border: 1rpx solid #ccc
  321. }
  322. }
  323. }
  324. </style>