index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // import { payDetail } from "./service";
  2. import { tradePay } from "../../utils/tradePay";
  3. import history from "../../utils/history";
  4. // import { reportApi, reportCmPV_YL } from "../../utils/cloudMonitorHelper";
  5. import { getSubscribeAuth } from "../../../../core/utils/ywtService";
  6. // import { createSubscribe } from "applet-page-component";
  7. Component({
  8. props: {},
  9. data: {
  10. authCode: undefined,
  11. canPay: true,
  12. prescriptionList: [
  13. {
  14. title: "就诊信息",
  15. list: [
  16. { label: "门诊类别", value: "门(急)诊" },
  17. { label: "门诊科室", value: "普通内科" },
  18. { label: "医生姓名", value: "张三" },
  19. { label: "处方时间", value: "2021/06/08 14:54:00" },
  20. { label: "费用总额", value: "368.50元", highlight: true },
  21. ],
  22. },
  23. {
  24. title: "诊断信息",
  25. list: [
  26. { label: "诊断名称", value: "外伤肿胀" },
  27. { label: "诊断编号", value: "E3D.25" },
  28. ],
  29. },
  30. {
  31. title: "费用信息",
  32. list: [
  33. { label: "万通胫骨贴*1", subLabel: "8g/片/3", value: "37.80元" },
  34. { label: "阿莫西林*1", subLabel: "8g/片/3", value: "7.80元" },
  35. ],
  36. },
  37. ],
  38. actionsheetVisible: false,
  39. },
  40. didMount() {
  41. this.payDetail(this.$page.data.query);
  42. },
  43. methods: {
  44. saveSubscribe(ref) {
  45. this.subscribe = ref;
  46. },
  47. payDetail(query) {
  48. console.log("query ==>", query);
  49. return;
  50. my.getAuthCode({
  51. scopes: ["nhsamp", "auth_user"], // 主动授权:auth_user,静默授权:auth_base。或者其它scopes
  52. success: (res) => {
  53. if (res.authCode) {
  54. // 认证成功
  55. // 调用自己的服务端接口,让服务端进行后端的授权认证,并且利用session,需要解决跨域问题
  56. my.request({
  57. url: "https://isv.com/auth", // 该url是您自己的服务地址,实现的功能是服务端拿到authcode去开放平台进行token验证
  58. data: {
  59. authcode: res.authCode,
  60. },
  61. success: () => {
  62. // 授权成功并且服务器端登录成功
  63. },
  64. fail: () => {
  65. // 根据自己的业务场景来进行错误处理
  66. },
  67. });
  68. }
  69. },
  70. });
  71. },
  72. // 查看更多
  73. openForm() {
  74. this.setData({
  75. expand: !this.data.expand,
  76. });
  77. },
  78. medicareExpand() {
  79. this.setData({
  80. medicareExpand: !this.data.medicareExpand,
  81. });
  82. },
  83. handleActionsheet() {
  84. this.setData({
  85. actionsheetVisible: !this.data.actionsheetVisible,
  86. });
  87. },
  88. // 发起支付
  89. async onPay(e) {
  90. const { medicareBinded = false } = e.target.dataset;
  91. const { order: oreder } = this.data;
  92. let result = false;
  93. try {
  94. my.showLoading();
  95. // 获取授权
  96. await getSubscribeAuth();
  97. if (oreder.type === 1) {
  98. result = await tradePay(
  99. {
  100. type: oreder.type,
  101. idNum: oreder.outTradeNo,
  102. depName: oreder.depName,
  103. },
  104. {
  105. tradeType: "Appointment",
  106. }
  107. );
  108. } else if (oreder.type === 2) {
  109. // 充值
  110. result = await tradePay(
  111. {
  112. type: oreder.type,
  113. idNum: oreder.outTradeNo,
  114. amount: oreder.amount,
  115. },
  116. {
  117. tradeType: "Appointment",
  118. }
  119. );
  120. } else {
  121. // 门诊订单
  122. const {
  123. hisPatientId,
  124. age,
  125. sex,
  126. orderId,
  127. hisOrderNo,
  128. amount,
  129. deptName,
  130. doctorName,
  131. doctorCode,
  132. total,
  133. hisClinicCode,
  134. name,
  135. prescribeDate,
  136. } = oreder;
  137. result = await tradePay(
  138. {
  139. useBalance: !medicareBinded,
  140. useMedicare: medicareBinded,
  141. outTradeNo: oreder.outTradeNo,
  142. hisPatientId,
  143. age,
  144. sex,
  145. orderId,
  146. hisOrderNo,
  147. amount,
  148. deptName,
  149. doctorName,
  150. doctorCode,
  151. total,
  152. hisClinicCode,
  153. name,
  154. prescribeDate,
  155. },
  156. {
  157. tradeType: "Outpatient",
  158. }
  159. );
  160. }
  161. } catch (error) {
  162. console.log("error ===>", error);
  163. } finally {
  164. my.hideLoading();
  165. }
  166. // 支付成功刷新页面
  167. this.payDetail(this.$page.data.query);
  168. if (result) {
  169. // 支付成功后返回列表页
  170. my.navigateBack();
  171. }
  172. },
  173. hrefTo() {
  174. my.ap.navigateToAlipayPage({
  175. path: "alipays://platformapi/startapp?appId=77700284&page=pages/medical/index?chInfo=YY_xiaochengxu",
  176. });
  177. },
  178. toH5(e) {
  179. const { url } = e.target.dataset;
  180. history.toH5(url);
  181. },
  182. },
  183. });
  184. function numFix(val) {
  185. const num = val * 1;
  186. return num.toFixed(2);
  187. }