const app = getApp(); import yygh from "../../../../config/api/yygh/index.js"; import pay from "../../../../config/api/pay/index.js"; import regeneratorRuntime from "../../../../../utils/runtime.js"; import common from "../../../../../utils/common.js"; import publicFn from "../../../../../utils/publicFn.js"; import { pagesPatientFn } from '@/utils'; import apiRootUrl from "../../../../../config/api.js"; import icon from "../../../../../utils/icon.js"; Page({ data: { iconUrl:icon, withoutCard:false,//是否可以无卡预约 noDataValue: '当前医生暂无排班', //医生是否有排班 doctorItem: {}, dateInfoSelected: {}, //当前选择的排班时间 showCon: false, showNoData: false, numberList: [], //预约时段 numberInfoSelected: {}, //当前选中的预约时段 currentUser: {}, doctorInfoIsShow: false, doctorInfo: {}, //医生详情信息 doctorListConfig: {}, //医生列表页配置 serviceId:'', }, onLoad: function(options) { let queryBean = app.globalData.queryBean || {}; /**医生列表页配置 */ let doctorListConfig = common.deepCopy(app.globalData.config.pageConfiguration.yyghDoctorList_config) /**当前页面配置 */ let pageConfig = common.deepCopy(app.globalData.config.pageConfiguration.yyghClinicMsg_config) let dateInfoSelected = {} /**通过上级页面传的item和点击的排班Index 取到当前点击的排班时间 如果是从预约挂号页面进来的 则取挂号排班时间*/ if(options?.schedule){ dateInfoSelected = common.parse(options?.schedule) }else if (queryBean.Data_1 && options.selectedIndex) { dateInfoSelected = queryBean.Data_1[options.selectedIndex] } options?.deptCode && (queryBean.DeptCode = options?.deptCode) options?.doctorCode && (queryBean.DoctorCode = options?.doctorCode) this.setData({ options:options, serviceId:options.serviceId || '', queryBean: queryBean, dateInfoSelected: dateInfoSelected, doctorListConfig: doctorListConfig, pageConfig: pageConfig, withoutCard: app.globalData.withoutCard }) }, onShow: function() { this.main() }, async main() { this.setData({ currentUser: app.globalData.currentUser }) let showNoData = true; /**获取医生信息 */ await this.setterDoctorList(); if (!common.isEmpty(this.data.doctorItem)) { showNoData = false /**获取预约时间段 */ await this.queryNumbers() } this.setData({ showCon: true, showNoData: showNoData }) }, /** * 医生详情点击 */ async doctorInfoClick() { let doctorItem = this.data.doctorItem; let queryData = { HosId: app.globalData.districtId || app.globalData.hosId, DeptCode: doctorItem.DeptCode || '', DoctorCode: doctorItem.DoctorCode || '', DoctorName: '' } let resp = await yygh.queryClinicBaseDoctor(queryData); if (!common.isEmpty(resp)) { this.setData({ doctorInfoIsShow: true, doctorInfo: resp[0] }) } }, /** * 预约时段点击 */ numberClick(e) { this.setData({ numberInfoSelected: this.data.numberList[e.currentTarget.dataset.index] }) }, /** * 日期选择 */ timeClick(e) { let item = e.currentTarget.dataset.item; let index = e.currentTarget.dataset.index; let schedulIndex = e.currentTarget.dataset.schedulindex; if ((item.IsHalt == 7 && item.WaitLeaveCount <= 0) || item.IsHalt == '2') { return; } this.setData({ numberList:[], dateInfoSelected: item }) // 判断不等于约满或者不等于停诊查询号源 if(item.IsHalt !=7 && item.IsHalt != '2'){ this.queryNumbers() } }, /** * 获取号源列表 */ async queryNumbers() { let dateInfoSelected = this.data.dateInfoSelected; let queryData = { HosId: app.globalData.districtId || app.globalData.hosId, DeptCode: dateInfoSelected.DeptCode, DoctorCode: dateInfoSelected.DoctorCode, RegDate: dateInfoSelected.RegDate, TimeSlice: dateInfoSelected.TimeSlice, ScheduleId: dateInfoSelected.ScheduleId, TransactionCode: 2002, } let numberList = await yygh.queryNumbers(queryData) let numberInfoSelected = {} if(!common.isEmpty(this.data.options?.number)){ numberInfoSelected = common.parse(this.data.options?.number) }else{ numberInfoSelected = numberList[0] } this.setData({ numberList: numberList || [], numberInfoSelected: numberInfoSelected, //默认选中第一个号源 }) }, /** * 处理医生列表返回值 */ async setterDoctorList() { let queryBean = this.data.queryBean; let dateInfoSelected = this.data.dateInfoSelected; let result = []; let hasAllSchedules = this.data.doctorListConfig.hasAllSchedules; let queryData = { HosId: app.globalData.districtId || app.globalData.hosId, DeptCode: queryBean.DeptCode, DoctorCode: queryBean.DoctorCode, WorkDateStart: hasAllSchedules ? "" : dateInfoSelected.RegDate, WorkDateEnd: hasAllSchedules ? "" : dateInfoSelected.RegDate, TitleCode: "", OrderByDoc: '1', WaitRule: '1' } // 判断为当日挂号 if(this.data.serviceId == '009'){ queryData.WorkDateStart = common.getDate() queryData.WorkDateEnd = common.getDate() queryData.ServiceId = this.data.serviceId } let resp = await yygh.queryClinicDoctorSchedule(queryData) if (!common.isEmpty(resp)) { let doctorItem = resp[0]; /**如果医生头像没有域名 添加域名 */ if (doctorItem.PhotoUrl && doctorItem.PhotoUrl.indexOf('http') == '-1') { doctorItem.PhotoUrl = apiRootUrl.ApiRootUrl + doctorItem.PhotoUrl } doctorItem.PhotoUrl = doctorItem.PhotoUrl.replace(/\\/g, '/') doctorItem.Data_1.map(item => { item.RegDateDiy = item.RegDate.substring(5) item.WeekName = item.RegDate == common.newDay()?'今天':item.WeekName item.DeptName = doctorItem.DeptName item.DeptCode = doctorItem.DeptCode item.DoctorName = doctorItem.DoctorName item.DoctorCode = doctorItem.DoctorCode }) // 数据处理 医生多科室 let obj = [{ Check:true, DeptName:doctorItem.DeptName, DeptCode:doctorItem.DeptCode, DoctorName:doctorItem.DoctorName, DoctorCode:doctorItem.DoctorCode, Data_1:doctorItem.Data_1, }] doctorItem.Scheduling = obj /**重新赋值当前项 否则提交订单后后退不刷新值 */ let dateInfoSelected = resp.filter(item => item && item.ScheduleId == this.data.dateInfoSelected.ScheduleId)[0] || this.data.dateInfoSelected this.setData({ doctorItem: doctorItem, /**历史医生进入 无ScheduleId 重新赋值 */ dateInfoSelected: this.data.dateInfoSelected.ScheduleId ? dateInfoSelected : doctorItem && doctorItem.Data_1 && doctorItem.Data_1[0] || {} }) } }, switchChange(e) { let value = e.detail.value; this.setData({ reducibleOnly: value }) this.main() }, /** * 立即预约点击 */ async confirmClick(e) { let currentUser = this.data.currentUser; let formId = e.detail.formId; let dateInfoSelected = this.data.dateInfoSelected; let numberInfoSelected = this.data.numberInfoSelected; let doctorItem = this.data.doctorItem; // 查询当前用户 是否被授权 if(await publicFn.isCurrentUserAuth(currentUser,'Book',true)) return /**是否存在待支付订单 */ if (await pagesPatientFn.hasOrderToBePaid('0,009')) return common.throttle(async() => { if (common.isEmpty(this.data.dateInfoSelected)) { common.showToast('请选择预约日期') return } if (common.isEmpty(this.data.numberInfoSelected)) { common.showToast('请选择预约时间') return } /**消息推送 */ // let pushData = { // SceneId: formeId, // OpenId: wx.getStorageSync('openid') // } // await complete.pushBaiduAndWxSceneId(pushData) /**锁号 */ let queryData = { HosId: app.globalData.districtId || app.globalData.hosId, ScheduleId: dateInfoSelected.ScheduleId, DeptCode: dateInfoSelected.DeptCode, DoctorCode: dateInfoSelected.DoctorCode, RegType: '1', RegDate: dateInfoSelected.RegDate, TimeSlice: dateInfoSelected.TimeSlice, SqNo: numberInfoSelected.SqNo, CommendTime: numberInfoSelected.EndTime ? `${numberInfoSelected.StartTime}-${numberInfoSelected.EndTime}` : numberInfoSelected.StartTime, SourceCode: numberInfoSelected.SourceCode, MemberId:currentUser.memberId, CardType: '1', CardNo: currentUser.cardNo || '', MemberStore:{ cardEncryptionStore: currentUser.encryptionStore || '', baseMemberEncryptionStore:currentUser.baseMemberEncryptionStore }, Store:{ cardEncryptionStore: currentUser.encryptionStore || '', baseMemberEncryptionStore:currentUser.baseMemberEncryptionStore } } let lockResp = await yygh.lockOrder(queryData); if (!common.isEmpty(lockResp)) { /**锁号成功 */ /**本地下单 */ let addorderData = { HosId: app.globalData.hosId, OrderId: lockResp[0].OrderId, PrescNo: '', PayMoney: lockResp[0].Fee, TotalMoney: lockResp[0].Fee, IsOnlinePay: lockResp[0].IsOnlinePay, PriceName: '挂号支付', OperatorId: wx.getStorageSync('openid'), ServiceId: '0', PayFeeItem: '0', EqptType: '1', BankCardNo: '', BankSeqNo: '', ChargeSource: '', MemberId: currentUser.memberId, OperatorName: currentUser.MemberName, Store:{ cardEncryptionStore: currentUser.encryptionStore || '', baseMemberEncryptionStore:currentUser.baseMemberEncryptionStore }, Data_1: { DoctorCode: dateInfoSelected.DoctorCode || doctorItem.DoctorCode, DoctorName: dateInfoSelected.DoctorName || doctorItem.DoctorName, DeptCode: dateInfoSelected.DeptCode || doctorItem.DeptCode, DeptName: dateInfoSelected.DeptName || doctorItem.DeptName, RegDate: dateInfoSelected.RegDate, CommendTime: numberInfoSelected.CommendTime, scene_id: formId, FeeInfo: lockResp[0].FeeInfo, scene_type: '1', TransactionCode: '6001' } } let addOrderResp = await pay.addOrderLocal(addorderData) if (!common.isEmpty(addOrderResp)) { /**本地下单成功 */ let url = `/pagesPatient/st1/business/pay/payState/payState?pageType=yygh&orderId=${lockResp[0].OrderId}` if (lockResp[0].IsOnlinePay == '1') { /**在线支付 */ url = `/pagesPatient/st1/business/pay/payMent/payMent?orderId=${lockResp[0].OrderId}` } else if (lockResp[0].IsOnlinePay == '2') { /**不支付 boockService挂号 */ let queryData = { HosId: app.globalData.districtId || app.globalData.hosId, OrderId: lockResp[0].OrderId, OperatorId: wx.getStorageSync('openid'), TransactionCode: "3003", MemberId: currentUser.memberId, SourceType:0, Store:{ cardEncryptionStore: currentUser.encryptionStore || '', baseMemberEncryptionStore:currentUser.baseMemberEncryptionStore }, } let {resp,resData} = await yygh.bookService(queryData) if (resData.RespCode != 10000) { await yygh.unlock({OrderId:lockResp[0].OrderId}) return } } common.goToUrl(url) } } }) }, /** * 查询医生其它科室排班 */ async queryScheduleList(e){ let hasAllSchedules = this.data.doctorListConfig.hasAllSchedules; let dateInfoSelected = this.data.dateInfoSelected; let doctorItem = this.data.doctorItem let querData = { workDateEnd: hasAllSchedules ? "" : dateInfoSelected.RegDate, workDateStart: hasAllSchedules ? "" : dateInfoSelected.RegDate, doctorCode: doctorItem.DoctorCode, deptCode:doctorItem.DeptCode , hosId: app.globalData.districtId || app.globalData.hosId, WaitRule: '1' } let res = await yygh.queryScheduleList(querData) if(common.isNotEmpty(res)){ let scheduleList = [] res.map(async (item,index)=>{ // 转换返回数据 小写转大写 item.hisQueryClinicSchedules = common.changeObj(item.hisQueryClinicSchedules) item.hisQueryBaseDoctor = common.changeObj(item.hisQueryBaseDoctor) if(item.hisQueryClinicSchedules.length > 0){ // 判断是否多数据处理 星期 时间 上下午 if(item.hisQueryClinicSchedules.length > 0){ item.hisQueryClinicSchedules.map(ele=>{ ele.WeekName = ele.RegDate == common.newDay()?'今天':common.weekDay(ele.RegDate,1) ele.RegDateDiy = ele.RegDate.substring(5) ele.TimeSliceStr = ele.TimeSlice==1?'上午':ele.TimeSlice==2?'下午':'全天' }) } scheduleList.push({ Check:item.hisQueryBaseDoctor.DeptCode==doctorItem.DeptCode?true:false, DeptName:item.hisQueryBaseDoctor.DeptName, DeptCode:item.hisQueryBaseDoctor.DeptCode, DoctorName:doctorItem.DoctorName, DoctorCode:doctorItem.DoctorCode, Data_1:item.hisQueryClinicSchedules, showAllSchedu:item.showAllSchedu, }) } }) // 给当前查询的医生新加列表 doctorItem.Scheduling = scheduleList } // 查询过的医生 不展示switch doctorItem.ShowDeptSwitch = true this.setData({ doctorItem:doctorItem }) }, /** * 折叠列表 */ foldList(e) { let schedulIndex = e.currentTarget.dataset.schedulindex let doctorItem = this.data.doctorItem // 当前点击的科室是打开的状态,则进行关闭,不查号源 if(doctorItem.Scheduling[schedulIndex].Check){ doctorItem.Scheduling[schedulIndex].Check = false this.setData({ doctorItem }) }else{ let dateInfoSelected = {} // 全部遍历关闭展开数据信息 doctorItem.Scheduling.map(item=>item.Check = false) // 当前打开 doctorItem.Scheduling[schedulIndex].Check = true // 过滤当前打开的排班信息 获取到未满未停诊的排班 let dateInfoSelecteds = doctorItem.Scheduling[schedulIndex].Data_1.filter(item=>item.IsHalt != '7' || item.IsHalt != '2') // 判断过滤条件是否为空 为空踢提示 if(common.isEmpty(dateInfoSelecteds)){ common.showToast("查询号源失败,请选择一个排班信息") }else{ // 否者查询号源 dateInfoSelected = dateInfoSelecteds[0] } this.setData({ dateInfoSelected: dateInfoSelected, doctorItem }) this.queryNumbers() } }, // 候补登记 async waitRegistration(){ let currentUser = this.data.currentUser; let dateInfoSelected = this.data.dateInfoSelected; let doctorItem = this.data.doctorItem; if(dateInfoSelected.WaitLeaveCount<=0)return let queryData = { HosId: app.globalData.districtId ||app.globalData.hosId, OpenId: wx.getStorageSync("openid"), MemberId: currentUser.memberId, ScheduleId: dateInfoSelected.ScheduleId, DeptCode: doctorItem.DeptCode, DoctorCode: doctorItem.DoctorCode, RegDate: dateInfoSelected.RegDate, WeekId: dateInfoSelected.WeekId, TimeId: dateInfoSelected.TimeSlice, Store:{ cardEncryptionStore: currentUser.encryptionStore || '', baseMemberEncryptionStore:currentUser.baseMemberEncryptionStore } } let {resp,resData} = await yygh.checkBeforeAddWaitList(queryData) if (resData.RespCode == '10000') { doctorItem.Intro = '' doctorItem.Data_1 = '' doctorItem.Scheduling = '' let querBen = encodeURIComponent(JSON.stringify({ doctorItem, dateInfoSelected })) common.goToUrl(`/pagesPatient/st1/business/yygh/waitRegistration/waitRegistration?querBen=${querBen}`) } } })