index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import { getPreSettlementDetail, creatOrder } from './service';
  2. import history from '../../utils/history';
  3. import { tradeResult } from '../../service/common';
  4. Component({
  5. data: {
  6. preSettlementDetail: {},
  7. // 预结算详情内容
  8. inpatientId: '',
  9. // 住院记录id
  10. useMedicare: false,
  11. // 使用医保结算,如果使用医保结算需要医保电子凭证授权进行预结算
  12. payAuthNo: '',
  13. // 医保线上支付授权编码
  14. repay: '' // 是true为补交,false是退款
  15. },
  16. didMount() {
  17. // 获取参数住院IDhospitalDistrictId
  18. const optionsValue = JSON.parse(JSON.stringify(this.$page.data.query));
  19. const {
  20. inpatientId,
  21. medicareAble,
  22. payAuthNo,
  23. repay
  24. } = optionsValue;
  25. console.log(repay);
  26. this.setData({
  27. inpatientId,
  28. payAuthNo,
  29. useMedicare: medicareAble,
  30. repay
  31. }, () => {
  32. // 获取预结算详情内容
  33. this.getPreSettlementDetailInfo();
  34. });
  35. },
  36. methods: {
  37. /**
  38. * 获取预结算详情内容
  39. */
  40. async getPreSettlementDetailInfo() {
  41. const {
  42. inpatientId
  43. } = this.data;
  44. const params = {
  45. inpatientId
  46. };
  47. const preSettlementDetail = await getPreSettlementDetail(params);
  48. this.setData({
  49. preSettlementDetail
  50. });
  51. },
  52. /**
  53. * 立即结算 - 获取交易号/唤起收银台参数
  54. */
  55. async onImmediateSettlement() {
  56. const {
  57. inpatientId,
  58. useMedicare,
  59. payAuthNo
  60. } = this.data;
  61. const params = {
  62. inpatientId,
  63. useMedicare,
  64. payAuthNo
  65. };
  66. const resData = await creatOrder(params);
  67. const {
  68. orderStr,
  69. status
  70. } = resData || {}; // 如果生成订单失败,toast提示
  71. if (status === 'SUCCESS') {
  72. // 无须支付/有退款
  73. const settlementType = 'supportMedicalPreSettlement';
  74. history.push({
  75. query: {
  76. settlementType,
  77. inpatientId
  78. },
  79. title: '出院结算',
  80. pageType: 'discharge-settlement'
  81. });
  82. }
  83. if (status === 'WAIT_BUYER_PAY') {
  84. // 医保需支付
  85. // 医保需支付
  86. if (!orderStr) {
  87. my.showToast({
  88. type: 'fail',
  89. content: '生成结算订单失败!',
  90. duration: 2000
  91. });
  92. return;
  93. } // 如果生成订单成功,唤起支付(预授权orderStr)
  94. my.tradePay({
  95. orderStr,
  96. success: async res => {
  97. // const { resultCode } = res;
  98. // // 支付成功, 跳转至出院结算结果页
  99. // if (resultCode === '9000') {
  100. // // 跳转类型 supportMedicalPreSettlement - 支持医保,预结算-补交
  101. // const settlementType = 'supportMedicalPreSettlement';
  102. // history.push({
  103. // query: {
  104. // settlementType,
  105. // inpatientId,
  106. // },
  107. // title: '出院结算',
  108. // pageType: 'discharge-settlement',
  109. // });
  110. // return;
  111. // }
  112. // 4000 订单处理失败
  113. // 6001 用途中途取消支付
  114. // 6002 网络链接出错
  115. if (res.resultCode === '4000' || res.resultCode === '6002' || res.resultCode === '6001') {
  116. // 支付失败
  117. my.showToast({
  118. type: 'fail',
  119. content: res.memo || '订单支付失败'
  120. });
  121. } else {
  122. // 其他情况调用接口确认
  123. const payRes = await tradeResult({
  124. tradeNo: resData.tradeNo,
  125. resultCode: res.resultCode
  126. });
  127. if (payRes.status === 'TRADE_SUCCESS') {
  128. // 跳转类型 supportMedicalPreSettlement - 支持医保,预结算-补交
  129. const settlementType = 'supportMedicalPreSettlement';
  130. history.push({
  131. query: {
  132. settlementType,
  133. inpatientId
  134. },
  135. title: '出院结算',
  136. pageType: 'discharge-settlement'
  137. });
  138. } else {
  139. my.showToast({
  140. type: 'fail',
  141. content: res.memo || '订单支付失败'
  142. });
  143. }
  144. }
  145. }
  146. });
  147. }
  148. }
  149. }
  150. });