import { createSubscribe } from "applet-page-component"; import * as utils from "./../../utils"; import { getDepDoctorList, getDepOrderSourceRemain } from "./service"; import { getRegisteredAnnouncement, recordOpLog, } from "../../../../core/utils/ywtService"; /* 判断日期是不是今天 */ const isToday = (date) => { const _date = new Date(); const year = _date.getFullYear(); const month = _date.getMonth() + 1; const day = _date.getDate(); const check = (val) => (`${val}`.length <= 1 ? `0${val}` : val); return date === [year, check(month), check(day)].join("/"); }; const copy = (obj) => JSON.parse(JSON.stringify(obj)); const defaultSource = { normal: { items: [], type: "normal", name: "", }, expert: { items: [], name: "", type: "expert", }, }; Component( createSubscribe({ /* 分页逻辑 */ async onReachBottom() { const { loading, isLastPage } = this.data; if (loading || isLastPage) return; this.pageIndex = this.pageIndex + 1; await this.updateData({ loading: true, }); await this.onSplitPage(); }, })({ props: { componentData: {}, }, data: { date: "", loading: true, dateList: [], /* 原始的列表 */ nativeList: [], /* 是否为最后一页 */ isLastPage: false, dataSource: copy(defaultSource), headerHeight: utils.getHeaderHeight(), // 弹窗按钮配置 buttons: [ { text: "确定", extClass: "buttonBold", }, ], title: "标题", content: "", showModal: false, modalBtnNum: 10, }, async didMount() { await this.onRefresh(); await this.fetchDateRemainList(); this.getNotice(); }, methods: { getQuery() { const { $routeConfig } = this.$page; return $routeConfig.query; }, // 获取公告 async getNotice() { const { departmentId, hospitalId } = this.getQuery(); const [err, result] = await getRegisteredAnnouncement({ hospitalId: Number(hospitalId), type: 4, deptId: Number(departmentId), }); if (!err && result && result.id > 0) { this.setData( { content: result.content, title: result.title, showModal: true, }, () => { this.handleCountDown(); } ); } }, async onModalClick() { const { modalBtnNum } = this.data; if (modalBtnNum > 0) return; await recordOpLog({ type: 235 }); this.setData({ showModal: false, }); }, sleeping(ms) { return new Promise((resolve) => { setTimeout(resolve, ms); }); }, async handleCountDown() { const { modalBtnNum } = this.data; await this.sleeping(1000); this.setData({ modalBtnNum: modalBtnNum - 1 }, () => { if (this.data.modalBtnNum > 0) { this.handleCountDown(); } }); }, updateData(data) { return new Promise((resolve) => this.setData(data, resolve)); }, async onChange(date) { await this.onRefresh(date); }, /* 获取日期列表 */ async fetchDateRemainList() { /* 获取日期列表 */ const { departmentId, depCode } = this.getQuery(); const list = await getDepOrderSourceRemain({ depId: departmentId, depCode, }); /* 处理数据 */ const dateList = list.map((item) => { const { date } = item; const _date = date.replace(/-/g, "/"); const today = isToday(_date); const day = new Date(_date).getDate(); const week = utils.getWeek(_date); return { ...item, date: _date, showDay: day, today, week }; }); await this.updateData({ dateList, }); }, /* 数据处理 */ formatData(list = []) { const { dataSource } = this.data; list.forEach((item) => { const { items } = dataSource[item.type]; if (items) items.push(item); }); return { ...dataSource }; }, /* 分页显示医生列表 */ async onSplitPage() { let total = 0; let dataList = []; let success = true; const { date, isLastPage } = this.data; let { date: curDate = "" } = date || {}; if (curDate) { const reg = new RegExp("/", "gm"); curDate = curDate.replace(reg, "-"); } const { departmentId, depCode } = this.getQuery(); const params = { date: curDate, pageSize: 10, depId: departmentId, depCode, pageIndex: this.pageIndex, }; if (!isLastPage) { try { const { list = [], pagination = {} } = await getDepDoctorList( params ); dataList = list; total = pagination.total || 0; } catch (e) { success = false; } } let state = { loading: false, }; if (success) { const { nativeList } = this.data; const _list = [...nativeList, ...dataList]; state = { ...state, nativeList: _list, isLastPage: _list.length >= total, dataSource: this.formatData(dataList), }; } await this.updateData(state); }, /* 刷新数据 */ async onRefresh(curDate = "") { /* 初始化数据 */ this.pageIndex = 1; await this.updateData({ date: curDate, loading: true, nativeList: [], isLastPage: false, dataSource: copy(defaultSource), }); await this.onSplitPage(); }, }, }) );