index.js 4.8 KB

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