wpfw_ewei_wxapp/pages/quickbuy/search.js
2023-02-26 08:10:18 +08:00

299 lines
8.1 KiB
JavaScript

var t = getApp(), e = t.requirejs("core"), a = t.requirejs("jquery"), s = t.requirejs("biz/diyform"), i = t.requirejs("biz/goodspicker");
t.requirejs("foxui");
Page({
data: {
specs: [],
options: [],
diyform: {},
specsTitle: "",
total: 1,
active: "",
slider: "",
tempname: "",
buyType: "",
icons: t.requirejs("icons"),
isFilterShow: !1,
listmode: "block",
listsort: "",
page: 1,
loaded: !1,
loading: !0,
allcategory: [],
catlevel: -1,
opencategory: !1,
category: {},
category_child: [],
category_third: [],
filterBtns: {},
isfilter: 0,
list: [],
params: {},
count: 0,
defaults: {
keywords: "",
isrecommand: "",
ishot: "",
isnew: "",
isdiscount: "",
issendfree: "",
istime: "",
cate: "",
order: "",
by: "desc",
merchid: 0
},
lastcat: "",
fromsearch: !1,
searchRecords: [],
areas: [],
limits: !1,
modelShow: !1,
canload: !0,
quick: "",
pageid: ""
},
onLoad: function(e) {
var s = this;
if (s.setData({
imgUrl: t.globalData.approot
}), setTimeout(function() {
s.setData({
areas: t.getCache("cacheset").areas
});
}, 3e3), !a.isEmptyObject(e)) {
var i = e.isrecommand || e.isnew || e.ishot || e.isdiscount || e.issendfree || e.istime ? 1 : 0;
this.setData({
params: e,
isfilter: i,
filterBtns: e,
fromsearch: e.fromsearch || !1
}), console.log(s.data.params);
}
e.fromsearch || this.getList(), e.quick && s.setData({
quick: e.quick,
pageid: e.id
});
},
onShow: function() {
this.data.fromsearch && this.setFocus();
var e = this;
t.checkAuth(function() {
e.setData({
limits: !0
});
}, 0);
},
onReachBottom: function() {
this.data.loaded || this.data.list.length == this.data.total || 1 == this.data.canload && this.getList();
},
getList: function() {
var t = this;
t.setData({
loading: !0
}), this.data.canload = !1, t.data.params.page = t.data.page, t.data.params.id = t.data.pageid,
e.post("quick/index/searchgoods", t.data.params, function(e) {
var a = {
loading: !1,
count: e.total,
total: e.total,
show: !0
};
e.list || (e.list = []), e.list.length > 0 && (a.page = t.data.page + 1, a.list = t.data.list.concat(e.list),
e.list.length < e.pagesize && (a.loaded = !0)), t.setData(a), t.data.canload = !0;
});
},
changeMode: function() {
"block" == this.data.listmode ? this.setData({
listmode: ""
}) : this.setData({
listmode: "block"
});
},
bindSort: function(t) {
var e = t.currentTarget.dataset.order, a = this.data.params;
if ("" == e) {
if (a.order == e) return;
a.order = "", this.setData({
listorder: ""
});
} else if ("minprice" == e) this.setData({
listorder: ""
}), a.order == e ? "desc" == a.by ? a.by = "asc" : a.by = "desc" : a.by = "asc",
a.order = e, this.setData({
listorder: a.by
}); else if ("sales" == e) {
if (a.order == e) return;
this.setData({
listorder: ""
}), a.order = "sales", a.by = "desc";
}
this.setData({
params: a,
page: 1,
list: [],
loading: !0,
loaded: !1,
sort_selected: e
}), this.getList();
},
showFilter: function() {
this.setData({
isFilterShow: !this.data.isFilterShow
});
},
bindSearch: function(t) {
t.target;
this.setData({
list: [],
loading: !0,
loaded: !1
});
var e = a.trim(t.detail.value), s = this.data.defaults;
"" != e ? (s.keywords = e, this.setData({
page: 1,
params: s,
fromsearch: !1
}), this.getList(), this.setRecord(e)) : (s.keywords = "", this.setData({
page: 1,
params: s,
listorder: "",
fromsearch: !1
}), this.getList());
},
bindInput: function(t) {
var e = a.trim(t.detail.value), s = this.data.defaults;
s.keywords = "", s.order = this.data.params.order, s.by = this.data.params.by, "" == e && (this.setData({
page: 1,
list: [],
loading: !0,
loaded: !1,
params: s,
listorder: s.by,
fromsearch: !0
}), this.getRecord());
},
bindFocus: function(t) {
"" == a.trim(t.detail.value) && this.setData({
fromsearch: !0
});
},
bindback: function() {
wx.navigateBack();
},
bindnav: function(t) {
var e = a.trim(t.currentTarget.dataset.text), s = this.data.defaults;
s.keywords = e, this.setData({
params: s,
page: 1,
fromsearch: !1
}), this.getList(), this.setRecord(e);
},
getRecord: function() {
var e = t.getCache("searchRecords");
this.setData({
searchRecords: e
});
},
setRecord: function(e) {
if ("" != e) {
var s = t.getCache("searchRecords");
if (a.isArray(s)) {
var i = [];
for (var r in i.push(e), s) {
if (i.length > 20) break;
s[r] != e && null != s && "null" != s && i.push(s[r]);
}
s = i;
} else (s = []).push(e);
t.setCache("searchRecords", s);
} else t.setCache("searchRecords", []);
this.getRecord();
},
delRecord: function() {
this.setRecord(""), this.setData({
fromsearch: !0
});
},
setFocus: function() {
var t = this;
setTimeout(function() {
t.setData({
focusin: !0
});
}, 1e3);
},
selectPicker: function(e) {
var a = this;
if (t.checkAuth(function() {
a.setData({
limits: !0
});
}, 1), a.data.limits) {
i.selectpicker(e, a, "goodslist");
}
},
specsTap: function(t) {
i.specsTap(t, this);
},
chooseGift: function(t) {
i.chooseGift(t, this);
},
emptyActive: function() {
this.setData({
active: "",
slider: "out",
tempname: "",
specsTitle: ""
});
},
buyNow: function(t) {
i.buyNow(t, this);
},
getCart: function(t) {
i.getCart(t, this);
},
select: function() {
i.select(this);
},
inputNumber: function(t) {
i.inputNumber(t, this);
},
number: function(t) {
i.number(t, this);
},
onChange: function(t) {
return s.onChange(this, t);
},
DiyFormHandler: function(t) {
return s.DiyFormHandler(this, t);
},
selectArea: function(t) {
return s.selectArea(this, t);
},
bindChange: function(t) {
return s.bindChange(this, t);
},
onCancel: function(t) {
return s.onCancel(this, t);
},
onConfirm: function(t) {
return s.onConfirm(this, t);
},
getIndex: function(t, e) {
return s.getIndex(t, e);
},
cancelclick: function() {
this.setData({
modelShow: !1
});
},
confirmclick: function() {
this.setData({
modelShow: !1
}), wx.openSetting({
success: function(t) {}
});
}
});