index.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. import {
  2. settradePayRe,
  3. getDischargeSettlementDetails,
  4. getsubscribeID,
  5. } from "./service";
  6. import history from "../../utils/history";
  7. import { debounce } from "../../utils/index";
  8. import { reportCmPV_YL } from "../../utils/cloudMonitorHelper";
  9. import { tradeResult } from "../../service/common";
  10. Component({
  11. data: {
  12. jsonData: {
  13. Inpatient: {},
  14. },
  15. moneyArray: ["¥100", "¥200", "¥300", "¥500", "¥1000", "¥2000"],
  16. selectedMoney: null,
  17. money: null,
  18. inpatientId: "",
  19. // 住院人的id
  20. selectIndex: 0,
  21. // 默认选择的住院人的index
  22. isReady: false,
  23. attention: "",
  24. },
  25. didMount() {
  26. const { inpatientId, attention } = this.$page.data.query || {};
  27. this.setData({
  28. inpatientId,
  29. attention,
  30. });
  31. // this.subscribeMsg();
  32. /* 服务预警,押金缴纳 */
  33. reportCmPV_YL({
  34. title: "住院缴费",
  35. });
  36. },
  37. methods: {
  38. subscribeMsg() {
  39. const pluginId = 2021001155639035;
  40. my.loadPlugin({
  41. plugin: `${pluginId}@*`,
  42. success: () => {
  43. this.setData({
  44. isReady: true,
  45. }); // 储存插件实列
  46. // eslint-disable-next-line no-undef
  47. const pluginInstance = requirePlugin(`dynamic-plugin://${pluginId}`);
  48. this.requestSubscribeMessage = pluginInstance.requestSubscribeMessage;
  49. },
  50. });
  51. },
  52. pageScrollToFn(scrollTop) {
  53. my.pageScrollTo({
  54. scrollTop,
  55. });
  56. },
  57. // 当input框失焦时候,自动返回顶部
  58. onBlurChange() {
  59. this.pageScrollToFn(0);
  60. },
  61. // 由于唤起支付弹窗时候,会遮挡掉支付按钮,所以对页面做了自动滚动处理
  62. onFocusChange() {
  63. setTimeout(() => {
  64. this.pageScrollToFn(100);
  65. }, 100);
  66. },
  67. async getJsonData(info) {
  68. const { inpatientId } = this.data;
  69. try {
  70. // 分为两种情况,第一种当从住院人列表跳转过来的时候,有住院人id,第二种是从首页跳转过来,无住院人id
  71. if (!inpatientId) {
  72. const infoDetail = info && info.length > 0;
  73. this.setData({
  74. jsonData: {
  75. Inpatient: infoDetail ? info[0] : {},
  76. },
  77. inpatientId: infoDetail ? info[0].inpatientId : "",
  78. });
  79. } else {
  80. const res = await getDischargeSettlementDetails({
  81. inpatientId,
  82. });
  83. this.choosePatient(res);
  84. }
  85. } catch (error) {
  86. console.log(error, "error");
  87. }
  88. },
  89. onGetDatas(info) {
  90. if (!info || info.length === 0) {
  91. return false;
  92. } else {
  93. my.hideToast();
  94. }
  95. this.getJsonData(info);
  96. },
  97. // 跳转到绑定就诊人管理
  98. addPatientNew() {
  99. my.navigateTo({
  100. url: "/antbuilder/industry/hospitalV2/pages/page-no-pull/index?header=show&pageType=edit-patient&title=添加就诊人",
  101. });
  102. },
  103. selectMoney(event) {
  104. this.setData(
  105. {
  106. selectedMoney: event.target.dataset.index,
  107. money: parseInt(
  108. this.data.moneyArray[event.target.dataset.index].replace("¥", "")
  109. ),
  110. },
  111. () => {
  112. this.payMoney();
  113. }
  114. );
  115. },
  116. changeMoney: debounce((event, that) => {
  117. let { value: money } = event.detail;
  118. const defaultValue = money === "";
  119. const diff = money.indexOf(".") !== -1;
  120. money = money.replace(/\s*/g, "");
  121. if (diff) {
  122. const diffLength = money.indexOf(".");
  123. if (money.slice(diffLength).length > 3) {
  124. return;
  125. }
  126. if (money.length > diffLength + 1 && money[money.length - 1] !== "0") {
  127. money = Number(money);
  128. } else if (money[money.length - 1] != 0) {
  129. money = `${Number(money)}.`;
  130. }
  131. } else {
  132. money = Number(money);
  133. }
  134. that.setData({
  135. money: defaultValue ? "" : money,
  136. });
  137. }, 100),
  138. popOverClose() {
  139. // 关闭弹出框
  140. this.$page.$popModal.hidePopover();
  141. },
  142. /**
  143. * 选择住院人
  144. */
  145. choosePatient(info) {
  146. const { hospitalizationRecordList } = this.$page.$popModal.data;
  147. const selectIndex = hospitalizationRecordList.findIndex(
  148. (item) => info.inpatientId === item.inpatientId
  149. ); // 获取用户id
  150. this.setData({
  151. jsonData: {
  152. Inpatient: info,
  153. },
  154. inpatientId: info.inpatientId,
  155. selectIndex,
  156. });
  157. this.$page.$popModal.hidePopover();
  158. },
  159. /**
  160. * 增加住院人
  161. */
  162. addPatient() {
  163. history.push({
  164. title: "添加住院人",
  165. pageType: "add-inpatient-information",
  166. query: {
  167. color: "#000",
  168. backBtnColor: "#000",
  169. background: "#fff",
  170. },
  171. });
  172. this.$page.$popModal.hidePopover();
  173. },
  174. onAdmissionRegistration() {
  175. this.$page.$popModal.showPopover({
  176. title: "选择住院人",
  177. popupPosition: "bottom",
  178. onButtonClose: () => this.popOverClose(),
  179. // 弹出框关闭
  180. onChoosePatient: (info) => this.choosePatient(info),
  181. // 选择就诊人
  182. onAddPatient: () => this.addPatient(), // 添加就诊人
  183. });
  184. },
  185. // 订阅插件要用时,请放开注释
  186. requestSubscribeMessageFn(subscribeID) {
  187. const that = this;
  188. return new Promise((resolve) => {
  189. my.requestSubscribeMessage({
  190. // 模板id列表,最多3个
  191. entityIds: [subscribeID],
  192. complete() {
  193. that.setTrade();
  194. resolve(true);
  195. },
  196. });
  197. });
  198. },
  199. // 支付前先要订阅
  200. async payMoney() {
  201. try {
  202. // const subscribeID = await getsubscribeID();
  203. // await this.requestSubscribeMessageFn(subscribeID.depositTemplateId);
  204. this.setTrade();
  205. } catch (error) {
  206. console.log(error, "error");
  207. }
  208. },
  209. // 支付弹窗
  210. async setTrade() {
  211. const { money, inpatientId, jsonData } = this.data;
  212. try {
  213. if (money) {
  214. my.showLoading();
  215. const {
  216. tradeNo: tradeNO,
  217. outTradeNo,
  218. depositId,
  219. } = await settradePayRe({
  220. amount: money,
  221. inpatientId,
  222. admNo: jsonData.Inpatient.admNo || "",
  223. });
  224. my.tradePay({
  225. tradeNO,
  226. success: async (res) => {
  227. // 4000 订单处理失败
  228. // 6001 用途中途取消支付
  229. // 6002 网络链接出错
  230. if (
  231. res.resultCode === "4000" ||
  232. res.resultCode === "6002" ||
  233. res.resultCode === "6001"
  234. ) {
  235. // 支付失败
  236. my.showToast({
  237. type: "fail",
  238. content: res.memo || "订单支付失败",
  239. });
  240. } else {
  241. // 其他情况调用接口确认
  242. const payRes = await tradeResult({
  243. tradeNo: tradeNO,
  244. outTradeNo,
  245. resultCode: res.resultCode,
  246. });
  247. if (payRes.status === "TRADE_SUCCESS") {
  248. // history.push({
  249. // query: {
  250. // depositId,
  251. // color: "#000",
  252. // backBtnColor: "#000",
  253. // background: "#fff",
  254. // inpatientId,
  255. // hisPatientId: inpatientId,
  256. // },
  257. // title: "押金缴纳详情",
  258. // pageType: "pay-result",
  259. // });
  260. // 因为押金缴纳完成后,不能获取到收据No,所以需要跳转到押金缴纳记录
  261. history.push({
  262. query: {
  263. inpatientId,
  264. color: "#000",
  265. backBtnColor: "#000",
  266. background: "#fff",
  267. },
  268. title: "押金缴纳记录",
  269. pageType: "deposit-list",
  270. });
  271. } else {
  272. my.showToast({
  273. type: "fail",
  274. content: res.memo || "订单支付失败",
  275. });
  276. }
  277. }
  278. },
  279. });
  280. }
  281. } catch (error) {
  282. console.log(error, "error");
  283. } finally {
  284. my.hideLoading();
  285. }
  286. },
  287. },
  288. });