index.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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. 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. // todo 添加智能推送接口
  310. const [err, authResult] = await getAuthUser([
  311. "auth_user",
  312. "hospital_order",
  313. ]);
  314. console.log("authResult ===>", authResult.authCode);
  315. if (err) {
  316. my.showToast({
  317. type: "fail",
  318. content: "智能消息推送授权失败",
  319. });
  320. }
  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. },
  349. onJudgeForm(result) {
  350. const arr = Object.getOwnPropertyNames(result); // 校验表单答案
  351. const isFalse = arr.some((item) => item.split("&")[1] !== result[item]);
  352. if (isFalse) {
  353. my.alert({
  354. title: "您的情况不支持预约",
  355. content: "请前往医院发热门诊接受筛查",
  356. });
  357. return false;
  358. }
  359. return true;
  360. },
  361. },
  362. })
  363. );