index.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. resultCode,
  45. } = this.$page.data.query;
  46. const _this = this;
  47. const ramdonNum = generateRandomFourDigitNumber();
  48. const userId = app.globalData.ywtUserId || "";
  49. const queryReqBizNo = reqBizNo || `${hisOrdNum}-${userId}-${ramdonNum}`;
  50. const query = Object.assign(this.$page.data.query, {
  51. reqBizNo: queryReqBizNo,
  52. });
  53. const qsResult = `?${qs.stringify(query)}`;
  54. const callUrl = encodeURIComponent(
  55. `antbuilder/industry/hospitalV2/pages/page-no-pull/index${qsResult}`
  56. );
  57. if (type === "onShow") {
  58. // 需要路由传递一个参数,用于判断是否授权,确定授权则下一步;取消授权则返回上一页
  59. console.log(
  60. "this.$page.data.query ===>",
  61. this.$page.data.query,
  62. this.$page.data,
  63. resultCode
  64. );
  65. // if (resultCode === "SUCCESS") {
  66. // my.navigateBack();
  67. // return;
  68. // }
  69. my.getAuthCode({
  70. scopes: ["nhsamp", "auth_user"], // 主动授权:auth_user,静默授权:auth_base。或者其它scopes
  71. success: (res) => {
  72. if (res.authCode) {
  73. _this.requestGetPayAuthInfo(
  74. res.authCode,
  75. callUrl,
  76. queryReqBizNo,
  77. type
  78. );
  79. }
  80. },
  81. });
  82. } else {
  83. this.requestGetPayAuthInfo(authCode, callUrl, queryReqBizNo, type);
  84. }
  85. },
  86. async requestGetPayAuthInfo(authCode, callUrl, reqBizNo, lifeType) {
  87. const _this = this;
  88. const [err, result] = await getPayAuthInfo({
  89. authCode,
  90. callUrl,
  91. reqBizNo,
  92. });
  93. if (!err) {
  94. const { payAuthNo, authNo, medicalCardInstId, medicalCardId } =
  95. result;
  96. if (result.authNo) {
  97. this.setData(
  98. {
  99. payAuthNo,
  100. authNo,
  101. medicalCardInstId,
  102. medicalCardId,
  103. isCulculate: true,
  104. },
  105. () => {
  106. _this.handlePrePayConfirm();
  107. }
  108. );
  109. return;
  110. }
  111. if (result.authUrl && lifeType === 'didMount') {
  112. // 跳转医保授权页面
  113. my.ap.openURL({
  114. url: result.authUrl,
  115. fail() {
  116. my.navigateBack();
  117. },
  118. });
  119. }else{
  120. my.navigateBack();
  121. }
  122. }
  123. },
  124. async handlePrePayConfirm() {
  125. my.showLoading({ mask: true });
  126. try {
  127. const {
  128. hisOrderNo: hisOrdNum,
  129. hisPatientId: patientId,
  130. hisClinicCode: clinicCode,
  131. total: orderSum,
  132. orderInsType,
  133. } = this.$page.data.query;
  134. const { payAuthNo, authNo, medicalCardInstId, medicalCardId } =
  135. this.data;
  136. const [err, result] = await prePayConfirm({
  137. patientId,
  138. clinicCode,
  139. hisOrdNum,
  140. orderSum,
  141. payInsType: "2",
  142. orderInsType,
  143. payAuthNo,
  144. authNo,
  145. medicalCardInstId,
  146. medicalCardId,
  147. });
  148. if (!err) {
  149. // 预结算成功
  150. const ybData = getYbParams(result);
  151. this.setData({
  152. preConfirmInfo: Object.assign(result, ybData),
  153. isCulculate: false,
  154. canPay: true,
  155. });
  156. } else {
  157. my.navigateBack();
  158. throw `${err}`;
  159. }
  160. } catch (error) {
  161. console.log("error ===>", error);
  162. } finally {
  163. my.hideLoading();
  164. }
  165. },
  166. parseDetailItems(detailItems) {
  167. const list = detailItems
  168. ? JSON.parse(decodeURIComponent(detailItems || ""))
  169. : [];
  170. const newList = list.map((item) => {
  171. return {
  172. label: `${item.itemName}*${item.itemNum}`,
  173. // subLabel: `${item.unit || ""}`,
  174. value: `${item.amount || 0}元`,
  175. };
  176. });
  177. return newList || [];
  178. },
  179. handleIsUserPersonalAccount(e) {
  180. my.showLoading();
  181. const _this = this;
  182. const { valuex } = e.currentTarget.dataset;
  183. this.setData(
  184. {
  185. isUserPersonalAccount: valuex,
  186. isCulculate: true,
  187. },
  188. () => {
  189. setTimeout(() => {
  190. my.hideLoading();
  191. _this.setData({
  192. isCulculate: false,
  193. });
  194. }, 3000);
  195. }
  196. );
  197. },
  198. getPayDetail(query) {
  199. let infoList = [];
  200. if (query) {
  201. infoList = [
  202. {
  203. title: "就诊信息",
  204. list: [
  205. // { label: "门诊类别", value: info.deptName },
  206. { label: "门诊科室", value: query.deptName },
  207. { label: "医生姓名", value: query.doctorName },
  208. { label: "处方时间", value: query.prescribeDate },
  209. {
  210. label: "费用总额",
  211. value: parseFloat(query.total / 100, 2) || 0 + "元",
  212. highlight: true,
  213. },
  214. ],
  215. },
  216. {
  217. title: "费用信息",
  218. list: this.parseDetailItems(query.orderItems),
  219. },
  220. ];
  221. this.setData({ prescriptionList: infoList });
  222. }
  223. },
  224. // 查看更多
  225. openForm() {
  226. this.setData({
  227. expand: !this.data.expand,
  228. });
  229. },
  230. medicareExpand() {
  231. this.setData({
  232. medicareExpand: !this.data.medicareExpand,
  233. });
  234. },
  235. handleActionsheet() {
  236. this.setData({
  237. actionsheetVisible: !this.data.actionsheetVisible,
  238. });
  239. },
  240. // 发起支付
  241. async onPay(e) {
  242. const { canPay } = this.data;
  243. if (!canPay) return;
  244. const {
  245. hisPatientId,
  246. age,
  247. sex,
  248. orderId,
  249. hisOrderNo,
  250. amount,
  251. deptName,
  252. doctorName,
  253. doctorCode,
  254. hisClinicCode,
  255. total,
  256. name,
  257. orderInsType,
  258. prescribeDate,
  259. payInsType = "2",
  260. consumeType = "0",
  261. medInsFee,
  262. selfFee,
  263. payName,
  264. patName,
  265. outTradeNo,
  266. } = this.$page.data.query;
  267. const {
  268. preConfirmInfo: { invoiceNo, insuAdmDr, insUploadFeeResp },
  269. } = this.data;
  270. console.log("this.$page.data.query ==>", this.$page.data.query);
  271. let result = false;
  272. console.log("requset data ==>", {
  273. useBalance: false,
  274. useMedicare: true,
  275. outTradeNo,
  276. hisPatientId,
  277. age,
  278. sex,
  279. orderId,
  280. hisOrderNo,
  281. amount,
  282. deptName,
  283. doctorName,
  284. doctorCode,
  285. total,
  286. hisClinicCode,
  287. name,
  288. prescribeDate,
  289. orderInsType,
  290. payInsType,
  291. consumeType,
  292. totalFee: total,
  293. medInsFee,
  294. selfFee,
  295. payName,
  296. patName,
  297. invoiceNo,
  298. insuAdmDr,
  299. insUploadFeeResp,
  300. });
  301. try {
  302. my.showLoading();
  303. // 门诊订单
  304. result = await tradePay(
  305. {
  306. useBalance: false,
  307. useMedicare: true,
  308. outTradeNo,
  309. hisPatientId,
  310. age,
  311. sex,
  312. orderId,
  313. hisOrderNo,
  314. amount,
  315. deptName,
  316. doctorName,
  317. doctorCode,
  318. total,
  319. hisClinicCode,
  320. name,
  321. prescribeDate,
  322. orderInsType,
  323. payInsType,
  324. consumeType,
  325. totalFee: total,
  326. medInsFee,
  327. selfFee,
  328. payName,
  329. patName,
  330. invoiceNo,
  331. insuAdmDr,
  332. insUploadFeeResp,
  333. },
  334. {
  335. tradeType: "Outpatient",
  336. }
  337. );
  338. } catch (error) {
  339. console.log("error ===>", error);
  340. } finally {
  341. my.hideLoading();
  342. }
  343. if (result) {
  344. // 支付成功后返回列表页
  345. my.navigateBack();
  346. }
  347. },
  348. },
  349. })
  350. );