0000
This commit is contained in:
112
pages/goodsSearch/goodsSearch.js
Normal file
112
pages/goodsSearch/goodsSearch.js
Normal file
@@ -0,0 +1,112 @@
|
||||
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"
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
6
pages/goodsSearch/goodsSearch.json
Normal file
6
pages/goodsSearch/goodsSearch.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"navigationBarTitleText": "聚美汽服",
|
||||
"usingComponents": {
|
||||
"recomond-list": "../goodsDetails/recomondList/recomondList"
|
||||
}
|
||||
}
|
||||
24
pages/goodsSearch/goodsSearch.wxml
Normal file
24
pages/goodsSearch/goodsSearch.wxml
Normal file
@@ -0,0 +1,24 @@
|
||||
<view>
|
||||
<view class="fixed">
|
||||
<view class="top">
|
||||
<view class="search">
|
||||
<input bindconfirm="submit" bindinput="input" class="input-placeholder" placeholder="搜索你心仪的商品" placeholderClass="placeholder" value="{{kw}}"></input>
|
||||
<view class="icon-search iconfont icon-sousuo"></view>
|
||||
<view class="img-close iconfont icon-guanbi"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="message" wx:if="{{historyList.length>0&&data.length==0}}">
|
||||
<view class="title">历史记录 <view bindtap="clearHistory" class="delete">
|
||||
<image src="/img/delete.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
<view class="tag-list">
|
||||
<view :key="index" bindtap="selectKw" class="tag" data-kw="{{item}}" wx:for="{{historyList}}"> {{item}} </view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="goods-list">
|
||||
<recomond-list list="{{data}}"></recomond-list>
|
||||
</view>
|
||||
<view class="loading" wx:if="{{loading}}">正在加载...</view>
|
||||
</view>
|
||||
113
pages/goodsSearch/goodsSearch.wxss
Normal file
113
pages/goodsSearch/goodsSearch.wxss
Normal file
@@ -0,0 +1,113 @@
|
||||
.top {
|
||||
background-color: #06a2b3;
|
||||
padding: 4vw;
|
||||
}
|
||||
|
||||
.top .search {
|
||||
-webkit-box-align: center;
|
||||
-ms-flex-align: center;
|
||||
align-items: center;
|
||||
color: #fff;
|
||||
display: -webkit-box;
|
||||
display: -ms-flexbox;
|
||||
display: -webkit-flex;
|
||||
display: flex;
|
||||
height: 10.667vw;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.top .search input {
|
||||
background: hsla(0,0%,96%,.3);
|
||||
border: none;
|
||||
border-radius: 5.333vw;
|
||||
color: #fff;
|
||||
font-size: 3.733vw;
|
||||
font-weight: 500;
|
||||
height: 100%;
|
||||
line-height: 10.667vw;
|
||||
padding-left: 12.8vw;
|
||||
padding-right: 12vw;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.top .search .icon-search {
|
||||
font-size: 4.267vw;
|
||||
left: 5.333vw;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
|
||||
.message {
|
||||
background-color: #fff;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
padding: 9.333vw 2.933vw 2.933vw;
|
||||
position: fixed;
|
||||
right: 0;
|
||||
top: 18.667vw;
|
||||
z-index: 106;
|
||||
}
|
||||
|
||||
.message .title {
|
||||
color: #787878;
|
||||
font-size: 3.467vw;
|
||||
font-weight: 500;
|
||||
line-height: 4vw;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.tag-list {
|
||||
display: -webkit-box;
|
||||
display: -ms-flexbox;
|
||||
display: -webkit-flex;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 5.333vw;
|
||||
margin-top: 4vw;
|
||||
}
|
||||
|
||||
.tag-list .tag {
|
||||
background-color: #f6f6f6;
|
||||
border-radius: 3.733vw;
|
||||
color: #2a2a2a;
|
||||
font-size: 3.467vw;
|
||||
font-weight: 500;
|
||||
height: 7.467vw;
|
||||
line-height: 7.467vw;
|
||||
margin: 0 .933vw 3.2vw 1.067vw;
|
||||
padding-left: 3.2vw;
|
||||
padding-right: 3.2vw;
|
||||
}
|
||||
|
||||
.delete {
|
||||
height: 60rpx;
|
||||
position: absolute;
|
||||
right: -15rpx;
|
||||
top: -15rpx;
|
||||
width: 60rpx;
|
||||
}
|
||||
|
||||
.delete image {
|
||||
height: 40rpx;
|
||||
margin: 10rpx;
|
||||
width: 40rpx;
|
||||
}
|
||||
|
||||
.goods-list {
|
||||
border-top: 2.667vw solid #f8f8f8;
|
||||
padding: 0 4vw 5.333vw;
|
||||
}
|
||||
|
||||
.loading {
|
||||
background: #fafafa;
|
||||
color: #969799;
|
||||
font-size: 14px;
|
||||
line-height: 50px;
|
||||
text-align: center;
|
||||
}
|
||||
Reference in New Issue
Block a user