|
|
|
//小程序开发api接口
|
|
|
|
const API_BASE_URL = 'https://mall.gylservice.com/gw?module=app'
|
|
|
|
|
|
|
|
const requestServer = (url, method, data) => {
|
|
|
|
let _url = API_BASE_URL + url
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
var userInfo = wx.getStorageSync('userInfo');
|
|
|
|
var token = userInfo.token;
|
|
|
|
var accessId = wx.getStorageSync('accessId');
|
|
|
|
// console.log('token:' + token);
|
|
|
|
wx.request({
|
|
|
|
url: _url,
|
|
|
|
method: method,
|
|
|
|
data: data,
|
|
|
|
header: {
|
|
|
|
'content-type': 'application/x-www-form-urlencoded',
|
|
|
|
// accessId: accessId,
|
|
|
|
language: '',
|
|
|
|
"Accept": "*/*",
|
|
|
|
},
|
|
|
|
dataType: 'json',
|
|
|
|
success(res) {
|
|
|
|
resolve(res.data)
|
|
|
|
},
|
|
|
|
fail(error) {
|
|
|
|
reject(error)
|
|
|
|
},
|
|
|
|
complete(aaa) {
|
|
|
|
//加载完成
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
//promise
|
|
|
|
Promise.prototype.finally = function(callback) {
|
|
|
|
var Promise = this.constructor
|
|
|
|
return this.then(
|
|
|
|
function(value) {
|
|
|
|
Promise.resolve(callback()).then(
|
|
|
|
function() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function(reason) {
|
|
|
|
Promise.resolve(callback()).then(
|
|
|
|
function() {
|
|
|
|
throw reason;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
requestServer,
|
|
|
|
appIndex: (data) => { //获取用户会话密钥
|
|
|
|
return requestServer('&action=app&m=index', 'post', data)
|
|
|
|
},
|
|
|
|
/* 首页 */
|
|
|
|
homeIndex: (data) => { //首页
|
|
|
|
return requestServer('&action=index&app=index', 'post', data)
|
|
|
|
},
|
|
|
|
newArrivalIndex: (data) => { //新品上市
|
|
|
|
return requestServer('&action=index&app=new_arrival', 'post', data)
|
|
|
|
},
|
|
|
|
recommendIndex: (data) => { //好物优选
|
|
|
|
return requestServer('&action=index&app=recommend', 'post', data)
|
|
|
|
},
|
|
|
|
productIndex: (data) => { //商品详情
|
|
|
|
return requestServer('&action=product&app=index', 'post', data)
|
|
|
|
},
|
|
|
|
/* 分类 */
|
|
|
|
searchIndex: (data) => { //分类页
|
|
|
|
return requestServer('&action=search&app=index', 'post', data)
|
|
|
|
},
|
|
|
|
/* 购物车 */
|
|
|
|
appCart: (data) => { //
|
|
|
|
return requestServer('&action=app&m=cart', 'post', data)
|
|
|
|
},
|
|
|
|
cartIndex: (data) => { //购物车
|
|
|
|
return requestServer('&action=cart&app=index', 'post', data)
|
|
|
|
},
|
|
|
|
/* 我的 */
|
|
|
|
userIndex: (data) => { //个人中心
|
|
|
|
return requestServer('&action=user&app=index', 'post', data)
|
|
|
|
},
|
|
|
|
/* 登录 */
|
|
|
|
login: (data) => { //登录
|
|
|
|
return requestServer('&action=login&app=login', 'post', data)
|
|
|
|
},
|
|
|
|
productSaveFormid: (data) => {
|
|
|
|
return requestServer('&action=product&m=save_formid', 'post', data)
|
|
|
|
},
|
|
|
|
userMaterial: (data) => { //
|
|
|
|
return requestServer('&action=user&m=material', 'post', data)
|
|
|
|
},
|
|
|
|
indexGetMore: (data) => { //更多
|
|
|
|
return requestServer('&action=index&app=get_more', 'post', data)
|
|
|
|
},
|
|
|
|
newProduct: (data) => { //新品
|
|
|
|
return requestServer('&action=product&m=new_product', 'post', data)
|
|
|
|
},
|
|
|
|
|
|
|
|
productToCollection: (data) => {
|
|
|
|
return requestServer('&action=product&m=to_Collection', 'post', data)
|
|
|
|
},
|
|
|
|
|
|
|
|
productUpcart: (data) => {
|
|
|
|
return requestServer('&action=product&m=up_cart', 'post', data)
|
|
|
|
},
|
|
|
|
productDelAllCart: (data) => { //清空
|
|
|
|
return requestServer('&action=product&m=delAll_cart', 'post', data)
|
|
|
|
},
|
|
|
|
// productShopping: (data) => {
|
|
|
|
// return requestServer('&action=product&m=Shopping', 'post', data)
|
|
|
|
// },
|
|
|
|
productDelcart: (data) => { //删除
|
|
|
|
return requestServer('&action=product&m=delcart', 'post', data)
|
|
|
|
},
|
|
|
|
addressManagement: (data) => { //添加地址
|
|
|
|
return requestServer('&action=user&m=AddressManagement', 'post', data)
|
|
|
|
},
|
|
|
|
getCityArr: (data) => { //根据省获取市
|
|
|
|
return requestServer('&action=user&m=getCityArr', 'post', data)
|
|
|
|
},
|
|
|
|
getCountyInfo: (data) => { //根据省市获取县
|
|
|
|
return requestServer('&action=user&m=getCountyInfo', 'post', data)
|
|
|
|
},
|
|
|
|
preservation: (data) => {
|
|
|
|
return requestServer('&action=user&m=Preservation', 'post', data)
|
|
|
|
},
|
|
|
|
saveAddress: (data) => {
|
|
|
|
return requestServer('&action=user&m=SaveAddress', 'post', data)
|
|
|
|
},
|
|
|
|
addressDelselect: (data) => {
|
|
|
|
return requestServer('&action=address&m=del_select', 'post', data)
|
|
|
|
},
|
|
|
|
addressIndex: (data) => {
|
|
|
|
return requestServer('&action=address&m=index', 'post', data)
|
|
|
|
},
|
|
|
|
addressSetDefault: (data) => { //设置默认地址
|
|
|
|
return requestServer('&action=address&m=set_default', 'post', data)
|
|
|
|
},
|
|
|
|
addressDelAdds: (data) => { //删除地址
|
|
|
|
return requestServer('&action=address&m=del_adds', 'post', data)
|
|
|
|
},
|
|
|
|
addressUpAddsIndex: (data) => { //修改地址
|
|
|
|
return requestServer('&action=address&m=up_addsindex', 'post', data)
|
|
|
|
},
|
|
|
|
addressUpAdds: (data) => { //修改地址
|
|
|
|
return requestServer('&action=address&m=up_adds', 'post', data)
|
|
|
|
},
|
|
|
|
envelopeIndex: (data) => { //
|
|
|
|
return requestServer('&action=envelope&m=index', 'post', data)
|
|
|
|
},
|
|
|
|
envelopeShare: (data) => { //
|
|
|
|
return requestServer('&action=envelope&m=share', 'post', data)
|
|
|
|
},
|
|
|
|
appUser: (data) => { //
|
|
|
|
return requestServer('&action=app&m=user', 'post', data)
|
|
|
|
},
|
|
|
|
getcodeProductShare: (data) => { //
|
|
|
|
return requestServer('&action=getcode&m=product_share', 'post', data)
|
|
|
|
},
|
|
|
|
userPerfectIndex: (data) => { //
|
|
|
|
return requestServer('&action=user&m=perfect_index', 'post', data)
|
|
|
|
},
|
|
|
|
userSecretKey: (data) => { //
|
|
|
|
return requestServer('&action=user&m=secret_key', 'post', data)
|
|
|
|
},
|
|
|
|
userPerfect: (data) => { //
|
|
|
|
return requestServer('&action=user&m=perfect', 'post', data)
|
|
|
|
},
|
|
|
|
|
|
|
|
productAddCart: (data) => { //
|
|
|
|
return requestServer('&action=product&m=add_cart', 'post', data)
|
|
|
|
},
|
|
|
|
addFavoritesIndex: (data) => { //
|
|
|
|
return requestServer('&action=addFavorites&m=index', 'post', data)
|
|
|
|
},
|
|
|
|
removeFavorites: (data) => { //
|
|
|
|
return requestServer('&action=addFavorites&m=removeFavorites', 'post', data)
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|