123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- (function(global,factory){
- typeof define == 'function' && define('store',['axios','helper'],factory);
- })(this,function(axios,$h){
- axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
- axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
- return {
- baseGet:function(url,successCallback,errorCallback,isMsg){
- axios.get(url).then(function(res){
- if(res.status == 200 && res.data.code == 200){
- successCallback && successCallback(res);
- }else{
- var err = res.data.msg || '请求失败!';
- errorCallback && errorCallback(err);
- isMsg || $h.pushMsgOnce(err);
- }
- }).catch(function(err){
- errorCallback && errorCallback(err);
- $h.pushMsgOnce(err)
- });
- },
- basePost:function(url,data,successCallback,errorCallback,isMsg){
- axios.post(url,data).then(function(res){
- if(res.status == 200 && res.data.code == 200){
- successCallback && successCallback(res);
- }else{
- var err = res.data.msg || '请求失败!';
- errorCallback && errorCallback(err);
- isMsg || $h.pushMsgOnce(err);
- }
- }).catch(function(err){
- errorCallback && errorCallback(err);
- $h.pushMsgOnce(err)
- });
- },
- setCart:function(opt,successCallback,errorCallback){
- axios.get($h.U({
- c:"auth_api",
- a:"set_cart",
- p:opt
- })).then(function(res){
- if(res.status == 200 && res.data.code == 200)
- successCallback && successCallback();
- else{
- var error = res.data.msg || '加入购物车失败!';
- errorCallback && errorCallback(error);
- $h.pushMsg(error);
- }
- }).catch(function(err){
- errorCallback && errorCallback(err);
- $h.pushMsg(err);
- });
- },
- goBuy:function(opt,successCallback,errorCallback){
- axios.get($h.U({
- c:"auth_api",
- a:"now_buy",
- p:opt
- })).then(function(res){
- if(res.status == 200 && res.data.code == 200)
- successCallback && successCallback(res.data.data.cartId);
- else{
- var error = res.data.msg || '订单生成失败!';
- errorCallback && errorCallback(error);
- $h.pushMsg(error);
- }
- }).catch(function(err){
- errorCallback && errorCallback(err);
- $h.pushMsg(err);
- });
- },
- addBargainShare:function(opt,successCallback,errorCallback){
- axios.get($h.U({
- c:"auth_api",
- a:"add_bargain_share",
- p:opt
- })).then(function(res){
- }).catch(function(err){
- });
- },
- likeProduct:function(productId,category,successCallback,errorCallback) {
- axios.get($h.U({
- c:"auth_api",
- a:"like_product",
- p:{productId:productId,category:category}
- })).then(function(res){
- if(res.status == 200 && res.data.code == 200){
- successCallback && successCallback(res.data);
- }else{
- var error = res.data.msg || '点赞失败!';
- errorCallback && errorCallback(error);
- $h.pushMsg(error);
- }
- }).catch(function(err){
- errorCallback && errorCallback(err);
- $h.pushMsg(err)
- });
- },
- bargainFriends:function(bargain,successCallback,errorCallback){
- this.basePost($h.U({
- c:'auth_api',
- a:'set_bargain_help'
- }),bargain,successCallback,errorCallback)
- },
- unlikeProduct:function(productId,category,successCallback,errorCallback) {
- axios.get($h.U({
- c:"auth_api",
- a:"unlike_product",
- p:{productId:productId,category:category}
- })).then(function(res){
- if(res.status == 200 && res.data.code == 200){
- successCallback && successCallback(res.data);
- }else{
- var error = res.data.msg || '取消点赞失败!';
- errorCallback && errorCallback(error);
- $h.pushMsg(error);
- }
- }).catch(function(err){
- errorCallback && errorCallback(err);
- $h.pushMsg(err)
- });
- },
- collectProduct(productId,category,successCallback,errorCallback){
- axios.get($h.U({
- c:'auth_api',
- a:'collect_product',
- p:{productId:productId,category:category}
- })).then(function(res){
- if(res.status == 200 && res.data.code == 200){
- successCallback && successCallback(res.data);
- }else{
- var error = res.data.msg || '收藏失败!';
- errorCallback && errorCallback(error);
- $h.pushMsg(error);
- }
- }).catch(function(err){
- errorCallback && errorCallback(err);
- $h.pushMsg(err)
- });
- },
- unCollectProduct(productId,category,successCallback,errorCallback){
- axios.get($h.U({
- c:'auth_api',
- a:'uncollect_product',
- p:{productId:productId,category:category}
- })).then(function(res){
- if(res.status == 200 && res.data.code == 200){
- successCallback && successCallback(res.data);
- }else{
- var error = res.data.msg || '取消收藏失败!';
- errorCallback && errorCallback(error);
- $h.pushMsg(error);
- }
- }).catch(function(err){
- errorCallback && errorCallback(err);
- $h.pushMsg(err)
- });
- },
- getCartNum:function(callback){
- axios.get($h.U({
- c:'auth_api',
- a:'get_cart_num'
- })).then(function(res){
- if(res.status == 200 && res.data.code == 200){
- callback && callback(res.data.data);
- }else{
- callback && callback(0);
- }
- }).catch(function(){
- callback && callback(0);
- });
- },
- changeCartNum:function(cartId,cartNum,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'change_cart_num',
- p:{cartId:cartId,cartNum:cartNum}
- }),successCallback,errorCallback);
- },
- getCartList:function(successCallback,errorCallback){
- axios.get($h.U({
- c:'auth_api',
- a:'get_cart_list'
- })).then(function(res){
- if(res.status == 200 && res.data.code == 200){
- successCallback && successCallback(res.data.data,res.data);
- }else{
- var error = res.data.msg || '获取购物车数据失败!';
- errorCallback && errorCallback(error);
- $h.pushMsg(error);
- }
- }).catch(function(err){
- errorCallback && errorCallback(err);
- $h.pushMsg(err)
- });
- },
- removeCart:function(cartId,successCallback,errorCallback){
- axios.get($h.U({
- c:'auth_api',
- a:'remove_cart',
- p:{ids:cartId}
- })).then(function(res){
- if(res.status == 200 && res.data.code == 200){
- successCallback && successCallback(res.data.data,res.data);
- }else{
- var error = res.data.msg || '删除失败!';
- errorCallback && errorCallback(error);
- $h.pushMsg(error);
- }
- }).catch(function(err){
- errorCallback && errorCallback(err);
- $h.pushMsg(err)
- });
- },
- getUseCoupon:function(successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'get_use_coupon'
- }),successCallback,errorCallback);
- },
- getArticleList:function(p,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'public_api',
- a:'get_cid_article',
- p:p
- }),successCallback,errorCallback)
- },
- getVideoList:function(p,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'public_api',
- a:'get_video_list',
- p:p
- }),successCallback,errorCallback)
- },
- getCollectProduct:function(p,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'get_user_collect_product',
- p:p
- }),successCallback,errorCallback)
- },
- removeCollectProduct:function(productId,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'remove_user_collect_product',
- p:{productId:productId}
- }),successCallback,errorCallback)
- },
- editUserAddress:function(addressInfo,successCallback,errorCallback){
- this.basePost($h.U({
- c:'auth_api',
- a:'edit_user_address'
- }),addressInfo,successCallback,errorCallback)
- },
- getUserDefaultAddress:function(successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'user_default_address'
- }),successCallback,errorCallback)
- },
- setUserDefaultAddress:function(addressId,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'set_user_default_address',
- p:{addressId:addressId}
- }),successCallback,errorCallback)
- },
- removeUserAddress:function(addressId,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'remove_user_address',
- p:{addressId:addressId}
- }),successCallback,errorCallback)
- },
- submitOrder:function(key,order,successCallback,errorCallback){
- this.basePost($h.U({
- c:'auth_api',
- a:'create_order',
- p:{key:key}
- }),order,successCallback,errorCallback)
- },
- getUserOrderList:function(p,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'get_user_order_list',
- p:p
- }),successCallback,errorCallback);
- },
- removeUserOrder:function(uni,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'user_remove_order',
- p:{uni:uni}
- }),successCallback,errorCallback);
- },
- payOrder:function(uni,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'pay_order',
- p:{uni:uni}
- }),successCallback,errorCallback);
- },
- orderApplyRefund:function(uni,text,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'apply_order_refund',
- p:{uni:uni,text:text}
- }),successCallback,errorCallback);
- },
- orderDetails:function(uni,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'order_details',
- p:{uni:uni}
- }),successCallback,errorCallback);
- },
- userTakeOrder:function(uni,successCallback,errorCallback) {
- this.baseGet($h.U({
- c:'auth_api',
- a:'user_take_order',
- p:{uni:uni}
- }),successCallback,errorCallback);
- },
- getProductCategory:function(successCallback,errorCallback) {
- this.baseGet($h.U({
- c:'auth_api',
- a:'get_product_category'
- }),successCallback,errorCallback);
- },
- userCommentProduct:function(unique,data,successCallback,errorCallback){
- this.basePost($h.U({
- c:'auth_api',
- a:'user_comment_product',
- p:{unique:unique}
- }),data,successCallback,errorCallback)
- },
- getSpreadList:function(p,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'get_spread_list',
- p:p
- }),successCallback,errorCallback);
- },
- getProductList:function(search,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'get_product_list',
- p:search
- }),successCallback,errorCallback);
- },
- getUserBalanceList:function(p,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'user_balance_list',
- p:p
- }),successCallback,errorCallback);
- },
- getUserIntegralList:function(p,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'user_integral_list',
- p:p
- }),successCallback,errorCallback);
- },
- getProductReply:function(p,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'product_reply_list',
- p:p
- }),successCallback,errorCallback);
- },
- getUserAddress:function(successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'user_address_list'
- }),successCallback,errorCallback);
- },
- getProductAttr:function(productId,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'product_attr_detail',
- p:{productId:productId}
- }),successCallback,errorCallback);
- },
- userWechatRecharge:function(price,successCallback,errorCallback) {
- this.baseGet($h.U({
- c:'auth_api',
- a:'user_wechat_recharge',
- p:{price:price}
- }),successCallback,errorCallback);
- },
- getNoticeList:function(p,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'get_notice_list',
- p:p
- }),successCallback,errorCallback);
- },
- seeNotice: function(p,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'see_notice',
- p:p
- }),successCallback,errorCallback);
- },
- getIssueCouponList:function(limit,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'get_issue_coupon_list',
- p:{limit:limit}
- }),successCallback,errorCallback);
- },
- getCategoryProductList:function(limit,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'public_api',
- a:'get_category_product_list',
- p:{limit:limit}
- }),successCallback,errorCallback);
- },
- getBestProductList:function(p,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'public_api',
- a:'get_best_product_list',
- p:p
- }),successCallback,errorCallback);
- },
- userGetCoupon:function(couponId,successCallback,errorCallback){
- this.baseGet($h.U({
- c:'auth_api',
- a:'user_get_coupon',
- p:{couponId:couponId}
- }),successCallback,errorCallback);
- },
- isLogin:function(){
- return $h.getCookie('is_login') == 1;
- },
- goLogin:function(){
- if(!this.isLogin()){
- $h.pushMsg('未登录,立即登陆',function(){
- location.href = $h.U({
- c:'login',
- a:'index',
- p:{ref:window.btoa(unescape(encodeURIComponent( location.href )))}
- });
- });
- return false;
- }
- return true;
- },
- wechatUploadImg:function(wxApi,count,successCallback,errorCallback){
- wxApi.chooseImage({count:count,sizeType:['compressed']},function(localIds){
- $h.prompt('图片上传中...');
- wxApi.uploadImage(localIds,function(serverIds){
- axios.get($h.U({
- c:"public_api",
- a:"wechat_media_id_by_image",
- p:{mediaIds:serverIds}
- })).then(function(result){
- $h.promptClear();
- if(result.status == 200 && result.data.code == 200)
- return Promise.resolve(result.data.data);
- else
- return Promise.reject('上传失败!');
- }).then(function(picList){
- if(!picList) return Promise.reject('请选择上传图片!');
- successCallback && successCallback(picList);
- }).catch(function(err){
- $h.promptClear();
- $h.pushMsgOnce(err);
- errorCallback && errorCallback(err);
- });
- })
- });
- }
- }
- });
|