index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. import { payHistory } from "./service";
  2. import history from "../../utils/history";
  3. import { tradePay } from "../../utils/tradePay";
  4. import { reportCmPV_YL } from "../../utils/cloudMonitorHelper";
  5. import { getSubscribeAuth } from "../../../../core/utils/ywtService";
  6. import { createSubscribe } from "applet-page-component";
  7. Component(
  8. createSubscribe({
  9. async onShow() {
  10. this.scrollRef.refresh();
  11. },
  12. })({
  13. props: {},
  14. data: {
  15. empty: true,
  16. clinicCard: {},
  17. filterParams: {
  18. type: "9",
  19. cardNum: "",
  20. endTime: "",
  21. startTime: "",
  22. medicCards: [],
  23. timeShow: false,
  24. },
  25. /* 赛选项目 */
  26. typeOptions: [],
  27. statusOptions: [
  28. {
  29. value: "0",
  30. label: "待支付",
  31. },
  32. {
  33. value: "1",
  34. label: "已支付",
  35. },
  36. ],
  37. showAll: false,
  38. showTimeSelector: true,
  39. showCardSelector: false,
  40. defaultLabel: "待支付",
  41. defaultName: "待支付",
  42. defaultStatus: "待支付",
  43. },
  44. didMount() {
  45. /* 服务预警,缴费记录查询 */
  46. reportCmPV_YL({
  47. title: "门诊缴费",
  48. });
  49. },
  50. onInit() {},
  51. methods: {
  52. onFilterHandel(filters) {
  53. const { status: prevStatus } = this.filters || {};
  54. const { status: curStatus } = filters || {};
  55. if (!this.hisPatientId) return;
  56. this.filters = filters;
  57. const { status, startTime, endTime } = this.filters || {};
  58. // 当状态未改变时,做时间筛选校验,拦截请求;当状态被改变时,做时间校验的同时,不拦截请求
  59. // 状态:已支付
  60. if (status && status === "1") {
  61. if (!startTime || this.getTimeChange(startTime, endTime, 15)) {
  62. my.showToast({
  63. type: "fail",
  64. content: "请选择15天以内的时间",
  65. duration: 1500,
  66. });
  67. if (prevStatus === curStatus) return;
  68. }
  69. }
  70. // 状态:未支付
  71. if (!status || status === "0") {
  72. if (!startTime || this.getTimeChange(startTime, endTime, 3)) {
  73. my.showToast({
  74. type: "fail",
  75. content: "请选择3天以内的时间",
  76. duration: 1500,
  77. });
  78. if (prevStatus === curStatus) return;
  79. }
  80. }
  81. this.scrollRef.refresh();
  82. },
  83. saveRef(ref) {
  84. this.scrollRef = ref;
  85. },
  86. saveSubscribe(ref) {
  87. this.subscribe = ref;
  88. },
  89. getTimeChange(startTime, endTime, len) {
  90. if (!startTime || !endTime) {
  91. return true;
  92. }
  93. const time1 = Date.parse(startTime);
  94. const time2 = Date.parse(endTime);
  95. const timeDiff = time2 - time1;
  96. const duration = len * 24 * 60 * 60 * 1000;
  97. return timeDiff < 0 || timeDiff > duration;
  98. },
  99. onService(page) {
  100. const { status, startTime, endTime } = this.filters || {};
  101. if (!this.hisPatientId) return;
  102. return payHistory({
  103. ...this.filters,
  104. status: status || "0",
  105. ...page,
  106. hisPatientId: this.hisPatientId,
  107. });
  108. },
  109. onAutoFilter(patient) {
  110. if (patient) {
  111. this.hisPatientId = patient.hisPatientId;
  112. this.scrollRef.refresh();
  113. }
  114. },
  115. // 进入详情
  116. toDetail(e) {
  117. const {
  118. item: {
  119. type,
  120. outTradeNo,
  121. status,
  122. tradeNo,
  123. invoiceNo,
  124. hisPatientId,
  125. date,
  126. depName,
  127. amount,
  128. name,
  129. age,
  130. sex,
  131. prescribeDate,
  132. hisOrderNo,
  133. doctorName,
  134. doctorCode,
  135. total,
  136. hisClinicCode,
  137. deptName,
  138. orderItems,
  139. },
  140. } = e.target.dataset;
  141. history.push({
  142. title: "缴费详情",
  143. query: {
  144. type: type || 0,
  145. outTradeNo,
  146. status,
  147. tradeNo,
  148. invoiceNo,
  149. hisPatientId,
  150. date,
  151. depName,
  152. amount,
  153. name,
  154. age,
  155. sex,
  156. prescribeDate,
  157. hisOrderNo,
  158. doctorName,
  159. doctorCode,
  160. total,
  161. hisClinicCode,
  162. deptName,
  163. orderItems: encodeURIComponent(JSON.stringify(orderItems || "")),
  164. },
  165. pageType: "hospital-payment-detail",
  166. });
  167. },
  168. // 付款
  169. async onPayment(e) {
  170. const { medicareBinded = false, item } = e.target.dataset; // 同意订阅消息后发起支付
  171. try {
  172. my.showLoading();
  173. // 获取智能消息推送授权
  174. await getSubscribeAuth();
  175. // 挂号
  176. if (item.type === 1) {
  177. await tradePay(
  178. {
  179. type: item.type,
  180. idNum: item.outTradeNo,
  181. depName: item.depName,
  182. },
  183. {
  184. tradeType: "Appointment",
  185. }
  186. );
  187. } else if (item.type === 2) {
  188. // 充值
  189. await tradePay(
  190. {
  191. type: item.type,
  192. idNum: item.outTradeNo,
  193. amount: item.amount,
  194. },
  195. {
  196. tradeType: "Appointment",
  197. }
  198. );
  199. } else {
  200. // 门诊订单
  201. await tradePay(
  202. {
  203. useBalance: !medicareBinded,
  204. useMedicare: medicareBinded,
  205. outTradeNo: item.outTradeNo,
  206. ...item,
  207. },
  208. {
  209. tradeType: "Outpatient",
  210. }
  211. );
  212. }
  213. } catch (error) {
  214. } finally {
  215. my.hideLoading();
  216. }
  217. this.scrollRef.refresh();
  218. // 支付成功去订单详情页
  219. this.toDetail({
  220. target: {
  221. dataset: {
  222. outTradeNo: item.outTradeNo,
  223. type: item.type ? item.type : 0,
  224. ...item,
  225. },
  226. },
  227. }); // 发起消息订阅
  228. // this.subscribe.subscribeMessage();
  229. },
  230. },
  231. })
  232. );