import util from '@/utils/util.js'
const jsonType = {'content-type': 'application/json'}
const formType = {'content-type': 'application/x-www-form-urlencoded'}
const dataType = {'content-type': 'multipart/form-data'}

let orderApiFun = function(vm){
	// 接口公共前缀
	const prefix = '/wxh-worker-rest/rest/'
	let order = '/wxh-worker-rest/rest/order/' 
	let settle = '/wxh-worker-rest/rest/settle/'
	
	let listByRecommendOrder = async (params = {}) => await vm.$u.get('/wxh-worker-rest/rest/recommend/order', params);
	/**
	 * 工单数量查询接口
	 */
	let listOrderCount = async (params = {}) => await vm.$u.get(prefix + vm.vuex_token + '/wokerOrder/queryOrdersCount/V2', params);
	/**
	 * 订单管理工单数量查询接口
	 */
	 let manageOrderCount = async (params = {}) => await vm.$u.get(prefix + vm.vuex_token + '/wokerOrder/countOrderByTimeRange', params);
	/**
	 * 根据订单id数组获取订单列表
	 */
	let listOrderByIds = async (string) => await vm.$u.get('/wxh-worker-rest/rest/order/revision/listOrderByIds' + string);
	/**
	 * 工单列表接口
	 */
	let listOrder = async (params = {}) => await vm.$u.get('/wxh-worker-rest/rest/order/revision/' + vm.vuex_token + '/list', params);
	/**
	 * 订单管理工单列表接口
	 */
	let manageOrderList = async (params = {}) => await vm.$u.get('/wxh-worker-rest/rest/order/revision/listOrderByTimeRange', params);

	/**
	 * 获取师傅的预约日历
	 */
	let workerCalendar = async (params = {}) => await vm.$u.get(prefix + vm.vuex_token + '/wokerOrder/appointment/calendar', params);

	/**
	 * 师傅预约
	 */
	let workerAppointment = async (params = {}, orderId) => await vm.$u.post('/wxh-worker-rest/rest/order/traceAndAppointment/trace/V2/' + vm.vuex_token + '/'+orderId, params)

	// 联系顾客时间更新接口，暂时没有

	/**
	 * 师傅签到接口
	 */
	let maintainWorkerCheckin = async (params = {},orderId) => await vm.$u.post(prefix + vm.vuex_token + '/order/'+orderId+'/maintainWorkerCheckin', params,formType);
	/**
	 * 订单详情查询
	 */
	let orderDetail = async (params = {},orderId) => await vm.$u.get('/wxh-worker-rest/rest/order/revision/'+ vm.vuex_token+'/'+orderId, params);
	/**
	 * 结算详情查询
	 */
	let querySettleByOrder = async (params = {},orderId) => await vm.$u.get('/wxh-worker-rest/rest/settle/'+ vm.vuex_token+'/querySettleByOrder/'+orderId, params);
	/* 过程反馈查询接口 */
	let feedbackConfig = async (params = {}) => await vm.$u.get('/wxh-worker-rest/rest/order/v2/getFeedBack/' + vm.vuex_token, params)

	/* 预约+过程反馈 接口 */
	let traceAndAppointment = async (params = {}, orderId) => await vm.$u.post('/wxh-worker-rest/rest/order/traceAndAppointment/trace/V2/' + vm.vuex_token + `/`+orderId, params)

	/* 师傅拒单 */
	let rejectOrder = async (params = {}, orderId) => await vm.$u.post(prefix + vm.vuex_token + `/order/${orderId}/workerReject/V2`, params, formType)


	/**
	 * 查询工单操作记录列表接口
	 */
	let listOrderRecord = async (params = {}) => await vm.$u.get('/wxh-worker-rest/rest/order/record/'+ vm.vuex_token+'/listOrderRecord/V2/'+params.orderId, params);

	/**
	 * 接单
	 */
	let orderAccept = async (params = {},orderId) => await vm.$u.post(prefix + vm.vuex_token+'/order/'+orderId+'/accept', params, formType);

	/**
	 * 抢单
	 */
	let orderGan = async (params = {},orderId) => await vm.$u.post('/wxh-worker-rest/rest/order/revision/applets/'+ vm.vuex_token+'/order/acceptAppletsOrder', params,formType);

	/**
	 * 获取拍照标准
	 */
	let orderStandard = async (params = {}) => await vm.$u.get(prefix + vm.vuex_token+'/photo/standard', params);
	/**
	 * 获取拍照标准单独项目
	 */
	let orderStandardItem = async (params = {}) => await vm.$u.get(prefix + vm.vuex_token+'/photo/standard/only', params);

	/**
	 * 保存图片信息
	 */
	let saveImage = async (params = {},orderId) => await vm.$u.post(prefix + vm.vuex_token + '/order/'+orderId+'/maintain/saveImage', params);

	/**
	 * 获取师傅水印 or 默认水印
	 */
	let getWatermark = async (params = {}) => await vm.$u.get(prefix + vm.vuex_token + '/photo/watermark', params);

	/**
	 * 保存师傅水印
	 */
	let saveWatermark = async (params = {}) => await vm.$u.post(prefix + vm.vuex_token + '/photo/watermark', params);

	/**
	 * 获取师傅开放可选时间段
	 */
	let openTimerange = async (params = {}) => await vm.$u.get(prefix + vm.vuex_token + '/wokerOrder/appointment/timerange', params);

	/**
	 * 联系时间接口
	 */
	let contactTime = async (params = {},orderId) => await vm.$u.get('/wxh-worker-rest/rest/order/record/'+ vm.vuex_token+'/contact/'+orderId, params);

	/**
	 * 检查是否可以拒单
	 */
	let checkRejectable = async (params = {}) => await vm.$u.get('/wxh-worker-rest/rest/'+ vm.vuex_token+'/wokerOrder/checkRejectable', params);

	/**
	 * 获取签到距离
	 */
	let getSignDistance = async (params = {}) => await vm.$u.get('/wxh-worker-rest/rest/' + vm.vuex_token + `/wokerOrder/sign/distance`, params)


	/**
	 * 获取订单的完工项目(配置+数据)
	 */
	let getCompleteConfigAndData= async (orderId) => await vm.$u.get(prefix + vm.vuex_token+'/order/'+ orderId +'/maintain/info');

	/**
	 * 完工项阶段下一步
	 */
	 let completeNextStep= async (params = {}, orderId) => await vm.$u.post(prefix + vm.vuex_token+'/order/'+ orderId +'/maintain/nextStep', params);

	/**
	 * 查询措施
	 */
	let getMeasure= async (params = {}) => await vm.$u.get('wxh-worker-rest/rest/service/'+ vm.vuex_token+'/measure/queryMeasureItems', params);
	let getMeasureV2= async (params = {}) => await vm.$u.get('wxh-worker-rest/rest/service/'+ vm.vuex_token+'/measure/queryMeasureItems/V2', params);

	/**
	 * 查询工单材信息
	 */
	let getOrderMaterial= async (orderId) => await vm.$u.get('/wxh-cloud-rest/rest/thirdparty/shzhida/material/' + orderId);

	/**
	 * 保存售后记录
	 */
	let saveCompleteData = async (params = {},orderId) => await vm.$u.post(prefix + vm.vuex_token+'/order/'+ orderId +'/maintain/saveMaintainInfoV3', params);

	/**
	 * 保内工单完工
	 */
	let inOrderFinish = async (orderId) => await vm.$u.post(prefix + vm.vuex_token+'/order/'+ orderId +'/finishedAndConfirm',{}, formType);
	/**
	 * 保外工单完工
	 */
	let outOrderFinish = async (params = {},orderId) => await vm.$u.post(prefix + vm.vuex_token+'/order/'+ orderId +'/v1/finishedAndConfirmOutGuaranteePeriod', params, formType);


	/**
	 * 获取工单联系人经纬度
	 */
	let addressToCoordinate= async (orderId) => await vm.$u.get(prefix+'order/specialfee/'+ vm.vuex_token +'/address/coordinate/'+orderId);

	/**
	 * 我的库存明细（物料）
	 */
	let listBystock= async () => await vm.$u.get(prefix + vm.vuex_token +'/myinfo/stock', {}, jsonType);
	/**
	 * 我的出入库流水
	 */
	let listAccessHistory= async (params = {}) => await vm.$u.get(prefix + vm.vuex_token +'/myinfo/access/history', params, jsonType);
	
	// 获取我的钱包-资产信息
	let getAssets = async (params = {}) => await vm.$u.get(settle + vm.vuex_token + '/v3/total', params);
	// 获取我的钱包-收入流水
	let listStatement = async (params = {}) => await vm.$u.get(settle + vm.vuex_token + '/v2/statement', params);
	// 获取我的钱包-收入流水
	let listStatementDetails = async (params = {}) => await vm.$u.get(settle + vm.vuex_token + '/queryStatementByPayableNo', params);
	// 获取我的钱包-支付单一览
	let payableRecord = async (params = {}) => await vm.$u.post(settle + vm.vuex_token + '/payable/v2/queryPayableRecord', params, formType);
	// 获取我的钱包-支付单一览版本3
	let listPayableRecordByPayTime = async (params = {}) => await vm.$u.post(settle + vm.vuex_token + '/payable/listPayableRecordByPayTime', params, formType);
	// 获取我的钱包-师傅提现
	let workerApplyPay = async () => await vm.$u.get(prefix + vm.vuex_token + '/applypay/batch/workerApplyPay');
	// 是否有特殊登录权限
	let allowLogin = async (params = {}) => await vm.$u.get(prefix + 'other/auth/' + vm.vuex_token + '/allow/login', params);
	// 特殊登录切换师傅
	let otherUser = async (params = {}) => await vm.$u.get(prefix + 'other/auth/' + vm.vuex_token + '/other/user', params);
	// 是否添加客服
	let checkAddCustomer = async (params = {}) => await vm.$u.get(prefix + 'order/revision/' + vm.vuex_token + '/checkAddCustomer', params);
	// 工单文件标签
	let fileLabel = async (params = {}) => await vm.$u.get(prefix + 'config/' + vm.vuex_token + '/finish/file/lable/', params);
	// 工单文件列表
	let fileList = async (params = {}) => await vm.$u.get(prefix + 'config/' + vm.vuex_token + '/finish/file', params);
	// 订单配件列表
	let applyList = async (params = {}) => await vm.$u.get(prefix + 'parts/' + vm.vuex_token + '/orders', params);
	// 返件列表
	let returnedParts  = async (params = {}) => await vm.$u.get(prefix + 'parts/' + vm.vuex_token + '/return', params);
	// 物料仓列表
	let reserveList  = async (params = {}) => await vm.$u.get(prefix + 'parts/' + vm.vuex_token + '/items/reserve', params);
	// 配件物流
	let getLogistics = async (orderId) => await vm.$u.get(prefix + 'parts/' + vm.vuex_token + '/orders/'+ orderId +'/express',{}, formType);
	// 配件申请单-数量统计
	let getOrderPartsSum = async (orderId) => await vm.$u.get(prefix + 'parts/' + vm.vuex_token + '/orders/' + orderId +'/sum',{}, formType);
	// 配件申请单-签收
	let receiveParts = async (partOrderId) => await vm.$u.put(prefix + 'parts/' + vm.vuex_token + '/orders/' + partOrderId +'/receive',{}, formType);
	// 配件申请单-取消申请
	let cancelParts = async (partOrderId) => await vm.$u.put(prefix + 'parts/' + vm.vuex_token + '/orders/'+ partOrderId +'/cancel',{}, formType);
	// 点击了异常单去处理
	let workerDealWithError = async (orderId, params = {}) => await vm.$u.post( prefix + vm.vuex_token + '/order/' + orderId + '/workerDealWithError', params)
	
	// 工单搜索联想
	let association = async (params = {}) => await vm.$u.get('/wxh-worker-rest/rest/order/revision/association', params);

	let getWorkerData = async (params = {}) => await vm.$u.get('/wxh-worker-rest/rest/order/revision/' + vm.vuex_token + `/getWorkerData`, params)
	let getOrderTime = async (params = {}) => await vm.$u.get('/wxh-worker-rest/rest/order/revision/' + vm.vuex_token + `/getOrderTime/${params.id}`, params)
	
	// 完工-安装信息-充电桩信息-验证箱体二维码
	let parsingScanCode = async (params = {}) => await vm.$u.get('/wxh-worker-rest/rest/parts/' + vm.vuex_token + `/take/stock/parsing/code`, params)

	const orderApi = {
		listByRecommendOrder,
		listOrderCount,
		manageOrderCount,
		listOrderByIds,
		listOrder,
		manageOrderList,
		workerCalendar,
		workerAppointment,
		maintainWorkerCheckin,
		orderDetail,
		querySettleByOrder,
		listOrderRecord,
		orderAccept,
		orderGan,
		feedbackConfig,
		traceAndAppointment,
		rejectOrder,
		orderStandard,
		orderStandardItem,
		saveImage,
		getWatermark,
		saveWatermark,
		openTimerange,
		contactTime,
		checkRejectable,
		getSignDistance,
		getCompleteConfigAndData,
		getMeasure,
		getMeasureV2,
		getOrderMaterial,
		saveCompleteData,
		inOrderFinish,
		outOrderFinish,
		addressToCoordinate,
		listBystock,
		listAccessHistory,
		getAssets,
		listStatement,
		payableRecord,
		listPayableRecordByPayTime,
		listStatementDetails,
		workerApplyPay,
		allowLogin,
		otherUser,
		checkAddCustomer,
		fileLabel,
		fileList,
		completeNextStep,
		applyList,
		returnedParts,
		reserveList,
		getLogistics,
		getOrderPartsSum,
		receiveParts,
		cancelParts,
		workerDealWithError,
		association,
		getWorkerData,
		getOrderTime,
		parsingScanCode
	}
	return orderApi
}
module.exports =  {
	orderApiFun
}
