JMApp/pages/goodsSearch/goodsSearch.js
2024-03-20 11:39:05 +08:00

112 lines
3.7 KiB
JavaScript

var t = require("../../@babel/runtime/helpers/interopRequireDefault")(require("../../@babel/runtime/regenerator")), a = require("../../@babel/runtime/helpers/toConsumableArray"), e = require("../../@babel/runtime/helpers/slicedToArray"), i = require("../../@babel/runtime/helpers/asyncToGenerator"), s = (getApp(),
require("../../utils/login.js"));
Page({
data: {
kw: "",
historyList: [],
data: []
},
onLoad: function(t) {
var a = this;
wx.getStorage({
key: "historyList",
success: function(t) {
console.log(t), "getStorage:ok" == t.errMsg && a.setData({
historyList: t.data
});
}
});
},
onReachBottom: function() {
this.getData();
},
onShareAppMessage: function() {},
onUnload: function() {
this.data.historyList.length > 0 && wx.setStorage({
key: "historyList",
data: this.data.historyList
});
},
input: function(t) {
this.setData({
kw: t.detail.value
});
},
submit: function() {
if ("" == this.data.kw.trim()) return wx.showToast({
title: "请输入关键字",
icon: "none"
}), !1;
this.setData({
loading: !1,
page: 1
});
var t = this.data.historyList.indexOf(this.data.kw);
t > -1 && this.data.historyList.splice(t, 1), this.data.historyList.unshift(this.data.kw),
this.setData({
historyList: this.data.historyList
}), this.getData();
},
getData: function() {
var r = this;
return i(t.default.mark(function i() {
var n, o;
return t.default.wrap(function(t) {
for (;;) switch (t.prev = t.next) {
case 0:
if (!r.data.loading && r.data.page && "" != r.data.kw.trim()) {
t.next = 2;
break;
}
return t.abrupt("return", !1);
case 2:
return r.setData({
loading: !0
}), r, t.prev = 4, t.next = 7, s.request(s.baseUrl + "shop/search", {
keyword: r.data.kw
}, !0);
case 7:
n = t.sent, o = n.data, console.log("data,data", o), o.data.length < o.limit ? r.data.page = 0 : r.data.page += 1,
o.data.forEach(function(t) {
var a = t.price.split("."), i = e(a, 2);
t.price_buck = i[0], t.price_cent = i[1];
}), r.setData({
loading: !1,
page: r.data.page,
data: [].concat(a(r.data.data), a(o.data))
}), t.next = 18;
break;
case 15:
t.prev = 15, t.t0 = t.catch(4), console.log(t.t0);
case 18:
case "end":
return t.stop();
}
}, i, null, [ [ 4, 15 ] ]);
}))();
},
selectKw: function(t) {
this.setData({
kw: t.currentTarget.dataset.kw
}), this.submit();
},
clearHistory: function() {
var t = this;
wx.showModal({
title: "提示",
content: "清空后不能恢复哦~",
success: function(a) {
1 == a.confirm && (t.setData({
historyList: []
}), wx.removeStorage({
key: "historyList"
}));
}
});
}
});