index.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. alertTitle: "",
  44. },
  45. didMount() {
  46. /* 服务预警,缴费记录查询 */
  47. reportCmPV_YL({
  48. title: "门诊缴费",
  49. });
  50. },
  51. onInit() {},
  52. methods: {
  53. onFilterHandel(filters) {
  54. const { status: prevStatus } = this.filters || {};
  55. const { status: curStatus } = filters || {};
  56. if (!this.hisPatientId) return;
  57. this.filters = filters;
  58. const { status, startTime, endTime } = this.filters || {};
  59. // 当状态未改变时,做时间筛选校验,拦截请求;当状态被改变时,做时间校验的同时,不拦截请求
  60. // 状态:已支付
  61. if (status && status === "1") {
  62. this.setData({
  63. alertTitle: "温馨提醒:每次最多能查询15天时间段的记录",
  64. });
  65. if (!startTime || this.getTimeChange(startTime, endTime, 15)) {
  66. my.showToast({
  67. type: "fail",
  68. content: "请选择15天以内的时间",
  69. duration: 1500,
  70. });
  71. if (prevStatus === curStatus) return;
  72. }
  73. }
  74. // 状态:未支付
  75. if (!status || status === "0") {
  76. this.setData({
  77. alertTitle: "",
  78. });
  79. if (!startTime || this.getTimeChange(startTime, endTime, 3)) {
  80. my.showToast({
  81. type: "fail",
  82. content: "请选择3天以内的时间",
  83. duration: 1500,
  84. });
  85. if (prevStatus === curStatus) return;
  86. }
  87. }
  88. this.scrollRef.refresh();
  89. },
  90. saveRef(ref) {
  91. this.scrollRef = ref;
  92. },
  93. saveSubscribe(ref) {
  94. this.subscribe = ref;
  95. },
  96. getTimeChange(startTime, endTime, len) {
  97. if (!startTime || !endTime) {
  98. return true;
  99. }
  100. const time1 = Date.parse(startTime);
  101. const time2 = Date.parse(endTime);
  102. const timeDiff = time2 - time1;
  103. const duration = len * 24 * 60 * 60 * 1000;
  104. return timeDiff < 0 || timeDiff > duration;
  105. },
  106. onService(page) {
  107. const { status, startTime, endTime } = this.filters || {};
  108. if (!this.hisPatientId) return;
  109. return payHistory({
  110. ...this.filters,
  111. status: status || "0",
  112. ...page,
  113. hisPatientId: this.hisPatientId,
  114. });
  115. },
  116. onAutoFilter(patient) {
  117. if (patient) {
  118. this.hisPatientId = patient.hisPatientId;
  119. this.scrollRef.refresh();
  120. }
  121. },
  122. // 进入详情
  123. toDetail(e) {
  124. const {
  125. item: {
  126. type,
  127. outTradeNo,
  128. status,
  129. tradeNo,
  130. invoiceNo,
  131. hisPatientId,
  132. date,
  133. depName,
  134. amount,
  135. name,
  136. age,
  137. sex,
  138. prescribeDate,
  139. hisOrderNo,
  140. doctorName,
  141. doctorCode,
  142. total,
  143. hisClinicCode,
  144. deptName,
  145. orderItems,
  146. },
  147. } = e.target.dataset;
  148. history.push({
  149. title: "缴费详情",
  150. query: {
  151. type: type || 0,
  152. outTradeNo,
  153. status,
  154. tradeNo,
  155. invoiceNo,
  156. hisPatientId,
  157. date,
  158. depName,
  159. amount,
  160. name,
  161. age,
  162. sex,
  163. prescribeDate,
  164. hisOrderNo,
  165. doctorName,
  166. doctorCode,
  167. total,
  168. hisClinicCode,
  169. deptName,
  170. orderItems: encodeURIComponent(JSON.stringify(orderItems || "")),
  171. },
  172. pageType: "hospital-payment-detail",
  173. });
  174. },
  175. // 付款
  176. async onPayment(e) {
  177. const { medicareBinded = false, item } = e.target.dataset; // 同意订阅消息后发起支付
  178. try {
  179. my.showLoading();
  180. // 获取智能消息推送授权
  181. await getSubscribeAuth();
  182. // 挂号
  183. if (item.type === 1) {
  184. await tradePay(
  185. {
  186. type: item.type,
  187. idNum: item.outTradeNo,
  188. depName: item.depName,
  189. },
  190. {
  191. tradeType: "Appointment",
  192. }
  193. );
  194. } else if (item.type === 2) {
  195. // 充值
  196. await tradePay(
  197. {
  198. type: item.type,
  199. idNum: item.outTradeNo,
  200. amount: item.amount,
  201. },
  202. {
  203. tradeType: "Appointment",
  204. }
  205. );
  206. } else {
  207. // 门诊订单
  208. await tradePay(
  209. {
  210. useBalance: !medicareBinded,
  211. useMedicare: medicareBinded,
  212. outTradeNo: item.outTradeNo,
  213. ...item,
  214. },
  215. {
  216. tradeType: "Outpatient",
  217. }
  218. );
  219. }
  220. } catch (error) {
  221. } finally {
  222. my.hideLoading();
  223. }
  224. this.scrollRef.refresh();
  225. // 支付成功去订单详情页
  226. this.toDetail({
  227. target: {
  228. dataset: {
  229. outTradeNo: item.outTradeNo,
  230. type: item.type ? item.type : 0,
  231. ...item,
  232. },
  233. },
  234. }); // 发起消息订阅
  235. // this.subscribe.subscribeMessage();
  236. },
  237. },
  238. })
  239. );