index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. import { getPriceDetails, settlementAuth, settlementExecute, configInfo } from './service';
  2. import history from '../../utils/history';
  3. import { tradeResult } from '../../service/common'; // js策略设计模式
  4. const setObjectMap = {
  5. // 统一处理格式
  6. doexist(label, value, index) {
  7. return {
  8. label,
  9. value,
  10. index
  11. };
  12. },
  13. // 已缴押金格式处理
  14. depositTotalAmount(detail) {
  15. return this.doexist('已缴押金', `¥${detail}`, 0);
  16. },
  17. // 费用支出格式处理
  18. spendTotalAmount(detail) {
  19. return this.doexist('费用实际支出', `-¥${detail}`, 1);
  20. },
  21. // 应补缴金额格式处理
  22. repayAmount(detail) {
  23. return this.doexist('应补缴金额', `¥${detail}`, 2);
  24. },
  25. // 押金余额格式处理
  26. depositBalance(detail) {
  27. return this.doexist('押金余额', `¥${detail}`, 2);
  28. },
  29. // 医保报销格式处理
  30. reimbursableAmount(detail) {
  31. return this.doexist('医保报销', `¥${detail}`, 3);
  32. }
  33. };
  34. Component({
  35. data: {
  36. details: null,
  37. inpatientId: '',
  38. // 住院id
  39. medicareAble: '',
  40. // 是否是医保结算
  41. repay: false,
  42. // 是否唤起支付弹窗
  43. buttons: [{
  44. text: '取消'
  45. }, {
  46. text: '去结算',
  47. extClass: 'buttonBold'
  48. }],
  49. // 弹窗按钮配置
  50. showModal: false,
  51. completed: false,
  52. logo: 'https://gw.alipayobjects.com/mdn/rms_8ed4a1/afts/img/A*SctSR5ZZwrcAAAAAAAAAAAAAARQnAQ'
  53. },
  54. didMount() {
  55. // 获取参数住院IDhospitalDistrictId
  56. const optionsValue = JSON.parse(JSON.stringify(this.$page.data.query));
  57. const {
  58. inpatientId,
  59. hospitalDistrictId
  60. } = optionsValue;
  61. this.setData({
  62. inpatientId
  63. }, async () => {
  64. // 获取住院人结算详情
  65. this.getDeails(); // 院区配置信息 [新增]
  66. const detailInfos = await configInfo({
  67. hospitalDistrictId
  68. });
  69. this.setData({
  70. detailInfos: detailInfos.configInfo
  71. });
  72. });
  73. this.initAnimation();
  74. },
  75. methods: {
  76. initAnimation() {
  77. const animation = my.createAnimation({
  78. duration: 10000,
  79. timingFunction: 'linear' // 匀速
  80. });
  81. animation.translateX(parseInt(-400)).step();
  82. this.setData({
  83. animationData: animation.export(),
  84. // 此处为动画
  85. animation // 此处为方法
  86. });
  87. setTimeout(() => {
  88. this.animationend();
  89. }, 10500);
  90. },
  91. animationend() {
  92. const animation = my.createAnimation({
  93. duration: 0,
  94. timingFunction: 'linear'
  95. });
  96. animation.translateX(0).step();
  97. this.setData({
  98. animationData: animation.export()
  99. });
  100. setTimeout(() => {
  101. this.initAnimation();
  102. }, 200);
  103. },
  104. async getDeails() {
  105. const {
  106. inpatientId
  107. } = this.data;
  108. const authCode = await this.getAuthCodeFn();
  109. try {
  110. const details = await getPriceDetails({
  111. inpatientId,
  112. authCode
  113. });
  114. let priceArrs = [];
  115. if (details) {
  116. Object.keys(details).forEach(item => {
  117. if (item === 'refundAmount' && Number(details[item]) !== 0 || item === 'repayAmount' && Number(details[item]) !== 0) {
  118. if (item === 'repayAmount') {
  119. // repayAmount应补缴金额需要唤起支付功能.refundAmount应退款金额
  120. this.setData({
  121. repay: true
  122. });
  123. } else {
  124. this.setData({
  125. repay: false
  126. });
  127. }
  128. details.headerTitle = {
  129. label: item === 'refundAmount' ? '应退金额' : '应补缴金额',
  130. value: `${details[item]}`
  131. };
  132. }
  133. if (Number(details[item]) === 0) {
  134. Reflect.deleteProperty(details, item);
  135. } else if (setObjectMap[item]) {
  136. priceArrs.push(setObjectMap[item](details[item]));
  137. Reflect.deleteProperty(details, item);
  138. }
  139. });
  140. priceArrs = priceArrs.sort((a, b) => a.index - b.index);
  141. details.priceArrs = priceArrs;
  142. this.setData({
  143. details,
  144. medicareAble: !!details.medicareAble,
  145. completed: true
  146. });
  147. }
  148. } catch (error) {
  149. console.log(error, 'error');
  150. }
  151. },
  152. getAuthCodeFn() {
  153. return new Promise(resolve => {
  154. my.getAuthCode({
  155. scopes: 'auth_user',
  156. success: res => {
  157. resolve(res.authCode);
  158. }
  159. });
  160. });
  161. },
  162. navigateToAlipayPageFn(path) {
  163. return new Promise(resolve => {
  164. // 跳转H5页面
  165. my.ap.navigateToAlipayPage({
  166. path,
  167. success: () => {
  168. resolve(true);
  169. },
  170. fail: () => {
  171. resolve(false);
  172. }
  173. });
  174. });
  175. },
  176. async onModalClick(e) {
  177. const {
  178. inpatientId
  179. } = this.data;
  180. const {
  181. index
  182. } = e.currentTarget.dataset;
  183. if (index === 1) {
  184. // 结算成功跳转结算成功页面
  185. // 跳转类型 notSupportMedicalRefund - 不支持医保,预结算-退款
  186. const settlementType = 'notSupportMedicalRefund';
  187. history.push({
  188. query: {
  189. settlementType,
  190. inpatientId
  191. },
  192. title: '出院结算',
  193. pageType: 'discharge-settlement'
  194. }); // my.navigateTo({
  195. // url: `/pages/discharge-settlement/index?settlementType=notSupportMedicalRefund&inpatientId=${inpatientId}`
  196. // });
  197. }
  198. this.setData({
  199. showModal: false
  200. });
  201. },
  202. showToast(msg, type = 'success') {
  203. my.showToast({
  204. type,
  205. content: msg,
  206. duration: 1500
  207. });
  208. },
  209. async goSettlement() {
  210. const {
  211. inpatientId,
  212. medicareAble,
  213. repay
  214. } = this.data; // @ts-ignore
  215. // const { appId: parentAppId } = my.getParentAppIdSync();
  216. // @ts-ignore
  217. const {
  218. appId
  219. } = my.getAppIdSync();
  220. try {
  221. const authCode = await this.getAuthCodeFn();
  222. const callUrl = `alipays://platformapi/startapp?appId=${appId}&page=/pages/discharge-settlement-detail/index?medicareAble=${medicareAble}&inpatientId=${inpatientId}&repay=${repay}`;
  223. if (medicareAble) {
  224. // 支持医保结算
  225. const details = await settlementAuth({
  226. authCode,
  227. callUrl
  228. });
  229. if (details.needAuth) {
  230. // 医保支付需要授权
  231. this.navigateToAlipayPageFn(details.authUrl); // 判断授权成功进入预结算页面callUrl
  232. } else {
  233. // 不需要授权跳转预结算页面
  234. history.push({
  235. query: {
  236. settlementType: 'supportMedicalPreSettlement',
  237. inpatientId,
  238. payAuthNo: details.payAuthNo,
  239. // 医保支付授权编码
  240. medicareAble,
  241. repay,
  242. color: '#000',
  243. backBtnColor: '#000',
  244. background: '#fff'
  245. },
  246. title: '出院结算',
  247. pageType: 'pre-settlement'
  248. });
  249. }
  250. } else if (repay) {
  251. // 不支持支持医保补缴直接需唤起支付功能 支付成功跳转详情
  252. const detail = await settlementExecute({
  253. inpatientId,
  254. useMedicare: medicareAble
  255. });
  256. if (detail.tradeNo) {
  257. // 需要自费补缴时tradeNo
  258. my.tradePay({
  259. tradeNO: detail.tradeNo,
  260. success: async res => {
  261. // // 支付成功跳转结算成功页面
  262. // if (res.resultCode === '9000') {
  263. // // 跳转类型 notSupportMedicalSupplementary - 不支持医保,预结算-自费补缴
  264. // const settlementType = 'notSupportMedicalSupplementary';
  265. // history.push({
  266. // query: {
  267. // settlementType,
  268. // inpatientId,
  269. // color: '#000',
  270. // backBtnColor: '#000',
  271. // background: '#fff',
  272. // },
  273. // title: '出院结算',
  274. // pageType: 'discharge-settlement',
  275. // });
  276. // }
  277. // 4000 订单处理失败
  278. // 6001 用途中途取消支付
  279. // 6002 网络链接出错
  280. if (res.resultCode === '4000' || res.resultCode === '6002' || res.resultCode === '6001') {
  281. // 支付失败
  282. my.showToast({
  283. type: 'fail',
  284. content: res.memo || '订单支付失败'
  285. });
  286. } else {
  287. // 其他情况调用接口确认
  288. const payRes = await tradeResult({
  289. tradeNo: detail.tradeNo,
  290. resultCode: res.resultCode
  291. });
  292. if (payRes.status === 'TRADE_SUCCESS') {
  293. // 跳转类型 notSupportMedicalSupplementary - 不支持医保,预结算-自费补缴
  294. const settlementType = 'notSupportMedicalSupplementary';
  295. history.push({
  296. query: {
  297. settlementType,
  298. inpatientId,
  299. color: '#000',
  300. backBtnColor: '#000',
  301. background: '#fff'
  302. },
  303. title: '出院结算',
  304. pageType: 'discharge-settlement'
  305. });
  306. } else {
  307. my.showToast({
  308. type: 'fail',
  309. content: res.memo || '订单支付失败'
  310. });
  311. }
  312. }
  313. }
  314. });
  315. }
  316. } else {
  317. // 不支持支持医保且退款需二次提醒
  318. this.setData({
  319. showModal: true
  320. });
  321. }
  322. } catch (error) {
  323. console.log(error, 'error');
  324. }
  325. }
  326. }
  327. });