index.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. import { createSubscribe } from 'applet-page-component';
  2. import { getTestTimeList, getQuestionnaire, getItemList, nucleicOrderConfirm } from '../../service/common';
  3. import { getPatientList } from '../edit-patient/service';
  4. import history from '../../utils/history';
  5. import { tradePay } from '../../utils/tradePay';
  6. import { reportCmPV_YL } from '../../utils/cloudMonitorHelper';
  7. Component(createSubscribe({
  8. async onShow() {
  9. await this.getPatientLists();
  10. }
  11. })({
  12. data: {
  13. personItem: {},
  14. hospitalDistrictId: '',
  15. projects: [],
  16. personList: [],
  17. timeList: {},
  18. disabled: true,
  19. isFinish: false,
  20. finishForm: {},
  21. formList: [],
  22. questionList: [],
  23. loading: false,
  24. hospitalName: '',
  25. personIndex: undefined,
  26. showPerson: false,
  27. timer: null,
  28. setShowTime: false,
  29. setShowForm: false,
  30. setDayTime: '半天',
  31. onlinePay: false
  32. },
  33. props: {
  34. componentData: {}
  35. },
  36. async didMount() {
  37. const {
  38. personItem,
  39. hospitalDistrictId,
  40. hospitalName,
  41. componentExtInfo,
  42. personIndex
  43. } = this.$page.data.query ? this.$page.data.query : {};
  44. this.setData({
  45. hospitalDistrictId
  46. });
  47. await this.getProject();
  48. await this.getPatientLists();
  49. let setInfo = {}; // 是否直接进入核酸预约页面
  50. if (this.props.componentData.componentExtInfo) {
  51. setInfo = this.props.componentData.componentExtInfo;
  52. this.onShowPerson();
  53. } else {
  54. setInfo = componentExtInfo ? JSON.parse(componentExtInfo) : {};
  55. this.setData({
  56. personItem: personItem ? JSON.parse(personItem) : {},
  57. personIndex: Number(personIndex)
  58. });
  59. }
  60. const {
  61. setShowTime,
  62. setShowForm,
  63. setDayTime,
  64. onlinePay,
  65. hospitalNameInput
  66. } = setInfo; // personItem可能参数过长,先decode
  67. this.setData({
  68. hospitalName: hospitalName || hospitalNameInput,
  69. setShowTime: setShowTime === 'true',
  70. setShowForm: setShowForm === 'true',
  71. setDayTime,
  72. onlinePay: onlinePay === 'true'
  73. });
  74. /* 服务预警,核酸预约 */
  75. reportCmPV_YL({
  76. title: '核酸预约'
  77. });
  78. },
  79. didUnmount() {
  80. clearTimeout(this.data.timer);
  81. },
  82. methods: {
  83. async getProject() {
  84. const {
  85. hospitalDistrictId
  86. } = this.data;
  87. const timeList = await getTestTimeList({
  88. hospitalDistrictId
  89. });
  90. const {
  91. questionList: formList
  92. } = await getQuestionnaire({
  93. hospitalDistrictId
  94. });
  95. const projects = await getItemList({
  96. hospitalDistrictId
  97. });
  98. this.setData({
  99. projects,
  100. timeList,
  101. formList,
  102. questionList: formList
  103. });
  104. },
  105. // 选择就诊人部分
  106. async getPatientLists() {
  107. const personList = await getPatientList();
  108. this.setData({
  109. personList
  110. });
  111. },
  112. onShowPerson() {
  113. const {
  114. personList
  115. } = this.data; // 判就诊人列表三种情况
  116. if (personList.length === 0) {
  117. // 没有就诊人信息
  118. my.alert({
  119. content: '您还未添加就诊人,无法进行核酸预约',
  120. buttonText: '去新增',
  121. success: () => {
  122. // 没有就诊人信息
  123. history.replace({
  124. title: '添加就诊人',
  125. pageType: 'edit-patient'
  126. });
  127. }
  128. });
  129. } else if (personList.length === 1) {
  130. this.setData({
  131. personItem: personList[0]
  132. });
  133. } else {
  134. // 选择就诊人
  135. this.setData({
  136. showPerson: true
  137. });
  138. }
  139. },
  140. onOpenPerson() {
  141. this.setData({
  142. showPerson: true
  143. });
  144. },
  145. onClosePerson() {
  146. if (!this.data.personItem.name) {
  147. my.showToast({
  148. content: '请选择就诊人'
  149. });
  150. return;
  151. }
  152. this.setData({
  153. showPerson: false
  154. });
  155. },
  156. onPersonChange(item, index) {
  157. // 如果有流调表,重置表单
  158. if (this.data.formList) {
  159. this.onReset();
  160. }
  161. this.setData({
  162. personItem: item,
  163. showPerson: false,
  164. personIndex: index
  165. });
  166. },
  167. // 项目其他部分
  168. onReset() {
  169. const {
  170. formList
  171. } = this.data;
  172. this.setData({
  173. finishForm: {},
  174. formList: []
  175. });
  176. this.onFinishForm();
  177. this.data.timer = setTimeout(() => {
  178. this.setData({
  179. formList
  180. });
  181. }, 100);
  182. },
  183. onChangeProject(e) {
  184. const {
  185. item
  186. } = e.target.dataset;
  187. this.setData({
  188. projectItem: item
  189. });
  190. this.onDisableButton();
  191. },
  192. onCloseTime(item) {
  193. this.setData({
  194. timeItem: item
  195. });
  196. this.onDisableButton();
  197. },
  198. onRadioChange(e) {
  199. const {
  200. name
  201. } = e.target.dataset;
  202. const {
  203. value
  204. } = 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 {
  213. finishForm
  214. } = 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 {
  223. projectItem,
  224. timeItem,
  225. isFinish,
  226. setShowTime,
  227. setShowForm
  228. } = this.data;
  229. this.setData({
  230. disabled: !projectItem || !timeItem && setShowTime || !isFinish && !!setShowForm
  231. });
  232. },
  233. async onSubmit(e) {
  234. // 是否需要检验表单 && 校验表单是否符合要求
  235. let isTrue = true;
  236. if (this.data.setShowForm) {
  237. isTrue = this.onJudgeForm(e.detail.value);
  238. }
  239. if (isTrue) {
  240. const {
  241. projectItem,
  242. timeItem,
  243. personItem,
  244. hospitalDistrictId,
  245. setShowTime,
  246. onlinePay
  247. } = this.data; // 获取订单ID
  248. const res = await nucleicOrderConfirm({
  249. cardNum: personItem.bindCardNum,
  250. nucleicItemId: projectItem.nucleicItemId,
  251. hospitalDistrictId,
  252. testTimeId: setShowTime && timeItem ? timeItem.testTimeId : ''
  253. }); // 区分支持线上支付 和 不支持线上支付
  254. if (res.amount && onlinePay) {
  255. // const orderRes = await tradeNoQuery({
  256. // type: 1,
  257. // idNum: res.orderId,
  258. // amount: res.amount,
  259. // });
  260. // my.tradePay({
  261. // tradeNO: orderRes.tradeNo,
  262. // success: ({ resultCode }) => {
  263. // if (resultCode === '9000') {
  264. // history.replace({
  265. // query: {
  266. // hospitalDistrictId,
  267. // orderId: res.orderId,
  268. // type: '已支付',
  269. // },
  270. // title: '预约详情',
  271. // pageType: 'booking-detail',
  272. // });
  273. // }
  274. // },
  275. // });
  276. this.setData({
  277. loading: true
  278. });
  279. tradePay({
  280. type: 2,
  281. amount: res.amount,
  282. idNum: res.orderId
  283. }, {
  284. tradeType: 'Appointment'
  285. }).then(() => {
  286. history.replace({
  287. query: {
  288. hospitalDistrictId,
  289. orderId: res.orderId,
  290. type: '已支付'
  291. },
  292. title: '预约详情',
  293. pageType: 'booking-detail'
  294. });
  295. }).finally(() => {
  296. this.setData({
  297. loading: false
  298. });
  299. });
  300. } else {
  301. history.replace({
  302. query: {
  303. hospitalDistrictId,
  304. orderId: res.orderId,
  305. type: '未支付'
  306. },
  307. title: '预约详情',
  308. pageType: 'booking-detail'
  309. });
  310. }
  311. }
  312. },
  313. onJudgeForm(result) {
  314. const arr = Object.getOwnPropertyNames(result); // 校验表单答案
  315. const isFalse = arr.some(item => item.split('&')[1] !== result[item]);
  316. if (isFalse) {
  317. my.alert({
  318. title: '您的情况不支持预约',
  319. content: '请前往医院发热门诊接受筛查'
  320. });
  321. return false;
  322. }
  323. return true;
  324. }
  325. }
  326. }));