index.js 6.3 KB

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