search.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <template>
  2. <view>
  3. <view v-if="(data_base || null) != null">
  4. <!-- 搜索关键字 -->
  5. <view class="padding-horizontal-main padding-top-main padding-bottom-sm bg-white">
  6. <view class="search-keywords pr">
  7. <icon type="search" size="12" class="pa"></icon>
  8. <input type="text" confirm-type="search" placeholder="其实搜索很简单^_^ !" :value="search_keywords_value" @confirm="search_keywords_event" class="cr-base round wh-auto" placeholder-class="cr-grey">
  9. </view>
  10. </view>
  11. <!-- 分类 -->
  12. <scroll-view v-if="(category || null) != null && category.length > 0" class="nav-list scroll-view-horizontal bg-white oh" scroll-x="true">
  13. <view :class="'item cr-gray dis-inline-block padding-horizontal-main ' + (nav_active_value == 0 ? 'cr-main' : '')" @tap="nav_event" data-value="0">全部</view>
  14. <block v-for="(item, index) in category" :key="index">
  15. <view :class="'item cr-gray dis-inline-block padding-horizontal-main ' + (nav_active_value == item.id ? 'cr-main' : '')" @tap="nav_event" :data-value="item.id">{{item.name}}</view>
  16. </block>
  17. </scroll-view>
  18. <!-- 列表 -->
  19. <scroll-view :scroll-y="true" class="scroll-box" @scrolltolower="scroll_lower" lower-threshold="60">
  20. <view v-if="(data_list || null) != null && data_list.length > 0" class="plugins-blog-list padding-horizontal-main padding-top-main oh">
  21. <view v-for="(item, index) in data_list" class="item oh padding-main border-radius-main bg-white spacing-mb">
  22. <navigator :url="item.url" hover-class="none">
  23. <image class="blog-img fl radius" :src="item.cover" mode="aspectFill"></image>
  24. <view class="base fr">
  25. <view class="single-text text-size">{{item.title}}</view>
  26. <view class="cr-grey margin-top-sm">{{item.add_time_date_cn}}</view>
  27. <view class="cr-base text-size-sm multi-text margin-top-sm">{{item.describe}}</view>
  28. </view>
  29. </navigator>
  30. </view>
  31. </view>
  32. <view v-else>
  33. <!-- 提示信息 -->
  34. <component-no-data :propStatus="data_list_loding_status" :propMsg="data_list_loding_msg"></component-no-data>
  35. </view>
  36. <!-- 结尾 -->
  37. <component-bottom-line :propStatus="data_bottom_line_status"></component-bottom-line>
  38. </scroll-view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. const app = getApp();
  44. import componentNoData from "../../../../components/no-data/no-data";
  45. import componentBottomLine from "../../../../components/bottom-line/bottom-line";
  46. export default {
  47. data() {
  48. return {
  49. data_list_loding_status: 1,
  50. data_list_loding_msg: '',
  51. data_bottom_line_status: false,
  52. data_list: [],
  53. data_total: 0,
  54. data_page_total: 0,
  55. data_page: 1,
  56. params: null,
  57. data_base: null,
  58. category: [],
  59. nav_active_value: 0,
  60. search_keywords_value: '',
  61. // 自定义分享信息
  62. share_info: {}
  63. };
  64. },
  65. components: {
  66. componentNoData,
  67. componentBottomLine
  68. },
  69. props: {},
  70. onLoad(params) {
  71. this.setData({
  72. params: params,
  73. nav_active_value: params.id || 0,
  74. search_keywords_value: params.keywords || '',
  75. });
  76. // 数据加载
  77. this.get_data();
  78. },
  79. // 下拉刷新
  80. onPullDownRefresh() {
  81. this.setData({
  82. data_page: 1
  83. });
  84. this.get_data_list(1);
  85. },
  86. methods: {
  87. // 初始化
  88. get_data() {
  89. uni.showLoading({
  90. title: '加载中...'
  91. });
  92. uni.request({
  93. url: app.globalData.get_request_url("index", "search", "blog"),
  94. method: 'POST',
  95. data: {},
  96. dataType: 'json',
  97. success: res => {
  98. uni.hideLoading();
  99. uni.stopPullDownRefresh();
  100. if (res.data.code == 0) {
  101. var data = res.data.data;
  102. this.setData({
  103. data_base: data.base || null,
  104. category: data.category || []
  105. });
  106. // 标题
  107. var blog_main_name = ((data.base || null) == null) ? '博文' : (data.base.blog_main_name || '博文');
  108. uni.setNavigationBarTitle({title: blog_main_name+'搜索'});
  109. // 基础自定义分享
  110. var info = this.data_base;
  111. if((this.nav_active_value || 0) != 0 && this.category.length > 0) {
  112. for(var i in this.category) {
  113. if(this.nav_active_value == this.category[i]['id']) {
  114. info = this.category[i];
  115. break;
  116. }
  117. }
  118. }
  119. this.setData({
  120. share_info: {
  121. title: info.seo_title || this.data_base.application_name,
  122. desc: info.seo_desc,
  123. path: '/pages/plugins/blog/search/search',
  124. query: 'id=' +this.nav_active_value + '&keywords=' + this.search_keywords_value
  125. }
  126. });
  127. // 获取列表数据
  128. this.get_data_list(1);
  129. } else {
  130. this.setData({
  131. data_list_loding_status: 0,
  132. data_list_loding_msg: res.data.msg
  133. });
  134. app.globalData.showToast(res.data.msg);
  135. }
  136. // 分享菜单处理
  137. app.globalData.page_share_handle(this.share_info);
  138. },
  139. fail: () => {
  140. uni.hideLoading();
  141. uni.stopPullDownRefresh();
  142. this.setData({
  143. data_list_loding_status: 2
  144. });
  145. app.globalData.showToast('服务器请求出错');
  146. }
  147. });
  148. },
  149. // 获取数据列表
  150. get_data_list(is_mandatory) {
  151. // 分页是否还有数据
  152. if ((is_mandatory || 0) == 0) {
  153. if (this.data_bottom_line_status == true) {
  154. uni.stopPullDownRefresh();
  155. return false;
  156. }
  157. }
  158. // 加载loding
  159. uni.showLoading({
  160. title: '加载中...'
  161. });
  162. // 获取数据
  163. uni.request({
  164. url: app.globalData.get_request_url("datalist", "search", "blog"),
  165. method: 'POST',
  166. data: {
  167. page: this.data_page,
  168. id: this.nav_active_value,
  169. bwd: this.search_keywords_value
  170. },
  171. dataType: 'json',
  172. success: res => {
  173. uni.hideLoading();
  174. uni.stopPullDownRefresh();
  175. if (res.data.code == 0) {
  176. var data = res.data.data;
  177. if (data.data.length > 0) {
  178. if (this.data_page <= 1) {
  179. var temp_data_list = data.data;
  180. } else {
  181. var temp_data_list = this.data_list || [];
  182. var temp_data = data.data;
  183. for (var i in temp_data) {
  184. temp_data_list.push(temp_data[i]);
  185. }
  186. }
  187. this.setData({
  188. data_list: temp_data_list,
  189. data_total: data.total,
  190. data_page_total: data.page_total,
  191. data_list_loding_status: 3,
  192. data_page: this.data_page + 1
  193. });
  194. // 是否还有数据
  195. this.setData({
  196. data_bottom_line_status: (this.data_page > 1 && this.data_page > this.data_page_total)
  197. });
  198. } else {
  199. this.setData({
  200. data_list_loding_status: 0,
  201. data_list_loding_msg: '没有相关数据'
  202. });
  203. if (this.data_page <= 1) {
  204. this.setData({
  205. data_list: [],
  206. data_bottom_line_status: false
  207. });
  208. }
  209. }
  210. } else {
  211. this.setData({
  212. data_list_loding_status: 0,
  213. data_list_loding_msg: res.data.msg
  214. });
  215. app.globalData.showToast(res.data.msg);
  216. }
  217. },
  218. fail: () => {
  219. uni.hideLoading();
  220. uni.stopPullDownRefresh();
  221. this.setData({
  222. data_list_loding_status: 2
  223. });
  224. app.globalData.showToast('服务器请求出错');
  225. }
  226. });
  227. },
  228. // 滚动加载
  229. scroll_lower(e) {
  230. this.get_data_list();
  231. },
  232. // 导航事件
  233. nav_event(e) {
  234. this.setData({
  235. nav_active_value: e.currentTarget.dataset.value || 0,
  236. data_page: 1
  237. });
  238. this.get_data_list(1);
  239. },
  240. // 关键字输入事件
  241. search_keywords_event(e) {
  242. this.setData({
  243. search_keywords_value: e.detail.value || '',
  244. data_page: 1
  245. });
  246. this.get_data_list(1);
  247. }
  248. }
  249. };
  250. </script>
  251. <style>
  252. @import './search.css';
  253. </style>