index.js 7.4 KB

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