index.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <view v-show="display" class="tui-common-words-container">
  3. <view class="tui-common-words-box">
  4. <view class="tui-common-words-title">
  5. <view>请选择常用语</view>
  6. <view style="color: #006EFF; font-family: PingFangSC-Regular;" class="tui-common-words-close" @tap="handleClose">关闭</view>
  7. </view>
  8. <view class="tui-search-bar">
  9. <image class="tui-searchcion" src="/static/assets/serach-icon.svg"></image>
  10. <input class="tui-search-bar-input" :value="words" placeholder="请输入关键字搜索" @input="wordsInput" />
  11. </view>
  12. <scroll-view class="tui-common-words-list" scroll-y="true" enable-flex="true">
  13. <view v-for="(item, index) in commonWordsMatch" :key="index" class="tui-common-words-item" @tap="sendMessage" :data-words="item">{{ item }}</view>
  14. </scroll-view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. const commonWordsList = [
  20. '你好在吗',
  21. '问题A',
  22. '问题B'
  23. ];
  24. export default {
  25. data() {
  26. return {
  27. words: '',
  28. commonWordsMatch: commonWordsList
  29. };
  30. },
  31. components: {},
  32. props: {
  33. display: {
  34. type: Boolean,
  35. default: false
  36. }
  37. },
  38. watch: {
  39. display: {
  40. handler: function(newVal) {
  41. // this.setData({
  42. // display: newVal
  43. // });
  44. },
  45. immediate: true
  46. }
  47. },
  48. methods: {
  49. handleClose() {
  50. this.$emit('close', {
  51. detail: {
  52. key: '0'
  53. }
  54. });
  55. },
  56. wordsInput(e) {
  57. (this.commonWordsMatch = []),
  58. commonWordsList.forEach(item => {
  59. if (item.indexOf(e.detail.value) > -1) {
  60. this.commonWordsMatch.push(item);
  61. }
  62. });
  63. this.setData({
  64. words: e.detail.value,
  65. commonWordsMatch: this.commonWordsMatch
  66. });
  67. },
  68. sendMessage(e) {
  69. this.$emit('sendMessage', {
  70. detail: {
  71. message: e.currentTarget.dataset.words
  72. }
  73. });
  74. }
  75. }
  76. };
  77. </script>
  78. <style>
  79. @import './index.css';
  80. </style>