d-search-log.vue 8.9 KB

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