diff --git a/pages/goods/search/search.js b/pages/goods/search/search.js index 2fb8bb1..5b25d2a 100644 --- a/pages/goods/search/search.js +++ b/pages/goods/search/search.js @@ -1,9 +1,9 @@ -var t = function (t) { +var t = function(t) { return t && t.__esModule ? t : { default: t }; }(require("../../../utils/LoadMore.js")), ut = require("../../../utils/util.js"), - a = getApp(), e = new t.default(), rq = a.request, oo = a.globalData.setting; + a = getApp(), e = new t.default(), rq = a.request, oo = a.globalData.setting; Page({ data: { @@ -18,157 +18,147 @@ Page({ requestUrl: "", //hotWords: [ [ "手机", "小米", "iphone" ], [ "三星", "华为", "冰箱" ] ] hotWords: null, - is_no_plus:1, + tabname: "sort", //排序的字段 adname: "asc", //升降的字段 - rq_data: null, - searchRecord: [], - keyword: '', - is_his: 0, + rq_data:null, + + + searchRecord: [], + keyword: '', + is_his:0, + + hiddenClear: true, }, - - onLoad: function (t) { - this.data.rq_data = t; + + onLoad: function(t) { + this.data.rq_data=t; //接受有没有导购的参数 - var first_leader = t.first_leader; - if (first_leader) { - getApp().globalData.first_leader = first_leader; + var first_leader=t.first_leader; + if(first_leader){ + getApp().globalData.first_leader=first_leader; //调用接口判断是不是会员 - getApp().request.promiseGet("/api/weshop/shoppingGuide/get/" + oo.stoid + "/" + first_leader, {}).then(res => { - if (res.data.code == 0) { - getApp().globalData.guide_id = res.data.data.id; + getApp().request.promiseGet("/api/weshop/shoppingGuide/get/"+oo.stoid+"/"+first_leader,{}).then(res=>{ + if(res.data.code==0){ + getApp().globalData.guide_id=res.data.data.id; } }) } - var th = this; - //调用接口判断商家plus有没有过期 - rq.promiseGet("/store/storemoduleendtime/page?store_id=" + oo.stoid + "&type=3", {}).then(res => { - if (res.data.code == 0) { - var arr = res.data.data.pageData; - if (arr.length > 0) { - var item = arr[0]; - if (item.is_sy == 0) { - var now = Date.parse(new Date()); now = now / 1000; - if (item.end_time < now) { - th.setData({ is_no_plus: 0 }) - } - } - } - } - }) - a.getConfig2(function (rs) { - console.log('getConfig2', rs); - var arr = new Array(), arr2 = new Array(); - if (rs.hot_keywords != null && ut.trim(rs.hot_keywords) != "") { - var arr1 = rs.hot_keywords.split('|'); - for (var i = 0; i < arr1.length; i++) { - if (i % 5 == 0 && i != 0) { - arr.push(arr2); - arr2 = []; - } else { - arr2.push(arr1[i]); - } - } - if (arr2.length > 0) arr.push(arr2); - th.setData({ hotWords: arr }); - } - - - //计算等级价相关 - var swithc_list = rs.switch_list; - var sw_arr = JSON.parse(swithc_list); - console.log('sw_arr', sw_arr); - //---如果后台又开等级卡的开关--- - if (sw_arr.rank_switch && sw_arr.rank_switch == "2") { - th.setData({ rank_switch: true }); - var user = getApp().globalData.userInfo; - var ti = setInterval(function () { - if (!user) return false; - clearInterval(ti); - //---回调卡的列表--- - th.getPlusCardType(function (ob) { - th.setData({ card_list: ob.card_list }); - if (user.card_field) { - var str = user['card_expiredate'].replace(/-/g, '/'); - var end = new Date(str); - end = Date.parse(end) / 1000; - var now = ut.gettimestamp(); - //--- 判断是等级会员,且在有效期范围内 --- - if (user.card_field && now < end) { - var card_name = ob.name_map.get(user.card_field); - if (card_name.length > 7) card_name = card_name.substring(0, 8); - th.setData({ card_field: user.card_field, card_name: card_name, card_list: ob.card_list }); - } - } - }) - }, 500) + var th=this; + a.getConfig2(function(rs) { + var arr=new Array(),arr2=new Array(); + if (rs.hot_keywords != null && ut.trim(rs.hot_keywords)!="" ){ + var arr1 = rs.hot_keywords.split('|'); + for (var i = 0; i < arr1.length;i++){ + if(i%5==0 && i!=0){ + arr.push(arr2); + arr2=[]; + }else{ + arr2.push(arr1[i]); + } } - - - + if (arr2.length > 0) arr.push(arr2); + th.setData({ hotWords: arr}); + } + + + //计算等级价相关 + var swithc_list=rs.switch_list; + var sw_arr=JSON.parse(swithc_list); + //---如果后台又开等级卡的开关--- + if(sw_arr.rank_switch && sw_arr.rank_switch=="2"){ + th.setData({rank_switch:true}); + var user=getApp().globalData.userInfo; + var ti=setInterval(function(){ + if(!user) return false; + clearInterval(ti); + //---回调卡的列表--- + th.getPlusCardType(function(ob){ + th.setData({card_list:ob.card_list}); + if(user.card_field ){ + var str = user['card_expiredate'].replace(/-/g, '/'); + var end = new Date(str); + end = Date.parse(end) / 1000; + var now = ut.gettimestamp(); + + //--- 判断是等级会员,且在有效期范围内 --- + if(user.card_field && now7) card_name=card_name.substring(0,8); + th.setData({card_field:user.card_field,card_name:card_name,card_list:ob.card_list}); + } + } + }) + },500) + } + + + + }) + //e.init(this, "", "requestData"); + var url = this.data.baseUrl; + + //扫一扫过来,显示搜索的内容 + var s_key = t.s_key; + if (s_key){ + s_key=s_key.trim(); + this.search(s_key); this.openSearchModal(); + return; + } + + if (0 != t.brand_id && t.brand_id!=undefined){ url += "&brand_id=" + t.brand_id;} + if (0 != t.nation_id && t.nation_id!=undefined) { url += "&nation_id=" + t.nation_id;} + if (0 != t.max_price && t.max_price!=undefined) { url += "&min_pirce=" + t.min_pirce + "&max_price=" + t.max_price;} + if (0 != t.ladder_id && t.ladder_id != undefined) { + url += "&ladder_id=" + t.ladder_id; + this.setData({ + baseUrl:url, }) - //e.init(this, "", "requestData"); - var url = this.data.baseUrl; - - //扫一扫过来,显示搜索的内容 - var s_key = t.s_key; - if (s_key) { - s_key = s_key.trim(); - this.search(s_key); this.openSearchModal(); - return; - } - - if (0 != t.brand_id && t.brand_id != undefined) { url += "&brand_id=" + t.brand_id; } - if (0 != t.nation_id && t.nation_id != undefined) { url += "&nation_id=" + t.nation_id; } - if (0 != t.max_price && t.max_price != undefined) { url += "&min_pirce=" + t.min_pirce + "&max_price=" + t.max_price; } - if (0 != t.ladder_id && t.ladder_id != undefined) { - url += "&ladder_id=" + t.ladder_id; - this.setData({ - baseUrl: url, - - }) - } - if (url != this.data.baseUrl) return this.requestSearch(url); - this.openSearchModal(); + } + if (url != this.data.baseUrl) return this.requestSearch(url); + this.openSearchModal(); // 获取历史搜索记录 - this.getHistorySearch(); + this.getHistorySearch(); }, - changeTab: function (t) { - var ord = t.currentTarget.dataset.href; - var ad = t.currentTarget.dataset.ad; - - var url = this.data.requestUrl; - - if (this.data.tabname != ord) { - this.setData({ tabname: ord, adname: "desc" }); - } else { - ad = ad == "desc" ? "asc" : "desc"; - this.setData({ adname: ad }); - } - this.resetData(), this.requestSearch(url); + + + changeTab: function(t) { + var ord = t.currentTarget.dataset.href; + var ad = t.currentTarget.dataset.ad; + + var url = this.data.requestUrl; + + if (this.data.tabname != ord) { + this.setData({ tabname: ord, adname: "desc" }); + } else { + ad = ad == "desc" ? "asc" : "desc"; + this.setData({ adname: ad }); + } + this.resetData(), this.requestSearch(url); }, //-----------真的调用地址进行搜索------------ - requestSearch: function (t) { - if (this.data.loading) return false; - this.data.loading = 1; - var e = this, th = e; - if (getApp().globalData.userInfo) { - t += "&user_id=" + getApp().globalData.userInfo.user_id; - } + requestSearch: function(t) { + console.log('t===>', t); + if(this.data.loading) return false; + this.data.loading=1; + var e = this,th=e; + if(getApp().globalData.userInfo) { + t += "&user_id=" + getApp().globalData.userInfo.user_id; + } this.data.requestUrl = t; - var user_id = getApp().globalData.user_id; - if (!user_id) user_id = 0; + var user_id=getApp().globalData.user_id; + if(!user_id) user_id=0; - getApp().request.promiseGet(t, { data: { is_mainshow: 1, isonsale: 1, store_id: oo.stoid, orderField: e.data.tabname, orderType: e.data.adname, page: e.data.currentPage } }).then(async res => { - th.data.loading = 0; - if (ut.ajax_ok(res)) { - if (!e.data.requestData) e.data.requestData = []; - for (let i in res.data.data.pageData) { - let item = res.data.data.pageData[i]; + getApp().request.promiseGet(t, {data:{is_mainshow: 1, isonsale: 1, store_id: oo.stoid,orderField: e.data.tabname, orderType: e.data.adname, page: e.data.currentPage}}).then(async res=>{ + th.data.loading=0; + if(ut.ajax_ok(res)){ + if(!e.data.requestData) e.data.requestData=[]; + for(let i in res.data.data.pageData){ + let item=res.data.data.pageData[i]; item.original_img = th.data.url + item.original_img; /*-- @@ -185,48 +175,48 @@ Page({ })--*/ var prom_type = item.prom_type; //0普通商品 1秒杀 6拼单 2团购 4积分购 - var prom_id = item.prom_id; - var now = ut.gettimestamp(); + var prom_id=item.prom_id; + var now=ut.gettimestamp(); var url = ""; - switch (prom_type) { + switch (prom_type){ case 1: - url = "/api/ms/flash_sale/getNew/" + oo.stoid + "/" + user_id + "/" + prom_id; + url = "/api/ms/flash_sale/getNew/" +oo.stoid + "/" +user_id+"/"+ prom_id; break; case 2: - url = "/api/weshop/goods/groupBuy/getActInfo/" + oo.stoid + "/" + item.goods_id + "/" + prom_id + url ="/api/weshop/goods/groupBuy/getActInfo/" +oo.stoid + "/" +item.goods_id+"/"+ prom_id break; case 4: - url = "/api/weshop/integralbuy/get/" + oo.stoid + "/" + prom_id; + url ="/api/weshop/integralbuy/get/"+oo.stoid +"/"+prom_id; break; case 6: url = "/api/weshop/teamlist/get/" + oo.stoid + "/" + prom_id; - await getApp().request.promiseGet("/api/weshop/teamlist/pageteam/1", { - data: { - store_id: oo.stoid, - is_end: 0, - is_show: 1, - user_id: getApp().globalData.user_id, - pageSize: 1000, + await getApp().request.promiseGet("/api/weshop/teamlist/pageteam/1",{ + data:{ + store_id: oo.stoid, + is_end: 0, + is_show: 1, + user_id: getApp().globalData.user_id, + pageSize:1000, } - }).then(pd => { - let pd_list = pd.data.data.pageData; - if (res.data.code == 0 && pd_list.length > 0) { - var flag = pd_list.some(pd => { - return pd.goods_id == item.goods_id - }) - - if (!flag) { - item.prom_type = 0; - item.prom_id = 0; - item.prom_price = null; - } + }).then(pd=>{ + let pd_list=pd.data.data.pageData; + if(res.data.code==0 && pd_list.length>0){ + var flag = pd_list.some(pd=>{ + return pd.goods_id==item.goods_id + }) + + if(!flag){ + item.prom_type=0; + item.prom_id=0; + item.prom_price=null; + } } - }) + }) break; case 8: var presell_id = prom_id; var url1 = "/api/weshop/marketing/marketingPresellList/list"; - var rd = { + var rd= { store_id: oo.stoid, presell_id: presell_id, goods_id: item.goods_id @@ -238,247 +228,269 @@ Page({ if (res.data.code == 0 && res.data.data && res.data.data.length > 0) { var arr = res.data.data[0]; item.prom_price = arr.luck_goods_price; - item.sales_sum = arr.buy_goodnum + (arr.virtual_qty ? arr.virtual_qty : 0); + item.sales_sum=arr.buy_goodnum+(arr.virtual_qty?arr.virtual_qty:0); } }) break; default: - break - } - if (url != null && url != '') { + break; + }; + if(url!=null && url!=''){ await getApp().request.promiseGet(url, {}).then(async res => { - var prom = null; - if (res.data.code == 0 && res.data.data) { - prom = res.data.data; + var prom =null; + if(res.data.code==0 && res.data.data){ + prom=res.data.data; - if (prom != null && prom.is_end == 0 && prom.end_time > now && (prom.start_time < now || (prom.show_time && prom.show_time < now))) { + if (prom != null && prom.is_end==0 && prom.end_time>now && (prom.start_time 0) { - pagePath += "&first_leader=" + getApp().globalData.user_id; - } else { - pagePath += "?first_leader=" + getApp().globalData.user_id; + if(pagePath.indexOf("?")>0){ + pagePath+="&first_leader="+getApp().globalData.user_id; + }else{ + pagePath+="?first_leader="+getApp().globalData.user_id; } } - console.log("11-11" + pagePath); + // console.log("11-11"+pagePath); return { title: "商品搜索", - path: pagePath, + path:pagePath, } }, //---------图片失败,默认图片-------- bind_bnerr: function (e) { - var _errImg = e.target.dataset.errorimg; - var _errObj = {}; - _errObj[_errImg] = this.data.url + "/miniapp/images/default_g_img.gif"; - this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; + var _errImg = e.target.dataset.errorimg; + var _errObj = {}; + _errObj[_errImg] = this.data.url+ "/miniapp/images/default_g_img.gif"; + this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; }, - - //--- 获取卡类列表 --- - getPlusCardType: function (func) { - var storid = oo.stoid; - var th = this; - getApp().request.promiseGet("/api/weshop/plus/vip/mem/bership/list?" + "storeId=" + storid, {}).then(res => { - var plusCard = res.data.data; - var arr = [1219, 2089, 3031]; - var new_arr = new Array(); - var card_name_map = new Map(); - var user = getApp().globalData.userInfo; - - for (var i = 0; i < plusCard.length; i++) { - if ((!user || user.card_field == null || user.card_field == "") && (plusCard[i].IsStopBuy == true)) { - continue; - } - var name = "card" + plusCard[i].CorrPrice.toLowerCase(); - card_name_map.set(name, plusCard[i].CardName); - new_arr.push(plusCard[i]); - - } - - var ob = { "card_list": new_arr, "name_map": card_name_map }; - func(ob); - }) - }, - - - getInput(e) { - this.setData({ - keyword: e.detail.value - }); - }, - - historyRecord(w) { - let keyword = w; - let self = this; - if (!keyword) { - keyword = this.data.key_str.trim(); - } - let searchRecord = this.data.searchRecord; - if (!searchRecord || searchRecord.length == 0) searchRecord = wx.getStorageSync('searchRecord') || []; - - if (keyword) { - - var index = searchRecord.indexOf(keyword); - if (index > -1) { - // 已经存在该值 - searchRecord.splice(index, 1); - searchRecord.unshift(keyword); - - // 将历史记录添加到缓存中 - wx.setStorage({ - key: 'searchRecord', - data: searchRecord, - success: function (res) { - self.setData({ - searchRecord, - }) - } - }) - - return; - } else { - if (searchRecord.length >= 10) { - searchRecord.pop(); // 删除最早的一条记录 - }; - searchRecord.unshift(keyword); - - // // 将历史记录添加到缓存中 - wx.setStorage({ - key: 'searchRecord', - data: searchRecord, - success: function (res) { - self.setData({ - searchRecord, - }) - } - }) - }; - }; - }, - - - - - getHistorySearch() { - this.setData({ - searchRecord: wx.getStorageSync('searchRecord') || [] //若无存储则为空 - }); - }, - - clearSearchRecord() { - wx.clearStorageSync('searchRecord'); - this.setData({ - searchRecord: [] - }); - }, - - go_url: function (e) { - var url = e.currentTarget.dataset.url; + + //--- 获取卡类列表 --- + getPlusCardType: function (func) { + var storid = oo.stoid; + var th = this; + getApp().request.promiseGet("/api/weshop/plus/vip/mem/bership/list?" + "storeId=" + storid, {}).then(res => { + var plusCard = res.data.data; + var arr = [1219, 2089, 3031]; + var new_arr = new Array(); + var card_name_map=new Map(); + var user = getApp().globalData.userInfo; + + for (var i = 0; i < plusCard.length; i++) { + if ((!user || user.card_field==null || user.card_field=="") && (plusCard[i].IsStopBuy==true)) { + continue; + } + var name="card"+plusCard[i].CorrPrice.toLowerCase(); + card_name_map.set(name,plusCard[i].CardName); + new_arr.push(plusCard[i]); + + } + + var ob={"card_list":new_arr,"name_map":card_name_map}; + func(ob); + }) + }, + + + getInput(e) { + let val = e.detail.value; + if(val) { + this.setData({ + keyword: e.detail.value, + hiddenClear: false, + }); + } else { + this.setData({ + hiddenClear: true, + }); + } + + }, + + historyRecord(w) { + let keyword =w; + let self = this; + if(!keyword){ + keyword = this.data.key_str.trim(); + } + let searchRecord = this.data.searchRecord; + if(!searchRecord || searchRecord.length==0) searchRecord=wx.getStorageSync('searchRecord') || []; + + if(keyword) { + + var index=searchRecord.indexOf(keyword); + if(index > -1) { + // 已经存在该值 + searchRecord.splice(index,1); + searchRecord.unshift(keyword); + + // 将历史记录添加到缓存中 + wx.setStorage({ + key: 'searchRecord', + data: searchRecord, + success: function(res) { + self.setData({ + searchRecord, + }) + } + }) + + return; + } else { + if(searchRecord.length >= 10) { + searchRecord.pop(); // 删除最早的一条记录 + }; + searchRecord.unshift(keyword); + + // // 将历史记录添加到缓存中 + wx.setStorage({ + key: 'searchRecord', + data: searchRecord, + success: function(res) { + self.setData({ + searchRecord, + }) + } + }) + }; + }; + }, + + + + // 获取历史搜索记录 + getHistorySearch() { + this.setData({ + searchRecord: wx.getStorageSync('searchRecord') || [] //若无存储则为空 + }); + }, + + // 清除历史搜素记录 + clearSearchRecord() { + wx.clearStorageSync('searchRecord'); + this.setData({ + searchRecord: [] + }); + }, + + go_url:function (e) { + var url=e.currentTarget.dataset.url; getApp().goto(url); - } + }, + + clearInput() { + this.setData({ + keyword: '', + hiddenClear: true, + openSearchModal: true, + }); + } }); \ No newline at end of file diff --git a/pages/goods/search/search.wxml b/pages/goods/search/search.wxml index e4196f4..a034b28 100644 --- a/pages/goods/search/search.wxml +++ b/pages/goods/search/search.wxml @@ -1,32 +1,81 @@ + - - - - - - - - - + + +
+ + + + + + + +
+
+ + + + + + + 历史搜索 + + + + + {{item}} + + + 暂无历史搜索记录 + + + + 热门搜索 + + + {{item}} + + + + + + + + + + + + + + + + + + + + + @@ -38,10 +87,10 @@ - {{item.prom_integral}}积分 - + - ¥{{item.prom_price}} - + {{item.prom_integral}}积分 + + + ¥{{item.prom_price}} + ¥{{item.market_price}} 评论{{item.comment_count}} 已售{{item.sales_sum}} @@ -49,7 +98,7 @@ - + @@ -57,9 +106,9 @@ ¥{{item[card_field]}} - - - {{card_name}} + + + {{card_name}} @@ -85,10 +134,10 @@ ¥{{g_filter.get_card_price(item,card_list,0)}} - - - {{g_filter.get_card_price(item,card_list,1)}} - + + + {{g_filter.get_card_price(item,card_list,1)}} + 评论{{item.comment_count}} 已售{{item.sales_sum}} @@ -117,12 +166,22 @@ - - - 没有相关的数据 - 去逛逛 - + + + + + 没有相关的数据 + 去逛逛 + + + + + +
+ + + - + + + + \ No newline at end of file diff --git a/pages/goods/search/search.wxss b/pages/goods/search/search.wxss index 1711e17..fa01b29 100644 --- a/pages/goods/search/search.wxss +++ b/pages/goods/search/search.wxss @@ -1,16 +1,18 @@ .container { color: #666; + overflow: visible; } .nav-item { - float: left; + /* float: left; width: 30%; height: 90rpx; - line-height: 90rpx; + line-height: 90rpx; */ + padding: 14rpx 10rpx; display: flex; align-items: center; justify-content: center; - font-size: 32rpx; + font-size: 28rpx; border-bottom: 2rpx solid #E6E6E6; background-color: #fff; } @@ -160,7 +162,7 @@ } .search-modal { - position: fixed; + /* position: fixed; top: 0; right: 0; left: 0; @@ -170,12 +172,16 @@ overflow-x: hidden; padding: 80rpx 30rpx; font-size: 30rpx; - color: #555; + color: #555; */ } .search-bar { - width: 100%; - box-sizing: border-box; + /* width: 100%; + box-sizing: border-box; */ + background-color: white; + position: sticky; + top: 0; + z-index: 1; } .search-input { @@ -212,21 +218,21 @@ .hot-title { font-size: 35rpx; color: black; - margin-bottom: 30rpx; + /* margin-bottom: 30rpx; */ } .hot-row { display: flex; /*--justify-content: space-between---*/ - padding: 15rpx 10rpx; + padding: 10rpx 0; } .hot-item { - padding: 8rpx 8rpx; - border: 1rpx solid #e0e0e0; - border-radius: 10rpx; + padding: 6rpx 20rpx; + border: 2rpx solid #e0e0e0; + border-radius: 40rpx; font-size: 28rpx; - margin-left: 15rpx; + margin-right: 16rpx; } /* .card_bg { @@ -303,9 +309,69 @@ background-color: #f0f0f0; color: #7b7b7b; border: none; - margin-bottom: 8rpx; + margin-bottom: 16rpx; } .history:first-of-type { + /* margin-left: 0; */ +} + +.input-box { + position: relative; + flex: 1; + padding-left: 50rpx; + padding-right: 70rpx; + background-color: #f0f0f0; + border-radius: 60rpx; +} + +.input-box::before { + font-family: iconfont; + position: absolute; + left: 20rpx; + top: 50%; + transform: translateY(-50%); + content: '\e618'; +} + +.input-search { + position: relative; + padding: 10rpx; + font-size: 28rpx; +} + + +.btn { margin-left: 0; + margin-right: 0; + line-height: 1; + padding: 20rpx; + font-size: 30rpx; +} + +.btn::after { + border: none; } + +.icon-guan { + font-size: 20rpx; + padding: 10rpx; + position: absolute; + right: 20rpx; + top: 50%; + transform: translateY(-50%); +} + +.lookat { + display: inline-block; + color: #FF6768; + border: 2rpx solid #FF6768; + border-radius: 80rpx; + font-size: 30rpx; +} + +.no-data .no-data-title { + font-size: 28rpx; + color: #999; +} +