index.js 6.2 KB

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