123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- import { get,post } from "../../common/request.js"
- import stylemap from "../../common/stylemap"
- import share from "../../common/share"
- import pathmap from "../../common/pathmap"
- import { retCartData } from "../../data/car"
- import bindSearch from "../../module/search/search.js"
- const app = getApp();
- // pages/buy/buy.js
- Page(Object.assign({
- /**
- * 页面的初始数据
- */
- data: {
-
- list:false,
- limit:10,
- pageindex:0,
- lock:false,
- searchfouce:false,
- selectbar:null,
- hasloadall:false,
- filters:[
- {
- title:"排序",
- name:"sortby"
- },
- {
- title:"品牌",
- name:"brand"
- },
- {
- title:"价格",
- name:"price"
- },
- {
- title:"更多",
- name:"more"
- }
- ],
- sortbymap:[
- {
- title:"默认排序",
- value:""
- },
- {
- title:"价格最低",
- value:"price&asc"
- },
- {
- title:"价格最高",
- value:"price&desc"
- },
- {
- title:"车龄最短",
- value:"car_age&desc"
- },
- {
- title:"里程最少",
- value:"mileage&asc"
- },
- {
- title:"最新发布",
- value:"new&desc"
- }
- ],
- searchdata:{
- sortby:"",
- price:"",
- keys:"",
- car_age:"",
- mileage:"",
- transmission:"",
- displacement:"",
- emission:"",
- colour:"",
- filterlock:true
- },
- keylist:[],
- morebtheight:app.globalData.isIpx?120:98
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- bindSearch(this);
- //initialheight = initialheight-initialheight%2;
- var searchdata = Object.assign(this.data.searchdata,options);
- this.setData(stylemap);
- this.getWheres();
- this.getList(this.data.searchdata);
- this.loadBrandRecommend()
- },
- transformSearchData:function(searchdata){
- var para = Object.assign({},searchdata);
- var sortby = para.sortby;
- if(sortby){
- var sortinfo = sortby.split("&");
- para.order_key = sortinfo[0];
- para.order_val = sortinfo[1];
- }
- delete para.sortby;
- return para;
- },
- //获取筛选信息
- getWheres:function(){
- var _self = this;
- var wheres = wx.getStorageSync("wheres");
- if(wheres){
- _self.setData({
- wheres: wheres
- })
- }else{
- get(pathmap.wheres, {
- no_brand_series:1
- }, function (json) {
- _self.setData({
- wheres: json.data
- })
- wx.setStorageSync("wheres",json.data);
- })
- }
- },
- loadBrandRecommend:function(){
- var _self = this;
- get(pathmap.brandrecommend, {
- }, function (json) {
- _self.setData({
- brandrecommend:json.data
- })
- })
- },
- getList:function(searchdata){
- var _self = this;
- var para = this.transformSearchData(searchdata);
- if (searchdata.keys){
- searchdata.keylist = searchdata.keys.split(/\W+/);
- }
- para.offset = 0;
- para.limit = this.data.limit;
- if(!this.data.lock){
- this.setData({
- lock:true
- })
- get(pathmap.searchcar, para, function (json) {
- var list = retCartData(json.data&&json.data.list);
- var key = _self.data.searchdata.keys.replace(/(^\s*)|(\s*$)/g, "");
- var keylist = key?key.split(/\s+/):[];
- var obj = {
- lock:false,
- list:list,
- searchdata:searchdata,
- offset:_self.data.limit,
- keylist: keylist
- }
- if(json.data.total<=_self.data.limit){
- obj.hasloadall=true;
- }else{
- obj.hasloadall=false;
- }
- _self.setData(obj);
- if(list.length==0){
- _self.loadLikeCar()
- }
- })
- }
- },
- loadListMore:function(){
- var _self = this;
- var para = this.transformSearchData(this.data.searchdata);
- para.offset = this.data.offset;
- para.limit = this.data.limit;
- if(!this.data.lock&&!this.data.hasloadall){
- this.setData({
- lock:true
- })
- get(pathmap.searchcar, para, function (json) {
- var list = retCartData(json.data&&json.data.list);
- var nextoffset = _self.data.offset+_self.data.limit
- var obj = {
- lock:false,
- list:_self.data.list.concat(list),
- offset:nextoffset
- }
- if(json.data.total<=nextoffset){
- obj.hasloadall=true;
- }else{
- obj.hasloadall=false;
- }
- _self.setData(obj);
- })
- }
- },
- showFilter:function(e){
- var el = e.currentTarget;
- var name = el.dataset.name;
- if(name==this.data.selectbar){
- name=null;
- }
- this.setData({
- selectbar:name
- })
- },
- changeSort:function(e){
- var el = e.currentTarget;
- var name = el.dataset.sort;
- var searchdata = Object.assign(this.data.searchdata,{sortby:name});
- this.setData({
- selectbar:""
- })
- this.getList(searchdata);
- },
- changePrice:function(e){
- var el = e.currentTarget;
- var id = el.dataset.id;
- var searchdata = Object.assign(this.data.searchdata,{price:id});
- this.setData({
- selectbar:"" //关闭筛选卡
- })
- this.getList(searchdata);
- },
- loadLikeCar:function(){
- var _self = this;
- if(!this.data.like){
- get(pathmap.like, {
- offset: 0,
- limit: 10
- }, function (json) {
- var list = retCartData(json.data.list)
- _self.setData({
- like: list
- })
- })
- }
- },
- getMoreFilter:function(e){
- var info = e.currentTarget.dataset;
- var obj = {};
- obj[info.type]=info.value;
- this.setData({searchdata:Object.assign(this.data.searchdata,obj)})
- },
- resetFilter:function(){
- this.setData({searchdata:Object.assign(this.data.searchdata,{
- car_age:"",
- mileage:"",
- transmission:"",
- displacement:"",
- emission:"",
- colour:""
- })})
- },
- moreSearch:function(){
- this.setData({selectbar:""})
- this.getList(this.data.searchdata);
- },
- lockFilter:function(e){
- if(e.detail&&!this.data.filterlock){
- this.setData({
- filterlock:true
- })
- }else if(!e.detail&&this.data.filterlock){
- this.setData({
- filterlock:false
- })
- }
- },
- submitsearchinfo:function(obj){
- this.getList(Object.assign(this.data.searchdata,obj));
- this.setData({searchshow:false})
- },
- closeBrandList:function(){
- this.setData({selectbar:""});
- },
- filterBack:function(){
- this.setData({selectbar:""});
- },
- selectSeries:function(e){
- var series = e.detail.series;
- this.setData({
- selectbar:""
- })
- this.getList(Object.assign(this.data.searchdata,{car_series:series.car_series_id}));
- },
- checkAll:function(e){
- this.getList({
- sortby:"",
- price:"",
- car_age:"",
- mileage:"",
- transmission:"",
- displacement:"",
- emission:"",
- colour:"",
- filterlock:true,
- keys:""
- });
- },
- deletekey:function(e){
- var index = e.currentTarget.dataset.index;
- this.data.keylist.splice(index,1)
- var keys = this.data.keylist.join(" ");
- this.submitsearchinfo({keys:keys});
- }
- },share))
|