index.js 9.2 KB

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