index.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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. if (!err) {
  195. // 预结算成功
  196. const ybData = await getYbParams(result);
  197. this.setData(
  198. {
  199. preConfirmInfo: Object.assign(result, ybData),
  200. isCulculate: false,
  201. canPay: true,
  202. },
  203. () => {
  204. my.hideLoading();
  205. }
  206. );
  207. } else {
  208. my.hideLoading();
  209. my.showToast({
  210. type: "fail",
  211. content: err.info || "未知错误",
  212. duration: 2000,
  213. complete() {
  214. my.navigateBack();
  215. },
  216. });
  217. }
  218. },
  219. async handleIsUserPersonalAccount(e) {
  220. const _this = this;
  221. const { valuex } = e.currentTarget.dataset;
  222. const { hisOrderNo, hisPatientId } = this.$page.data.query;
  223. const { preConfirmInfo, isUserPersonalAccount } = this.data;
  224. if (isUserPersonalAccount === valuex) return;
  225. my.showLoading();
  226. this.setData(
  227. {
  228. isUserPersonalAccount: valuex,
  229. isCulculate: true,
  230. },
  231. async () => {
  232. const [err, result] = await revokeSettle({
  233. hisOrderNo,
  234. insuDivId: preConfirmInfo.insuDivId || "",
  235. hisPatientId,
  236. isInsV2: true,
  237. });
  238. if (!err) {
  239. _this.handlePrePayConfirm();
  240. } else {
  241. my.showToast({
  242. type: "fail",
  243. content: "撤销预结算失败",
  244. duration: 2000,
  245. complete() {
  246. my.hideLoading();
  247. my.navigateBack();
  248. },
  249. });
  250. }
  251. }
  252. );
  253. },
  254. getPayDetail1(query) {
  255. let infoList = [];
  256. if (query) {
  257. infoList = [
  258. {
  259. title: "就诊信息",
  260. list: [
  261. // { label: "门诊类别", value: info.deptName },
  262. { label: "门诊科室", value: query.deptName },
  263. { label: "医生姓名", value: query.doctorName },
  264. { label: "处方时间", value: query.prescribeDate },
  265. {
  266. label: "费用总额",
  267. value: parseFloat(query.total / 100, 2) || 0 + "元",
  268. highlight: true,
  269. },
  270. ],
  271. },
  272. {
  273. title: "费用信息",
  274. list: parseDetailItems(query.orderItems),
  275. },
  276. ];
  277. this.setData({ prescriptionList: infoList });
  278. }
  279. },
  280. // 查看更多
  281. openForm() {
  282. this.setData({
  283. expand: !this.data.expand,
  284. });
  285. },
  286. medicareExpand() {
  287. this.setData({
  288. medicareExpand: !this.data.medicareExpand,
  289. });
  290. },
  291. handleActionsheet() {
  292. this.setData({
  293. actionsheetVisible: !this.data.actionsheetVisible,
  294. });
  295. },
  296. // 发起支付
  297. async onPay(e) {
  298. const { canPay } = this.data;
  299. console.log("canPay ==>", canPay);
  300. if (!canPay) return;
  301. this._paying = true;
  302. const {
  303. hisPatientId,
  304. age,
  305. sex,
  306. orderId,
  307. hisOrderNo,
  308. amount,
  309. deptName,
  310. doctorName,
  311. doctorCode,
  312. hisClinicCode,
  313. total,
  314. name,
  315. orderInsType,
  316. prescribeDate,
  317. payInsType = "2",
  318. medInsFee,
  319. selfFee,
  320. payName,
  321. patName,
  322. outTradeNo,
  323. } = this.$page.data.query;
  324. const {
  325. preConfirmInfo: { invoiceNo, insuAdmDr, insUploadFeeResp },
  326. isUserPersonalAccount,
  327. } = this.data;
  328. let result = false;
  329. my.showLoading();
  330. // 门诊订单
  331. result = await tradePay(
  332. {
  333. useBalance: false,
  334. useMedicare: true,
  335. outTradeNo,
  336. hisPatientId,
  337. age,
  338. sex,
  339. orderId,
  340. hisOrderNo,
  341. amount,
  342. deptName,
  343. doctorName,
  344. doctorCode,
  345. total,
  346. hisClinicCode,
  347. name,
  348. prescribeDate,
  349. orderInsType,
  350. payInsType,
  351. totalFee: total,
  352. medInsFee,
  353. selfFee,
  354. payName,
  355. patName,
  356. invoiceNo,
  357. insuAdmDr,
  358. insUploadFeeResp,
  359. consumeType: isUserPersonalAccount ? 0 : 2,
  360. },
  361. {
  362. tradeType: "Outpatient",
  363. }
  364. );
  365. my.hideLoading();
  366. if (result) {
  367. this._paying = false;
  368. console.log("pay result ===>", result);
  369. // 支付成功后返回列表页
  370. // my.navigateBack();
  371. history.replace({
  372. title: "支付成功",
  373. query: {},
  374. pageType: "hospital-payment-detail-yibao-result",
  375. });
  376. } else {
  377. this._paying = false;
  378. }
  379. },
  380. },
  381. })
  382. );