index.js 8.5 KB

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