import { common } from '@/uni-app-base/utils'; import icon from '@/utils/icon'; // TODO: 需要创建 pagesNetHos 相关的 API 服务 // import { cancelConsultWater } from '@/pagesNetHos/service/doctor'; // import { HisYyWaterList_V2, regSign } from '@/pagesNetHos/service/enquire'; // import { GetSysConfigEntity, orderCancel, orderListLocal } from '@/pagesNetHos/service/record'; import { getOrderStateName } from './getState'; import { strChineseFirstPY } from './code'; /** * 页面公用逻辑函数 */ const app = getApp(); /** * 获取首字母 */ export const getFirst = function (str: string): string { if (typeof (str) != "string") { return ''; } var word = str.charAt(0); return checkUnicode(word); }; /** * 转换字符 */ export const checkUnicode = function (word: string): string { var code = word.charCodeAt(0); if (code > 40869 || 40869 < 19968) { return ''; } return strChineseFirstPY.charAt(code - 19968); }; /** * 处理医生返回值 */ export const doctorListHandle = function (list: any[]): any[] { if (common.isEmpty(list)) { return list; } for (let i of list) { if (i.DoctorPhotourl) { if (i.DoctorPhotourl.indexOf("http") == -1) { // TODO: 需要获取 API 根路径 // i.DoctorPhotourl = api.ApiRootUrl + i.DoctorPhotourl.replace(/\\/g, "/"); } } else { i.DoctorPhotourl = icon.equire_doctor; } // 计算价格 i.phoneFeeDiy = i.PhoneFee ? common.centToYuan(i.PhoneFee).toFixed(2) : 0; i.videoFeeDiy = i.VideoFee ? common.centToYuan(i.VideoFee).toFixed(2) : 0; i.consultFeeDiy = i.ConsultFee ? common.centToYuan(i.ConsultFee).toFixed(2) : 0; let AvgAppraiseScore = '-'; // 用于做排序判断 let AvgAppraiseScoreTag = 0; if (i.AppraiseCount > 0 && i.AppraiseScore > 0) { AvgAppraiseScore = (i.AppraiseScore / i.AppraiseCount / 5 * 100).toFixed(0) + "%"; AvgAppraiseScoreTag = Number((i.AppraiseScore / i.AppraiseCount / 5 * 100).toFixed(0)); } i.AvgAppraiseScore = AvgAppraiseScore; i.AvgAppraiseScoreTag = AvgAppraiseScoreTag; // 计算好评率 if (true) { // TODO: 需要从 app.globalData.config 获取配置 const config = (app.globalData as any).config; if (config?.net_pageConfiguration_patient?.currency_config) { let highCount = config.net_pageConfiguration_patient.currency_config.iniHighAppraiseCount + (i.HighAppraiseCountCons || 0); let totalCount = config.net_pageConfiguration_patient.currency_config.iniHighAppraiseCount + (i.AppraiseCount !== undefined ? i.AppraiseCount : i.AppraiseCountCons || 0); let percentage = (highCount / totalCount) * 100; if (Number.isNaN(percentage)) { i.percentage = '100%'; } else { i.percentage = Math.ceil(percentage) + "%"; } } } i.scoreDiy = "5.0"; if ((i.AppraiseCount !== undefined ? i.AppraiseCount : i.AppraiseCountCons) && (i.AppraiseScore !== undefined ? i.AppraiseScore : i.AppraiseScoreCons)) { // 评分 i.scoreDiy = Math.ceil((i.AppraiseScore !== undefined ? i.AppraiseScore : i.AppraiseScoreCons) / (i.AppraiseCount !== undefined ? i.AppraiseCount : i.AppraiseCountCons)).toFixed(1); } if (i.AppraiseRule) { try { i.AppraiseRule = JSON.parse(i.AppraiseRule); } catch (err) { console.log('i.AppraiseRule格式化失败'); } } try { i.DoctorName = i.DoctorName.split('-')[0]; } catch (err) { } } return list; }; /** * 咨询记录返回值处理 */ export const consultListHandle = function (list: any[]): any[] { let arr = [ { status: 0, name: "未支付", isShow: 0 }, { status: 1, name: "待接单", isShow: 0 }, { status: 2, name: "进行中", isShow: 0 }, { status: 3, name: "已结束", isShow: 0 }, { status: 4, name: "超时未支付", isShow: 0 }, { status: 5, name: "已评价", isShow: 0 }, { status: 6, name: "仲裁中", isShow: 0 }, { status: 7, name: "仲裁被驳回", isShow: 0 }, { status: 8, name: "仲裁成功", isShow: 0 }, { status: 9, name: "超时未接单", isShow: 0 }, { status: 10, name: "已退费", isShow: 0 }, { status: 11, name: "接单驳回", isShow: 0 }, { status: 12, name: "视频未接通", isShow: 0 }, { status: 13, name: "视频已中断", isShow: 0 }, { status: 14, name: "已终结", isShow: 0 }, { status: 15, name: "医生团队待接单", isShow: 0 }, { status: 16, name: "待签到", isShow: 0 }, { status: 17, name: "已取消", isShow: 0 }, { status: 18, name: "超时未签到", isShow: 0 } ]; for (let item of list) { item.FirstMsgContent = item.FirstMsgContent ? JSON.parse(item.FirstMsgContent) : []; item.MedicalInfo = item.MedicalInfo ? JSON.parse(item.MedicalInfo) : {}; item.Yuan = common.centToYuan(item.ConsultFee); let firstMsgContentDiy: any = {}; for (let msgItem of item.FirstMsgContent) { firstMsgContentDiy[msgItem.key] = msgItem.value; } item.firstMsgContentDiy = firstMsgContentDiy; if (item.DoctorPhotourl) { if (item.DoctorPhotourl.indexOf("http") == -1) { // TODO: 需要获取 API 根路径 // item.DoctorPhotourl = api.ApiRootUrl + item.DoctorPhotourl.replace(/\\/g, "/"); } } else { item.DoctorPhotourl = icon.equire_doctor; } if (item.ConsultType == 1) { item.consultNameDiy = '图文咨询'; } else if (item.ConsultType == 2) { item.consultNameDiy = '视频咨询'; } else if (item.ConsultType == 3) { item.consultNameDiy = '电话咨询'; } item.consultFeeDiy = item.ConsultFee ? common.centToYuan(item.ConsultFee).toFixed(2) : 0; for (let i of arr) { if (i.status == item.Status) { item.statusDiy = i.name; break; } } } return list; }; /** * 取消咨询订单 */ export const cancelConsultOrder = async function (data: any, callBack?: () => void, type?: string): Promise { console.log(data, 'data'); let tip = '您正在进行退号操作,为了避免误操作带来的不必要损失,系统需要您再次确认,谢谢!'; if (type == 'qxzx') { tip = '您正在进行取消操作,为了避免误操作带来的不必要损失,系统需要您再次确认,谢谢!'; } common.showModal(tip, async () => { // TODO: 需要实现 API 调用 // const { resData } = await cancelConsultWater(data); // if (resData.RespCode == '10000') { // if (callBack instanceof Function) { // callBack(); // } // } }, { cancelText: "取消" }); }; /** * 签到 */ export const signOrCancel = async function (e: any, context?: any): Promise { // 列表为item 详情为orderInfo let item = e.currentTarget?.dataset?.item || (context?.data?.orderInfo) || (context?.data?.conItem); let { currentUser } = app.globalData as any; let waterData = { OrderId: item.YyWaterId, MemberId: item.MemberId, sourceType: '006', cardEncryptionStore: currentUser?.encryptionStore || '', memberEncryptionStore: currentUser?.baseMemberEncryptionStore || '', hosId: (app.globalData as any).hosId }; // TODO: 需要实现 API 调用 // const { resp: waterResp } = await HisYyWaterList_V2(waterData, { showLoading: false }); // if (!common.isEmpty(waterResp)) { // let data = { // HosId: (app.globalData as any).hosId, // OrderId: item.YyWaterId || waterResp[0].orderId, // MemberId: waterResp[0].MemberId || item.MemberId, // CardNo: waterResp[0].CardNo || waterResp[0].cardNo, // CardType: waterResp[0].CType || waterResp[0].cardType || "1", // HisOrderId: waterResp[0].HisOrderId || waterResp[0].hisOrderId, // SourceType: waterResp[0].sourceType || "006", // ChannelId: (app.globalData as any).channelId, // DeptCode: waterResp[0].DeptCode || waterResp[0].deptCode, // DoctorCode: waterResp[0].DoctorCode || waterResp[0].doctorCode, // DeptName: waterResp[0].DeptName || waterResp[0].deptName, // RegisterDate: waterResp[0].Registerdate || common.getDate(), // QueueNo: item.sqNo || waterResp[0].sqNo, // Store: { // cardEncryptionStore: currentUser?.encryptionStore || '', // baseMemberEncryptionStore: currentUser?.baseMemberEncryptionStore || '' // } // }; // const { resp, resData } = await regSign(data, { showLoading: false }); // if (!common.isEmpty(resp)) { // (app as any).connectWebsocket(true); // common.goToUrl(`/pagesNetHos/st1/business/doctor/waiting/waiting`); // } else { // common.showToast(resData.RespMessage); // } // } }; /** * 查询配置 */ export const getSysConfigEntity = function (): Promise { let data = { ParamKey: "PRESC_CONFIG_KEY" }; return new Promise(async resolve => { // TODO: 需要实现 API 调用 // const { resData } = await GetSysConfigEntity(data); // if (resData.RespCode == '10000') { // if (common.isNotEmpty(resData.Data)) { // resData.Data[0].ParamValue = JSON.parse(resData.Data[0].ParamValue); // } // resolve(resData.Data[0].ParamValue); // } else { // common.showToast(resData.RespMessage); // resolve(undefined); // } resolve(undefined); }); }; /** * 取消订单 */ export const cancelOrder = function (item: any, callback?: () => void): void { /**取消订单 */ common.showModal('是否确定取消该订单?', async () => { let orderCancelData = { OperatorName: item.OperatorName, OperatorId: item.OperatorId, OrderId: item.OrderId }; // TODO: 需要实现 API 调用 // const { resData } = await orderCancel(orderCancelData, item.ServiceId); // if (resData.RespCode === '10000') { // /**取消成功 */ // common.showModal('订单已取消', callback, { // confirmText: '好的' // }); // } else { // common.showToast(resData.RespMessage); // } }, { cancelText: '取消', confirmText: '确定' }); }; /** * 获取订单列表 * serviceId * pIndex 默认查询第0页 */ export const orderListLocal = async function (queryData: any): Promise<{ list: any[]; showNoData: boolean }> { // TODO: 需要实现 API 调用 // const { resp: listResp } = await orderListLocal(queryData); let listResp: any[] = []; let showNoData = true; let list: any[] = []; if (!common.isEmpty(listResp)) { listResp.map(item => { item.StateTxt = getOrderStateName(item.ServiceId, item.IsOnlinePay, item.PayState, item.BizState, item.OverState); if (!common.isEmpty(item.OrderMemo)) { item.OrderMemo = JSON.parse(item.OrderMemo); item.OrderMemo.formatWeek = common.dateFormat(new Date(item.OrderMemo.RegDate)).week; } }); } // 预约记录过滤已锁号 listResp = listResp.filter(item => item && item.StateTxt != '已锁号'); if (!common.isEmpty(listResp)) { list = listResp; showNoData = false; } return { list, showNoData }; }; /** * 判断是否有待支付订单 */ export const hasOrderToBePaid = async function (serviceId: string, memberId?: string): Promise { let queryData = { BeginDate: common.dateFormat(new Date(Date.now() - (30 * 24 * 60 * 60 * 1000))).formatYear, //开始时间 EndDate: common.dateFormat(new Date(Date.now() + (24 * 60 * 60 * 1000))).formatYear, //结束时间加一天 MemberId: memberId || ((app.globalData as any).currentUser && (app.globalData as any).currentUser.MemberId), BizState: '0', OverState: '0', PayState: '0', ServiceId: serviceId, OpenId: uni.getStorageSync('openid'), CardNo: '', CardType: '', Page: { PIndex: 0, PSize: 10 } }; // TODO: 需要实现 API 调用 // const { resp: listResp } = await orderListLocal(queryData); let listResp: any[] = []; listResp = listResp.filter(item => item.IsOnlinePay == '1'); if (!common.isEmpty(listResp)) { /**默认跳转预约挂号 预约挂号查询时传入0和009 与case判断不符 默认为预约记录路径*/ let url = `/pagesNetHos/st1/business/record/appointmentRecord/appointmentRecord`; switch (serviceId) { /**门诊住院充值 */ case '006': case '007': url = `/pagesNetHos/st1/business/record/topUpRecord/topUpRecord?serviceId=${serviceId}`; break; /**门诊结算 */ case '011': case '008': /**图文,视频咨询 */ case '019,024': case '040': url = `/pagesNetHos/st1/business/record/paymentRecord/paymentRecord`; break; } common.showModal(`您当前存在待支付订单,请前往订单管理中进行处理,谢谢您的合作!`, () => { common.goToUrl(url); }, { cancelText: '取消' }); return true; } return false; };