index.js 7.9 KB

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