/**
 * Copyright (c) 2013-Now http://aidex.vip All rights reserved.
 */
// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作
const install = (Vue, vm) => {
	
	// 参数配置对象
	const config = vm.vuex_config;
	console.log('install u',config)

	// 接口前缀统一走 hcscm（apiurl 已在 config.js 配置为 hcscm 服务）
	// 部分基础资料（往来单位、营销体系）仍在 hcscm_weave
	const getApiUrl = () => String(vm.$store.state.apiurl || '');
	const getWeaveApiUrl = () => {
		const url = getApiUrl();
		if (url.indexOf('hcscm_weave') !== -1) return url;
		return url.replace('/hcscm/', '/hcscm_weave/');
	};

	const GFM_OTHER_DELIVERY_PREFIX = '/grey_fabric_manage/gfmOtherDeliveryOrder/';
	const gfmOtherDeliveryUrl = (name) => getApiUrl() + GFM_OTHER_DELIVERY_PREFIX + name;

	const GFM_WAREHOUSE_PREFIX = '/grey_fabric_manage/gfmWarehouse/';
	const gfmWarehouseUrl = (name) => getApiUrl() + GFM_WAREHOUSE_PREFIX + name;

	const FPM_PROCESS_IN_PREFIX = '/product/fpmProcessInOrder/';
	const fpmProcessInUrl = (name) => getApiUrl() + FPM_PROCESS_IN_PREFIX + name;

	const FPM_PROCESS_OUT_PREFIX = '/product/fpmProcessOutOrder/';
	const fpmProcessOutUrl = (name) => getApiUrl() + FPM_PROCESS_OUT_PREFIX + name;

	// 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
	vm.$u.api = {

		// 坯布出仓单（其他出货单）相关接口
		gfmOtherDeliveryOrder: {
			// 获取坯布出仓单列表（query: page,size,order_no,audit_status）
			list: (params = {}) => vm.$u.get(gfmOtherDeliveryUrl('getGfmOtherDeliveryOrderList'), params),
			// 获取坯布出仓单详情（query: id）
			detail: (params = {}) => vm.$u.get(gfmOtherDeliveryUrl('getGfmOtherDeliveryOrder'), params),
			// 新增坯布出仓单（提交表头信息保存，返回 { id }）
			add: (params = {}) => vm.$u.postJson(gfmOtherDeliveryUrl('addGfmOtherDeliveryOrder'), params),
			// 扫码新增/删除细码（scan_type: 1新增 2删除；勾选锁定维度时附带 *_lock 字段），返回最新详情
			scanUpdate: (params = {}) => vm.$u.putJson(gfmOtherDeliveryUrl('updateGfmOtherDeliveryOrder'), params),
			// 审核
			statusPass: (params = {}) => vm.$u.putJson(gfmOtherDeliveryUrl('updateGfmOtherDeliveryOrderStatusPass'), params),
			// 消审
			statusWait: (params = {}) => vm.$u.putJson(gfmOtherDeliveryUrl('updateGfmOtherDeliveryOrderStatusWait'), params),
			// 驳回
			statusReject: (params = {}) => vm.$u.putJson(gfmOtherDeliveryUrl('updateGfmOtherDeliveryOrderStatusReject'), params),
			// 作废
			statusCancel: (params = {}) => vm.$u.putJson(gfmOtherDeliveryUrl('updateGfmOtherDeliveryOrderStatusCancel'), params),
		},

		// 坯布库存相关接口
		gfmWarehouse: {
			groupSummaryList: (params = {}) => vm.$u.get(gfmWarehouseUrl('getGfmWarehouseSummaryWeavingFactoryStockGroupList'), params),
			stockSummaryList: (params = {}) => vm.$u.get(gfmWarehouseUrl('getGfmWarehouseSummaryWeavingFactoryStockList'), params),
			detailList: (params = {}) => vm.$u.get(gfmWarehouseUrl('getGfmWarehouseList'), params),
		},

		// 加工进仓单
		fpmProcessInOrder: {
			list: (params = {}) => vm.$u.get(fpmProcessInUrl('getFpmProcessInOrderList'), params),
			detail: (params = {}) => vm.$u.get(fpmProcessInUrl('getFpmProcessInOrder'), params),
			add: (params = {}) => vm.$u.postJson(fpmProcessInUrl('addFpmProcessInOrder'), params),
			scanUpdate: (params = {}) => vm.$u.putJson(fpmProcessInUrl('updateFpmProcessInOrder'), params),
			statusPass: (params = {}) => vm.$u.putJson(fpmProcessInUrl('updateFpmProcessInOrderStatusPass'), params),
			statusWait: (params = {}) => vm.$u.putJson(fpmProcessInUrl('updateFpmProcessInOrderStatusWait'), params),
			statusReject: (params = {}) => vm.$u.putJson(fpmProcessInUrl('updateFpmProcessInOrderStatusReject'), params),
			statusCancel: (params = {}) => vm.$u.putJson(fpmProcessInUrl('updateFpmProcessInOrderStatusCancel'), params),
		},

		// 加工出仓单
		fpmProcessOutOrder: {
			list: (params = {}) => vm.$u.get(fpmProcessOutUrl('getFpmProcessOutOrderList'), params),
			detail: (params = {}) => vm.$u.get(fpmProcessOutUrl('getFpmProcessOutOrder'), params),
			add: (params = {}) => vm.$u.postJson(fpmProcessOutUrl('addFpmProcessOutOrder'), params),
			scanUpdate: (params = {}) => vm.$u.putJson(fpmProcessOutUrl('updateFpmProcessOutOrder'), params),
			statusPass: (params = {}) => vm.$u.putJson(fpmProcessOutUrl('updateFpmProcessOutOrderStatusPass'), params),
			statusWait: (params = {}) => vm.$u.putJson(fpmProcessOutUrl('updateFpmProcessOutOrderStatusWait'), params),
			statusReject: (params = {}) => vm.$u.putJson(fpmProcessOutUrl('updateFpmProcessOutOrderStatusReject'), params),
			statusCancel: (params = {}) => vm.$u.putJson(fpmProcessOutUrl('updateFpmProcessOutOrderStatusCancel'), params),
		},

		// 物理仓库下拉
		physicalWarehouse: {
			getDropdownList: (params = {}) => vm.$u.get('/warehouse/physicalWarehouse/getPhysicalWarehouseDropdownList', params),
		},

		// 仓位查询（Request: qr_code / warehouse_id / name；Response: GetPhysicalWarehouseBinData）
		warehouseBin: {
			getByQrCode: (params = {}) => vm.$u.get('/warehouse/warehouseBin/getWarehouseBin', params),
		},

		// 营销体系下拉（基础资料在 hcscm_weave）
		saleSystem: {
			getDropdownList: (params = {}) => vm.$u.get(getWeaveApiUrl() + '/saleSystem/getSaleSystemDropdownList', params),
		},

		// 往来单位列表
		businessUnit: {
			list: (params = {}) => vm.$u.get('/business_unit/list', params),
		},

		// 字典明细枚举（路径相对 apiurl：.../pda/v1/dictionaryDetail/getDictionaryDetailEnumList）
		dictionary: {
			getDetailEnumList: (params = {}) => vm.$u.get('/dictionaryDetail/getDictionaryDetailEnumList', params),
		},
		
		// 基础服务：登录登出、身份信息、菜单授权、切换系统、字典数据等
		lang: (params = {}) => vm.$u.get('/lang/'+params.lang),
		index: (params = {}) => vm.$u.get(config.productionApiUrl+'/mobile/index', params),
		getUserInfo: (params = {}) => vm.$u.get(config.productionApiUrl+'/mobile/user/getUserInfo', params),
		login: (params = {}) => vm.$u.post(config.productionApiUrl+'/mobile/login/loginByPassword', params),
		// PDA登录接口
		pdaLogin: (params = {}) => vm.$u.postJson('/login', params),
		pdaLogout: (params = {}) => vm.$u.postJson('/logout', params),
		// 获取配布单列表
		getFpmArrangeOrderList: (params = {}) => vm.$u.get('/product/fpmArrangeOrder/getFpmArrangeOrderList', params),
		// 获取成品配布单详情
		getFpmArrangeOrder: (params = {}) => vm.$u.get('/product/fpmArrangeOrder/getFpmArrangeOrder', params),
		// 生成出仓单
		outFpmArrangeOrder: (params = {}) => vm.$u.putJson('/product/fpmArrangeOrder/outFpmArrangeOrder', params),
		sendCode: (params = {}) => vm.$u.post(config.productionApiUrl+'/mobile/login/sendCode', params),
		registerUser: (params = {}) => vm.$u.post(config.productionApiUrl+'/mobile/user/registerUser', params),
		//首页相关api
		getIndexCardInfo: (params = {}) => vm.$u.get(config.productionApiUrl+'/mobile/index/getIndexCardInfo', params),
		getM2mOrderFlowList: (params = {}) => vm.$u.get(config.productionApiUrl+'/mobile/index/getM2mOrderFlowList', params),
		//获取卡可购买套餐包
		getM2mOrderPackageList: (params = {}) => vm.$u.get(config.productionApiUrl+'/mobile/index/getM2mOrderPackageList', params),
		
		logout: (params = {}) => vm.$u.get(config.productionApiUrl+'/mobile/login/logout', params),
		authInfo: (params = {}) => vm.$u.get(config.productionApiUrl+'/authInfo', params),
		menuTree: (params = {}) => vm.$u.get(config.productionApiUrl+'/menuTree', params),
		switchSys: (params = {}) => vm.$u.get(config.productionApiUrl+'/switch/'+params.sysCode),
		dictData: (params = {}) => vm.$u.get(config.a取dminPath+'/system/dict/data/type/'+params.dictType),
		
		// 账号服务：验证码接口、忘记密码接口、注册账号接口等
		validCode: (params = {}) => vm.$u.getText('/validCode', params),
		getFpValidCode: (params = {}) => vm.$u.post('/account/getFpValidCode', params),
		savePwdByValidCode: (params = {}) => vm.$u.post('/account/savePwdByValidCode', params),
		getRegValidCode: (params = {}) => vm.$u.post('/account/getRegValidCode', params),
		saveRegByValidCode: (params = {}) => vm.$u.post('/account/saveRegByValidCode', params),
		
		// APP公共服务
		upgradeCheck: (params = {}) => vm.$u.putJson('/version/check', params),
		commentSave: (params = {}) => vm.$u.post('/app/comment/save', params),
		
		// 个人信息修改
		user: {
			saveUserInfo: (params = {}) => vm.$u.post(config.productionApiUrl+'/mobile/user/saveUserInfo', params),
			infoSavePwd: (params = {}) => vm.$u.put(config.productionApiUrl+'/system/user/profile/updatePwd', params),
			infoSavePqa: (params = {}) => vm.$u.post(config.productionApiUrl+'/sys/user/infoSavePqa', params),
		},
		
		// 员工用户查询
		empUser: {
			listData: (params = {}) => vm.$u.get(config.productionApiUrl+'/sys/empUser/listData', params),
		},
		
		// 组织机构查询
		office: {
			treeData: (params = {}) => vm.$u.get(config.productionApiUrl+'/sys/office/treeData', params),
		},
		
		// 增删改查例子
		testData: {
			form: (params = {}) => vm.$u.post(config.productionApiUrl+'/test/testData/form', params),
			list: (params = {}) => vm.$u.post(config.productionApiUrl+'/test/testData/listData', params),
			save: (params = {}) => vm.$u.postJson(config.productionApiUrl+'/test/testData/save', params),
			disable: (params = {}) => vm.$u.post(config.productionApiUrl+'/test/testData/disable', params),
			enable: (params = {}) => vm.$u.post(config.productionApiUrl+'/test/testData/enable', params),
			delete: (params = {}) => vm.$u.post(config.productionApiUrl+'/test/testData/delete', params),
		},
		
	};
	
}

export default {
	install
}
