index.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. import { createSubscribe } from "applet-page-component";
  2. import * as utils from "./../../utils";
  3. import { getDepDoctorList, getDepOrderSourceRemain } from "./service";
  4. import {
  5. getRegisteredAnnouncement,
  6. recordOpLog,
  7. } from "../../../../core/utils/ywtService";
  8. /* 判断日期是不是今天 */
  9. const isToday = (date) => {
  10. const _date = new Date();
  11. const year = _date.getFullYear();
  12. const month = _date.getMonth() + 1;
  13. const day = _date.getDate();
  14. const check = (val) => (`${val}`.length <= 1 ? `0${val}` : val);
  15. return date === [year, check(month), check(day)].join("/");
  16. };
  17. const copy = (obj) => JSON.parse(JSON.stringify(obj));
  18. const defaultSource = {
  19. normal: {
  20. items: [],
  21. type: "normal",
  22. name: "",
  23. },
  24. expert: {
  25. items: [],
  26. name: "",
  27. type: "expert",
  28. },
  29. };
  30. Component(
  31. createSubscribe({
  32. /* 分页逻辑 */
  33. async onReachBottom() {
  34. const { loading, isLastPage } = this.data;
  35. if (loading || isLastPage) return;
  36. this.pageIndex = this.pageIndex + 1;
  37. await this.updateData({
  38. loading: true,
  39. });
  40. await this.onSplitPage();
  41. },
  42. })({
  43. props: {
  44. componentData: {},
  45. },
  46. data: {
  47. date: "",
  48. loading: true,
  49. dateList: [],
  50. /* 原始的列表 */
  51. nativeList: [],
  52. /* 是否为最后一页 */
  53. isLastPage: false,
  54. dataSource: copy(defaultSource),
  55. headerHeight: utils.getHeaderHeight(),
  56. // 弹窗按钮配置
  57. buttons: [
  58. {
  59. text: "确定",
  60. extClass: "buttonBold",
  61. },
  62. ],
  63. title: "标题",
  64. content: "",
  65. showModal: false,
  66. modalBtnNum: 10,
  67. },
  68. async didMount() {
  69. await this.onRefresh();
  70. await this.fetchDateRemainList();
  71. this.getNotice();
  72. },
  73. methods: {
  74. getQuery() {
  75. const { $routeConfig } = this.$page;
  76. return $routeConfig.query;
  77. },
  78. // 获取公告
  79. async getNotice() {
  80. const { departmentId, hospitalId } = this.getQuery();
  81. const [err, result] = await getRegisteredAnnouncement({
  82. hospitalId: Number(hospitalId),
  83. type: 4,
  84. deptId: Number(departmentId),
  85. });
  86. if (!err && result && result.id > 0) {
  87. this.setData(
  88. {
  89. content: result.content,
  90. title: result.title,
  91. showModal: true,
  92. },
  93. () => {
  94. this.handleCountDown();
  95. }
  96. );
  97. }
  98. },
  99. async onModalClick() {
  100. const { modalBtnNum } = this.data;
  101. if (modalBtnNum > 0) return;
  102. await recordOpLog({ type: 235 });
  103. this.setData({
  104. showModal: false,
  105. });
  106. },
  107. sleeping(ms) {
  108. return new Promise((resolve) => {
  109. setTimeout(resolve, ms);
  110. });
  111. },
  112. async handleCountDown() {
  113. const { modalBtnNum } = this.data;
  114. await this.sleeping(1000);
  115. this.setData({ modalBtnNum: modalBtnNum - 1 }, () => {
  116. if (this.data.modalBtnNum > 0) {
  117. this.handleCountDown();
  118. }
  119. });
  120. },
  121. updateData(data) {
  122. return new Promise((resolve) => this.setData(data, resolve));
  123. },
  124. async onChange(date) {
  125. await this.onRefresh(date);
  126. },
  127. /* 获取日期列表 */
  128. async fetchDateRemainList() {
  129. /* 获取日期列表 */
  130. const { departmentId, depCode } = this.getQuery();
  131. const list = await getDepOrderSourceRemain({
  132. depId: departmentId,
  133. depCode,
  134. });
  135. /* 处理数据 */
  136. const dateList = list.map((item) => {
  137. const { date } = item;
  138. const _date = date.replace(/-/g, "/");
  139. const today = isToday(_date);
  140. const day = new Date(_date).getDate();
  141. const week = utils.getWeek(_date);
  142. return { ...item, date: _date, showDay: day, today, week };
  143. });
  144. await this.updateData({
  145. dateList,
  146. });
  147. },
  148. /* 数据处理 */
  149. formatData(list = []) {
  150. const { dataSource } = this.data;
  151. list.forEach((item) => {
  152. const { items } = dataSource[item.type];
  153. if (items) items.push(item);
  154. });
  155. return { ...dataSource };
  156. },
  157. /* 分页显示医生列表 */
  158. async onSplitPage() {
  159. let total = 0;
  160. let dataList = [];
  161. let success = true;
  162. const { date, isLastPage } = this.data;
  163. let { date: curDate = "" } = date || {};
  164. if (curDate) {
  165. const reg = new RegExp("/", "gm");
  166. curDate = curDate.replace(reg, "-");
  167. }
  168. const { departmentId, depCode } = this.getQuery();
  169. const params = {
  170. date: curDate,
  171. pageSize: 10,
  172. depId: departmentId,
  173. depCode,
  174. pageIndex: this.pageIndex,
  175. };
  176. if (!isLastPage) {
  177. try {
  178. const { list = [], pagination = {} } = await getDepDoctorList(
  179. params
  180. );
  181. dataList = list;
  182. total = pagination.total || 0;
  183. } catch (e) {
  184. success = false;
  185. }
  186. }
  187. let state = {
  188. loading: false,
  189. };
  190. if (success) {
  191. const { nativeList } = this.data;
  192. const _list = [...nativeList, ...dataList];
  193. state = {
  194. ...state,
  195. nativeList: _list,
  196. isLastPage: _list.length >= total,
  197. dataSource: this.formatData(dataList),
  198. };
  199. }
  200. await this.updateData(state);
  201. },
  202. /* 刷新数据 */
  203. async onRefresh(curDate = "") {
  204. /* 初始化数据 */
  205. this.pageIndex = 1;
  206. await this.updateData({
  207. date: curDate,
  208. loading: true,
  209. nativeList: [],
  210. isLastPage: false,
  211. dataSource: copy(defaultSource),
  212. });
  213. await this.onSplitPage();
  214. },
  215. },
  216. })
  217. );