index.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. my.showToast({
  92. content: this.data.attention || "请绑定住院人",
  93. duration: 1500,
  94. });
  95. return false;
  96. } else {
  97. my.hideToast();
  98. }
  99. this.getJsonData(info);
  100. },
  101. selectMoney(event) {
  102. this.setData(
  103. {
  104. selectedMoney: event.target.dataset.index,
  105. money: parseInt(
  106. this.data.moneyArray[event.target.dataset.index].replace("¥", "")
  107. ),
  108. },
  109. () => {
  110. this.payMoney();
  111. }
  112. );
  113. },
  114. changeMoney: debounce((event, that) => {
  115. let { value: money } = event.detail;
  116. const defaultValue = money === "";
  117. const diff = money.indexOf(".") !== -1;
  118. money = money.replace(/\s*/g, "");
  119. if (diff) {
  120. const diffLength = money.indexOf(".");
  121. if (money.slice(diffLength).length > 3) {
  122. return;
  123. }
  124. if (money.length > diffLength + 1 && money[money.length - 1] !== "0") {
  125. money = Number(money);
  126. } else if (money[money.length - 1] != 0) {
  127. money = `${Number(money)}.`;
  128. }
  129. } else {
  130. money = Number(money);
  131. }
  132. that.setData({
  133. money: defaultValue ? "" : money,
  134. });
  135. }, 100),
  136. popOverClose() {
  137. // 关闭弹出框
  138. this.$page.$popModal.hidePopover();
  139. },
  140. /**
  141. * 选择住院人
  142. */
  143. choosePatient(info) {
  144. const { hospitalizationRecordList } = this.$page.$popModal.data;
  145. const selectIndex = hospitalizationRecordList.findIndex(
  146. (item) => info.inpatientId === item.inpatientId
  147. ); // 获取用户id
  148. this.setData({
  149. jsonData: {
  150. Inpatient: info,
  151. },
  152. inpatientId: info.inpatientId,
  153. selectIndex,
  154. });
  155. this.$page.$popModal.hidePopover();
  156. },
  157. /**
  158. * 增加住院人
  159. */
  160. addPatient() {
  161. history.push({
  162. title: "添加住院人",
  163. pageType: "add-inpatient-information",
  164. query: {
  165. color: "#000",
  166. backBtnColor: "#000",
  167. background: "#fff",
  168. },
  169. });
  170. this.$page.$popModal.hidePopover();
  171. },
  172. onAdmissionRegistration() {
  173. this.$page.$popModal.showPopover({
  174. title: "选择住院人",
  175. popupPosition: "bottom",
  176. onButtonClose: () => this.popOverClose(),
  177. // 弹出框关闭
  178. onChoosePatient: (info) => this.choosePatient(info),
  179. // 选择就诊人
  180. onAddPatient: () => this.addPatient(), // 添加就诊人
  181. });
  182. },
  183. // 订阅插件要用时,请放开注释
  184. requestSubscribeMessageFn(subscribeID) {
  185. const that = this;
  186. return new Promise((resolve) => {
  187. my.requestSubscribeMessage({
  188. // 模板id列表,最多3个
  189. entityIds: [subscribeID],
  190. complete() {
  191. that.setTrade();
  192. resolve(true);
  193. },
  194. });
  195. });
  196. },
  197. // 支付前先要订阅
  198. async payMoney() {
  199. try {
  200. // const subscribeID = await getsubscribeID();
  201. // await this.requestSubscribeMessageFn(subscribeID.depositTemplateId);
  202. this.setTrade();
  203. } catch (error) {
  204. console.log(error, "error");
  205. }
  206. },
  207. // 支付弹窗
  208. async setTrade() {
  209. const { money, inpatientId, jsonData } = this.data;
  210. try {
  211. if (money) {
  212. my.showLoading();
  213. const {
  214. tradeNo: tradeNO,
  215. outTradeNo,
  216. depositId,
  217. } = await settradePayRe({
  218. amount: money,
  219. inpatientId,
  220. admNo: jsonData.Inpatient.admNo || "",
  221. });
  222. my.tradePay({
  223. tradeNO,
  224. success: async (res) => {
  225. // 4000 订单处理失败
  226. // 6001 用途中途取消支付
  227. // 6002 网络链接出错
  228. if (
  229. res.resultCode === "4000" ||
  230. res.resultCode === "6002" ||
  231. res.resultCode === "6001"
  232. ) {
  233. // 支付失败
  234. my.showToast({
  235. type: "fail",
  236. content: res.memo || "订单支付失败",
  237. });
  238. } else {
  239. // 其他情况调用接口确认
  240. const payRes = await tradeResult({
  241. tradeNo: tradeNO,
  242. outTradeNo,
  243. resultCode: res.resultCode,
  244. });
  245. if (payRes.status === "TRADE_SUCCESS") {
  246. // history.push({
  247. // query: {
  248. // depositId,
  249. // color: "#000",
  250. // backBtnColor: "#000",
  251. // background: "#fff",
  252. // inpatientId,
  253. // hisPatientId: inpatientId,
  254. // },
  255. // title: "押金缴纳详情",
  256. // pageType: "pay-result",
  257. // });
  258. // 因为押金缴纳完成后,不能获取到收据No,所以需要跳转到押金缴纳记录
  259. history.push({
  260. query: {
  261. inpatientId,
  262. color: "#000",
  263. backBtnColor: "#000",
  264. background: "#fff",
  265. },
  266. title: "押金缴纳记录",
  267. pageType: "deposit-list",
  268. });
  269. } else {
  270. my.showToast({
  271. type: "fail",
  272. content: res.memo || "订单支付失败",
  273. });
  274. }
  275. }
  276. },
  277. });
  278. }
  279. } catch (error) {
  280. console.log(error, "error");
  281. } finally {
  282. my.hideLoading();
  283. }
  284. },
  285. },
  286. });