index.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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. console.log("query", query);
  105. my.showLoading();
  106. const projects = await getItemList({
  107. hospitalDistrictId,
  108. deptCode: deptCodeMap[query.hospitalName],
  109. });
  110. this.setData({
  111. projects,
  112. timeList,
  113. formList,
  114. questionList: formList,
  115. });
  116. my.hideLoading();
  117. },
  118. // 选择就诊人部分
  119. async getPatientLists() {
  120. const personList = await getPatientList();
  121. this.setData({
  122. personList,
  123. });
  124. },
  125. onShowPerson() {
  126. const { personList } = this.data; // 判就诊人列表三种情况
  127. if (personList.length === 0) {
  128. // 没有就诊人信息
  129. my.alert({
  130. content: "您还未添加就诊人,无法进行核酸预约",
  131. buttonText: "去新增",
  132. success: () => {
  133. // 没有就诊人信息
  134. history.replace({
  135. title: "添加就诊人",
  136. pageType: "edit-patient",
  137. });
  138. },
  139. });
  140. } else if (personList.length === 1) {
  141. this.setData({
  142. personItem: personList[0],
  143. });
  144. } else {
  145. // 选择就诊人
  146. this.setData({
  147. showPerson: true,
  148. });
  149. }
  150. },
  151. onOpenPerson() {
  152. this.setData({
  153. showPerson: true,
  154. });
  155. },
  156. onClosePerson() {
  157. if (!this.data.personItem.name) {
  158. my.showToast({
  159. content: "请选择就诊人",
  160. });
  161. return;
  162. }
  163. this.setData({
  164. showPerson: false,
  165. });
  166. },
  167. onPersonChange(item, index) {
  168. // 如果有流调表,重置表单
  169. if (this.data.formList) {
  170. this.onReset();
  171. }
  172. this.setData({
  173. personItem: item,
  174. showPerson: false,
  175. personIndex: index,
  176. });
  177. },
  178. // 项目其他部分
  179. onReset() {
  180. const { formList } = this.data;
  181. this.setData({
  182. finishForm: {},
  183. formList: [],
  184. });
  185. this.onFinishForm();
  186. this.data.timer = setTimeout(() => {
  187. this.setData({
  188. formList,
  189. });
  190. }, 100);
  191. },
  192. onChangeProject(e) {
  193. const { item } = e.target.dataset;
  194. this.setData({
  195. projectItem: item,
  196. });
  197. this.onDisableButton();
  198. },
  199. onCloseTime(item) {
  200. this.setData({
  201. timeItem: item,
  202. });
  203. this.onDisableButton();
  204. },
  205. onRadioChange(e) {
  206. const { name } = e.target.dataset;
  207. const { value } = e.detail;
  208. this.data.finishForm[name] = value;
  209. this.setData({
  210. finishForm: this.data.finishForm,
  211. });
  212. this.onFinishForm();
  213. },
  214. onFinishForm() {
  215. const { finishForm } = this.data;
  216. const arr = Object.getOwnPropertyNames(finishForm);
  217. this.setData({
  218. isFinish: arr.length === this.data.questionList.length,
  219. });
  220. this.onDisableButton();
  221. },
  222. onDisableButton() {
  223. const { projectItem, timeItem, isFinish, setShowTime, setShowForm } =
  224. this.data;
  225. this.setData({
  226. disabled:
  227. !projectItem ||
  228. (!timeItem && setShowTime) ||
  229. (!isFinish && !!setShowForm),
  230. });
  231. },
  232. async onSubmit(e) {
  233. // 是否需要检验表单 && 校验表单是否符合要求
  234. let isTrue = true;
  235. if (this.data.setShowForm) {
  236. isTrue = this.onJudgeForm(e.detail.value);
  237. }
  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. if (res.amount && onlinePay) {
  277. // const orderRes = await tradeNoQuery({
  278. // type: 1,
  279. // idNum: res.orderId,
  280. // amount: res.amount,
  281. // });
  282. // my.tradePay({
  283. // tradeNO: orderRes.tradeNo,
  284. // success: ({ resultCode }) => {
  285. // if (resultCode === '9000') {
  286. // history.replace({
  287. // query: {
  288. // hospitalDistrictId,
  289. // orderId: res.orderId,
  290. // type: '已支付',
  291. // },
  292. // title: '预约详情',
  293. // pageType: 'booking-detail',
  294. // });
  295. // }
  296. // },
  297. // });
  298. this.setData({
  299. loading: true,
  300. });
  301. tradePay(
  302. {
  303. type: 2,
  304. amount: res.amount,
  305. idNum: res.orderId,
  306. },
  307. {
  308. tradeType: "Appointment",
  309. }
  310. )
  311. .then(async () => {
  312. const [err, authResult] = await getAuthUser([
  313. "auth_user",
  314. "hospital_order",
  315. ]);
  316. if (err) {
  317. my.showToast({
  318. type: "fail",
  319. content: "智能消息推送授权失败",
  320. });
  321. } else {
  322. const [error, result] = await submitAuthCode({
  323. authCode: authResult.authCode,
  324. });
  325. if (!error) {
  326. my.showToast({
  327. type: "success",
  328. content: "消息订阅成功",
  329. });
  330. }
  331. }
  332. history.replace({
  333. query: {
  334. hospitalDistrictId,
  335. orderId: res.orderId,
  336. type: "已支付",
  337. },
  338. title: "预约详情",
  339. pageType: "booking-detail",
  340. });
  341. })
  342. .finally(() => {
  343. this.setData({
  344. loading: false,
  345. });
  346. });
  347. } else {
  348. const [err, authResult] = await getAuthUser([
  349. "auth_user",
  350. "hospital_order",
  351. ]);
  352. if (err) {
  353. my.showToast({
  354. type: "fail",
  355. content: "智能消息推送授权失败",
  356. });
  357. } else {
  358. const [error, result] = await submitAuthCode({
  359. authCode: authResult.authCode,
  360. });
  361. if (!error) {
  362. my.showToast({
  363. type: "success",
  364. content: "消息订阅成功",
  365. });
  366. }
  367. }
  368. history.replace({
  369. query: {
  370. hospitalDistrictId,
  371. orderId: res.orderId,
  372. type: "未支付",
  373. },
  374. title: "预约详情",
  375. pageType: "booking-detail",
  376. });
  377. }
  378. }
  379. },
  380. onJudgeForm(result) {
  381. const arr = Object.getOwnPropertyNames(result); // 校验表单答案
  382. const isFalse = arr.some((item) => item.split("&")[1] !== result[item]);
  383. if (isFalse) {
  384. my.alert({
  385. title: "您的情况不支持预约",
  386. content: "请前往医院发热门诊接受筛查",
  387. });
  388. return false;
  389. }
  390. return true;
  391. },
  392. },
  393. })
  394. );