index.js 8.8 KB

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