Commit 4f22036cc83fa378c3d6c8a57a2b6c0f5e7c6c14

Authored by yvan.ni
1 parent bc2acacf

商品搜索和商品列表

pages/goods/goodsInfo/goodsInfo.js
@@ -798,9 +798,14 @@ Page({ @@ -798,9 +798,14 @@ Page({
798 }); 798 });
799 } 799 }
800 800
801 - //-- 把商品的赋值 -- 801 + //-- 把商品的赋值,同时给活动赋值 --
802 ee.data.fir_goods = JSON.parse(JSON.stringify(t.data.data)); 802 ee.data.fir_goods = JSON.parse(JSON.stringify(t.data.data));
803 - if(ee.data.prom_type!=1 && ee.data.prom_type!=4 && ee.data.prom_type!=6 && ee.data.prom_type!=2) 803 + if(t.data.data.prom_type && t.data.data.prom_id){
  804 + ee.data.prom_type=t.data.data.prom_type;
  805 + ee.data.prom_id=t.data.data.prom_id;
  806 + }
  807 +
  808 + if(ee.data.prom_type!=1 && ee.data.prom_type!=4 && ee.data.prom_type!=6 && ee.data.prom_type!=2)
804 ee.check_is_youhui(ee.data.gid); 809 ee.check_is_youhui(ee.data.gid);
805 810
806 t.data.data.on_time = ut.formatTime(t.data.data.on_time, 'yyyy-MM-dd hh:mm:ss'); 811 t.data.data.on_time = ut.formatTime(t.data.data.on_time, 'yyyy-MM-dd hh:mm:ss');
pages/goods/goodsList/goodsList.js
@@ -42,7 +42,9 @@ Page({ @@ -42,7 +42,9 @@ Page({
42 } 42 }
43 43
44 var th=this; 44 var th=this;
45 - a.init(this, "", "requestData"); 45 +
  46 + //a.init(this, "", "requestData");
  47 +
46 var url = this.data.baseUrl; 48 var url = this.data.baseUrl;
47 this.data.is_new=t.is_new; 49 this.data.is_new=t.is_new;
48 this.data.is_hot=t.is_hot; 50 this.data.is_hot=t.is_hot;
@@ -171,10 +173,12 @@ Page({ @@ -171,10 +173,12 @@ Page({
171 } 173 }
172 this.resetData(), this.requestGoodsList(url); 174 this.resetData(), this.requestGoodsList(url);
173 }, 175 },
174 - requestGoodsList: function(t) {  
175 - var e = this; 176 + requestGoodsList:function(t) {
  177 + if(this.data.loading) return false;
  178 + this.data.loading=1;
  179 + var e = this,th=e;
176 this.data.requestUrl = t; 180 this.data.requestUrl = t;
177 - 181 +
178 //不是商品分组的,不是默认排序的 182 //不是商品分组的,不是默认排序的
179 if(t.indexOf("group_id")==-1 || e.data.tabname!="sort" ){ 183 if(t.indexOf("group_id")==-1 || e.data.tabname!="sort" ){
180 t += "&orderField=" + e.data.tabname; 184 t += "&orderField=" + e.data.tabname;
@@ -182,14 +186,94 @@ Page({ @@ -182,14 +186,94 @@ Page({
182 } 186 }
183 187
184 t +="&page=" + e.data.currentPage; 188 t +="&page=" + e.data.currentPage;
185 - a.request(t,  
186 - function(t) {  
187 - e.setData({is_go:1});  
188 - e.data.currentPage++, null == e.data.allData && (e.data.allData = Object.assign({}, t.data.result)),  
189 - wx.stopPullDownRefresh();  
190 - },  
191 - null, { is_mainshow: 1, isonsale: 1, store_id: oo.stoid}  
192 - ); 189 + getApp().request.promiseGet(t, {data:{is_mainshow: 1, isonsale: 1, store_id: oo.stoid}}).then(async res=>{
  190 + th.data.loading=0;
  191 + e.setData({is_go:1});
  192 + if(ut.ajax_ok(res)){
  193 + e.data.currentPage++;
  194 + if(!e.data.requestData) e.data.requestData=[];
  195 + for(let i in res.data.data.pageData){
  196 + let item=res.data.data.pageData[i];
  197 + item.original_img = th.data.url + item.original_img;
  198 +
  199 + var url="/api/weshop/activitylist/getGoodActInfo";
  200 + var req_data={
  201 + store_id:oo.stoid,goodsidlist:item.goods_id,is_detail:1
  202 + };
  203 + //获取商品的实际活动
  204 + await getApp().request.promiseGet(url, {data:req_data}).then(res=>{
  205 + if(res.data.code==0 && res.data.data && res.data.data.length==1){
  206 + item.prom_type=res.data.data[0].prom_type;
  207 + item.prom_id=res.data.data[0].act_id;
  208 + }
  209 + })
  210 +
  211 + var prom_type = item.prom_type; //0普通商品 1秒杀 6拼单 2团购 4积分购
  212 + var prom_id=item.prom_id;
  213 + var now=ut.gettimestamp();
  214 + var url = "";
  215 + switch (prom_type){
  216 + case 1:
  217 + var user_id=getApp().globalData.user_id;
  218 + if(!user_id) user_id=0;
  219 + url = "/api/ms/flash_sale/getNew/" +oo.stoid + "/" +user_id+"/"+ prom_id;
  220 + break;
  221 + case 2:
  222 + url ="/api/weshop/goods/groupBuy/getActInfo/" +oo.stoid + "/" +item.goods_id+"/"+ prom_id
  223 + break;
  224 + case 4:
  225 + url ="/api/weshop/integralbuy/get/"+oo.stoid +"/"+prom_id;
  226 + break;
  227 + case 6:
  228 + url = "/api/weshop/teamlist/get/" + oo.stoid + "/" + prom_id;
  229 + break;
  230 + case 8:
  231 + var presell_id = prom_id;
  232 + var url1 = "/api/weshop/marketing/marketingPresellList/list";
  233 + var rd= {
  234 + store_id: oo.stoid,
  235 + presell_id: presell_id,
  236 + goods_id: val.goods_id
  237 + }
  238 + //------获取预售从表----------
  239 + await getApp().request.promiseGet(url1, {
  240 + data: rd
  241 + }).then(res => {
  242 + if (res.data.code == 0 && res.data.data && res.data.data.length > 0) {
  243 + var arr = res.data.data[0];
  244 + item.prom_price = arr.luck_goods_price;
  245 + item.sales_sum=arr.buy_goodnum+(arr.virtual_qty?arr.virtual_qty:0);
  246 + }
  247 + })
  248 + break;
  249 + default:
  250 + break
  251 + }
  252 + if(url!=null && url!=''){
  253 + await getApp().request.promiseGet(url, {}).then(res => {
  254 + var prom =null;
  255 + if(res && res.data) prom=res.data.data;
  256 + if (prom != null && prom.is_end==0 && prom.end_time>now && (prom.start_time<now || (prom.show_time && prom.show_time<now)) ) {
  257 + item.prom_price = res.data.data.price;
  258 + if(res.data.data.user_price) item.prom_price=res.data.data.user_price;
  259 + var vNum=res.data.data.virtual_num?res.data.data.virtual_num:0;
  260 + var vNum1=res.data.data.virtualNum?res.data.data.virtualNum:0;
  261 + var vNum2=res.data.data.virtual?res.data.data.virtual:0;
  262 + item.sales_sum=res.data.data.buy_num+(vNum+vNum1+vNum2);
  263 + }else{
  264 + item.prom_type=0;
  265 + item.prom_id=0;
  266 + item.prom_price=null;
  267 + }
  268 + })
  269 + }
  270 +
  271 + e.data.requestData.push(item);
  272 + e.setData({requestData: e.data.requestData})
  273 + }
  274 + }
  275 + })
  276 + wx.stopPullDownRefresh();
193 }, 277 },
194 onReachBottom: function() { 278 onReachBottom: function() {
195 a.canloadMore() && this.requestGoodsList(this.data.requestUrl); 279 a.canloadMore() && this.requestGoodsList(this.data.requestUrl);
pages/goods/goodsList/goodsList.wxml
@@ -62,7 +62,7 @@ @@ -62,7 +62,7 @@
62 <view class="item-cont"> 62 <view class="item-cont">
63 <view class="title ellipsis-2">{{item.goods_name}}</view> 63 <view class="title ellipsis-2">{{item.goods_name}}</view>
64 <!-- 判断是否有活动价 --> 64 <!-- 判断是否有活动价 -->
65 - <block wx:if="{{(item.prom_price>0 || item.prom_integral>0) && item.prom_type!=2}}"> 65 + <block wx:if="{{(item.prom_price>0 || item.prom_integral>0) && item.prom_id>0 }}">
66 <view class="flex on"> 66 <view class="flex on">
67 <!-- 活动价 --> 67 <!-- 活动价 -->
68 <view class="price"> 68 <view class="price">
pages/goods/search/search.js
@@ -31,7 +31,6 @@ Page({ @@ -31,7 +31,6 @@ Page({
31 31
32 onLoad: function(t) { 32 onLoad: function(t) {
33 this.data.rq_data=t; 33 this.data.rq_data=t;
34 -  
35 //接受有没有导购的参数 34 //接受有没有导购的参数
36 var first_leader=t.first_leader; 35 var first_leader=t.first_leader;
37 if(first_leader){ 36 if(first_leader){
@@ -95,7 +94,7 @@ Page({ @@ -95,7 +94,7 @@ Page({
95 94
96 95
97 }) 96 })
98 - e.init(this, "", "requestData"); 97 + //e.init(this, "", "requestData");
99 var url = this.data.baseUrl; 98 var url = this.data.baseUrl;
100 99
101 //扫一扫过来,显示搜索的内容 100 //扫一扫过来,显示搜索的内容
@@ -112,9 +111,8 @@ Page({ @@ -112,9 +111,8 @@ Page({
112 111
113 if (url != this.data.baseUrl) return this.requestSearch(url); 112 if (url != this.data.baseUrl) return this.requestSearch(url);
114 this.openSearchModal(); 113 this.openSearchModal();
115 -  
116 - // 获取历史搜索记录  
117 - this.getHistorySearch(); 114 + // 获取历史搜索记录
  115 + this.getHistorySearch();
118 }, 116 },
119 changeTab: function(t) { 117 changeTab: function(t) {
120 var ord = t.currentTarget.dataset.href; 118 var ord = t.currentTarget.dataset.href;
@@ -134,24 +132,100 @@ Page({ @@ -134,24 +132,100 @@ Page({
134 132
135 //-----------真的调用地址进行搜索------------ 133 //-----------真的调用地址进行搜索------------
136 requestSearch: function(t) { 134 requestSearch: function(t) {
137 - var a = this;  
138 - 135 + if(this.data.loading) return false;
  136 + this.data.loading=1;
  137 + var e = this,th=e;
139 if(getApp().globalData.userInfo){ 138 if(getApp().globalData.userInfo){
140 t += "&user_id=" + getApp().globalData.userInfo.user_id; 139 t += "&user_id=" + getApp().globalData.userInfo.user_id;
141 } 140 }
  141 + this.data.requestUrl = t;
  142 + 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=>{
  143 + th.data.loading=0;
  144 + if(ut.ajax_ok(res)){
  145 + if(!e.data.requestData) e.data.requestData=[];
  146 + for(let i in res.data.data.pageData){
  147 + let item=res.data.data.pageData[i];
  148 + item.original_img = th.data.url + item.original_img;
  149 +
  150 + var url="/api/weshop/activitylist/getGoodActInfo";
  151 + var req_data={
  152 + store_id:oo.stoid,goodsidlist:item.goods_id,is_detail:1
  153 + };
  154 + //获取商品的实际活动
  155 + await getApp().request.promiseGet(url, {data:req_data}).then(res=>{
  156 + if(res.data.code==0 && res.data.data && res.data.data.length==1){
  157 + item.prom_type=res.data.data[0].prom_type;
  158 + item.prom_id=res.data.data[0].act_id;
  159 + }
  160 + })
  161 +
  162 + var prom_type = item.prom_type; //0普通商品 1秒杀 6拼单 2团购 4积分购
  163 + var prom_id=item.prom_id;
  164 + var now=ut.gettimestamp();
  165 + var url = "";
  166 + switch (prom_type){
  167 + case 1:
  168 + var user_id=getApp().globalData.user_id;
  169 + if(!user_id) user_id=0;
  170 + url = "/api/ms/flash_sale/getNew/" +oo.stoid + "/" +user_id+"/"+ prom_id;
  171 + break;
  172 + case 2:
  173 + url ="/api/weshop/goods/groupBuy/getActInfo/" +oo.stoid + "/" +item.goods_id+"/"+ prom_id
  174 + break;
  175 + case 4:
  176 + url ="/api/weshop/integralbuy/get/"+oo.stoid +"/"+prom_id;
  177 + break;
  178 + case 6:
  179 + url = "/api/weshop/teamlist/get/" + oo.stoid + "/" + prom_id;
  180 + break;
  181 + case 8:
  182 + var presell_id = prom_id;
  183 + var url1 = "/api/weshop/marketing/marketingPresellList/list";
  184 + var rd= {
  185 + store_id: oo.stoid,
  186 + presell_id: presell_id,
  187 + goods_id: val.goods_id
  188 + }
  189 + //------获取预售从表----------
  190 + await getApp().request.promiseGet(url1, {
  191 + data: rd
  192 + }).then(res => {
  193 + if (res.data.code == 0 && res.data.data && res.data.data.length > 0) {
  194 + var arr = res.data.data[0];
  195 + item.prom_price = arr.luck_goods_price;
  196 + item.sales_sum=arr.buy_goodnum+(arr.virtual_qty?arr.virtual_qty:0);
  197 + }
  198 + })
  199 + break;
  200 + default:
  201 + break
  202 + }
  203 + if(url!=null && url!=''){
  204 + await getApp().request.promiseGet(url, {}).then(res => {
  205 + var prom =null;
  206 + if(res && res.data) prom=res.data.data;
  207 + if (prom != null && prom.is_end==0 && prom.end_time>now && (prom.start_time<now || (prom.show_time && prom.show_time<now)) ) {
  208 + item.prom_price = res.data.data.price;
  209 + if(res.data.data.user_price) item.prom_price=res.data.data.user_price;
  210 + var vNum=res.data.data.virtual_num?res.data.data.virtual_num:0;
  211 + var vNum1=res.data.data.virtualNum?res.data.data.virtualNum:0;
  212 + var vNum2=res.data.data.virtual?res.data.data.virtual:0;
  213 + item.sales_sum=res.data.data.buy_num+(vNum+vNum1+vNum2);
  214 + }else{
  215 + item.prom_type=0;
  216 + item.prom_id=0;
  217 + item.prom_price=null;
  218 + }
  219 + })
  220 + }
  221 + th.data.requestData.push(item);
  222 + e.setData({requestData: e.data.requestData});
  223 + e.closeSearchModal();
  224 + }
  225 + }
  226 +
  227 + })
142 228
143 - this.data.requestUrl = t,  
144 - //t += "&orderField=" + a.data.tabname;  
145 - //t += "&orderType=" + a.data.adname;  
146 - //t += "&page=" + a.data.currentPage,  
147 - e.request(t, function(t) {  
148 - a.data.currentPage++ ,  
149 - null == a.data.allData && (a.data.allData = t.data.data.pageData),  
150 - a.closeSearchModal();  
151 - },  
152 - null, { is_mainshow: 1, isonsale: 1, store_id: oo.stoid,  
153 - orderField: a.data.tabname, orderType: a.data.adname, page: a.data.currentPage}  
154 - );  
155 }, 229 },
156 onReachBottom: function() { 230 onReachBottom: function() {
157 this.data.openSearchModal || e.canloadMore() && this.requestSearch(this.data.requestUrl); 231 this.data.openSearchModal || e.canloadMore() && this.requestSearch(this.data.requestUrl);
pages/goods/search/search.wxml
@@ -35,7 +35,7 @@ @@ -35,7 +35,7 @@
35 <view class="item-cont"> 35 <view class="item-cont">
36 <view class="title ellipsis-2">{{item.goods_name}}</view> 36 <view class="title ellipsis-2">{{item.goods_name}}</view>
37 <!-- 判断是否有活动价,小程序没有有团购和拼单 --> 37 <!-- 判断是否有活动价,小程序没有有团购和拼单 -->
38 - <block wx:if="{{(item.prom_price>0 || item.prom_integral) && item.prom_type!=2 && item.prom_id>0}}"> 38 + <block wx:if="{{(item.prom_price>0 || item.prom_integral) && item.prom_id>0}}">
39 <!-- 活动价 --> 39 <!-- 活动价 -->
40 <view class="price"> 40 <view class="price">
41 <text wx:if="{{item.prom_integral}}">{{item.prom_integral}}积分</text> 41 <text wx:if="{{item.prom_integral}}">{{item.prom_integral}}积分</text>