123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- import history from "./../../utils/history";
- import { getContentHeight } from "../../utils";
- import { getDepartmentList } from "./service";
- import { queryServiceByCode } from "../../service/common";
- import { reportCmPV_YL } from "../../utils/cloudMonitorHelper";
- Component({
- props: {
- componentData: {},
- },
- data: {
- index: 0,
- show: false,
- menus: [],
- cache: {},
- lastCache: {},
- loading: true,
- serviceItem: null,
- contentHeight: getContentHeight(),
- },
- async didMount() {
- /* 服务预警, 预约挂号 */
- reportCmPV_YL({
- title: "预约挂号",
- });
- const { hospitalDistrictId } = this.getQuery();
- try {
- await this.getServiceDetail(); // eslint-disable-next-line no-empty
- } catch (e) {}
- await this.fetchMenus(hospitalDistrictId);
- },
- methods: {
- updateData(data) {
- return new Promise((resolve) => this.setData(data, resolve));
- },
- async getServiceDetail() {
- const code = "hospital_service_code";
- const { link, uuid, title, linkType, accessMode, serviceDesc } =
- await queryServiceByCode(code);
- if (uuid) {
- const serviceItem = {
- url: link,
- accessMode,
- name: title,
- serviceDesc,
- urlType: linkType,
- serviceUUID: uuid,
- };
- await this.updateData({
- serviceItem,
- });
- }
- },
- getQuery() {
- const { $routeConfig } = this.$page;
- return $routeConfig.query;
- },
- async fetchProxy(func, ...arg) {
- my.showLoading();
- await func(...arg).finally(my.hideLoading);
- },
- /* 检测缓存 */
- hasCache() {
- const { index, cache } = this.data;
- return (cache[index] || []).length > 0;
- },
- /* 设置缓存 */
- setCache(list) {
- const { index: i, cache: _cache } = this.data;
- const cache = { ..._cache };
- cache[i] = list;
- return this.updateData({
- cache,
- });
- },
- /* 获取一级列表数据 */
- async fetchMenus(hospitalDistrictId) {
- const params = {
- hospitalDistrictId,
- };
- const list = await getDepartmentList(params);
- await this.updateData({
- menus: list,
- loading: false,
- });
- /* 获取一级列表下面的第一项的第一个 */
- const departmentId = this.getDepartmentId(0);
- await this.fetchDepartments(departmentId, list[0]);
- },
- /* 获取二级列表 */
- async fetchDepartments(departmentId, item) {
- if (this.hasCache()) return;
- const list = !departmentId
- ? [item]
- : await getDepartmentList({
- parentId: departmentId,
- });
- this.setCache(list);
- },
- /* 获取科室id */
- getDepartmentId(index) {
- const { menus = [] } = this.data;
- const { hasChildren, departmentId } = menus[index] || {};
- if (hasChildren) return departmentId;
- },
- /* 切换科室 */
- async onTapMenu(i) {
- const item = this.data.menus[i];
- await this.updateData({
- index: i,
- });
- const departmentId = this.getDepartmentId(i);
- await this.fetchDepartments(departmentId, item);
- },
- /* 获取三级列表数据 */
- async onTapOpenLast(item) {
- const { departmentId } = item;
- const { lastCache } = this.data;
- const cacheList = lastCache[departmentId] || [];
- if (cacheList.length > 0) return cacheList;
- my.showLoading();
- const list = await getDepartmentList({
- parentId: departmentId,
- }).finally(my.hideLoading);
- lastCache[departmentId] = list;
- await this.updateData({
- lastCache: { ...lastCache },
- });
- return list;
- },
- onTapItem(item) {
- const query = this.getQuery();
- const { name: areaName } = query;
- const { componentData } = this.props;
- const {
- departmentId,
- name: dpName,
- departmentCode: depCode,
- hospitalId,
- } = item;
- history.push({
- query: {
- departmentId,
- depCode,
- hospitalId,
- yuanqu: areaName,
- },
- title: `${dpName}(${areaName})`,
- pageType: "hospital-num-source",
- componentData: { ...componentData, department: item },
- });
- },
- },
- });
|