index.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. import qs from "qs";
  2. import { getYbParams, generateRandomFourDigitNumber } from "./service";
  3. import { tradePay } from "../../utils/tradePay";
  4. import {
  5. prePayConfirm,
  6. getPayAuthInfo,
  7. } from "../../../../core/utils/ywtService";
  8. import history from "../../utils/history";
  9. import { createSubscribe } from "applet-page-component";
  10. Component(
  11. createSubscribe({
  12. onShow() {
  13. this.init("onShow");
  14. },
  15. })({
  16. props: {},
  17. data: {
  18. authCode: undefined,
  19. canPay: false,
  20. prescriptionList: [],
  21. actionsheetVisible: false,
  22. isUserPersonalAccount: true,
  23. isCulculate: false,
  24. preConfirmInfo: {},
  25. },
  26. didMount() {
  27. this.init("didMount");
  28. },
  29. didUnmount() {},
  30. methods: {
  31. init(type) {
  32. this.getPayDetail(this.$page.data.query);
  33. this.hanldeGetPayAuthInfo(type);
  34. },
  35. saveSubscribe(ref) {
  36. this.subscribe = ref;
  37. },
  38. async hanldeGetPayAuthInfo(type) {
  39. const app = getApp();
  40. const {
  41. hisOrderNo: hisOrdNum,
  42. authCode,
  43. reqBizNo,
  44. } = this.$page.data.query;
  45. const _this = this;
  46. const ramdonNum = generateRandomFourDigitNumber();
  47. const userId = app.globalData.ywtUserId || "";
  48. const queryReqBizNo = reqBizNo || `${hisOrdNum}-${userId}-${ramdonNum}`;
  49. const query = Object.assign(this.$page.data.query, {
  50. reqBizNo: queryReqBizNo,
  51. });
  52. const qsResult = `?${qs.stringify(query)}`;
  53. const callUrl = encodeURIComponent(
  54. `antbuilder/industry/hospitalV2/pages/page-no-pull/index${qsResult}`
  55. );
  56. if (type === "onShow") {
  57. my.getAuthCode({
  58. scopes: ["nhsamp", "auth_user"], // 主动授权:auth_user,静默授权:auth_base。或者其它scopes
  59. success: (res) => {
  60. if (res.authCode) {
  61. _this.requestGetPayAuthInfo(
  62. res.authCode,
  63. callUrl,
  64. queryReqBizNo,
  65. type
  66. );
  67. }
  68. },
  69. });
  70. } else {
  71. this.requestGetPayAuthInfo(authCode, callUrl, queryReqBizNo, type);
  72. }
  73. },
  74. async requestGetPayAuthInfo(authCode, callUrl, reqBizNo, lifeType) {
  75. const _this = this;
  76. const [err, result] = await getPayAuthInfo({
  77. authCode,
  78. callUrl,
  79. reqBizNo,
  80. });
  81. if (!err) {
  82. const { payAuthNo, authNo, medicalCardInstId, medicalCardId } =
  83. result;
  84. if (result.authNo) {
  85. this.setData(
  86. {
  87. payAuthNo,
  88. authNo,
  89. medicalCardInstId,
  90. medicalCardId,
  91. isCulculate: true,
  92. },
  93. () => {
  94. _this.handlePrePayConfirm();
  95. }
  96. );
  97. return;
  98. }
  99. if (result.authUrl && lifeType === "didMount") {
  100. // 跳转医保授权页面
  101. my.ap.openURL({
  102. url: result.authUrl,
  103. fail() {
  104. my.navigateBack();
  105. },
  106. });
  107. } else {
  108. my.navigateBack();
  109. }
  110. }
  111. },
  112. async handlePrePayConfirm() {
  113. my.showLoading({ mask: true });
  114. try {
  115. const {
  116. hisOrderNo: hisOrdNum,
  117. hisPatientId: patientId,
  118. hisClinicCode: clinicCode,
  119. total: orderSum,
  120. orderInsType,
  121. } = this.$page.data.query;
  122. const {
  123. payAuthNo,
  124. authNo,
  125. medicalCardInstId,
  126. medicalCardId,
  127. isUserPersonalAccount,
  128. } = this.data;
  129. const [err, result] = await prePayConfirm({
  130. patientId,
  131. clinicCode,
  132. hisOrdNum,
  133. orderSum,
  134. payInsType: "2",
  135. orderInsType,
  136. payAuthNo,
  137. authNo,
  138. medicalCardInstId,
  139. medicalCardId,
  140. consumeType: isUserPersonalAccount ? 0 : 2,
  141. });
  142. if (!err) {
  143. // 预结算成功
  144. const ybData = getYbParams(result);
  145. this.setData({
  146. preConfirmInfo: Object.assign(result, ybData),
  147. isCulculate: false,
  148. canPay: true,
  149. });
  150. } else {
  151. console.log("err ==>", err, typeof err, JSON.stringify(err));
  152. my.navigateBack();
  153. }
  154. } finally {
  155. my.hideLoading();
  156. }
  157. },
  158. parseDetailItems(detailItems) {
  159. const list = detailItems
  160. ? JSON.parse(decodeURIComponent(detailItems || ""))
  161. : [];
  162. const newList = list.map((item) => {
  163. return {
  164. label: `${item.itemName}*${item.itemNum}`,
  165. // subLabel: `${item.unit || ""}`,
  166. value: `${item.amount || 0}元`,
  167. };
  168. });
  169. return newList || [];
  170. },
  171. handleIsUserPersonalAccount(e) {
  172. my.showLoading();
  173. const _this = this;
  174. const { valuex } = e.currentTarget.dataset;
  175. this.setData(
  176. {
  177. isUserPersonalAccount: valuex,
  178. isCulculate: true,
  179. },
  180. () => {
  181. my.hideLoading();
  182. _this.handlePrePayConfirm();
  183. }
  184. );
  185. },
  186. getPayDetail(query) {
  187. let infoList = [];
  188. if (query) {
  189. infoList = [
  190. {
  191. title: "就诊信息",
  192. list: [
  193. // { label: "门诊类别", value: info.deptName },
  194. { label: "门诊科室", value: query.deptName },
  195. { label: "医生姓名", value: query.doctorName },
  196. { label: "处方时间", value: query.prescribeDate },
  197. {
  198. label: "费用总额",
  199. value: parseFloat(query.total / 100, 2) || 0 + "元",
  200. highlight: true,
  201. },
  202. ],
  203. },
  204. {
  205. title: "费用信息",
  206. list: this.parseDetailItems(query.orderItems),
  207. },
  208. ];
  209. this.setData({ prescriptionList: infoList });
  210. }
  211. },
  212. // 查看更多
  213. openForm() {
  214. this.setData({
  215. expand: !this.data.expand,
  216. });
  217. },
  218. medicareExpand() {
  219. this.setData({
  220. medicareExpand: !this.data.medicareExpand,
  221. });
  222. },
  223. handleActionsheet() {
  224. this.setData({
  225. actionsheetVisible: !this.data.actionsheetVisible,
  226. });
  227. },
  228. // 发起支付
  229. async onPay(e) {
  230. const { canPay } = this.data;
  231. if (!canPay) return;
  232. const {
  233. hisPatientId,
  234. age,
  235. sex,
  236. orderId,
  237. hisOrderNo,
  238. amount,
  239. deptName,
  240. doctorName,
  241. doctorCode,
  242. hisClinicCode,
  243. total,
  244. name,
  245. orderInsType,
  246. prescribeDate,
  247. payInsType = "2",
  248. consumeType = "0",
  249. medInsFee,
  250. selfFee,
  251. payName,
  252. patName,
  253. outTradeNo,
  254. } = this.$page.data.query;
  255. const {
  256. preConfirmInfo: { invoiceNo, insuAdmDr, insUploadFeeResp },
  257. } = this.data;
  258. let result = false;
  259. try {
  260. my.showLoading();
  261. // 门诊订单
  262. result = await tradePay(
  263. {
  264. useBalance: false,
  265. useMedicare: true,
  266. outTradeNo,
  267. hisPatientId,
  268. age,
  269. sex,
  270. orderId,
  271. hisOrderNo,
  272. amount,
  273. deptName,
  274. doctorName,
  275. doctorCode,
  276. total,
  277. hisClinicCode,
  278. name,
  279. prescribeDate,
  280. orderInsType,
  281. payInsType,
  282. consumeType,
  283. totalFee: total,
  284. medInsFee,
  285. selfFee,
  286. payName,
  287. patName,
  288. invoiceNo,
  289. insuAdmDr,
  290. insUploadFeeResp,
  291. },
  292. {
  293. tradeType: "Outpatient",
  294. }
  295. );
  296. } catch (error) {
  297. console.log("error ===>", error);
  298. } finally {
  299. my.hideLoading();
  300. }
  301. if (result) {
  302. console.log("pay result ===>", result);
  303. // 支付成功后返回列表页
  304. my.navigateBack();
  305. }
  306. },
  307. },
  308. })
  309. );