search.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <!-- +---------------------------------------------------------------------- -->
  2. <!-- | CRMEB [ CRMEB赋能开发者,助力企业发展 ] -->
  3. <!-- +---------------------------------------------------------------------- -->
  4. <!-- | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved. -->
  5. <!-- +---------------------------------------------------------------------- -->
  6. <!-- | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 -->
  7. <!-- +---------------------------------------------------------------------- -->
  8. <!-- | Author: CRMEB Team <admin@crmeb.com> -->
  9. <!-- +---------------------------------------------------------------------- -->
  10. {extend name="public/container"}
  11. {block name="title"}搜索{/block}
  12. {block name="content"}
  13. <div v-cloak id="app" class="search-page">
  14. <form @submit.prevent="onSearch(search)">
  15. <label>
  16. <i class="iconfont iconsousuo"></i>
  17. <input v-model.trim="search" type="search" placeholder="输入搜索课程">
  18. <i v-show="search" class="iconfont iconguanbi2" @click="search = ''"></i>
  19. </label>
  20. <input type="submit" value="搜索">
  21. </form>
  22. <div v-if="historyList.length" class="section">
  23. <div class="title">
  24. <div class="text">历史记录</div>
  25. <i class="iconfont iconshanchu" @click="deleteHistory"></i>
  26. </div>
  27. <div class="content">
  28. <span v-for="(item, index) in historyList" :key="index" @click="onSearch(item.search)">{{ item.search }}</span>
  29. </div>
  30. </div>
  31. <div v-if="hotList.length" class="section">
  32. <div class="title">
  33. <div class="text">热门搜索</div>
  34. </div>
  35. <div class="content">
  36. <span v-for="(item, index) in hotList" :key="index" @click="onSearch(item)">{{ item }}</span>
  37. </div>
  38. </div>
  39. <div v-if="specialList.length" class="special-section">
  40. <div class="title">专题</div>
  41. <div>
  42. <a v-for="item in specialList" :key="item.id" :href="(item.is_light ? singleDetailsURL : detailsURL) + '?id=' + item.id">
  43. <div class="image">
  44. <img :src="item.image" :alt="item.title">
  45. <div v-if="item.type == 1" class="type">图文</div>
  46. <div v-else-if="item.type == 2" class="type">音频</div>
  47. <div v-else-if="item.type == 3" class="type">视频</div>
  48. <div v-else-if="item.type == 5" class="type">专栏</div>
  49. </div>
  50. <div class="text">
  51. <div class="special-title">{{ item.title }}</div>
  52. <div class="label">
  53. <span v-for="(label, index) in item.label" :key="index">{{ label }}</span>
  54. </div>
  55. <div class="money-total">
  56. <div class="money">¥<span>{{ item.money }}</span></div>
  57. <div v-if="!item.is_light" class="total">共{{ item.count }}节</div>
  58. </div>
  59. </div>
  60. </a>
  61. </div>
  62. </div>
  63. <img v-if="isEmpty" class="empty" src="{__WAP_PATH}zsff/images/no_search.png" alt="暂无搜索结果">
  64. </div>
  65. {/block}
  66. {block name="foot"}
  67. <script>
  68. require(['vue', 'store'], function (Vue, store) {
  69. new Vue({
  70. el: '#app',
  71. data: {
  72. search: '',
  73. historyList: [],
  74. hotList: [],
  75. specialList: [],
  76. limit: 10,
  77. singleDetailsURL: '',
  78. detailsURL: '',
  79. isEmpty: false
  80. },
  81. watch: {
  82. specialList: function (val) {
  83. this.isEmpty = !val.length;
  84. }
  85. },
  86. created: function () {
  87. this.getSearchHistory();
  88. this.getHotSearch();
  89. this.singleDetailsURL = $h.U({
  90. c: 'special',
  91. a: 'single_details'
  92. });
  93. this.detailsURL = $h.U({
  94. c: 'special',
  95. a: 'details'
  96. });
  97. },
  98. methods: {
  99. // 获取搜索历史
  100. getSearchHistory: function () {
  101. var vm = this;
  102. store.baseGet($h.U({
  103. c: 'index',
  104. a: 'get_search_history'
  105. }), function (res) {
  106. vm.historyList = res.data.data;
  107. });
  108. },
  109. // 获取热门搜索
  110. getHotSearch: function () {
  111. var vm = this;
  112. store.baseGet($h.U({
  113. c: 'index',
  114. a: 'get_host_search'
  115. }), function (res) {
  116. vm.hotList = res.data.data;
  117. });
  118. },
  119. // 搜索内容
  120. onSearch: function (search) {
  121. var vm = this;
  122. if (!search || this.loading) {
  123. return;
  124. }
  125. $h.loadFFF();
  126. store.baseGet($h.U({
  127. c: 'index',
  128. a: 'go_search',
  129. q: {
  130. search: search,
  131. limit: this.limit
  132. }
  133. }), function (res) {
  134. $h.loadClear();
  135. vm.specialList = res.data.data.special;
  136. }, function () {
  137. $h.loadClear();
  138. });
  139. },
  140. // 删除搜索历史
  141. deleteHistory: function () {
  142. var vm = this;
  143. store.baseGet($h.U({
  144. c: 'index',
  145. a: 'del_search_history'
  146. }), function () {
  147. vm.historyList = [];
  148. });
  149. }
  150. }
  151. });
  152. });
  153. </script>
  154. {/block}