// 如果没有通过拦截器配置域名的话，可以在这里写上完整的URL(加上域名部分)
let hotSearchUrl = '/ebapi/store_api/hot_search';
let indexUrl = '/ebapi/public_api/index';

// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作，更多内容详见uView对拦截器的介绍部分：
// https://uviewui.com/js/http.html#%E4%BD%95%E8%B0%93%E8%AF%B7%E6%B1%82%E6%8B%A6%E6%88%AA%EF%BC%9F
const install = (Vue, vm) => {
	// 此处没有使用传入的params参数
	let getSearch = (params = {}) => vm.$u.get(hotSearchUrl, {
		id: 2
	});
	// 此处使用了传入的params参数，一切自定义即可
	let getInfo = (params = {}) => vm.$u.get(`/index.php/api/user/info/`, params);
	
	let gettest = (params = {}) => vm.$u.get('/system/test/', params);
	let login = (params = {}) => vm.$u.post('/index.php/api/login', params);
	// 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
	let getBanners =(params = {}) => vm.$u.get('/index.php/api/banner/index', params);
	let getCategory =(params = {}) => vm.$u.get('/index.php/api/category', params);
	let getGoods = (id, params={}) => vm.$u.get(`/index.php/api/goods/goods_list/cid/${id}`, params);
	let getGood = (id, params={}) => vm.$u.get(`/index.php/api/goods/index/id/${id}`, params);
	let searchGood = (keyword, page)=> vm.$u.get(`/index.php/api/goods/search_list/keyword/${keyword}/page/${page}/`);
	let getComments = (id, params={})=>vm.$u.get(`index.php/api/comment/index/aid/${id}`, params); //获取商品评论
	let getAddress = (params = {}) => vm.$u.get('/index.php/api/user/address/', params);//获取地址 
	let getCart = (params = {}) => vm.$u.get('/index.php/api/car/index/');//购物车 
	let getInvoice = (params = {}) => vm.$u.get('/index.php/api/invoice/index', params);//我的开票信息
	let addInvoice = (params = {}) => vm.$u.post('/index.php/api/invoice/add', params);//新增开票信息
	let editInvoice = (id, params = {}) => vm.$u.post(`/index.php/api/invoice/edit/id/${id}/`, params);//修改开票
	let delInvoice = (id, params = {}) => vm.$u.post(`/index.php/api/invoice/delete/id/${id}/`);//删除开票信息
	let logout = ()=>vm.$u.get('/index.php/api/login/unbundling');//解绑微信
	let editAddress = (id, params = {}) => vm.$u.post(`/index.php/api/address/edit/id/${id}/`, params);//修改地址
	let addAddress = (params = {}) => vm.$u.post('/index.php/api/address/add', params);//新增地址
	let delAddress = (id, params = {}) => vm.$u.post(`/index.php/api/address/delete/id/${id}/`);//删除地址
	let removeFromCart = (id) => vm.$u.get(`/index.php/api/car/delete_one/id/${id}/`);//
	let addtoCart =(id, num)=> vm.$u.get(`index.php/api/car/add/id/${id}/num/${num}`);//加入购物车
	let addOrder = (params={})=>vm.$u.post('/index.php/api/car/submit', params);
	let getFreight = (params={})=>vm.$u.post(`/index.php/api/car/get_freight/shop_uid`,params);//获取商家免运费价格
	let getOrders = (params={})=>vm.$u.get('index.php/api/order/index', params);//我的订单
	let qxdd = (id)=>vm.$u.get(`index.php/api/order/cancel_order/id/${id}`);//取消订单
	let qrsh = (id)=>vm.$u.get(`/index.php/api/order/confirm/id/${id}`);//收货确认
	let qrfp = (id)=>vm.$u.get(`/index.php/api/order/invoice_confirm/id/${id}`);//发票确认
	let tjkp = (id, params)=>vm.$u.post(`/index.php/api/order/invoice_add/id/${id}`, params);//提交开票信息
	let upFile = (params={})=>vm.$u.post(`index.php/index/attachment/upload?dir=images&from=base64&module=index`, params);
	let tjfk = (params={})=>vm.$u.post('index.php/api/order/payment_voucher', params);//提交付款凭证
	let getCode = (id)=>vm.$u.get(`/index.php/api/login/getnum/type/mobphone/to/${id}`);//获取注册码
	let register = (params={})=>vm.$u.post('/index.php/api/login/reg', params);//注册
	let checkUserName = (params={})=>vm.$u.get(`/index.php/api/login/check_username`, params);//注册时检查用户名是否
	let getCodeRepass = (id,params)=>vm.$u.get(`/index.php/api/login/getpwdnum/type/mobphone/to/${id}`,params);//获取验证码
	let changepwd = ( params)=>vm.$u.post(`/index.php/api/login/changepwd`, params);//修改密码
	let wxReg = ( params)=>vm.$u.post(`/index.php/api/login/one_key_reg`, params);//微信一键注册
	
	vm.$u.api = {
		getSearch, 
		getInfo, 
		gettest, 
		login,
		getBanners,
		getCategory,
		getGoods,
		getGood,
		getComments,
		getAddress,
		getCart,
		getInvoice,
		logout,
		editAddress,
		addAddress,
		delAddress,
		addInvoice,
		editInvoice,
		delInvoice,
		removeFromCart,
		searchGood,
		addtoCart,
		addOrder,
		getFreight,
		getOrders,
		qrsh,
		qrfp,
		tjkp,
		qxdd,
		upFile,
		tjfk,
		getCode,
		getCodeRepass,
		changepwd,
		checkUserName,
		register,
		wxReg};
}

export default {
	install
}