123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- 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();
- },
- },
- })
- );
|