publicFn.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  1. /**
  2. * 页面公用逻辑函数
  3. */
  4. import { common } from '@kasite/uni-app-base/utils';
  5. import icon from './icon.js';
  6. import { request } from '@kasite/uni-app-base';
  7. import { REQUEST_CONFIG } from '@/config';
  8. // Helper to simulate old base API return structure
  9. const callApi = async (url, data) => {
  10. try {
  11. const resData = await request.doPost(`${REQUEST_CONFIG.BASE_URL}${url}`, data);
  12. return { resp: resData.Data, resData };
  13. } catch (e) {
  14. console.error('API Call Error', url, e);
  15. return { resp: null, resData: { RespCode: -1 } };
  16. }
  17. };
  18. const app = getApp();
  19. export default {
  20. // 判断app状态进行跳转
  21. async judgeAppStatus() {
  22. const {
  23. fixedAppjsGlobalData
  24. } = uni.getStorageSync("frontEndConfig")
  25. const {
  26. status,
  27. content
  28. } = await callApi('wsgw/basic/basicApi/GetAppStatus/callApiJSON.do', {
  29. appId: fixedAppjsGlobalData?.appId
  30. }).then(r => r.resp || {});
  31. switch (status) {
  32. case "maintain":
  33. uni.reLaunch({
  34. url: `/pages/st1/business/errorPage/maintain/maintain?content=${content}`,
  35. });
  36. break;
  37. case "offline":
  38. uni.reLaunch({
  39. url: "/pages/st1/business/errorPage/offline/offline",
  40. });
  41. break;
  42. default:
  43. break;
  44. }
  45. },
  46. /**
  47. * 首页 更多 个人中心 菜单点击
  48. */
  49. async menuClick(e, _this, skipWay = 'navigateTo') {
  50. let itemParent = e.currentTarget ? e.currentTarget.dataset.itemParent : {};
  51. let item = e.currentTarget ? e.currentTarget.dataset.item : e;
  52. let url = item.Url;
  53. // 判断为分院区
  54. if (getApp().globalData.hasDistrict && item.MenuName == "预约挂号") {
  55. url = `/pagesPatient/st1/business/otherService/hospitalDistrict/hospitalDistrict`
  56. }
  57. /**判断是否使用 */
  58. if ((itemParent && itemParent.IsUse && itemParent.IsUse != '1') || item.IsUse && item.IsUse != '1') {
  59. url = `/pages/st1/business/otherService/building/building`
  60. common.goToUrl(url)
  61. return;
  62. }
  63. // 当日挂号需要判断距离
  64. if (item.MenuName == "当日挂号") {
  65. try {
  66. const limitDistance = getApp().globalData.config.pageConfiguration.signInList_config.signDistance || 1; // 判断半径(取签到距离配置)
  67. await this.getHospitalLocationDistance(limitDistance);
  68. } catch (err) {
  69. await new Promise((resolve) => {
  70. common.showModal('需到院后才能挂当日号,且不支持无就诊卡进行挂号操作', resolve, {
  71. title: '温馨提示'
  72. });
  73. })
  74. }
  75. }
  76. /**来院导航 */
  77. if (item.MenuName == '来院导航') {
  78. this.getLocation()
  79. return;
  80. }
  81. /**跳转小程序 */
  82. if (item.AppId) {
  83. uni.navigateToMiniProgram({
  84. appId: item.AppId,
  85. path: item.Url
  86. })
  87. return;
  88. }
  89. /**判跳转第三方地址 */
  90. if (url.startsWith('https')) {
  91. common.goToUrl(`/pages/st1/business/h5/h5?url=${encodeURIComponent(url)}`)
  92. return;
  93. }
  94. /**如果有二级菜单页 */
  95. if (!common.isEmpty(item.Children)) {
  96. let queryBean = JSON.stringify(item)
  97. url = `${item.Url}`
  98. /**queryBena太长无法传值 赋值给globalData */
  99. getApp().globalData.selectUrl_x = queryBean;
  100. }
  101. /**
  102. * 以下菜单 判断是否有就诊人 没有则进入添加页面
  103. */
  104. let needMemberMenu = [
  105. 'rechargeMoney', // 充值缴费
  106. 'reportIndex', // 报告查询
  107. 'appointmentRecord', // 预约记录
  108. 'outpatientCosts', // 门诊清单
  109. 'hospitalCosts', // 住院清单
  110. 'cardRecord', // 门诊记录
  111. 'hosRecord', // 住院记录
  112. 'supplement', // 互联网医院提交咨询
  113. 'enquireList', // 互联网医院咨询记录
  114. 'doctorLike', // 互联网医院关注医生
  115. 'signInList', // 在线签到
  116. 'queueList', // 候诊查询
  117. 'orderPayment', // 门诊结算
  118. "prescriptionList", // 当日处方
  119. "paymentRecord", // 缴费记录
  120. "personalCenter", // 个人中心
  121. "continuationList", // 在线续方
  122. "drugCredentials", // 取药凭证
  123. "settlementRecord", // 结算记录
  124. "waitRecord", // 候补记录
  125. "dischargeMedication", // 出院带药
  126. "home", // 我的随访
  127. "chat-room", // AI智能就医助手
  128. "topUpRecord", //充值记录
  129. "newPrescriptionList", //当日处方2.0
  130. "prescriptionRecipe", //处方取药2.0
  131. "medicalTech", // 医技预约
  132. "outpatientRefund", //在线退费
  133. "selfProject", // 自助开单
  134. "mdtList", // MDT列表
  135. "recordList", // MDT记录
  136. "diseaseIndex", // 罕见病
  137. ];
  138. let has = false;
  139. for (let i of needMemberMenu) {
  140. if (url.indexOf(i) != '-1') {
  141. has = true;
  142. break;
  143. }
  144. }
  145. if (has) {
  146. // 是否需要跳转授权页
  147. if (this.isToAuthPage()) {
  148. return;
  149. }
  150. /**如果当前menu在上面数组中 判断是否有就诊人 有就诊人根据条件判断是否需要就诊卡、住院号、授权信息
  151. * 不满足条件跳转到相应添加就诊卡或添加住院号页面
  152. */
  153. if (await this.toAddMemberOrNot(url)) {
  154. return
  155. }
  156. }
  157. common.goToUrl(url, {
  158. skipWay: skipWay
  159. })
  160. },
  161. /**
  162. * 是否需要跳转授权页
  163. */
  164. isToAuthPage() {
  165. // 判断小程序登录返回的wechatOpenid是否为null,null没有关注公众号,需要跳转授权页面进行授权处理
  166. if (uni.getStorageSync('wechatOpenid') === null && getApp().globalData.officialAuthOn) {
  167. common.goToUrl(`/pages/st1/business/h5/h5?type=0`, {
  168. skipWay: 'redirectTo'
  169. })
  170. return true;
  171. }
  172. // 判断没有获取登录Account信息
  173. if(common.isEmpty(getApp().globalData.userAccount)){
  174. this.isLoginAccount()
  175. return true;
  176. }
  177. return false
  178. },
  179. /**
  180. * 判断当前是否有就诊人 没有则前往添加页面
  181. * 返回url 或 undefined
  182. */
  183. async toAddMemberOrNot(url) {
  184. let cardType = '1'
  185. /**如果支持无卡预约 以下菜单不判断是否有就诊卡:挂号记录 在线签到 结算记录*/
  186. if (getApp().globalData.withoutCard) {
  187. let needCardArr = ['appointmentRecord', 'signInList', "settlementRecord"]
  188. for (let i of needCardArr) {
  189. if (url.indexOf(i) != '-1') {
  190. cardType = ''
  191. break;
  192. }
  193. }
  194. }
  195. /**以下菜单需要住院号:住院充值 住院报告 住院清单 住院记录 出院带药*/
  196. let needHosArr = ['rechargeMoney?pageType=zyjf', 'reportIndex?queryType=2', 'hospitalCosts', 'hosRecord', "dischargeMedication"]
  197. for (let i of needHosArr) {
  198. if (url.indexOf(i) != '-1') {
  199. cardType = '14'
  200. break;
  201. }
  202. }
  203. let member = await this.getDefaultMember({
  204. isKeepPage: true,
  205. cardType: cardType,
  206. url: url
  207. });
  208. if (common.isEmpty(member)) {
  209. // 判断如果是不全等于null 是跳转添加界面 ,因如果全等于null安卓机跳转中间件
  210. if (member !== null) {
  211. getApp().globalData.toUrl = url;
  212. getApp().globalData.cardType = cardType;
  213. common.goToUrl(`/pagesPersonal${uni.getStorageSync('wx_Slb')?'Slb':''}/st1/business/patientManagement/addMember/addMember`)
  214. }
  215. return true
  216. }
  217. return false
  218. },
  219. /**
  220. * 获取并全局默认操作人
  221. * 默认卡号可以为空 默认获取报告单
  222. * url(保留要跳转的页面)
  223. * cardType(查询类型) 1查询就诊卡 14查询住院号 空查询就诊人
  224. * isKeepPage(是否保留选择界面)
  225. */
  226. async getDefaultMember(data = {}) {
  227. getApp().globalData.cardType = null
  228. let member = {}
  229. let defaultInfo = await this.getMember('defaultInfo', data.cardType)
  230. if (!common.isEmpty(defaultInfo)) {
  231. member = await this.currentUsersFilter(defaultInfo, data.cardType)
  232. // 判断返回为空 或者 要查询到的是有卡类型的,当时过滤时返回的是没有的卡号的
  233. if (common.isEmpty(member) || (common.isNotEmpty(data.cardType) && common.isEmpty(member.cardNo))) {
  234. if (common.isNotEmpty(data.url)) {
  235. getApp().globalData.toUrl = data.url;
  236. }
  237. let type = data.cardType == 1 ? 'card' : data.cardType == 14 ? 'hospital' : 'member'
  238. let skipWay = data.isKeepPage ? 'navigateTo' : 'redirectTo'
  239. common.goToUrl(`/pagesPersonal${uni.getStorageSync('wx_Slb')?'Slb':''}/st1/business/patientManagement/selecteCardOrHos/selecteCardOrHos?type=${type}`, {
  240. skipWay: skipWay
  241. })
  242. return null
  243. }
  244. }
  245. getApp().globalData.currentUser = member
  246. return member
  247. },
  248. /**
  249. * 如果toUrl有值 即为添加就诊卡后跳转进toUrl页面 或 cardDeleted为true时(点击过删除按钮)
  250. * 需要判断卡列表是否为空 为空返回上一页
  251. * _this 当前调用页面
  252. */
  253. async cardListIsEmpty(cardType, _this) {
  254. if (getApp().globalData.toUrl) {
  255. getApp().globalData.toUrl = ""
  256. let member = await this.getDefaultMember({
  257. cardType: cardType,
  258. });
  259. if (common.isEmpty(member)) {
  260. common.showModal(`该功能需要添加就诊卡`, () => {
  261. common.navigateBack(1)
  262. })
  263. return true;
  264. }
  265. }
  266. return false;
  267. },
  268. // cardType (type为获取默认操作人,才有效果,1:获取默认人下默认就诊卡;14:取默认人下默认住院号)
  269. async getMember(type = 'memberList', cardType = 1) {
  270. // type 值
  271. // memberList: 查询就诊人列表,仅返回就诊人列表
  272. // cardList: 查询就诊人列表并循环查询卡列表,返回所有就诊人下的所有卡
  273. // defaultList: 查询就诊人列表,返回所有人列表,如果有默认就诊人就返回默认就诊人的就诊卡,如果没有就选第0条
  274. // defaultInfo: 获取默认人下的所有卡,搭配cardType并过滤不是默认卡,仅返回默认cardTyp类型组合的一个对象
  275. return new Promise(async (resolve, reject) => {
  276. let resp = await uni.getStorageSync('memberList') || []
  277. let memberList = []
  278. let currentUser = {}
  279. if (!resp.length && getApp().globalData.userAccount) {
  280. await this.preserMember()
  281. resp = uni.getStorageSync('memberList')
  282. }
  283. if (common.isNotEmpty(resp)) {
  284. memberList = resp
  285. // 判断为获取默认就诊人
  286. if (type == 'defaultInfo') {
  287. let memberLists = memberList.filter(item => item.userMemberList[0].isDefaultMember == 1)
  288. // 判断过滤默认操作人
  289. if (common.isNotEmpty(memberLists)) {
  290. currentUser = memberLists[0]
  291. } else {
  292. // 没有默认操作人查询人列表第一条
  293. currentUser = memberList[0]
  294. }
  295. if (common.isNotEmpty(cardType)) {
  296. let resp = await this.queryMemberCardList_V3(currentUser.memberId)
  297. if (common.isNotEmpty(resp)) {
  298. currentUser.data_1 = resp
  299. }
  300. }
  301. resolve(currentUser)
  302. }
  303. // 判断为获取默认列表 返回所有人列表,如果有默认就诊人就返回默认就诊人的就诊卡,如果没有就选第0条
  304. if (type == 'defaultList') {
  305. let memberListIndex = 0
  306. let userInfo = memberList[memberListIndex]
  307. memberList.forEach((item, index) => {
  308. if (item.userMemberList[0].isDefaultMember == 1) {
  309. userInfo = item
  310. memberListIndex = index
  311. }
  312. })
  313. let resp = await this.queryMemberCardList_V3(userInfo.memberId)
  314. if (common.isNotEmpty(resp)) {
  315. memberList[memberListIndex].data_1 = resp
  316. }
  317. resolve(memberList)
  318. }
  319. // 判断为获取所有人下所有卡列数据
  320. if (type == 'cardList') {
  321. for (var item of memberList) {
  322. let resp = await this.queryMemberCardList_V3(item.memberId)
  323. if (common.isNotEmpty(resp)) {
  324. item.Data_1 = resp
  325. } else {
  326. item.Data_1 = []
  327. }
  328. }
  329. }
  330. resolve(memberList)
  331. } else {
  332. resolve([])
  333. }
  334. })
  335. },
  336. // 获取就诊人下的his卡信息
  337. async queryMemberCardList_V3(memberId) {
  338. return new Promise(async (resolve, reject) => {
  339. let querData = {
  340. hosId: getApp().globalData.hosId,
  341. memberId: memberId,
  342. cardNoFormatDesensitization: "false"
  343. }
  344. let {
  345. resp,
  346. resData
  347. } = await callApi('wsgw/accountMember/api/QueryMemberCardList_V3/callApiJSON.do', querData)
  348. if (resData.RespCode == 10000 && common.isNotEmpty(resp)) {
  349. resolve(resp)
  350. } else {
  351. resolve([])
  352. }
  353. })
  354. },
  355. // 过滤使用人信息
  356. async currentUsersFilter(currentUsers, cardType) {
  357. return new Promise(async (resolve, reject) => {
  358. let currentUser = {}
  359. let cardUser = {}
  360. // 判断存在数据进行过滤
  361. if (currentUsers.data_1) {
  362. let cardDataList = []
  363. for (var item of currentUsers.data_1) {
  364. if (item.cardType == cardType) {
  365. cardDataList.push(item)
  366. }
  367. if (item.isDefault == 1 && item.cardType == cardType) {
  368. cardUser = item
  369. }
  370. }
  371. if (common.isEmpty(cardUser)) {
  372. cardUser = cardDataList[0]
  373. }
  374. if (common.isNotEmpty(cardUser)) {
  375. currentUser = common.mergeObject(currentUsers, cardUser)
  376. } else {
  377. if (common.isEmpty(cardType)) {
  378. currentUser = currentUsers
  379. }
  380. }
  381. } else if (common.isNotEmpty(currentUsers)) {
  382. currentUser = currentUsers
  383. }
  384. resolve(currentUser)
  385. })
  386. },
  387. //查询并保存全局所有就诊人数据信息 (就诊人改变后都要重新调用,并保存一遍)
  388. async preserMember() {
  389. let queryData = {
  390. isCache: false,
  391. isEncrypt: true,
  392. hosId: getApp().globalData.districtId || getApp().globalData.hosId,
  393. openid: uni.getStorageSync('openid'),
  394. }
  395. let {
  396. resp,
  397. resData
  398. } = await callApi('wsgw/accountMember/api/QueryBaseMemberList_V3/callApiJSON.do', queryData)
  399. // 请求成功且有返回值保存全局就诊人数据列表
  400. getApp().globalData.currentUser = null;
  401. if (resData.RespCode == 10000 && common.isNotEmpty(resp)) {
  402. uni.setStorageSync('memberList', resp)
  403. } else {
  404. // 否则保存空
  405. uni.setStorageSync('memberList', null)
  406. }
  407. },
  408. /**
  409. * 倒计时
  410. */
  411. countDown(timer) {
  412. // This assumes this context has setData (Options API or legacy Page)
  413. if (this.data && this.data.seconds <= 0) {
  414. this.setData({
  415. seconds: 120
  416. })
  417. }
  418. let seconds = this.data ? this.data.seconds : 0;
  419. if (timer) {
  420. clearInterval(timer)
  421. }
  422. timer = setInterval(() => {
  423. if (seconds > 0) {
  424. seconds--
  425. } else {
  426. seconds = 0
  427. clearInterval(timer)
  428. }
  429. if (this.setData) {
  430. this.setData({
  431. seconds
  432. })
  433. }
  434. }, 1000)
  435. },
  436. /**
  437. * 来院导航
  438. */
  439. getLocation() {
  440. let hospitalInfo = getApp().globalData.hospitalInfo;
  441. let data = {
  442. latitude: Number(hospitalInfo.Wd), //要去的纬度-地址
  443. longitude: Number(hospitalInfo.Jd), //要去的经度-地址
  444. name: hospitalInfo.HospitalAlias,
  445. address: hospitalInfo.HospitalAddress
  446. }
  447. this.locationIsauthorization('gcj02', () => {
  448. uni.openLocation(data)
  449. })
  450. },
  451. /**
  452. * 地理位置是否授权
  453. */
  454. locationIsauthorization(type, callBack) {
  455. uni.getLocation({
  456. type: type,
  457. success: function (res) {
  458. callBack(res)
  459. },
  460. fail: function (err) {
  461. if (err.errMsg.includes('1')) {
  462. common.showToast('访问个人地址失败,请查看是否开启地理位置权限')
  463. } else {
  464. common.showModal('位置信息获取失败,请打开应用权限', () => {
  465. uni.openSetting({
  466. success: function (res) {
  467. res.authSetting['scope.userLocation'];
  468. }
  469. });
  470. }, {
  471. cancelText: '取消',
  472. confirmText: '打开'
  473. })
  474. }
  475. }
  476. });
  477. },
  478. // 判断当前业务页面用户是否需要授权
  479. isPageUserAuth(currentUser, _this) {
  480. return new Promise(async (resolve, reject) => {
  481. // 返回值
  482. let has = false
  483. // 获取统一要授权的业务页面配置信息
  484. let authBusinessPageObj = getApp().globalData.config.pageConfiguration.currency_config.authBusinessPage
  485. // 获取当前业务页面地址
  486. let pages = getCurrentPages()
  487. let currentPage = pages[pages.length - 1]
  488. let businessPageUrls = currentPage.route.split("/");
  489. let pageObjName = businessPageUrls[businessPageUrls.length - 1]
  490. // 获取当前业务页面配置的授权信息
  491. let authLevel = authBusinessPageObj[pageObjName]
  492. // 判断 authLevel不为空且当前用户信息小余当前业务需要授权的业务等级,代表当前业务页面需要先授权
  493. if (common.isNotEmpty(authLevel)) {
  494. let res = await callApi('wsgw/accountMember/api/QueryAccountUserLevel/callApiJSON.do', {
  495. openId: uni.getStorageSync('openid'),
  496. memberId: currentUser.memberId,
  497. }).then(r => r.resp)
  498. has = res && res[0] && res[0].accountUserLevel < authLevel ? true : false
  499. }
  500. _this.setData({
  501. authorize: has,
  502. authLevel: authLevel
  503. })
  504. resolve(has)
  505. })
  506. },
  507. /**
  508. 判断当前用户是否被本人授权
  509. currentUser:查询的用户
  510. checkKey :{
  511. Book: 预约挂号授权
  512. Charge: 充值缴费授权
  513. }
  514. isShowMode: 是否弹窗提示
  515. */
  516. isCurrentUserAuth(currentUser, checkKey, isShowMode) {
  517. return new Promise(async (resolve, reject) => {
  518. // 判断如果是本人,不读取授权认证,皆为通过
  519. if (currentUser.memberType == 1) {
  520. resolve(false)
  521. } else {
  522. // 没有accountSn就代表没有验证过本人,不做授权判断
  523. if (common.isEmpty(currentUser.accountSn)) {
  524. resolve(false)
  525. }
  526. //否者就不是本人,查询授权数据信息,判断是否授权
  527. let {
  528. resp,
  529. resData
  530. } = await callApi('wsgw/accountMember/api/QueryAccountAuthDetail/callApiJSON.do', {
  531. accountSn: currentUser.accountSn,
  532. memberId: currentUser.memberId,
  533. seniorOpen: 1
  534. })
  535. let has = false
  536. if (resData.RespCode == '10000') {
  537. let authInfo = resp[0]
  538. // 判断当前用户 已开 启高级授权
  539. if (authInfo.SeniorOpen == 1) {
  540. // 判断 不在 授权时限内
  541. if (common.isNotEmpty(authInfo.SeniorTime) && common.getTowNumDay(authInfo.SeniorTime, common.getDate()) < 0) {
  542. has = true
  543. }
  544. } else {
  545. if (authInfo[checkKey + 'Open'] == 0 || (authInfo[checkKey + 'Open'] == 1 && common.isNotEmpty(authInfo[checkKey + 'Time']) && common.getTowNumDay(authInfo[checkKey + 'Time'], common.getDate()) < 0)) {
  546. // 判断普通授权,根据
  547. has = true
  548. }
  549. }
  550. if (has && isShowMode) {
  551. common.showModal('当前亲友成员未被授权,请联系本人授权后,在代为操作')
  552. }
  553. resolve(has)
  554. } else {
  555. resolve(false)
  556. }
  557. }
  558. })
  559. },
  560. // 是否登陆账号
  561. isLoginAccount() {
  562. const userAccount = getApp().globalData.userAccount || {}
  563. if (!Object.keys(userAccount).length) {
  564. // 未登陆账号,跳转到登陆页面
  565. common.goToUrl('/pages/st1/business/login/authorization/authorization')
  566. }
  567. },
  568. // OpenID 获取账号信息
  569. async getAccountByOpenid(clear) {
  570. const userAccout = getApp().globalData.userAccount
  571. if (userAccout && !clear) {
  572. return userAccout
  573. }
  574. if (userAccout && userAccout.keep) {
  575. delete userAccout.keep
  576. return userAccout
  577. }
  578. const {
  579. resp
  580. } = await callApi('wsgw/accountMember/api/GetLastLoginAccount/callApiJSON.do', {
  581. openId: uni.getStorageSync("openid")
  582. })
  583. if (resp) {
  584. getApp().globalData.userAccount = resp.length ? resp[0] : null
  585. }
  586. },
  587. // 手机号 获取账号信息,没有账号信息则默认新增
  588. async getAccountByPhone(code) {
  589. const {
  590. fixedAppjsGlobalData,
  591. webUiDiy
  592. } = uni.getStorageSync("frontEndConfig")
  593. // 获取账号信息
  594. const openid = uni.getStorageSync("openid")
  595. const {
  596. resp
  597. } = await callApi('wsgw/accountMember/api/CreateAccount/callApiJSON.do', {
  598. openId: openid,
  599. code,
  600. smallProConfigKey: fixedAppjsGlobalData?.configKey,
  601. })
  602. if (!resp) return
  603. // 如果没有最后一次登录信息,直接跳转
  604. // 或者没开短信验证,则不做验证,直接返回前面的页面
  605. // 或者openId 一直
  606. if (!resp[0].lastLoginInfo || !webUiDiy.pageConfiguration?.login_config?.messageSys || openid == resp[0].lastLoginInfo.openId) {
  607. getApp().globalData.userAccount = Object.assign({}, resp[0], {
  608. keep: true
  609. })
  610. uni.navigateBack()
  611. return
  612. }
  613. // 对比OpenId,不一致则跳转到短信登录验证页面
  614. if (openid != resp[0].lastLoginInfo.openId) {
  615. uni.redirectTo({
  616. url: `/pages/st1/business/login/verify/verify?accountSn=${resp[0].accountSn}&phone=${resp[0].mobile}`
  617. })
  618. }
  619. },
  620. async loadViewMenu() {
  621. const { resp } = await callApi('wsgw/basic/basicApi/CacheGetValue/callApiJSON.do', {
  622. key: 'smallproViewMenu'
  623. })
  624. if (resp && resp.length) {
  625. const menu = JSON.parse(resp[0].Value || "[]")
  626. menu.length && uni.setStorageSync('menuList', menu)
  627. }
  628. },
  629. /**
  630. * 获取当前位置与医院的距离
  631. * @param {Number} distance 距离半径(单位:公里)
  632. */
  633. getHospitalLocationDistance(limitDistance = 1) {
  634. const {
  635. hospitalInfo
  636. } = getApp().globalData; // 获取医院信息
  637. if (common.isEmpty(hospitalInfo)) {
  638. common.showModal(`获取医院信息失败`);
  639. return;
  640. }
  641. const {
  642. Wd: hosLat,
  643. Jd: hosLng
  644. } = hospitalInfo;
  645. if (common.isEmpty(hosLat) || common.isEmpty(hosLng)) {
  646. common.showModal(`获取医院配置失败`);
  647. return;
  648. }
  649. return new Promise((resolve, reject) => {
  650. this.locationIsauthorization('gcj02', (res) => {
  651. let distance = common.getDistance(res.latitude, res.longitude, hosLat, hosLng);
  652. distance > limitDistance ? reject() : resolve();
  653. })
  654. })
  655. },
  656. /**
  657. * 处理首页和医院概况轮播图片地址
  658. */
  659. handlePhoto() {
  660. let photoArr = []
  661. let hospitalInfo = common.deepCopy(app.globalData.hospitalInfo);
  662. if (!common.isEmpty(hospitalInfo.PhotoUrl)) {
  663. hospitalInfo.PhotoUrl = JSON.parse(hospitalInfo.PhotoUrl)
  664. /**处理图片url */
  665. for (let i in hospitalInfo.PhotoUrl) {
  666. hospitalInfo.PhotoUrl[i] = hospitalInfo.PhotoUrl[i].indexOf('http') != '-1' ? hospitalInfo.PhotoUrl[i] : `${REQUEST_CONFIG.BASE_URL}${hospitalInfo.PhotoUrl[i]}`
  667. photoArr.push(hospitalInfo.PhotoUrl[i])
  668. }
  669. }
  670. return photoArr
  671. },
  672. /**
  673. * 调起人脸识别
  674. */
  675. startFacialRecognitionVerify(data) {
  676. return new Promise((resolve, reject) => {
  677. // #ifdef MP-WEIXIN
  678. wx.startFacialRecognitionVerify({
  679. name: data.memberName,
  680. idCardNumber: data.idCardNo,
  681. checkAliveType: 1,
  682. success: function (res) {
  683. resolve({
  684. success: true,
  685. value: res
  686. })
  687. },
  688. fail: function (res) {
  689. reject({
  690. success: false,
  691. value: res
  692. })
  693. }
  694. })
  695. // #endif
  696. // #ifndef MP-WEIXIN
  697. common.showToast('非微信小程序环境不支持人脸识别');
  698. reject({ success: false, msg: 'Not supported' });
  699. // #endif
  700. })
  701. },
  702. // 处理医生返回值
  703. doctorListHandle(list) {
  704. if (common.isEmpty(list)) {
  705. return list
  706. }
  707. for (let i of list) {
  708. if (i.DoctorPhotourl) {
  709. if (i.DoctorPhotourl.indexOf("http")) {
  710. i.DoctorPhotourl = REQUEST_CONFIG.BASE_URL + i.DoctorPhotourl.replace(/\\/g, "/")
  711. }
  712. } else {
  713. i.DoctorPhotourl = icon.equire_doctor
  714. }
  715. // 计算价格
  716. i.phoneFeeDiy = i.PhoneFee ? common.centToYuan(i.PhoneFee).toFixed(2) : 0
  717. i.videoFeeDiy = i.VideoFee ? common.centToYuan(i.VideoFee).toFixed(2) : 0
  718. i.consultFeeDiy = i.ConsultFee ? common.centToYuan(i.ConsultFee).toFixed(2) : 0
  719. let AvgAppraiseScore = '-';
  720. // 用于做排序判断
  721. let AvgAppraiseScoreTag = 0;
  722. if (i.AppraiseCount > 0 && i.AppraiseScore > 0) {
  723. AvgAppraiseScore = (i.AppraiseScore / i.AppraiseCount / 5 * 100).toFixed(0) + "%";
  724. AvgAppraiseScoreTag = (i.AppraiseScore / i.AppraiseCount / 5 * 100).toFixed(0);
  725. }
  726. i.AvgAppraiseScore = AvgAppraiseScore;
  727. i.AvgAppraiseScoreTag = AvgAppraiseScoreTag;
  728. // 计算好评率
  729. if (true) {
  730. let highCount = getApp().globalData.config.net_pageConfiguration_patient.currency_config.iniHighAppraiseCount + i.HighAppraiseCountCons
  731. let totalCount = getApp().globalData.config.net_pageConfiguration_patient.currency_config.iniHighAppraiseCount + (i.AppraiseCount !== undefined ? i.AppraiseCount : i.AppraiseCountCons)
  732. let percentage = (highCount / totalCount) * 100
  733. if (Number.isNaN(percentage)) {
  734. i.percentage = '100%'
  735. } else {
  736. i.percentage = Math.ceil(percentage) > 100 ? 100 + "%" : Math.ceil(percentage) + "%"
  737. }
  738. }
  739. i.scoreDiy = "5.0"
  740. if ((i.AppraiseCount !== undefined ? i.AppraiseCount : i.AppraiseCountCons) && (i.AppraiseScore !== undefined ? i.AppraiseScore : i.AppraiseScoreCons)) {
  741. // 评分
  742. i.scoreDiy = Math.ceil((i.AppraiseScore !== undefined ? i.AppraiseScore : i.AppraiseScoreCons) / (i.AppraiseCount !== undefined ? i.AppraiseCount : i.AppraiseCountCons)).toFixed(1)
  743. }
  744. if (i.AppraiseRule) {
  745. try {
  746. i.AppraiseRule = JSON.parse(i.AppraiseRule)
  747. } catch (err) {
  748. console.log('i.AppraiseRule格式化失败')
  749. }
  750. }
  751. }
  752. return list
  753. },
  754. /** 查询患者分类列表
  755. * 规则:
  756. * 返参ClassificationType等于2为复诊患者规则,带入就诊记录(已签到)进行结果判断,符合则为复诊患者
  757. * 若接口返回空,则为初诊患者
  758. */
  759. async queryPatientClassifiyList(member, doctorCode, self) {
  760. return new Promise(async (resolve, reject) => {
  761. let data = {
  762. Status: 1
  763. }
  764. let {
  765. resp,
  766. resData
  767. } = await callApi('wsgw/yy/yygh/QueryPatientClassifiyList/callApiJSON.do', data)
  768. console.log("QueryPatientClassifiyList=====", resp)
  769. if (resData.RespCode == "10000") {
  770. if (common.isNotEmpty(resp)) {
  771. // 筛选出复诊患者规则
  772. let visit = resp.filter((item) => {
  773. return item.ClassificationType == 2
  774. })
  775. console.log("visit=====", visit)
  776. // 有复诊规则,执行预约记录的规则匹配逻辑
  777. if (common.isNotEmpty(visit)) {
  778. self.setData({
  779. patientClassificationId: 2
  780. })
  781. try {
  782. member.memberOtherInfo = JSON.parse(member.memberOtherInfo)
  783. console.log("true")
  784. } catch {
  785. member.memberOtherInfo = member.memberOtherInfo
  786. console.log("false")
  787. }
  788. console.log("member=======", member)
  789. resolve(await this.queryOutpatientVisitList(member, visit[0], doctorCode))
  790. } else {
  791. self.setData({
  792. patientClassificationId: 1
  793. })
  794. resolve(false)
  795. }
  796. } else {
  797. resolve(false)
  798. }
  799. } else {
  800. resolve(false)
  801. }
  802. })
  803. },
  804. /** 查询his预约记录并判断是否为复诊患者 */
  805. async queryOutpatientVisitList(member, rule, doctorCode) {
  806. return new Promise(async (resolve, reject) => {
  807. let day = common.mul(rule.IntervalNum, 30)
  808. var reqData = {
  809. HosId: getApp().globalData.districtId || getApp().globalData.hosId,
  810. StartDate: common.aFewDaysago(day),
  811. EndDate: common.newDay(),
  812. IgnoreHosId: true,
  813. QueryAll: getApp().globalData.districtId || getApp().globalData.hosId,
  814. MemberId: member.memberId,
  815. CardType: member.cardType || "1",
  816. CardNo: member.memberOtherInfo.defaultCard.cardNo,
  817. Store: {
  818. cardEncryptionStore: member.encryptionStore || '',
  819. baseMemberEncryptionStore: member.baseMemberEncryptionStore
  820. }
  821. }
  822. let {
  823. resp,
  824. resData
  825. } = await callApi('wsgw/member/memberApi/QueryOutpatientVisitList/callApiJSON.do', reqData)
  826. console.log("QueryOutpatientVisitList=====", resp)
  827. if (resData.RespCode == "10000") {
  828. if (common.isNotEmpty(resp)) {
  829. resp = resp.filter((item) => {
  830. return item.CardNo == member.cardNo
  831. })
  832. if (common.isNotEmpty(resp)) {
  833. // 返回列表
  834. if (member.List) {
  835. resolve(resp)
  836. return
  837. }
  838. // 需判断就诊记录和对应医生的匹配次数
  839. if (common.isNotEmpty(doctorCode)) {
  840. let docRecord = resp.filter((item) => {
  841. return item.DoctorCode == doctorCode
  842. })
  843. if (docRecord.length >= rule.HistoryMedicalTimesNum) {
  844. resolve(true)
  845. } else {
  846. resolve(false)
  847. }
  848. }
  849. // 直接判断就诊次数和配置中的是不是匹配
  850. else {
  851. if (resp.length >= rule.HistoryMedicalTimesNum) {
  852. resolve(true)
  853. } else {
  854. resolve(false)
  855. }
  856. }
  857. } else {
  858. resolve(false)
  859. }
  860. } else {
  861. resolve(false)
  862. }
  863. } else {
  864. resolve(false)
  865. }
  866. })
  867. },
  868. /**
  869. * 查询医生排班公共方法
  870. * @param {Object} data - 查询参数
  871. * @param {Object} options - 额外配置参数
  872. * @returns {Array} - 处理后的医生排班数据
  873. */
  874. async queryClinicDoctorSchedule(resp, options = {}) {
  875. if (!common.isEmpty(resp)) {
  876. for (let i of resp) {
  877. if (i.Data_1 && !common.isEmpty(i.Data_1)) {
  878. i.Data_1.map(item => {
  879. item.RegDateDiy = item.RegDate.substring(5),
  880. item.WeekName = item.RegDate == common.newDay() ? '今天' : item.WeekName
  881. })
  882. }
  883. /**如果医生头像没有域名 添加域名 */
  884. if (i.PhotoUrl && i.PhotoUrl.indexOf('http') == '-1') {
  885. i.PhotoUrl = REQUEST_CONFIG.BASE_URL + i.PhotoUrl
  886. }
  887. i.PhotoUrl = i.PhotoUrl.replace(/\\/g, '/')
  888. if (i.Data_1.length > 6) {
  889. i.Data_1_Diy = i.Data_1.slice(0, 5);
  890. i.showAllSchedu = false
  891. } else {
  892. i.Data_1_Diy = i.Data_1;
  893. i.showAllSchedu = true;
  894. }
  895. }
  896. }
  897. resp.map(item => {
  898. let obj = [{
  899. Check: true,
  900. DeptName: item.DeptName,
  901. DeptCode: item.DeptCode,
  902. DoctorName: item.DoctorName,
  903. DoctorCode: item.DoctorCode,
  904. Data_1: item.Data_1,
  905. Data_1_Diy: item.Data_1_Diy,
  906. showAllSchedu: item.showAllSchedu,
  907. }]
  908. item.Scheduling = obj
  909. item.HosId = options.hosId
  910. item.ChoiceHosId = options.hosId
  911. })
  912. return resp
  913. },
  914. /**
  915. * 医生与诊疗组匹配
  916. * @param {Array} doctors - 医生列表
  917. * @param {Array} groupList - 诊疗组列表
  918. */
  919. matchDoctorsWithGroup(doctors, groupList) {
  920. if (!groupList || !Array.isArray(groupList)) return;
  921. // 创建一个Map来存储诊疗组信息,key为医生代码
  922. const doctorGroupMap = new Map();
  923. // 遍历所有诊疗组,收集医生与诊疗组的对应关系
  924. groupList.forEach(group => {
  925. if (group.doctorList && Array.isArray(group.doctorList)) {
  926. group.doctorList.forEach(doctor => {
  927. if (doctor.code) {
  928. doctorGroupMap.set(doctor.code, group);
  929. }
  930. });
  931. }
  932. });
  933. // 标记医生是否属于诊疗组,并赋值诊疗组信息
  934. doctors.forEach(doctor => {
  935. const groupInfo = doctorGroupMap.get(doctor.DoctorCode);
  936. doctor.IsGroup = !!groupInfo;
  937. if (groupInfo) {
  938. doctor.GroupInfo = groupInfo;
  939. }
  940. });
  941. },
  942. /** 全局开启分享 */
  943. overShareMenu() {
  944. // #ifdef MP-WEIXIN
  945. wx.onAppRoute(() => {
  946. //获取加载的页面
  947. let pages = getCurrentPages(),
  948. //获取当前页面的对象
  949. view = pages[pages.length - 1];
  950. if (view && view.onShareAppMessage) {
  951. wx.showShareMenu({
  952. withShareTicket: true,
  953. menus: ['shareAppMessage', 'shareTimeline']
  954. })
  955. }
  956. })
  957. // #endif
  958. }
  959. }