index.js 8.6 KB

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