江夏区图书馆自助查询机
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
3.8 KiB

  1. <template>
  2. <div>
  3. <div class="search-header-bg" />
  4. <el-card class="box-card" style="margin: -220px 44px 0 44px; padding-bottom: 12px;">
  5. <h4 style="font-size: 30px; margin-bottom: 24px; text-align: center;">图书检索</h4>
  6. <div class="search-main">
  7. <!-- 搜索栏 -->
  8. <div class="search-content">
  9. <div class="input-search">
  10. <el-input
  11. v-model="keyword"
  12. placeholder="请输入关键词进行检索"
  13. />
  14. <el-button type="primary" @click="toSearch">搜索</el-button>
  15. </div>
  16. <el-button @click="resetSearch">重置</el-button>
  17. </div>
  18. <!-- 热门检索 -->
  19. <div class="hot-keyword">
  20. <p style="margin-left: 10px;">热门检索</p>
  21. <div class="keyword-item">
  22. <!-- @click="selectKeyWord(index)" -->
  23. <span v-for="(item,index) in keywordData" :key="index" :class="{ 'active': keyWordIndex === index }" @click="selectKeyWord(index)">{{ item }}</span>
  24. </div>
  25. </div>
  26. </div>
  27. </el-card>
  28. </div>
  29. </template>
  30. <script>
  31. import { FetchFindHotSearch } from '@/api/inquiryMachine'
  32. import { positionCrud } from '../mixins/index.js'
  33. export default {
  34. name: 'Search',
  35. mixins: [positionCrud],
  36. props: {
  37. searchType: {
  38. type: String,
  39. default: ''
  40. }
  41. },
  42. data() {
  43. return {
  44. keyword: '',
  45. keyWordIndex: null,
  46. keywordData: []
  47. }
  48. },
  49. created() {
  50. this.getHotSearch()
  51. },
  52. mounted() {
  53. },
  54. methods: {
  55. getHotSearch() {
  56. const params = {
  57. 'fondsCode': this.libcode,
  58. 'size': 30
  59. }
  60. FetchFindHotSearch(params).then(res => {
  61. this.keywordData = res.filter(item => {
  62. return item !== ''
  63. })
  64. }).catch(() => {
  65. this.$message.error('接口错误')
  66. })
  67. },
  68. resetData() {
  69. this.$parent.pageIndex = 1
  70. this.$parent.hasNextPage = true
  71. this.keyword = ''
  72. this.$parent.bookList = []
  73. },
  74. resetSearch() {
  75. this.$parent.pageIndex = 1
  76. this.$parent.hasNextPage = false
  77. this.keyword = ''
  78. this.$parent.bookList = []
  79. this.keyWordIndex = null
  80. console.log('this.totalNum ', this.$parent.totalNum)
  81. this.$parent.totalNum = 0
  82. // this.$parent.addMoreData()
  83. },
  84. toSearch() {
  85. if (this.keyword) {
  86. this.keyWordIndex = null
  87. if (this.searchType === 'noList') {
  88. localStorage.setItem('searchKey', this.keyword)
  89. this.$router.push({ path: '/bookList' })
  90. } else {
  91. this.$parent.pageIndex = 1
  92. this.$parent.hasNextPage = true
  93. this.$parent.bookList = []
  94. this.$parent.addMoreData()
  95. }
  96. } else {
  97. this.$message.error('请输入检索关键词')
  98. }
  99. },
  100. selectKeyWord(index) {
  101. this.resetData()
  102. if (parseInt(this.keyWordIndex) === index) {
  103. this.keyWordIndex = null
  104. } else {
  105. this.keyWordIndex = index
  106. this.keyword = this.keywordData[index]
  107. }
  108. this.$forceUpdate()
  109. if (this.searchType === 'noList') {
  110. localStorage.setItem('searchKey', this.keyword)
  111. localStorage.setItem('keyWordIndex', this.keyWordIndex)
  112. this.$router.push({ path: '/bookList' })
  113. this.$parent.pageIndex = 1
  114. } else {
  115. this.$parent.pageIndex = 1
  116. this.$parent.hasNextPage = true
  117. this.$parent.bookList = []
  118. this.$parent.addMoreData()
  119. }
  120. }
  121. }
  122. }
  123. </script>
  124. <style lang="scss" scoped>
  125. @import "~@/assets/styles/index.scss";
  126. .search-header-bg{
  127. height: 298px;
  128. background: url("~@/assets/images/top-bg.png") no-repeat left top;
  129. background-size: 100% 100%;
  130. }
  131. </style>