search.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <view>
  3. <view v-if="(data_base || null) != null">
  4. <!-- 顶部 -->
  5. <view class="bg-white padding-top-main padding-horizontal-main">
  6. <!-- 位置 -->
  7. <view class="nav-location dis-inline-block round single-text cr-base" @tap="choose_location_event">
  8. <view class="dis-inline-block va-m">
  9. <uni-icons type="map-pin-ellipse" size="12" color="#888"></uni-icons>
  10. </view>
  11. <text class="va-m margin-left-xs">
  12. <block v-if="(user_location || null) != null">{{user_location.name || user_location.address || ''}}</block>
  13. <block v-else>未选择位置</block>
  14. </text>
  15. </view>
  16. <!-- 搜索 -->
  17. <view class="nav-search fr">
  18. <component-search @onsearch="search_button_event" :propIsOnEvent="true" :propIsRequired="false" :propDefaultValue="search_keywords_value" propPlaceholder="输入门店名称" propPlaceholderClass="cr-grey"></component-search>
  19. </view>
  20. </view>
  21. <!-- 分类 -->
  22. <scroll-view v-if="(category || null) != null && category.length > 0" class="nav-base scroll-view-horizontal bg-white oh" scroll-x="true">
  23. <view :class="'item cr-gray dis-inline-block padding-horizontal-main ' + (nav_active_value == 0 ? 'cr-main' : '')" @tap="nav_event" data-value="0">全部</view>
  24. <block v-for="(item, index) in category" :key="index">
  25. <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>
  26. </block>
  27. </scroll-view>
  28. <!-- 列表 -->
  29. <scroll-view :scroll-y="true" class="scroll-box scroll-box-ece-nav" @scrolltolower="scroll_lower" lower-threshold="60">
  30. <block v-if="(data_list || null) != null && data_list.length > 0">
  31. <component-realstore-list :propDataList="data_list" :propFavorUser="favor_user"></component-realstore-list>
  32. </block>
  33. <view v-else>
  34. <!-- 提示信息 -->
  35. <component-no-data :propStatus="data_list_loding_status" :propMsg="data_list_loding_msg"></component-no-data>
  36. </view>
  37. <!-- 结尾 -->
  38. <component-bottom-line :propStatus="data_bottom_line_status"></component-bottom-line>
  39. </scroll-view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. const app = getApp();
  45. import componentNoData from "../../../../components/no-data/no-data";
  46. import componentBottomLine from "../../../../components/bottom-line/bottom-line";
  47. import componentSearch from "../../../../components/search/search";
  48. import componentRealstoreList from "../../../../components/realstore-list/realstore-list";
  49. export default {
  50. data() {
  51. return {
  52. data_list_loding_status: 1,
  53. data_list_loding_msg: '',
  54. data_bottom_line_status: false,
  55. data_list: [],
  56. data_total: 0,
  57. data_page_total: 0,
  58. data_page: 1,
  59. params: null,
  60. data_base: null,
  61. category: [],
  62. search_keywords_value: '',
  63. nav_active_value: 0,
  64. favor_user: [],
  65. // 用户位置信息
  66. user_location: null,
  67. // 自定义分享信息
  68. share_info: {}
  69. };
  70. },
  71. components: {
  72. componentNoData,
  73. componentBottomLine,
  74. componentSearch,
  75. componentRealstoreList
  76. },
  77. props: {},
  78. onLoad(params) {
  79. this.setData({
  80. params: params,
  81. search_keywords_value: params.keywords || '',
  82. nav_active_value: params.category_id || 0,
  83. });
  84. // 数据加载
  85. this.get_data();
  86. },
  87. onShow() {
  88. // 用户位置初始化
  89. this.user_location_init();
  90. },
  91. // 下拉刷新
  92. onPullDownRefresh() {
  93. this.setData({
  94. data_page: 1
  95. });
  96. this.get_data_list(1);
  97. },
  98. methods: {
  99. // 初始化
  100. get_data() {
  101. uni.showLoading({
  102. title: '加载中...'
  103. });
  104. uni.request({
  105. url: app.globalData.get_request_url("index", "search", "realstore"),
  106. method: 'POST',
  107. data: {},
  108. dataType: 'json',
  109. success: res => {
  110. uni.hideLoading();
  111. uni.stopPullDownRefresh();
  112. if (res.data.code == 0) {
  113. var data = res.data.data;
  114. this.setData({
  115. data_base: data.base || null,
  116. category: data.category || [],
  117. favor_user: data.favor_user || [],
  118. });
  119. if ((this.data_base || null) != null) {
  120. // 基础自定义分享
  121. this.setData({
  122. share_info: {
  123. title: this.search_keywords_value || this.data_base.seo_title || this.data_base.application_name,
  124. desc: this.data_base.seo_desc,
  125. path: '/pages/plugins/realstore/search/search',
  126. query: 'category_id='+this.nav_active_value+'&keywords='+this.search_keywords_value
  127. }
  128. });
  129. }
  130. // 获取列表数据
  131. this.get_data_list(1);
  132. } else {
  133. this.setData({
  134. data_list_loding_status: 0,
  135. data_list_loding_msg: res.data.msg
  136. });
  137. app.globalData.showToast(res.data.msg);
  138. }
  139. // 分享菜单处理
  140. app.globalData.page_share_handle(this.share_info);
  141. },
  142. fail: () => {
  143. uni.hideLoading();
  144. uni.stopPullDownRefresh();
  145. this.setData({
  146. data_list_loding_status: 2
  147. });
  148. app.globalData.showToast('服务器请求出错');
  149. }
  150. });
  151. },
  152. // 获取数据列表
  153. get_data_list(is_mandatory) {
  154. // 分页是否还有数据
  155. if ((is_mandatory || 0) == 0) {
  156. if (this.data_bottom_line_status == true) {
  157. uni.stopPullDownRefresh();
  158. return false;
  159. }
  160. }
  161. // 加载loding
  162. uni.showLoading({
  163. title: '加载中...'
  164. });
  165. // 用户位置
  166. var lng = 0;
  167. var lat = 0;
  168. if((this.user_location || null) != null) {
  169. lng = this.user_location.lng || 0;
  170. lat = this.user_location.lat || 0;
  171. }
  172. // 获取数据
  173. uni.request({
  174. url: app.globalData.get_request_url("datalist", "search", "realstore"),
  175. method: 'POST',
  176. data: {
  177. page: this.data_page,
  178. keywords: this.search_keywords_value,
  179. category_id: this.nav_active_value || 0,
  180. lng: lng,
  181. lat: lat
  182. },
  183. dataType: 'json',
  184. success: res => {
  185. uni.hideLoading();
  186. uni.stopPullDownRefresh();
  187. if (res.data.code == 0) {
  188. var data = res.data.data;
  189. if (data.data.length > 0) {
  190. if (this.data_page <= 1) {
  191. var temp_data_list = data.data;
  192. } else {
  193. var temp_data_list = this.data_list || [];
  194. var temp_data = data.data;
  195. for (var i in temp_data) {
  196. temp_data_list.push(temp_data[i]);
  197. }
  198. }
  199. this.setData({
  200. data_list: temp_data_list,
  201. data_total: data.total,
  202. data_page_total: data.page_total,
  203. data_list_loding_status: 3,
  204. data_page: this.data_page + 1
  205. });
  206. // 是否还有数据
  207. this.setData({
  208. data_bottom_line_status: (this.data_page > 1 && this.data_page > this.data_page_total)
  209. });
  210. } else {
  211. this.setData({
  212. data_list_loding_status: 0
  213. });
  214. if (this.data_page <= 1) {
  215. this.setData({
  216. data_list: [],
  217. data_bottom_line_status: false
  218. });
  219. }
  220. }
  221. } else {
  222. this.setData({
  223. data_list_loding_status: 0,
  224. data_list_loding_msg: res.data.msg
  225. });
  226. app.globalData.showToast(res.data.msg);
  227. }
  228. },
  229. fail: () => {
  230. uni.hideLoading();
  231. uni.stopPullDownRefresh();
  232. this.setData({
  233. data_list_loding_status: 2
  234. });
  235. app.globalData.showToast('服务器请求出错');
  236. }
  237. });
  238. },
  239. // 滚动加载
  240. scroll_lower(e) {
  241. this.get_data_list();
  242. },
  243. // 导航事件
  244. nav_event(e) {
  245. this.setData({
  246. nav_active_value: e.currentTarget.dataset.value || 0,
  247. data_page: 1
  248. });
  249. this.get_data_list(1);
  250. },
  251. // 搜索事件
  252. search_button_event(e) {
  253. this.setData({
  254. search_keywords_value: e || '',
  255. data_page: 1
  256. });
  257. this.get_data_list(1);
  258. },
  259. // 选择地理位置
  260. choose_location_event(e) {
  261. uni.navigateTo({
  262. url: '/pages/common/open-setting-location/open-setting-location'
  263. });
  264. },
  265. // 地址信息初始化
  266. user_location_init() {
  267. var result = uni.getStorageSync(app.globalData.data.cache_userlocation_key) || null;
  268. var data = null;
  269. if (result != null) {
  270. data = {
  271. name: result.name || null,
  272. address: result.address || null,
  273. lat: result.latitude || null,
  274. lng: result.longitude || null
  275. };
  276. }
  277. this.setData({
  278. user_location: data
  279. });
  280. }
  281. }
  282. };
  283. </script>
  284. <style>
  285. @import './search.css';
  286. </style>