index.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. import { createSubscribe } from "applet-page-component";
  2. import {
  3. getTestTimeList,
  4. getQuestionnaire,
  5. getItemList,
  6. nucleicOrderConfirm,
  7. } from "../../service/common";
  8. import { getPatientList } from "../edit-patient/service";
  9. import history from "../../utils/history";
  10. import { tradePay } from "../../utils/tradePay";
  11. import { reportCmPV_YL } from "../../utils/cloudMonitorHelper";
  12. const deptCodeMap = {
  13. 黄石总院: 500,
  14. 沙河分院: 500,
  15. };
  16. Component(
  17. createSubscribe({
  18. async onShow() {
  19. await this.getPatientLists();
  20. },
  21. })({
  22. data: {
  23. personItem: {},
  24. hospitalDistrictId: "",
  25. projects: [],
  26. personList: [],
  27. timeList: {},
  28. disabled: true,
  29. isFinish: false,
  30. finishForm: {},
  31. formList: [],
  32. questionList: [],
  33. loading: false,
  34. hospitalName: "",
  35. personIndex: undefined,
  36. showPerson: false,
  37. timer: null,
  38. setShowTime: false,
  39. setShowForm: false,
  40. setDayTime: "半天",
  41. onlinePay: false,
  42. },
  43. props: {
  44. componentData: {},
  45. },
  46. async didMount() {
  47. const {
  48. personItem,
  49. hospitalDistrictId,
  50. hospitalName,
  51. componentExtInfo,
  52. personIndex,
  53. } = this.$page.data.query ? this.$page.data.query : {};
  54. this.setData({
  55. hospitalDistrictId,
  56. });
  57. await this.getProject();
  58. await this.getPatientLists();
  59. let setInfo = {}; // 是否直接进入核酸预约页面
  60. if (this.props.componentData.componentExtInfo) {
  61. setInfo = this.props.componentData.componentExtInfo;
  62. this.onShowPerson();
  63. } else {
  64. setInfo = componentExtInfo ? JSON.parse(componentExtInfo) : {};
  65. this.setData({
  66. personItem: personItem ? JSON.parse(personItem) : {},
  67. personIndex: Number(personIndex),
  68. });
  69. }
  70. const {
  71. setShowTime,
  72. setShowForm,
  73. setDayTime,
  74. onlinePay,
  75. hospitalNameInput,
  76. } = setInfo; // personItem可能参数过长,先decode
  77. this.setData({
  78. hospitalName: hospitalName || hospitalNameInput,
  79. setShowTime: setShowTime === "true",
  80. setShowForm: setShowForm === "true",
  81. setDayTime,
  82. onlinePay: onlinePay === "true",
  83. });
  84. /* 服务预警,核酸预约 */
  85. reportCmPV_YL({
  86. title: "核酸预约",
  87. });
  88. },
  89. didUnmount() {
  90. clearTimeout(this.data.timer);
  91. },
  92. methods: {
  93. async getProject() {
  94. const { query } = this.$page.data;
  95. const { hospitalDistrictId } = this.data;
  96. const timeList = await getTestTimeList({
  97. hospitalDistrictId,
  98. });
  99. const { questionList: formList } = await getQuestionnaire({
  100. hospitalDistrictId,
  101. });
  102. const projects = await getItemList({
  103. hospitalDistrictId,
  104. deptCode: deptCodeMap[query.hospitalName],
  105. });
  106. this.setData({
  107. projects,
  108. timeList,
  109. formList,
  110. questionList: formList,
  111. });
  112. },
  113. // 选择就诊人部分
  114. async getPatientLists() {
  115. const personList = await getPatientList();
  116. this.setData({
  117. personList,
  118. });
  119. },
  120. onShowPerson() {
  121. const { personList } = this.data; // 判就诊人列表三种情况
  122. if (personList.length === 0) {
  123. // 没有就诊人信息
  124. my.alert({
  125. content: "您还未添加就诊人,无法进行核酸预约",
  126. buttonText: "去新增",
  127. success: () => {
  128. // 没有就诊人信息
  129. history.replace({
  130. title: "添加就诊人",
  131. pageType: "edit-patient",
  132. });
  133. },
  134. });
  135. } else if (personList.length === 1) {
  136. this.setData({
  137. personItem: personList[0],
  138. });
  139. } else {
  140. // 选择就诊人
  141. this.setData({
  142. showPerson: true,
  143. });
  144. }
  145. },
  146. onOpenPerson() {
  147. this.setData({
  148. showPerson: true,
  149. });
  150. },
  151. onClosePerson() {
  152. if (!this.data.personItem.name) {
  153. my.showToast({
  154. content: "请选择就诊人",
  155. });
  156. return;
  157. }
  158. this.setData({
  159. showPerson: false,
  160. });
  161. },
  162. onPersonChange(item, index) {
  163. // 如果有流调表,重置表单
  164. if (this.data.formList) {
  165. this.onReset();
  166. }
  167. this.setData({
  168. personItem: item,
  169. showPerson: false,
  170. personIndex: index,
  171. });
  172. },
  173. // 项目其他部分
  174. onReset() {
  175. const { formList } = this.data;
  176. this.setData({
  177. finishForm: {},
  178. formList: [],
  179. });
  180. this.onFinishForm();
  181. this.data.timer = setTimeout(() => {
  182. this.setData({
  183. formList,
  184. });
  185. }, 100);
  186. },
  187. onChangeProject(e) {
  188. const { item } = e.target.dataset;
  189. this.setData({
  190. projectItem: item,
  191. });
  192. this.onDisableButton();
  193. },
  194. onCloseTime(item) {
  195. this.setData({
  196. timeItem: item,
  197. });
  198. this.onDisableButton();
  199. },
  200. onRadioChange(e) {
  201. const { name } = e.target.dataset;
  202. const { value } = e.detail;
  203. this.data.finishForm[name] = value;
  204. this.setData({
  205. finishForm: this.data.finishForm,
  206. });
  207. this.onFinishForm();
  208. },
  209. onFinishForm() {
  210. const { finishForm } = this.data;
  211. const arr = Object.getOwnPropertyNames(finishForm);
  212. this.setData({
  213. isFinish: arr.length === this.data.questionList.length,
  214. });
  215. this.onDisableButton();
  216. },
  217. onDisableButton() {
  218. const { projectItem, timeItem, isFinish, setShowTime, setShowForm } =
  219. this.data;
  220. this.setData({
  221. disabled:
  222. !projectItem ||
  223. (!timeItem && setShowTime) ||
  224. (!isFinish && !!setShowForm),
  225. });
  226. },
  227. async onSubmit(e) {
  228. // 是否需要检验表单 && 校验表单是否符合要求
  229. let isTrue = true;
  230. if (this.data.setShowForm) {
  231. isTrue = this.onJudgeForm(e.detail.value);
  232. }
  233. if (isTrue) {
  234. const {
  235. projectItem,
  236. timeItem,
  237. personItem,
  238. hospitalDistrictId,
  239. setShowTime,
  240. onlinePay,
  241. } = this.data; // 获取订单ID
  242. const { id, bindCardNum } = personItem;
  243. const {
  244. nucleicItemId,
  245. deptCode,
  246. startTime,
  247. endTime,
  248. datePeriod,
  249. availableNumStr,
  250. deptName,
  251. doctorName,
  252. doctorCode,
  253. } = projectItem;
  254. const res = await nucleicOrderConfirm({
  255. cardNum: bindCardNum,
  256. nucleicItemId: nucleicItemId,
  257. hospitalDistrictId,
  258. testTimeId: setShowTime && timeItem ? timeItem.testTimeId : "",
  259. medicalId: id,
  260. deptCode,
  261. startTime,
  262. endTime,
  263. datePeriod,
  264. availableNumStr,
  265. deptName,
  266. doctorName,
  267. doctorCode,
  268. }); // 区分支持线上支付 和 不支持线上支付
  269. if (res.amount && onlinePay) {
  270. // const orderRes = await tradeNoQuery({
  271. // type: 1,
  272. // idNum: res.orderId,
  273. // amount: res.amount,
  274. // });
  275. // my.tradePay({
  276. // tradeNO: orderRes.tradeNo,
  277. // success: ({ resultCode }) => {
  278. // if (resultCode === '9000') {
  279. // history.replace({
  280. // query: {
  281. // hospitalDistrictId,
  282. // orderId: res.orderId,
  283. // type: '已支付',
  284. // },
  285. // title: '预约详情',
  286. // pageType: 'booking-detail',
  287. // });
  288. // }
  289. // },
  290. // });
  291. this.setData({
  292. loading: true,
  293. });
  294. tradePay(
  295. {
  296. type: 2,
  297. amount: res.amount,
  298. idNum: res.orderId,
  299. },
  300. {
  301. tradeType: "Appointment",
  302. }
  303. )
  304. .then(() => {
  305. history.replace({
  306. query: {
  307. hospitalDistrictId,
  308. orderId: res.orderId,
  309. type: "已支付",
  310. },
  311. title: "预约详情",
  312. pageType: "booking-detail",
  313. });
  314. })
  315. .finally(() => {
  316. this.setData({
  317. loading: false,
  318. });
  319. });
  320. } else {
  321. history.replace({
  322. query: {
  323. hospitalDistrictId,
  324. orderId: res.orderId,
  325. type: "未支付",
  326. },
  327. title: "预约详情",
  328. pageType: "booking-detail",
  329. });
  330. }
  331. }
  332. },
  333. onJudgeForm(result) {
  334. const arr = Object.getOwnPropertyNames(result); // 校验表单答案
  335. const isFalse = arr.some((item) => item.split("&")[1] !== result[item]);
  336. if (isFalse) {
  337. my.alert({
  338. title: "您的情况不支持预约",
  339. content: "请前往医院发热门诊接受筛查",
  340. });
  341. return false;
  342. }
  343. return true;
  344. },
  345. },
  346. })
  347. );