index.js 8.2 KB

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