index.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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. import { envContext } from "../../../../core/utils/constants";
  14. const deptCodeMap = {
  15. 541: 500, // 黄石
  16. 540: 499, // 沙河
  17. 12: 248 // 太和
  18. };
  19. Component(
  20. createSubscribe({
  21. async onShow() {
  22. await this.getPatientLists();
  23. },
  24. })({
  25. data: {
  26. personItem: {},
  27. hospitalDistrictId: "",
  28. projects: [],
  29. personList: [],
  30. timeList: {},
  31. disabled: true,
  32. isFinish: false,
  33. finishForm: {},
  34. formList: [],
  35. questionList: [],
  36. loading: false,
  37. hospitalName: "",
  38. personIndex: undefined,
  39. showPerson: false,
  40. timer: null,
  41. setShowTime: false,
  42. setShowForm: false,
  43. setDayTime: "半天",
  44. onlinePay: false,
  45. },
  46. props: {
  47. componentData: {},
  48. },
  49. async didMount() {
  50. const {
  51. personItem,
  52. hospitalDistrictId,
  53. hospitalName,
  54. componentExtInfo,
  55. personIndex,
  56. } = this.$page.data.query ? this.$page.data.query : {};
  57. this.setData({
  58. hospitalDistrictId,
  59. });
  60. await this.getProject();
  61. await this.getPatientLists();
  62. let setInfo = {}; // 是否直接进入核酸预约页面
  63. if (this.props.componentData.componentExtInfo) {
  64. setInfo = this.props.componentData.componentExtInfo;
  65. this.onShowPerson();
  66. } else {
  67. setInfo = componentExtInfo ? JSON.parse(componentExtInfo) : {};
  68. this.setData({
  69. personItem: personItem ? JSON.parse(personItem) : {},
  70. personIndex: Number(personIndex),
  71. });
  72. }
  73. const {
  74. setShowTime,
  75. setShowForm,
  76. setDayTime,
  77. onlinePay,
  78. hospitalNameInput,
  79. } = setInfo; // personItem可能参数过长,先decode
  80. this.setData({
  81. hospitalName: hospitalName || hospitalNameInput,
  82. setShowTime: setShowTime === "true",
  83. setShowForm: setShowForm === "true",
  84. setDayTime,
  85. onlinePay: onlinePay === "true",
  86. });
  87. /* 服务预警,核酸预约 */
  88. reportCmPV_YL({
  89. title: "核酸预约",
  90. });
  91. },
  92. didUnmount() {
  93. clearTimeout(this.data.timer);
  94. },
  95. methods: {
  96. async getProject() {
  97. const { query } = this.$page.data;
  98. const { hospitalDistrictId } = this.data;
  99. const timeList = await getTestTimeList({
  100. hospitalDistrictId,
  101. });
  102. const { questionList: formList } = await getQuestionnaire({
  103. hospitalDistrictId,
  104. });
  105. my.showLoading();
  106. const projects = await getItemList({
  107. hospitalDistrictId,
  108. deptCode: deptCodeMap[hospitalDistrictId],
  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. const query = this.$page.data.query || {};
  239. const { subHospitalId, subHospitalTitle } = query || {};
  240. try {
  241. my.showLoading();
  242. if (isTrue) {
  243. const {
  244. projectItem,
  245. timeItem,
  246. personItem,
  247. hospitalDistrictId,
  248. setShowTime,
  249. onlinePay,
  250. } = this.data; // 获取订单ID
  251. const { id, bindCardNum } = personItem;
  252. const {
  253. nucleicItemId,
  254. deptCode,
  255. startTime,
  256. endTime,
  257. datePeriod,
  258. availableNumStr,
  259. deptName,
  260. doctorName,
  261. doctorCode,
  262. fee,
  263. nucleicItemDesc
  264. } = projectItem;
  265. const res = await nucleicOrderConfirm({
  266. cardNum: bindCardNum,
  267. nucleicItemId: nucleicItemId,
  268. hospitalDistrictId,
  269. testTimeId: setShowTime && timeItem ? timeItem.testTimeId : "",
  270. medicalId: id,
  271. deptCode,
  272. startTime,
  273. endTime,
  274. datePeriod,
  275. availableNumStr,
  276. deptName,
  277. doctorName,
  278. doctorCode,
  279. fee,
  280. subHospitalId: subHospitalId ? parseInt(subHospitalId, 10) : "",
  281. registerDate: nucleicItemDesc && envContext === 'th' ? nucleicItemDesc.slice(0,10) : ''
  282. }); // 区分支持线上支付 和 不支持线上支付
  283. // 获取智能消息推送授权
  284. await getSubscribeAuth();
  285. if (res.amount && onlinePay) {
  286. // const orderRes = await tradeNoQuery({
  287. // type: 1,
  288. // idNum: res.orderId,
  289. // amount: res.amount,
  290. // });
  291. // my.tradePay({
  292. // tradeNO: orderRes.tradeNo,
  293. // success: ({ resultCode }) => {
  294. // if (resultCode === '9000') {
  295. // history.replace({
  296. // query: {
  297. // hospitalDistrictId,
  298. // orderId: res.orderId,
  299. // type: '已支付',
  300. // },
  301. // title: '预约详情',
  302. // pageType: 'booking-detail',
  303. // });
  304. // }
  305. // },
  306. // });
  307. this.setData({
  308. loading: true,
  309. });
  310. tradePay(
  311. {
  312. type: 2,
  313. amount: res.amount,
  314. idNum: res.orderId,
  315. },
  316. {
  317. tradeType: "Appointment",
  318. }
  319. )
  320. .then(async () => {
  321. history.replace({
  322. query: {
  323. hospitalDistrictId,
  324. orderId: res.orderId,
  325. type: "已支付",
  326. },
  327. title: "预约详情",
  328. pageType: "booking-detail",
  329. });
  330. })
  331. .finally(() => {
  332. this.setData({
  333. loading: false,
  334. });
  335. });
  336. } else {
  337. history.replace({
  338. query: {
  339. hospitalDistrictId,
  340. orderId: res.orderId,
  341. type: "未支付",
  342. },
  343. title: "预约详情",
  344. pageType: "booking-detail",
  345. });
  346. }
  347. }
  348. } catch (error) {
  349. } finally {
  350. my.hideLoading();
  351. }
  352. },
  353. onJudgeForm(result) {
  354. const arr = Object.getOwnPropertyNames(result); // 校验表单答案
  355. const isFalse = arr.some((item) => item.split("&")[1] !== result[item]);
  356. if (isFalse) {
  357. my.alert({
  358. title: "您的情况不支持预约",
  359. content: "请前往医院发热门诊接受筛查",
  360. });
  361. return false;
  362. }
  363. return true;
  364. },
  365. },
  366. })
  367. );