93 lines
2.9 KiB
JavaScript
93 lines
2.9 KiB
JavaScript
import { get, post } from './http'
|
|
|
|
export const SPECIAL_PRESCRIPTION_STORAGE_KEY = 'special_prescription_register_context'
|
|
|
|
/**
|
|
* 首页特色方配置
|
|
* @param params {{ store_id?: number|string }}
|
|
*/
|
|
export async function getSpecialPrescriptionHomeApi(params) {
|
|
return await get('/special-prescription/home', params, 3)
|
|
}
|
|
|
|
/**
|
|
* 特色方列表页配置
|
|
* @param params {{ store_id?: number|string }}
|
|
*/
|
|
export async function getSpecialPrescriptionListPageApi(params) {
|
|
return await get('/special-prescription/list-page', params, 3)
|
|
}
|
|
|
|
/**
|
|
* 特色方列表
|
|
* @param params {{ store_id?: number|string, category_id?: number, name?: string, page?: number, pageSize?: number }}
|
|
*/
|
|
export async function getSpecialPrescriptionListApi(params) {
|
|
return await get('/special-prescription/list', params, 3)
|
|
}
|
|
|
|
/**
|
|
* 特色方详情
|
|
* @param params {{ id: number|string, store_id?: number|string }}
|
|
*/
|
|
export async function getSpecialPrescriptionDetailApi(params) {
|
|
return await get('/special-prescription/detail', params, 3)
|
|
}
|
|
|
|
/**
|
|
* 特色方分类
|
|
*/
|
|
export async function getSpecialPrescriptionCategoriesApi(params = {}) {
|
|
return await get('/special-prescription/categories', params, 3)
|
|
}
|
|
|
|
/**
|
|
* 挂号成功后创建选方记录
|
|
* @param params {{ register_id, special_prescription_id, dose_count, store_id, doctor_id }}
|
|
*/
|
|
export async function createSpecialPrescriptionPatientRecordApi(params) {
|
|
return await post('/special-prescription/create-patient-record', params, 3)
|
|
}
|
|
|
|
export function saveSpecialPrescriptionRegisterContext(ctx) {
|
|
if (!ctx || !ctx.special_prescription_id) return
|
|
uni.setStorageSync(SPECIAL_PRESCRIPTION_STORAGE_KEY, {
|
|
special_prescription_id: ctx.special_prescription_id,
|
|
dose_count: ctx.dose_count || 1,
|
|
doctor_id: ctx.doctor_id || '',
|
|
})
|
|
}
|
|
|
|
export function getSpecialPrescriptionRegisterContext() {
|
|
return uni.getStorageSync(SPECIAL_PRESCRIPTION_STORAGE_KEY) || null
|
|
}
|
|
|
|
export function clearSpecialPrescriptionRegisterContext() {
|
|
uni.removeStorageSync(SPECIAL_PRESCRIPTION_STORAGE_KEY)
|
|
}
|
|
|
|
/**
|
|
* 挂号成功后绑定特色方选方记录(幂等,失败不阻断流程)
|
|
* @param registerId
|
|
*/
|
|
export async function tryCreateSpecialPrescriptionPatientRecord(registerId) {
|
|
if (!registerId) return
|
|
const ctx = getSpecialPrescriptionRegisterContext()
|
|
if (!ctx || !ctx.special_prescription_id) return
|
|
|
|
try {
|
|
const res = await createSpecialPrescriptionPatientRecordApi({
|
|
register_id: registerId,
|
|
special_prescription_id: ctx.special_prescription_id,
|
|
dose_count: ctx.dose_count || 1,
|
|
store_id: uni.getStorageSync('store_id') || '11001',
|
|
doctor_id: ctx.doctor_id,
|
|
})
|
|
if (res.data?.code === 0 || res.data?.code === '0') {
|
|
clearSpecialPrescriptionRegisterContext()
|
|
}
|
|
} catch (e) {
|
|
console.error('tryCreateSpecialPrescriptionPatientRecord', e)
|
|
}
|
|
}
|