goods-search.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. <template>
  2. <view>
  3. <!-- 排序 -->
  4. <view class="nav-sort bg-white oh pr">
  5. <view class="nav-sort-content">
  6. <block v-for="(item, index) in search_nav_sort_list" :key="index">
  7. <view class="item tc fl cp" :data-index="index" @tap="nav_sort_event">
  8. <text class="cr-base va-m">{{item.name}}</text>
  9. <image v-if="(item.icon || null) != null" class="icon va-m" :src="common_static_url + 'sort-' + item.icon + '-icon.png'" mode="aspectFill"></image>
  10. </view>
  11. </block>
  12. </view>
  13. <image class="screening-submit pa cp" :src="common_static_url+'search-submit-icon.png'" mode="aspectFill" @tap="popup_form_event_show"></image>
  14. <image class="show-type-submit pa cp" :src="common_static_url+'show-'+(data_show_type_value == 0 ? 'grid' : 'list')+'-icon.png'" mode="aspectFill" @tap="data_show_type_event"></image>
  15. </view>
  16. <!-- 列表 -->
  17. <scroll-view :scroll-y="true" class="scroll-box scroll-box-ece-nav" @scrolltolower="scroll_lower" lower-threshold="60">
  18. <view v-if="data_list.length > 0" class="padding-horizontal-main padding-top-main oh">
  19. <component-goods-list :propData="{style_type: data_show_type_value, goods_list: data_list}" :propLabel="plugins_label_data" :propCurrencySymbol="currency_symbol"></component-goods-list>
  20. </view>
  21. <view v-else>
  22. <!-- 提示信息 -->
  23. <component-no-data :propStatus="data_list_loding_status"></component-no-data>
  24. </view>
  25. <!-- 结尾 -->
  26. <component-bottom-line :propStatus="data_bottom_line_status"></component-bottom-line>
  27. </scroll-view>
  28. <!-- 筛选条件 popup -->
  29. <component-popup :propShow="is_show_popup_form" propPosition="left" @onclose="popup_form_event_close">
  30. <form @submit="form_submit_event" class="popup-form oh">
  31. <view class="search-map padding-main bg-base">
  32. <view class="padding-main border-radius-main bg-white">
  33. <view class="map-item map-base br-b">
  34. <text>筛选出</text>
  35. <text class="cr-main"> {{data_total}} </text>
  36. <text>条数据</text>
  37. <text class="fr cr-red cp" @tap="map_remove_event">清除</text>
  38. </view>
  39. <!-- 搜索关键字 -->
  40. <input type="text" confirm-type="search" placeholder="其实搜索很简单^_^ !" name="wd" :value="(post_data.wd || '')" class="map-keywords wh-auto round bg-base margin-top-lg" placeholder-class="cr-grey">
  41. </view>
  42. <!-- 品牌 -->
  43. <view v-if="((search_map_list.brand_list || null) != null && search_map_list.brand_list.length > 0) || ((search_map_info.brand || null) != null)" class="map-item padding-horizontal-main padding-top-main border-radius-main bg-white spacing-mt">
  44. <view class="map-nav br-b pr">
  45. <text>品牌</text>
  46. <text class="arrow-bottom pa cr-grey cp" v-if="search_map_list.brand_list.length > 3" @tap="more_event" data-value="brand_list">更多</text>
  47. </view>
  48. <view v-if="(search_map_info.brand || null) != null && (params.brand || null) != null" class="map-content brand-info oh margin-top-lg">
  49. <image v-if="(search_map_info.brand.logo || null) != null" :src="search_map_info.brand.logo" mode="aspectFit" class="fl"></image>
  50. <view v-else class="info-logo-empty tc fl">{{search_map_info.brand.name}}</view>
  51. <view class="info-right fr">
  52. <view v-if="(search_map_info.brand.logo || null) != null" class="info-name">{{search_map_info.brand.name}}</view>
  53. <view v-if="(search_map_info.brand.describe || null) != null" class="info-desc multi-text cr-grey">{{search_map_info.brand.describe}}</view>
  54. </view>
  55. </view>
  56. <view v-else class="map-content map-images-text-item map-brand-container oh margin-top-lg" :style="'height:' + map_fields_list.brand_list.height + ';'">
  57. <block v-for="(item, index) in search_map_list.brand_list" :key="index">
  58. <view :class="'item fl cr-base radius cp single-text tc ' + (item.active == 1 ? 'cr-main br-main' : '')" @tap="map_item_event" :data-index="index" data-field="brand_list">
  59. <image v-if="(item.logo || null) != null" :src="item.logo" mode="aspectFit"></image>
  60. <text v-else>{{item.name}}</text>
  61. </view>
  62. </block>
  63. </view>
  64. </view>
  65. <!-- 分类 -->
  66. <view v-if="(search_map_list.category_list || null) != null && search_map_list.category_list.length > 0" class="map-item padding-horizontal-main padding-top-main border-radius-main bg-white spacing-mt">
  67. <view class="map-nav pr br-b">
  68. <text>分类</text>
  69. <text class="arrow-bottom pa cr-grey cp" v-if="search_map_list.category_list.length > 3" @tap="more_event" data-value="category_list">更多</text>
  70. </view>
  71. <view class="map-content map-text-item map-category-container oh margin-top-lg" :style="'height:' + map_fields_list.category_list.height + ';'">
  72. <block v-for="(item, index) in search_map_list.category_list" :key="index">
  73. <view :class="'item fl cr-base radius cp ' + (item.active == 1 ? 'cr-main br-main' : '')" @tap="map_item_event" :data-index="index" data-field="category_list">{{item.name}}</view>
  74. </block>
  75. </view>
  76. </view>
  77. <!-- 价格 -->
  78. <view v-if="(search_map_list.screening_price_list || null) != null && search_map_list.screening_price_list.length > 0" class="map-item padding-horizontal-main padding-top-main border-radius-main bg-white spacing-mt">
  79. <view class="map-nav br-b pr">
  80. <text>价格</text>
  81. <text class="arrow-bottom pa cr-grey cp" v-if="search_map_list.screening_price_list.length > 3" @tap="more_event" data-value="screening_price_list">更多</text>
  82. </view>
  83. <view class="map-content map-text-item screening-price-container oh margin-top-lg" :style="'height:' + map_fields_list.screening_price_list.height + ';'">
  84. <block v-for="(item, index) in search_map_list.screening_price_list" :key="index">
  85. <view :class="'item fl cr-base radius cp ' + (item.active == 1 ? 'cr-main br-main' : '')" @tap="map_item_event" :data-index="index" data-field="screening_price_list">{{item.name}}</view>
  86. </block>
  87. </view>
  88. </view>
  89. <!-- 属性 -->
  90. <view v-if="(search_map_list.goods_params_list || null) != null && search_map_list.goods_params_list.length > 0" class="map-item padding-horizontal-main padding-top-main border-radius-main bg-white spacing-mt">
  91. <view class="map-nav br-b pr">
  92. <text>属性</text>
  93. <text class="arrow-bottom pa cr-grey cp" v-if="search_map_list.goods_params_list.length > 3" @tap="more_event" data-value="goods_params_list">更多</text>
  94. </view>
  95. <view class="map-content map-text-item goods-params-container oh margin-top-lg" :style="'height:' + map_fields_list.goods_params_list.height + ';'">
  96. <block v-for="(item, index) in search_map_list.goods_params_list" :key="index">
  97. <view :class="'item fl cr-base radius cp ' + (item.active == 1 ? 'cr-main br-main' : '')" @tap="map_item_event" :data-index="index" data-field="goods_params_list">{{item.value}}</view>
  98. </block>
  99. </view>
  100. </view>
  101. <!-- 规格 -->
  102. <view v-if="(search_map_list.goods_spec_list || null) != null && search_map_list.goods_spec_list.length > 0" class="map-item padding-horizontal-main padding-top-main border-radius-main bg-white spacing-mt">
  103. <view class="map-nav br-b pr">
  104. <text>规格</text>
  105. <text class="arrow-bottom pa cr-grey cp" v-if="search_map_list.goods_spec_list.length > 3" @tap="more_event" data-value="goods_spec_list">更多</text>
  106. </view>
  107. <view class="map-content map-text-item goods-spec-container oh margin-top-lg" :style="'height:' + map_fields_list.goods_spec_list.height + ';'">
  108. <block v-for="(item, index) in search_map_list.goods_spec_list" :key="index">
  109. <view :class="'item fl cr-base radius cp ' + (item.active == 1 ? 'cr-main br-main' : '')" @tap="map_item_event" :data-index="index" data-field="goods_spec_list">{{item.value}}</view>
  110. </block>
  111. </view>
  112. </view>
  113. <view class="search-submit padding-main pa">
  114. <button form-type="submit" class="bg-main cr-white text-size wh-auto round" :disabled="popup_form_loading_status" hover-class="none">确认</button>
  115. </view>
  116. </view>
  117. </form>
  118. </component-popup>
  119. <!-- 快捷导航 -->
  120. <component-quick-nav></component-quick-nav>
  121. </view>
  122. </template>
  123. <script>
  124. const app = getApp();
  125. import componentQuickNav from "../../components/quick-nav/quick-nav";
  126. import componentPopup from "../../components/popup/popup";
  127. import componentNoData from "../../components/no-data/no-data";
  128. import componentBottomLine from "../../components/bottom-line/bottom-line";
  129. import componentGoodsList from "../../components/goods-list/goods-list";
  130. var common_static_url = app.globalData.get_static_url('common');
  131. export default {
  132. data() {
  133. return {
  134. common_static_url: common_static_url,
  135. data_list_loding_status: 1,
  136. data_bottom_line_status: false,
  137. data_list: [],
  138. data_total: 0,
  139. data_page_total: 0,
  140. data_page: 1,
  141. params: null,
  142. post_data: {},
  143. is_show_popup_form: false,
  144. popup_form_loading_status: false,
  145. // 自定义分享信息
  146. share_info: {},
  147. // 排序导航
  148. search_nav_sort_index: 0,
  149. search_nav_sort_list: [
  150. { name: "综合", field: "default", sort: "asc", "icon": null },
  151. { name: "销量", field: "sales_count", sort: "asc", "icon": "default" },
  152. { name: "热度", field: "access_count", sort: "asc", "icon": "default" },
  153. { name: "价格", field: "min_price", sort: "asc", "icon": "default" },
  154. { name: "最新", field: "id", sort: "asc", "icon": "default" }
  155. ],
  156. // 数据展示样式(0图文、1九方格)
  157. data_show_type_value: 1,
  158. // 基础配置
  159. currency_symbol: app.globalData.data.currency_symbol,
  160. // 搜素条件
  161. search_map_list: {
  162. brand_list: [],
  163. category_list: [],
  164. screening_price_list: [],
  165. goods_params_list: [],
  166. goods_spec_list: []
  167. },
  168. search_map_info: [],
  169. map_fields_list: {
  170. brand_list: {height: "100rpx", default: "100rpx", form_key: "brand_ids"},
  171. category_list: {height: "82rpx", default: "82rpx", form_key: "category_ids"},
  172. screening_price_list: {height: "82rpx", default: "82rpx", form_key: "screening_price_values"},
  173. goods_params_list: {height: "82rpx", default: "82rpx", form_key: "goods_params_values"},
  174. goods_spec_list: {height: "82rpx", default: "82rpx", form_key: "goods_spec_values"}
  175. },
  176. // 标签插件
  177. plugins_label_data: null
  178. };
  179. },
  180. components: {
  181. componentQuickNav,
  182. componentPopup,
  183. componentNoData,
  184. componentBottomLine,
  185. componentGoodsList
  186. },
  187. props: {},
  188. onLoad(params) {
  189. this.setData({
  190. params: params,
  191. post_data: {
  192. wd: params.keywords || ''
  193. }
  194. });
  195. // 数据加载
  196. this.init();
  197. },
  198. onShow() {
  199. // 初始化配置
  200. this.init_config();
  201. },
  202. // 下拉刷新
  203. onPullDownRefresh() {
  204. this.setData({
  205. data_page: 1
  206. });
  207. this.get_data_list(1);
  208. },
  209. methods: {
  210. // 初始化配置
  211. init_config(status) {
  212. if ((status || false) == true) {
  213. this.setData({
  214. currency_symbol: app.globalData.get_config('currency_symbol')
  215. });
  216. } else {
  217. app.globalData.is_config(this, 'init_config');
  218. }
  219. },
  220. // 获取数据
  221. init() {
  222. // 获取数据
  223. this.get_data();
  224. },
  225. // 搜索
  226. search_event() {
  227. this.setData({
  228. data_list: [],
  229. data_page: 1
  230. });
  231. this.get_data_list(1);
  232. },
  233. // 初始化数据
  234. get_data() {
  235. uni.showLoading({
  236. title: '加载中...',
  237. mask: true
  238. });
  239. var post_data = this.request_map_handle();
  240. uni.request({
  241. url: app.globalData.get_request_url("index", "search"),
  242. method: 'POST',
  243. data: post_data,
  244. dataType: 'json',
  245. success: res => {
  246. uni.hideLoading();
  247. uni.stopPullDownRefresh();
  248. if (res.data.code == 0) {
  249. var data = res.data.data;
  250. this.setData({
  251. search_map_info: data.search_map_info || [],
  252. search_map_list: {
  253. brand_list: data.brand_list || [],
  254. category_list: data.category_list || [],
  255. screening_price_list: data.screening_price_list || [],
  256. goods_params_list: data.goods_params_list || [],
  257. goods_spec_list: data.goods_spec_list || []
  258. },
  259. plugins_label_data: (data.plugins_label_data || null) == null || (data.plugins_label_data.base || null) == null || (data.plugins_label_data.data || null) == null || data.plugins_label_data.data.length <= 0 ? null : data.plugins_label_data
  260. });
  261. // 获取数据列表
  262. this.get_data_list(1);
  263. } else {
  264. this.setData({
  265. data_list_loding_status: 0
  266. });
  267. app.globalData.showToast(res.data.msg);
  268. }
  269. // 基础自定义分享
  270. var category_id = this.params.category_id || 0;
  271. var brand = this.params.brand || 0;
  272. var keywords = this.params.keywords || '';
  273. this.setData({
  274. share_info: {
  275. path: '/pages/goods-search/goods-search',
  276. query: 'category_id=' + category_id + '&brand=' + brand + '&keywords=' + keywords
  277. }
  278. });
  279. // 分享菜单处理
  280. app.globalData.page_share_handle(this.share_info);
  281. },
  282. fail: () => {
  283. uni.hideLoading();
  284. uni.stopPullDownRefresh();
  285. this.setData({
  286. data_list_loding_status: 2
  287. });
  288. app.globalData.showToast('服务器请求出错');
  289. }
  290. });
  291. },
  292. // 获取数据列表
  293. get_data_list(is_mandatory) {
  294. // 分页是否还有数据
  295. if ((is_mandatory || 0) == 0) {
  296. if (this.data_bottom_line_status == true) {
  297. uni.stopPullDownRefresh();
  298. return false;
  299. }
  300. }
  301. // 获取数据
  302. uni.showLoading({
  303. title: '加载中...',
  304. mask: true
  305. });
  306. var post_data = this.request_map_handle();
  307. uni.request({
  308. url: app.globalData.get_request_url("datalist", "search"),
  309. method: 'POST',
  310. data: post_data,
  311. dataType: 'json',
  312. success: res => {
  313. uni.hideLoading();
  314. uni.stopPullDownRefresh();
  315. if (res.data.code == 0) {
  316. var data = res.data.data;
  317. if (data.data.length > 0) {
  318. if (this.data_page <= 1) {
  319. var temp_data_list = data.data;
  320. } else {
  321. var temp_data_list = this.data_list || [];
  322. var temp_data = data.data;
  323. for (var i in temp_data) {
  324. temp_data_list.push(temp_data[i]);
  325. }
  326. }
  327. this.setData({
  328. data_list: temp_data_list,
  329. data_total: data.total,
  330. data_page_total: data.page_total,
  331. data_list_loding_status: 3,
  332. data_page: this.data_page + 1
  333. });
  334. // 是否还有数据
  335. this.setData({
  336. data_bottom_line_status: (this.data_page > 1 && this.data_page > this.data_page_total)
  337. });
  338. } else {
  339. this.setData({
  340. data_list_loding_status: 0,
  341. data_total: 0
  342. });
  343. if (this.data_page <= 1) {
  344. this.setData({
  345. data_list: [],
  346. data_bottom_line_status: false
  347. });
  348. }
  349. }
  350. } else {
  351. this.setData({
  352. data_list_loding_status: 0
  353. });
  354. app.globalData.showToast(res.data.msg);
  355. }
  356. },
  357. fail: () => {
  358. uni.hideLoading();
  359. uni.stopPullDownRefresh();
  360. this.setData({
  361. data_list_loding_status: 2
  362. });
  363. app.globalData.showToast('服务器请求出错');
  364. }
  365. });
  366. },
  367. // 搜索条件处理
  368. request_map_handle() {
  369. var params = this.params;
  370. var post_data = this.post_data;
  371. post_data['page'] = this.data_page;
  372. // 指定分类、品牌
  373. post_data['category_id'] = params['category_id'] || 0;
  374. post_data['brand'] = params['brand'] || 0;
  375. // 搜索条件
  376. var temp_field = this.map_fields_list;
  377. var temp_list = this.search_map_list;
  378. for (var i in temp_field) {
  379. if (temp_list[i] != null != null && temp_list[i].length > 0) {
  380. var temp = {};
  381. var index = 0;
  382. for (var k in temp_list[i]) {
  383. if ((temp_list[i][k]['active'] || 0) == 1) {
  384. switch (i) {
  385. // 价格
  386. case 'screening_price_list':
  387. temp[index] = temp_list[i][k]['min_price'] + '-' + temp_list[i][k]['max_price'];
  388. break;
  389. // 属性、规格
  390. case 'goods_params_list':
  391. case 'goods_spec_list':
  392. temp[index] = temp_list[i][k]['value'];
  393. break;
  394. // 默认取值id
  395. default:
  396. temp[index] = temp_list[i][k]['id'];
  397. }
  398. index++;
  399. }
  400. }
  401. post_data[temp_field[i]['form_key']] = app.globalData.get_length(temp) > 0 ? JSON.stringify(temp) : '';
  402. }
  403. }
  404. // 排序
  405. var temp_index = this.search_nav_sort_index;
  406. var temp_search_nav_sort = this.search_nav_sort_list;
  407. post_data['order_by_type'] = temp_search_nav_sort[temp_index]['sort'] == 'desc' ? 'asc' : 'desc';
  408. post_data['order_by_field'] = temp_search_nav_sort[temp_index]['field'];
  409. return post_data;
  410. },
  411. // 滚动加载
  412. scroll_lower(e) {
  413. this.get_data_list();
  414. },
  415. // 搜索条件
  416. form_submit_event(e) {
  417. this.setData({
  418. post_data: e.detail.value,
  419. data_page: 1
  420. });
  421. this.popup_form_event_close();
  422. this.get_data_list(1);
  423. },
  424. // 筛选条件关闭
  425. popup_form_event_close(e) {
  426. this.setData({
  427. is_show_popup_form: false
  428. });
  429. },
  430. // 筛选条件开启
  431. popup_form_event_show(e) {
  432. this.setData({
  433. is_show_popup_form: true
  434. });
  435. },
  436. // 排序事件
  437. nav_sort_event(e) {
  438. var index = e.currentTarget.dataset.index || 0;
  439. var temp_search_nav_sort = this.search_nav_sort_list;
  440. var temp_sort = temp_search_nav_sort[index]['sort'] == 'desc' ? 'asc' : 'desc';
  441. for (var i in temp_search_nav_sort) {
  442. if (i != index) {
  443. if (temp_search_nav_sort[i]['icon'] != null) {
  444. temp_search_nav_sort[i]['icon'] = 'default';
  445. }
  446. temp_search_nav_sort[i]['sort'] = 'desc';
  447. }
  448. }
  449. temp_search_nav_sort[index]['sort'] = temp_sort;
  450. if (temp_search_nav_sort[index]['icon'] != null) {
  451. temp_search_nav_sort[index]['icon'] = temp_sort;
  452. }
  453. this.setData({
  454. search_nav_sort_index: index,
  455. search_nav_sort_list: temp_search_nav_sort,
  456. data_page: 1
  457. });
  458. this.get_data_list(1);
  459. },
  460. // 条件-更多数据展示事件
  461. more_event(e) {
  462. var value = e.currentTarget.dataset.value || null;
  463. var temp_more = this.map_fields_list;
  464. if (value != null && (temp_more[value] || null) != null) {
  465. temp_more[value]['height'] = temp_more[value]['height'] == 'auto' ? temp_more[value]['default'] : 'auto';
  466. this.setData({
  467. map_fields_list: temp_more
  468. });
  469. }
  470. },
  471. // 条件-选择事件
  472. map_item_event(e) {
  473. var index = e.currentTarget.dataset.index;
  474. var field = e.currentTarget.dataset.field;
  475. var temp_list = this.search_map_list;
  476. if ((temp_list[field] || null) != null && (temp_list[field][index] || null) != null) {
  477. temp_list[field][index]['active'] = (temp_list[field][index]['active'] || 0) == 0 ? 1 : 0;
  478. this.setData({
  479. search_map_list: temp_list
  480. });
  481. }
  482. },
  483. // 条件-清空
  484. map_remove_event(e) {
  485. var temp_list = this.search_map_list;
  486. var temp_post = this.post_data;
  487. // 关键字
  488. temp_post['wd'] = '';
  489. // 品牌、分类、价格、属性、规格
  490. for (var i in temp_list) {
  491. if((temp_list[i] || null) != null && temp_list[i].length > 0) {
  492. for(var k in temp_list[i]) {
  493. temp_list[i][k]['active'] = 0;
  494. }
  495. }
  496. }
  497. // 排序导航
  498. var temp_search_nav_sort = this.search_nav_sort_list;
  499. for (var i in temp_search_nav_sort) {
  500. temp_search_nav_sort[i]['sort'] = 'asc';
  501. temp_search_nav_sort[i]['icon'] = (temp_search_nav_sort[i]['field'] == 'default') ? null : 'default';
  502. }
  503. // 关闭弹窗、分页恢复1页、重新获取数据
  504. this.setData({
  505. search_map_list: temp_list,
  506. post_data: temp_post,
  507. is_show_popup_form: false,
  508. search_nav_sort_list: temp_search_nav_sort,
  509. search_nav_sort_index: 0,
  510. data_page: 1
  511. });
  512. this.get_data_list(1);
  513. },
  514. // 数据展示类型
  515. data_show_type_event(e) {
  516. this.setData({data_show_type_value: this.data_show_type_value == 0 ? 1 : 0});
  517. }
  518. }
  519. };
  520. </script>
  521. <style>
  522. @import './goods-search.css';
  523. </style>