index.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { getDepositDetails, getsubscribeID } from "./service";
  2. import { reportApi } from "../../utils/cloudMonitorHelper";
  3. import { getAuthUser } from "../../../../core/utils/jsapi";
  4. Component({
  5. data: {
  6. showSubscrible: false,
  7. // 是否显示订阅部分
  8. detail: null,
  9. // 缴纳详情
  10. isReady: false,
  11. },
  12. didMount() {
  13. const { depositId, inpatientId, hisPatientId, name } =
  14. this.$page.data.query || {};
  15. this.getDepositDetailsFn(depositId, inpatientId, hisPatientId, name);
  16. // this.subscribeMsg();
  17. /* 服务办结,押金缴纳完成 */
  18. reportApi("押金缴纳完成");
  19. },
  20. methods: {
  21. subscribeMsg() {
  22. const pluginId = 2021001155639035;
  23. my.loadPlugin({
  24. plugin: `${pluginId}@*`,
  25. success: () => {
  26. this.setData({
  27. isReady: true,
  28. }); // 储存插件实列
  29. // eslint-disable-next-line no-undef
  30. const pluginInstance = requirePlugin(`dynamic-plugin://${pluginId}`);
  31. this.requestSubscribeMessage = pluginInstance.requestSubscribeMessage;
  32. },
  33. });
  34. },
  35. showSubscrible() {
  36. this.setData({
  37. showSubscrible: false,
  38. });
  39. },
  40. // 订阅插件要用时,请放开注释
  41. requestSubscribeMessageFn(subscribeID) {
  42. return new Promise((resolve) => {
  43. my.requestSubscribeMessage({
  44. // 模板id列表,最多3个
  45. entityIds: [subscribeID],
  46. callback() {
  47. resolve(true);
  48. },
  49. complete(result) {
  50. console.log("result ==>", result);
  51. },
  52. });
  53. });
  54. },
  55. async gotoSubscrible() {
  56. try {
  57. // my.getAuthCode({
  58. // scopes: ["auth_user", "hospital_order"],
  59. // success: (res) => {
  60. // console.log("authCode ===>", res.authCode);
  61. // },
  62. // });
  63. const [err, authResult] = await getAuthUser(["hospital_order"]);
  64. console.log("authResult ===>", authResult.authCode);
  65. const subscribeID = await getsubscribeID();
  66. await this.requestSubscribeMessageFn(subscribeID.depositTemplateId);
  67. } catch (error) {
  68. console.log(error, "error");
  69. }
  70. },
  71. // 获取支付详情
  72. async getDepositDetailsFn(depositId, inpatientId, hisPatientId, name) {
  73. try {
  74. const detail = await getDepositDetails({
  75. depositId,
  76. hisPatientId: hisPatientId,
  77. receiptNo: depositId,
  78. name,
  79. });
  80. this.setData({
  81. detail,
  82. });
  83. } catch (error) {
  84. console.log(error, "error");
  85. }
  86. },
  87. },
  88. });