index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. },
  134. } = e.target.dataset;
  135. history.push({
  136. title: "缴费详情",
  137. query: {
  138. type: type || 0,
  139. outTradeNo,
  140. status,
  141. tradeNo,
  142. invoiceNo,
  143. hisPatientId,
  144. date,
  145. depName,
  146. amount,
  147. name,
  148. age,
  149. sex,
  150. prescribeDate,
  151. hisOrderNo,
  152. doctorName,
  153. doctorCode,
  154. total,
  155. hisClinicCode,
  156. deptName,
  157. },
  158. pageType: "hospital-payment-detail",
  159. });
  160. },
  161. // 付款
  162. async onPayment(e) {
  163. const { medicareBinded = false, item } = e.target.dataset; // 同意订阅消息后发起支付
  164. try {
  165. my.showLoading();
  166. // 获取智能消息推送授权
  167. await getSubscribeAuth();
  168. // 挂号
  169. if (item.type === 1) {
  170. await tradePay(
  171. {
  172. type: item.type,
  173. idNum: item.outTradeNo,
  174. depName: item.depName,
  175. },
  176. {
  177. tradeType: "Appointment",
  178. }
  179. );
  180. } else if (item.type === 2) {
  181. // 充值
  182. await tradePay(
  183. {
  184. type: item.type,
  185. idNum: item.outTradeNo,
  186. amount: item.amount,
  187. },
  188. {
  189. tradeType: "Appointment",
  190. }
  191. );
  192. } else {
  193. // 门诊订单
  194. await tradePay(
  195. {
  196. useBalance: !medicareBinded,
  197. useMedicare: medicareBinded,
  198. outTradeNo: item.outTradeNo,
  199. ...item,
  200. },
  201. {
  202. tradeType: "Outpatient",
  203. }
  204. );
  205. }
  206. } catch (error) {
  207. } finally {
  208. my.hideLoading();
  209. }
  210. // 支付成功去订单详情页
  211. this.toDetail({
  212. target: {
  213. dataset: {
  214. outTradeNo: item.outTradeNo,
  215. type: item.type ? item.type : 0,
  216. ...item,
  217. },
  218. },
  219. }); // 发起消息订阅
  220. // this.subscribe.subscribeMessage();
  221. },
  222. },
  223. });