index.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. import { getYbParams } 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. actionsheetVisible: false,
  15. isUserPersonalAccount: true,
  16. isCulculate: false
  17. },
  18. didMount() {
  19. this.getPayDetail(this.$page.data.query);
  20. },
  21. methods: {
  22. saveSubscribe(ref) {
  23. this.subscribe = ref;
  24. },
  25. parseDetailItems(detailItems) {
  26. const list = detailItems
  27. ? JSON.parse(decodeURIComponent(detailItems || ""))
  28. : [];
  29. const newList = list.map((item) => {
  30. return {
  31. label: `${item.itemName}*${item.itemNum}`,
  32. // subLabel: `${item.unit || ""}`,
  33. value: `${item.amount || 0}元`,
  34. };
  35. });
  36. return newList || [];
  37. },
  38. handleIsUserPersonalAccount(e) {
  39. my.showLoading();
  40. const _this = this
  41. const { valuex } = e.currentTarget.dataset;
  42. this.setData({
  43. isUserPersonalAccount: valuex,
  44. isCulculate: true
  45. }, () => {
  46. setTimeout(() => {
  47. my.hideLoading()
  48. _this.setData({
  49. isCulculate: false
  50. })
  51. }, 3000)
  52. })
  53. },
  54. getPayDetail(query) {
  55. console.log("query ==>", query);
  56. let infoList = [];
  57. if (query) {
  58. infoList = [
  59. {
  60. title: "就诊信息",
  61. list: [
  62. // { label: "门诊类别", value: info.deptName },
  63. { label: "门诊科室", value: query.deptName },
  64. { label: "医生姓名", value: query.doctorName },
  65. { label: "处方时间", value: query.prescribeDate },
  66. {
  67. label: "费用总额",
  68. value: parseFloat(query.total / 100, 2) || 0 + "元",
  69. highlight: true,
  70. },
  71. ],
  72. },
  73. {
  74. title: "费用信息",
  75. list: this.parseDetailItems(query.orderItems),
  76. },
  77. ];
  78. this.setData({ prescriptionList: infoList });
  79. }
  80. return;
  81. my.getAuthCode({
  82. scopes: ["nhsamp", "auth_user"], // 主动授权:auth_user,静默授权:auth_base。或者其它scopes
  83. success: (res) => {
  84. if (res.authCode) {
  85. // 认证成功
  86. // 调用自己的服务端接口,让服务端进行后端的授权认证,并且利用session,需要解决跨域问题
  87. my.request({
  88. url: "https://isv.com/auth", // 该url是您自己的服务地址,实现的功能是服务端拿到authcode去开放平台进行token验证
  89. data: {
  90. authcode: res.authCode,
  91. },
  92. success: () => {
  93. // 授权成功并且服务器端登录成功
  94. },
  95. fail: () => {
  96. // 根据自己的业务场景来进行错误处理
  97. },
  98. });
  99. }
  100. },
  101. });
  102. },
  103. // 查看更多
  104. openForm() {
  105. this.setData({
  106. expand: !this.data.expand,
  107. });
  108. },
  109. medicareExpand() {
  110. this.setData({
  111. medicareExpand: !this.data.medicareExpand,
  112. });
  113. },
  114. handleActionsheet() {
  115. this.setData({
  116. actionsheetVisible: !this.data.actionsheetVisible,
  117. });
  118. },
  119. // 发起支付
  120. async onPay(e) {
  121. const { medicareBinded = false } = e.target.dataset;
  122. const { order: oreder } = this.data;
  123. let result = false;
  124. try {
  125. my.showLoading();
  126. if (oreder.type === 1) {
  127. result = await tradePay(
  128. {
  129. type: oreder.type,
  130. idNum: oreder.outTradeNo,
  131. depName: oreder.depName,
  132. },
  133. {
  134. tradeType: "Appointment",
  135. }
  136. );
  137. } else if (oreder.type === 2) {
  138. // 充值
  139. result = await tradePay(
  140. {
  141. type: oreder.type,
  142. idNum: oreder.outTradeNo,
  143. amount: oreder.amount,
  144. },
  145. {
  146. tradeType: "Appointment",
  147. }
  148. );
  149. } else {
  150. // 门诊订单
  151. const {
  152. hisPatientId,
  153. age,
  154. sex,
  155. orderId,
  156. hisOrderNo,
  157. amount,
  158. deptName,
  159. doctorName,
  160. doctorCode,
  161. total,
  162. hisClinicCode,
  163. name,
  164. prescribeDate,
  165. } = oreder;
  166. result = await tradePay(
  167. {
  168. useBalance: !medicareBinded,
  169. useMedicare: medicareBinded,
  170. outTradeNo: oreder.outTradeNo,
  171. hisPatientId,
  172. age,
  173. sex,
  174. orderId,
  175. hisOrderNo,
  176. amount,
  177. deptName,
  178. doctorName,
  179. doctorCode,
  180. total,
  181. hisClinicCode,
  182. name,
  183. prescribeDate,
  184. },
  185. {
  186. tradeType: "Outpatient",
  187. }
  188. );
  189. }
  190. } catch (error) {
  191. console.log("error ===>", error);
  192. } finally {
  193. my.hideLoading();
  194. }
  195. if (result) {
  196. // 支付成功后返回列表页
  197. my.navigateBack();
  198. }
  199. },
  200. },
  201. });