Commit cff0e1914eccb0d510930d0824f902ab40b96d89

Authored by yvan.ni
1 parent 363b8983

自定义模板商品分组, 减少接口的调用

components/diy_goodsGroup/diy_goodsGroup.js
1   -// var e = function(e) {
2   -// return e && e.__esModule ? e : {
3   -// default: e
4   -// };
5   -// }(require("../../utils/LoadMore3.js")),
6   -// n = new e.default(),
7 1 var t = getApp(),
8 2 a = t.request,
9 3 o = t.globalData.setting,
... ... @@ -82,7 +76,6 @@ Component({
82 76 },
83 77 methods: {
84 78 // 这里是一个自定义方法
85   -
86 79 init: function (classstyle_id, wgroup) {
87 80 var th = this;
88 81 var g_id = this.data.g_id;
... ... @@ -93,9 +86,11 @@ Component({
93 86 }
94 87  
95 88 var th = this,
96   - app = getApp(),
97   - index = 0,
98   - gdata = [];
  89 + app = getApp(),
  90 + index = 0,
  91 + gdata = [];
  92 +
  93 + classstyle_id = classstyle_id + "";
99 94 switch (classstyle_id) {
100 95 case "1":
101 96 g_id.forEach(function (val, ind) {
... ... @@ -146,15 +141,15 @@ Component({
146 141 })
147 142 break;
148 143 case "2":
149   - console.log(2222222222222222222);
  144 +
150 145 var item = {};
151 146 app.request.promiseGet("/api/weshop/goods/page", {
152 147 data: {
153   - store_id: 1,
  148 + store_id: os.stoid ,
154 149 is_recommend: th.data.is_recommend,
155 150 is_hot: th.data.is_hot,
156 151 is_new: th.data.is_new,
157   - pageSize: th.data.goodscount ,
  152 + pageSize: th.data.goodscount,
158 153 page: th.data.currentPage,
159 154 }
160 155 }).then(res => {
... ... @@ -164,38 +159,34 @@ Component({
164 159 goods_btn: res.data.data.pageData,
165 160 total: res.data.data.total
166 161 })
167   - console.log(66666666677777777777);
168   - console.log(res.data.data.total);
169   - console.log(res.data);
170   - console.log(this.data.total);
171 162 th.data.currentPage++;
172 163  
173 164 goods.forEach(function (val, ind) {
174 165 var item = {};
175 166 var prom_id = null;
176 167 console.log(val.goodsid);
177   - app.request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + val.goods_id, {}).then(res => {
178   - //商品地址
179   - var goods = res.data.data;
  168 + //app.request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + val.goods_id, {}).then(res => {
  169 + //商品地址
  170 + //var goods = res.data.data;
180 171  
181   - item.goods_name = goods.goods_name;
182   - item.goods_img = th.data.imghost + goods.original_img;
183   - item.market_price = goods.market_price;
184   - item.shop_price = goods.shop_price;
185   - item.sales_sum = goods.sales_sum;
186   - item.goods_id = goods.goods_id;
187   - prom_id = res.data.data.prom_id;
  172 + item.goods_name = val.goods_name;
  173 + item.goods_img = th.data.imghost + val.original_img;
  174 + item.market_price = val.market_price;
  175 + item.shop_price = val.shop_price;
  176 + item.sales_sum = val.sales_sum;
  177 + item.goods_id = val.goods_id;
  178 + prom_id = val.prom_id;
188 179  
189   - var prom_type = res.data.data.prom_type; //0普通商品 1秒杀 6拼单
  180 + var prom_type = res.data.data.prom_type; //0普通商品 1秒杀 6拼单
190 181  
191   - var url = "";
192   - if (prom_type == 1) {
193   - url = "/api/weshop/teamlist/get/" + os.stoid + "/" + prom_id;
194   - } else if (prom_type == 6) {
195   - url = "/api/ms/flash_sale/get/" + os.stoid + "/" + prom_id;
196   - }
197   - return app.request.promiseGet(url, {})
198   - }).then(res => {
  182 + var url = "";
  183 + if (prom_type == 1) {
  184 + url = "/api/weshop/teamlist/get/" + os.stoid + "/" + prom_id;
  185 + } else if (prom_type == 6) {
  186 + url = "/api/ms/flash_sale/get/" + os.stoid + "/" + prom_id;
  187 + }
  188 +
  189 + app.request.promiseGet(url, {}).then(res => {
199 190 var prom = res.data.data;
200 191 if (prom != null) {
201 192 item.shop_price = res.data.data.price;
... ... @@ -203,19 +194,18 @@ Component({
203 194 th.data.requestData.push(item);
204 195 th.setData({
205 196 goods_array: th.data.requestData,
206   - page: th.data.currentPage-1,
  197 + page: th.data.currentPage - 1,
207 198 });
208 199 })
209 200 })
210 201  
211 202 })
212   -
213 203 break;
214 204 case "3":
215 205 var item = {};
216 206 app.request.promiseGet("/api/weshop/goodsGroup/pageGoodsList", {
217 207 data: {
218   - store_id: 1,
  208 + store_id:os.stoid ,
219 209 gpid: wgroup,
220 210 pageSize: th.data.goodscount,
221 211 page: th.data.currentPage,
... ... @@ -223,45 +213,41 @@ Component({
223 213 }).then(res => {
224 214 //商品地址
225 215 var goods = res.data.data.pageData;
226   - console.log("333333333zwp" );
227   - console.log(res.data.data);
228 216 th.setData({
229   - goods_btn: res.data.data.pageData,
230   - total: res.data.data.total
  217 + goods_btn: res.data.data.pageData, total: res.data.data.total
231 218 })
232   - console.log("goods_btn");
233   - console.log(th.data.goods_btn);
  219 +
234 220 th.data.currentPage++;
235 221 goods.forEach(function (val, ind) {
236 222 var item = {};
237 223 var prom_id = null;
238 224 console.log(val.goodsid);
239   - app.request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + val.goods_id, {}).then(res => {
240   - //商品地址
241   - var goods = res.data.data;
242   - console.log("goods");
243   - console.log(goods);
244   - // th.setData({
245   - // goods_btn: res.data.data
246   - // })
247   - item.goods_name = goods.goods_name;
248   - item.goods_img = th.data.imghost + goods.original_img;
249   - item.market_price = goods.market_price;
250   - item.shop_price = goods.shop_price;
251   - item.sales_sum = goods.sales_sum;
252   - item.goods_id = goods.goods_id;
253   - prom_id = res.data.data.prom_id;
  225 + //app.request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + val.goods_id, {}).then(res => {
  226 + //商品地址
  227 + var goods = res.data.data;
  228 + console.log("goods");
  229 + console.log(goods);
  230 + // th.setData({
  231 + // goods_btn: res.data.data
  232 + // })
  233 + item.goods_name = val.goods_name;
  234 + item.goods_img = th.data.imghost + val.original_img;
  235 + item.market_price = val.market_price;
  236 + item.shop_price = val.shop_price;
  237 + item.sales_sum = val.sales_sum;
  238 + item.goods_id = val.goods_id;
  239 + prom_id = val.prom_id;
254 240  
255   - var prom_type = res.data.data.prom_type; //0普通商品 1秒杀 6拼单
  241 + var prom_type = res.data.data.prom_type; //0普通商品 1秒杀 6拼单
256 242  
257   - var url = "";
258   - if (prom_type == 1) {
259   - url = "/api/weshop/teamlist/get/" + os.stoid + "/" + prom_id;
260   - } else if (prom_type == 6) {
261   - url = "/api/ms/flash_sale/get/" + os.stoid + "/" + prom_id;
262   - }
263   - return app.request.promiseGet(url, {})
264   - }).then(res => {
  243 + var url = "";
  244 + if (prom_type == 1) {
  245 + url = "/api/weshop/teamlist/get/" + os.stoid + "/" + prom_id;
  246 + } else if (prom_type == 6) {
  247 + url = "/api/ms/flash_sale/get/" + os.stoid + "/" + prom_id;
  248 + }
  249 +
  250 + app.request.promiseGet(url, {}).then(res => {
265 251 var prom = res.data.data;
266 252 if (prom != null) {
267 253 item.shop_price = res.data.data.price;
... ... @@ -269,14 +255,16 @@ Component({
269 255 th.data.requestData.push(item);
270 256 th.setData({
271 257 goods_array: th.data.requestData,
272   - page: th.data.currentPage-1,
  258 + page: th.data.currentPage - 1,
273 259 });
274 260 })
275 261 })
  262 +
276 263 })
277 264 break;
278 265 }
279 266 },
  267 +
280 268 setLoading: function () {
281 269 var that = this;
282 270 that.init(that.data.classstyle_id, that.data.wgroup);
... ... @@ -284,10 +272,10 @@ Component({
284 272  
285 273 //图片失败,默认图片
286 274 bind_bnerr3: function (e) {
287   - var _errImg = e.target.dataset.errorimg;
288   - var _errObj = {};
289   - _errObj[_errImg] = this.data.imghost+"/public/images/default_goods_image_240.gif";
290   - this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
291   - },
  275 + var _errImg = e.target.dataset.errorimg;
  276 + var _errObj = {};
  277 + _errObj[_errImg] = this.data.imghost + "/public/images/default_goods_image_240.gif";
  278 + this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
  279 + }
292 280 }
293 281 })
294 282 \ No newline at end of file
... ...