index.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. 沙河分院: 667,
  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. console.log("query", query);
  103. const projects = await getItemList({
  104. hospitalDistrictId,
  105. deptCode: deptCodeMap[query.hospitalName],
  106. });
  107. this.setData({
  108. projects,
  109. timeList,
  110. formList,
  111. questionList: formList,
  112. });
  113. },
  114. // 选择就诊人部分
  115. async getPatientLists() {
  116. const personList = await getPatientList();
  117. this.setData({
  118. personList,
  119. });
  120. },
  121. onShowPerson() {
  122. const { personList } = this.data; // 判就诊人列表三种情况
  123. if (personList.length === 0) {
  124. // 没有就诊人信息
  125. my.alert({
  126. content: "您还未添加就诊人,无法进行核酸预约",
  127. buttonText: "去新增",
  128. success: () => {
  129. // 没有就诊人信息
  130. history.replace({
  131. title: "添加就诊人",
  132. pageType: "edit-patient",
  133. });
  134. },
  135. });
  136. } else if (personList.length === 1) {
  137. this.setData({
  138. personItem: personList[0],
  139. });
  140. } else {
  141. // 选择就诊人
  142. this.setData({
  143. showPerson: true,
  144. });
  145. }
  146. },
  147. onOpenPerson() {
  148. this.setData({
  149. showPerson: true,
  150. });
  151. },
  152. onClosePerson() {
  153. if (!this.data.personItem.name) {
  154. my.showToast({
  155. content: "请选择就诊人",
  156. });
  157. return;
  158. }
  159. this.setData({
  160. showPerson: false,
  161. });
  162. },
  163. onPersonChange(item, index) {
  164. // 如果有流调表,重置表单
  165. if (this.data.formList) {
  166. this.onReset();
  167. }
  168. this.setData({
  169. personItem: item,
  170. showPerson: false,
  171. personIndex: index,
  172. });
  173. },
  174. // 项目其他部分
  175. onReset() {
  176. const { formList } = this.data;
  177. this.setData({
  178. finishForm: {},
  179. formList: [],
  180. });
  181. this.onFinishForm();
  182. this.data.timer = setTimeout(() => {
  183. this.setData({
  184. formList,
  185. });
  186. }, 100);
  187. },
  188. onChangeProject(e) {
  189. const { item } = e.target.dataset;
  190. this.setData({
  191. projectItem: item,
  192. });
  193. this.onDisableButton();
  194. },
  195. onCloseTime(item) {
  196. this.setData({
  197. timeItem: item,
  198. });
  199. this.onDisableButton();
  200. },
  201. onRadioChange(e) {
  202. const { name } = e.target.dataset;
  203. const { value } = e.detail;
  204. this.data.finishForm[name] = value;
  205. this.setData({
  206. finishForm: this.data.finishForm,
  207. });
  208. this.onFinishForm();
  209. },
  210. onFinishForm() {
  211. const { finishForm } = this.data;
  212. const arr = Object.getOwnPropertyNames(finishForm);
  213. this.setData({
  214. isFinish: arr.length === this.data.questionList.length,
  215. });
  216. this.onDisableButton();
  217. },
  218. onDisableButton() {
  219. const { projectItem, timeItem, isFinish, setShowTime, setShowForm } =
  220. this.data;
  221. this.setData({
  222. disabled:
  223. !projectItem ||
  224. (!timeItem && setShowTime) ||
  225. (!isFinish && !!setShowForm),
  226. });
  227. },
  228. async onSubmit(e) {
  229. // 是否需要检验表单 && 校验表单是否符合要求
  230. let isTrue = true;
  231. if (this.data.setShowForm) {
  232. isTrue = this.onJudgeForm(e.detail.value);
  233. }
  234. if (isTrue) {
  235. const {
  236. projectItem,
  237. timeItem,
  238. personItem,
  239. hospitalDistrictId,
  240. setShowTime,
  241. onlinePay,
  242. } = this.data; // 获取订单ID
  243. const { id, bindCardNum } = personItem;
  244. const {
  245. nucleicItemId,
  246. deptCode,
  247. startTime,
  248. endTime,
  249. datePeriod,
  250. availableNumStr,
  251. deptName,
  252. doctorName,
  253. doctorCode,
  254. fee,
  255. } = projectItem;
  256. const res = await nucleicOrderConfirm({
  257. cardNum: bindCardNum,
  258. nucleicItemId: nucleicItemId,
  259. hospitalDistrictId,
  260. testTimeId: setShowTime && timeItem ? timeItem.testTimeId : "",
  261. medicalId: id,
  262. deptCode,
  263. startTime,
  264. endTime,
  265. datePeriod,
  266. availableNumStr,
  267. deptName,
  268. doctorName,
  269. doctorCode,
  270. fee,
  271. }); // 区分支持线上支付 和 不支持线上支付
  272. if (res.amount && onlinePay) {
  273. // const orderRes = await tradeNoQuery({
  274. // type: 1,
  275. // idNum: res.orderId,
  276. // amount: res.amount,
  277. // });
  278. // my.tradePay({
  279. // tradeNO: orderRes.tradeNo,
  280. // success: ({ resultCode }) => {
  281. // if (resultCode === '9000') {
  282. // history.replace({
  283. // query: {
  284. // hospitalDistrictId,
  285. // orderId: res.orderId,
  286. // type: '已支付',
  287. // },
  288. // title: '预约详情',
  289. // pageType: 'booking-detail',
  290. // });
  291. // }
  292. // },
  293. // });
  294. this.setData({
  295. loading: true,
  296. });
  297. tradePay(
  298. {
  299. type: 2,
  300. amount: res.amount,
  301. idNum: res.orderId,
  302. },
  303. {
  304. tradeType: "Appointment",
  305. }
  306. )
  307. .then(() => {
  308. history.replace({
  309. query: {
  310. hospitalDistrictId,
  311. orderId: res.orderId,
  312. type: "已支付",
  313. },
  314. title: "预约详情",
  315. pageType: "booking-detail",
  316. });
  317. })
  318. .finally(() => {
  319. this.setData({
  320. loading: false,
  321. });
  322. });
  323. } else {
  324. history.replace({
  325. query: {
  326. hospitalDistrictId,
  327. orderId: res.orderId,
  328. type: "未支付",
  329. },
  330. title: "预约详情",
  331. pageType: "booking-detail",
  332. });
  333. }
  334. }
  335. },
  336. onJudgeForm(result) {
  337. const arr = Object.getOwnPropertyNames(result); // 校验表单答案
  338. const isFalse = arr.some((item) => item.split("&")[1] !== result[item]);
  339. if (isFalse) {
  340. my.alert({
  341. title: "您的情况不支持预约",
  342. content: "请前往医院发热门诊接受筛查",
  343. });
  344. return false;
  345. }
  346. return true;
  347. },
  348. },
  349. })
  350. );