index.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. import { payDetail, percent2percent25 } from "./service";
  2. import { tradePay } from "../../utils/tradePay";
  3. import history from "../../utils/history";
  4. import { getYbParams } from "../hospital-payment-detail-yibao/service";
  5. import { reportApi, reportCmPV_YL } from "../../utils/cloudMonitorHelper";
  6. import {
  7. getSubscribeAuth,
  8. prePayConfirm,
  9. } from "../../../../core/utils/ywtService";
  10. import { createSubscribe } from "applet-page-component";
  11. Component(
  12. createSubscribe({
  13. onShow() {
  14. this.payDetail(this.$page.data.query);
  15. },
  16. })({
  17. props: {},
  18. data: {
  19. order: {
  20. orderItems: [
  21. // {
  22. // itemName: '项目名称',
  23. // itemNum: 2,
  24. // amount: 999.99,
  25. // },
  26. ],
  27. depName: "",
  28. outTradeNo: "",
  29. tradeNo: "",
  30. type: null,
  31. // 1-挂号费订单 2-充值订单 3-诊间缴费订单
  32. userName: "",
  33. cardNum: "",
  34. amount: 0,
  35. createTime: "",
  36. payTime: "",
  37. payType: null,
  38. // 1-自费 2-医保 3-其他
  39. status: null,
  40. // 0-待支付 1-已支付 9-已取消
  41. medicareBinded: false,
  42. idNum: "",
  43. customInfo: "",
  44. payDetails: "",
  45. payDate: "",
  46. doctorName: "",
  47. reportRemind: "",
  48. checkRemind: "",
  49. medicineRemind: "",
  50. refundRemind: "",
  51. receiptRemind: "",
  52. },
  53. // 订单项
  54. fromItem: [
  55. {
  56. label: "就诊人",
  57. key: "name",
  58. },
  59. {
  60. label: "病人ID号",
  61. key: "hisPatientId",
  62. },
  63. {
  64. label: "就诊科室",
  65. key: "deptName",
  66. },
  67. {
  68. label: "医生",
  69. key: "doctorName",
  70. },
  71. // {
  72. // label: "费用日期",
  73. // key: "payDate",
  74. // },
  75. // {
  76. // label: "支付单号",
  77. // key: "outTradeNo",
  78. // },
  79. {
  80. label: "开单时间",
  81. key: "prescribeDate",
  82. },
  83. // {
  84. // label: "付款时间",
  85. // key: "payTime",
  86. // },
  87. ],
  88. medicareExpand: false,
  89. expand: false,
  90. medicare: {
  91. total: 0,
  92. own: 0,
  93. detail: {},
  94. },
  95. checkRemind: {},
  96. },
  97. didMount() {
  98. this.payDetail(this.$page.data.query);
  99. /* 服务办结,门诊缴费 */
  100. reportApi("门诊缴费");
  101. /* 服务预警,门诊缴费 */
  102. reportCmPV_YL({
  103. title: "门诊缴费",
  104. });
  105. },
  106. methods: {
  107. saveSubscribe(ref) {
  108. this.subscribe = ref;
  109. },
  110. payDetail(send) {
  111. const { orderItems } = send;
  112. const status0OrderItems = JSON.parse(
  113. decodeURIComponent(percent2percent25(orderItems) || "")
  114. );
  115. const newSend = Object.assign({}, send);
  116. delete newSend["orderItems"];
  117. payDetail(newSend).then((data) => {
  118. const payDetails = JSON.parse(data.payDetails || "{}");
  119. const detail = payDetails["医保支付"] || {};
  120. let total = 0;
  121. Object.entries(detail).forEach(([k, v]) => {
  122. detail[k] = numFix(v);
  123. total += v * 1;
  124. });
  125. this.setData({
  126. order: Object.assign({}, this.data.order, data, {
  127. orderItems: data.orderItems ? data.orderItems : status0OrderItems,
  128. }),
  129. medicare: {
  130. total: numFix(total),
  131. own: numFix(payDetails["自费支付金额"]) || "0.00",
  132. detail,
  133. },
  134. checkRemind: JSON.parse(data.checkRemind || "{}"),
  135. });
  136. });
  137. },
  138. async handlePrePayConfirm() {
  139. return new Promise(async (resolve) => {
  140. const {
  141. hisOrderNo: hisOrdNum,
  142. hisPatientId: patientId,
  143. hisClinicCode: clinicCode,
  144. total: orderSum,
  145. orderInsType,
  146. } = this.$page.data.query;
  147. const {
  148. payAuthNo = "",
  149. authNo = "",
  150. medicalCardInstId = "",
  151. medicalCardId = "",
  152. } = this.data;
  153. const [err, result] = await prePayConfirm({
  154. patientId,
  155. clinicCode,
  156. hisOrdNum,
  157. orderSum,
  158. payInsType: "1",
  159. orderInsType,
  160. payAuthNo,
  161. authNo,
  162. medicalCardInstId,
  163. medicalCardId,
  164. });
  165. if (!err) {
  166. // 预结算成功
  167. const ybData = await getYbParams(result);
  168. const preConfirmInfo = Object.assign(result, ybData);
  169. this.setData(
  170. {
  171. preConfirmInfo,
  172. },
  173. resolve(preConfirmInfo)
  174. );
  175. }
  176. });
  177. },
  178. // 查看更多
  179. openForm() {
  180. this.setData({
  181. expand: !this.data.expand,
  182. });
  183. },
  184. medicareExpand() {
  185. this.setData({
  186. medicareExpand: !this.data.medicareExpand,
  187. });
  188. },
  189. // 发起支付
  190. async onPay(e) {
  191. const { medicareBinded = false } = e.target.dataset;
  192. const { orderInsType, medInsFee, selfFee, payName, patName } =
  193. this.$page.data.query;
  194. const { order: oreder } = this.data;
  195. let result = false;
  196. const { invoiceNo = "" } = await this.handlePrePayConfirm();
  197. try {
  198. my.showLoading();
  199. // 获取授权
  200. await getSubscribeAuth();
  201. if (oreder.type === 1) {
  202. result = await tradePay(
  203. {
  204. type: oreder.type,
  205. idNum: oreder.outTradeNo,
  206. depName: oreder.depName,
  207. },
  208. {
  209. tradeType: "Appointment",
  210. }
  211. );
  212. } else if (oreder.type === 2) {
  213. // 充值
  214. result = await tradePay(
  215. {
  216. type: oreder.type,
  217. idNum: oreder.outTradeNo,
  218. amount: oreder.amount,
  219. },
  220. {
  221. tradeType: "Appointment",
  222. }
  223. );
  224. } else {
  225. // 门诊订单
  226. const {
  227. hisPatientId,
  228. age,
  229. sex,
  230. orderId,
  231. hisOrderNo,
  232. amount,
  233. deptName,
  234. doctorName,
  235. doctorCode,
  236. total,
  237. hisClinicCode,
  238. name,
  239. prescribeDate,
  240. } = oreder;
  241. result = await tradePay(
  242. {
  243. useBalance: !medicareBinded,
  244. useMedicare: medicareBinded,
  245. outTradeNo: oreder.outTradeNo,
  246. hisPatientId,
  247. age,
  248. sex,
  249. orderId,
  250. hisOrderNo,
  251. amount,
  252. deptName,
  253. doctorName,
  254. doctorCode,
  255. total,
  256. hisClinicCode,
  257. name,
  258. prescribeDate,
  259. // 新增参数
  260. invoiceNo,
  261. orderInsType,
  262. totalFee: total,
  263. payInsType: "1",
  264. medInsFee,
  265. selfFee,
  266. payName,
  267. patName,
  268. },
  269. {
  270. tradeType: "Outpatient",
  271. }
  272. );
  273. }
  274. } catch (error) {
  275. console.log("error ===>", error);
  276. } finally {
  277. my.hideLoading();
  278. }
  279. // 支付成功刷新页面
  280. this.payDetail(this.$page.data.query);
  281. if (result) {
  282. // 支付成功后返回列表页
  283. my.navigateBack();
  284. }
  285. },
  286. async onYbPay() {
  287. const query = this.$page.data.query;
  288. console.log("query ==>", query);
  289. await getSubscribeAuth();
  290. my.getAuthCode({
  291. scopes: ["nhsamp", "auth_user"], // 主动授权:auth_user,静默授权:auth_base。或者其它scopes
  292. success: (res) => {
  293. if (res.authCode) {
  294. history.push({
  295. title: "确认支付",
  296. query: Object.assign(query, {
  297. authCode: res.authCode,
  298. orderItems: percent2percent25(query.orderItems),
  299. }),
  300. pageType: "hospital-payment-detail-yibao",
  301. });
  302. }
  303. },
  304. });
  305. },
  306. hrefTo() {
  307. my.ap.navigateToAlipayPage({
  308. path: "alipays://platformapi/startapp?appId=77700284&page=pages/medical/index?chInfo=YY_xiaochengxu",
  309. });
  310. },
  311. toH5(e) {
  312. const { url } = e.target.dataset;
  313. history.toH5(url);
  314. },
  315. },
  316. })
  317. );
  318. function numFix(val) {
  319. const num = val * 1;
  320. return num.toFixed(2);
  321. }