import config from '../config.js';
import util from '../utils/util.js';
import * as taskState from '../constant/taskState.js';
import taskType from '../constant/taskType.js';

const queryTaskListUrlMapper = {
	'药品运送': config.urls.queryMedicineNewTask,

	'标本运送': config.urls.querySampleTasksheet,
}

const pageQueryTaskUrlMapper = {
	'药品运送': config.urls.pageQueryMedicineTask,
	
	'标本运送': config.urls.pageQuerySampleTasksheet,
}


const getTaskByIdUrlMapper = {
	'药品运送': config.urls.getMedicineTaskById ,
	
	'标本运送': config.urls.getSampleTaskById,
}


export default {
	/**
	 * 获取指定名称的数据字典
	 * @param {Object} name
	 */
	getDataDictionary(name) {
		return util.request({
			url: config.dataDictionaryUrl + name,
			method: 'GET'
		});
	},
	
	
	// 获取微信用户的OpenID
	queryOpenId(code){
		return util.request({
			url: config.urls.queryOpenId + code,
			method: 'GET'
		});
	},
	
	/**
	* 查询全部科室网格列表
	* @param {string} type
	* @param {object} params
	*/
	getGrids() {
		const staff = uni.getStorageSync("staff");
		return util.request({
			url: config.urls.getGridFromRedis,
			data: {
				abbre: null,
				gridCode: null,
				hospId: (staff==null || staff==undefined || staff == '')?config.defaultHospId:staff.hosp_id
			}
		});
	},
	
	/**
	 * 获取担架运送收费标准图片
	 */
	getStretcherTransportFeeImageUrl() {
		return util.request({
			url: config.urls.getStretcherTransportFeeImageUrl,
			method: 'GET'
		});
	},
	
	/**
	 * 获取新运单提示音
	 */
	getNewWaybillPromptWaveUrl() {
		return util.request({
			url: config.urls.getNewWaybillPromptWaveUrl,
			method: 'GET'
		});
	},
	
	/**
	 * 生成订单微信支付二维码
	 * @param {Object} params
	 */
	getStretcherTransportPayQRcode(params) {
		return util.request({
			url: config.urls.getStretcherTransportPayQRcode,
			data: {
				orderDec: params.orderDec,
				orderNo: params.orderNo,
				productId: params.productId,
				totalFree: params.totalFree
			},
			method: 'POST'
		});
	},
	
	
	/**
	 * 获取APP滑动广告图片
	 */
	getAppSlipPicUrl() {
		return util.request({
			url: config.urls.getAppSlipPicUrl,
			method: 'GET'
		});
	},
	
	// 根据id查询担架运单对象
	getStretcherTaskById(id){
		return util.request({
			url: config.urls.getStretcherTransportTaskById + id,
			method: 'GET'
		});
	},
	
	/**
	* 查询担架新运单列表
	* @param {object} params
	*/
	queryStretcherNewTask(params) {
		const staff = uni.getStorageSync("staff");
		params.userId = (staff==null || staff==undefined || staff == '')?null:staff.id
		return util.request({
			url: config.urls.queryStretcherNewTask,
			data: params
		});
	},
	
	/**
	 * 列表查询刚接单的担架运送任务
	 * @param {Object} params
	 */
	queryStretcherReceiptTask(params){
		return util.request({
			url: config.urls.queryStretcherReceiptTask,
			data: {
				decDept: params.decDept || null,
				decTel: params.decTel || null,
				decBedNo: params.decBedNo || null,
				index: 0,
				page: 0,
				size: 0,
				sort: null,
				hospId: null
			}
		});
	},
	
	/**
	 * 列表查询担架运单
	 * @param {Object} params
	 */
	queryStretcherTask(params){
		const staff = uni.getStorageSync("staff");
		return util.request({
			url: config.urls.queryStretcherTask,
			data: {
				decDept: params.decDept || null,
				decTel: params.decTel || null,
				decBedNo: params.decBedNo || null,
				needcontactTel: params.needcontactTel || null,
				openid: params.openid || null,
				decendDatetime: params.endTime || null,
				decstartDatetime: params.startTime || null,
				index: 0,
				page: 0,
				size: 0,
				sort: null,
				tasksheetStates: params.tasksheetStates || null,
				undertakePerson: (staff==null || staff==undefined || staff == '')?null:staff.id,
				hospId: null
			}
		});
	},
	
	/**
	 * 担架运送接单
	 * @param {Object} params
	 */
	receiptStretcherNewTask(params){
		const staff = uni.getStorageSync("staff");
		return util.request({
			url: config.urls.receiptStretcherNewTask,
			data: {
				id: params.id,
				acceptancePerson: (staff==null || staff==undefined || staff == '')?null:staff.id,
				decBedNo: params.decBedNo,
				decDept: null,
				delTel: params.delTel,
				exteamId: null,
				undertakePersons: null
			}
		});
	},
	
	/**
	 * 启运担架运单
	 * @param {Object} params
	 */
	startStretcherTransport(params){
		const staff = uni.getStorageSync("staff");
		return util.request({
			url: config.urls.startStretcherTransport,
			data: {
				acceptancePerson: (staff==null || staff==undefined || staff == '')?null:staff.id,
				sheetId: params.sheetId,
				smsStartCode: params.smsStartCode
			}
		});
	},
	
	/**
	 * 完工担架运单
	 * @param {Object} params
	 */
	finishStretcherTransport(params){
		const staff = uni.getStorageSync("staff");
		return util.request({
			url: config.urls.finishStretcherTransport,
			data: {
				acceptancePerson: (staff==null || staff==undefined || staff == '')?null:staff.id,
				finishWord: params.finishWord,
				sheetId: params.sheetId,
				smsFinishCode: params.smsFinishCode
			}
		});
	},
	
	/**
	 * 确认现金支付
	 * @param {Object} params
	 */
	confirmStretcherPay(params){
		const staff = uni.getStorageSync("staff");
		return util.request({
			url: config.urls.confirmStretcherPay,
			data: {
				acceptancePerson: (staff==null || staff==undefined || staff == '')?null:staff.id,
				paymentMethod: params.paymentMethod,
				serviceFee: params.serviceFee,
				sheetId: params.sheetId
			}
		});
	},
	
	/**
	 * 评价担架运单服务
	 * @param {Object} params
	 */
	evaluateStretcherTransport(params){
		//const staff = uni.getStorageSync("staff");
		return util.request({
			url: config.urls.evaluateStretcherTransport,
			data: {
				id: params.id,
				satisfactionContent: params.satisfactionContent,
				satisfactionEvaluation: params.satisfactionEvaluation || "5",
				tasksheetType: null
			}
		});
	},
	
	/**
	* 查询全部订单
	* @param {string} type
	* @param {object} params
	*/
	queryNewTask(type, params) {
		const staff = uni.getStorageSync("staff");
		return util.request({
			url: queryTaskListUrlMapper[type],
			data: {
				decendDatetime: params.endTime || null,
				decstartDatetime: params.startTime || null,
				index: 0,
				page: null,
				size: null,
				sort: null,
				tasksheetStates: params.tasksheetStates || null,
				tasksheetType: taskType[type],
				undertakePerson: (staff==null || staff==undefined || staff == '')?null:staff.id
			}
		});
	},

	/**
	* 分页查询运单
	* @param {string} type
	* @param {object} params
	*/
	pageQueryTask(type, params){
		return util.request({
			url: pageQueryTaskUrlMapper[type],
			data: {
				decendDatetime: params.endTime || null,
				decstartDatetime: params.startTime || null,
				index: 0,
				orderNo: params.orderNo || null,
				page: params.pageNo || 1,
				size: params.pageSize || 10,
				sort: null,
				tasksheetStates: params.tasksheetStates || null,
				tasksheetType: params.tasksheetType || null,
				undertakePerson: params.undertakePerson || null,
			}
		});
	},
	
	/**
	 * 分页查询未接单标本
	 * @param {Object} params
	 */
	pageQuerySpecimen(params){
		return util.request({
			url: config.urls.pageQuerySampleNewTask,
			data: {
				decendDatetime: params.endTime || null,
				decstartDatetime: params.startTime || null,
				index: 0,
				page: params.pageNo || 1,
				size: params.pageSize || 10,
				sheetId: null,
				sort: null,
				tasksheetState: params.tasksheetState || null,
				undertakePerson: params.undertakePerson || null,
				urgentDegrees: params.urgentDegrees || null
			}
		});
	},
	
	/**
	 * 查询全部未接单标本
	 * @param {Object} params
	 */
	querySpecimen(params){
		return util.request({
			url: config.urls.querySampleNewTask,
			data: {
				decendDatetime: params.endTime || null,
				decstartDatetime: params.startTime || null,
				index: 0,
				page: null,
				size: null,
				sheetId: null,
				sort: null,
				tasksheetState: params.tasksheetState || null,
				undertakePerson: params.undertakePerson || null,
			}
		});
	},
	
	/**
	 * 药品运送接单
	 * @param {string} type
	 * @param {Object} data
	 */
	receiptMedicineNewTask(params){
		const staff = uni.getStorageSync("staff");
		return util.request({
			url: config.urls.receiptMedicineNewTask,
			data: {
				acceptancePerson: params.acceptancePerson,
				dsordertype: params.dsordertype,
				tasksheetType: params.tasksheetType,
				id: params.id,
			}
		});
	},
	
	/**
	 * 启动运单
	 * @param {Object} taskId
	 */
	startMedicineTransport(taskId){
		return util.request({
			url: config.urls.startMedicineTransport + taskId,
		});
	},
	
	/**
	 * 完成药品运送
	 * @param {Object} type
	 * @param {Object} taskId
	 */
	completeMedicineTask(type, taskId){
		const staff = uni.getStorageSync("staff");
		return util.request({
			url: config.urls.completeMedicineTask,
			data: {
				acceptancePerson: (staff==null || staff==undefined || staff == '')?null:staff.id,
				finishWord: "完成送药",
				id: taskId,
				serviceItem: null,
				serviceItemType: null,
				materialconsumerecordSaveRequestList: null,
				sheetId: taskId,
				tasksheetType: taskType[type]
			}
		});
	},
	
	// 根据id查询
	getTaskById(type, id){
		console.log('getTaskByIdUrlMapper[type] + id',getTaskByIdUrlMapper[type] + id)
		return util.request({
			url: getTaskByIdUrlMapper[type] + id,
			method: 'GET'
		});
	},
	/**
	 * 根据sheedID查询运单下接收的标本
	 * @param {Object} params
	 */
	querySheetBySheetTd(sheetId){
		return util.request({
			url: config.urls.querySampleNewTask,
			data: {
				decendDatetime: null,
				decstartDatetime: null,
				index: 0,
				page: null,
				size: null,
				sheetId: sheetId || null,
				sort: null,
				tasksheetState: null,
				undertakePerson: null,
			}
		});
	},
	
	/**
	 * 扫码接收标本
	 * @param {Object} id
	 */
	receiptSampleNewTask(id){
		return util.request({
			url: config.urls.receiptSampleNewTask + id,
			method: 'GET'
		});
	},
	
		
	queryBarcodeFuzzySearch(params){
		return util.request({
			url: config.urls.querySampleNewTask,
			data: {
				barCode: params.barCode || null,
				decendDatetime: params.endTime || null,
				decstartDatetime: params.startTime || null,
				index: 0,
				page: null,
				size: null,
				sheetId: null,
				sort: null,
				tasksheetState: params.tasksheetState || null,
				undertakePerson: params.undertakePerson || null,
			}
		});
	},
	
	/**
	 * 创建标本运单
	 * @param {Object} dtos
	 * @param {Object} source
	 */
	createSampleTaskSheet(dtos, source){
		return util.request({
			url: config.urls.createSampleTaskSheet,
			data: {
				dtos: dtos,
				source: source,
			}
		})
	},
	
	/**
	 * 获得药品类型列表
	 */
	getMedicinetype(){
		return util.request({
			url: config.urls.getMedicineType,
			method: 'GET'
		})
	}

}