index.js 6.4 KB

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