index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import { tradePay } from '../../utils/tradePay';
  2. import history from '../../utils/history';
  3. import { reportCmPV_YL } from '../../utils/cloudMonitorHelper';
  4. Component({
  5. props: {},
  6. data: {
  7. modalOpened: false,
  8. buttons: [{
  9. text: '不,先留着'
  10. }, {
  11. text: '取消预约',
  12. extClass: 'buttonBold'
  13. }],
  14. clinicCard: {
  15. balance: 0,
  16. cardNum: ''
  17. },
  18. // 就诊卡
  19. cardList: [],
  20. amountItem: [100, 200, 300, 500, 1000, 2000],
  21. amountItemChecked: -1,
  22. amount: '',
  23. loading: false,
  24. patientId: '',
  25. defaultCardNum: '',
  26. patientName: ''
  27. },
  28. didMount() {
  29. const {
  30. query
  31. } = this.$page.data;
  32. const {
  33. id,
  34. cardNum
  35. } = query || {};
  36. this.setData({
  37. patientId: id,
  38. defaultCardNum: cardNum
  39. });
  40. /* 服务预警,门诊充值 */
  41. reportCmPV_YL({
  42. title: '门诊充值'
  43. });
  44. },
  45. methods: {
  46. // 切换就诊人
  47. onChange(item) {
  48. const patientName = item.name;
  49. const cardList = item.medicCards;
  50. const clinicCard = cardList.find(m => {
  51. if (item.id === this.data.patientId) {
  52. return m.cardNum === this.data.defaultCardNum;
  53. }
  54. return m.cardNum === item.bindCardNum;
  55. }) || cardList[0] || {};
  56. this.setData({
  57. clinicCard,
  58. cardList,
  59. patientName
  60. });
  61. },
  62. // 修改充值金额
  63. changeAmount(e) {
  64. this.setData({
  65. amountItemChecked: e.target.dataset.idx,
  66. amount: e.target.dataset.val
  67. });
  68. },
  69. bindKeyInput(e) {
  70. let amount = e.detail.value;
  71. const idx = amount.indexOf('.');
  72. const second = amount.indexOf('.', idx + 1);
  73. if (idx === 0) {
  74. amount = `0${amount}`;
  75. } else if (idx > 0) {
  76. amount = amount.slice(0, idx + 3);
  77. }
  78. if (second > 1) {
  79. amount = amount.slice(0, second);
  80. }
  81. this.setData({
  82. amountItemChecked: -1,
  83. amount
  84. });
  85. },
  86. // 发起付款
  87. onRecharge() {
  88. this.setData({
  89. loading: true
  90. });
  91. const {
  92. amount,
  93. clinicCard,
  94. patientName
  95. } = this.data;
  96. tradePay({
  97. type: 2,
  98. amount,
  99. idNum: clinicCard.cardNum
  100. }, {
  101. tradeType: 'Appointment'
  102. }).then(() => {
  103. history.push({
  104. pageType: 'payment-success',
  105. title: '充值成功',
  106. componentData: {
  107. result: [{
  108. name: '就诊人',
  109. value: patientName
  110. }, {
  111. name: '就诊卡号',
  112. value: clinicCard.cardNum
  113. }, {
  114. name: '充值金额',
  115. value: amount
  116. }]
  117. }
  118. });
  119. }).finally(() => {
  120. this.setData({
  121. loading: false
  122. });
  123. });
  124. },
  125. // 切换就诊卡
  126. changePatient() {
  127. this.setData({
  128. modalOpened: true
  129. });
  130. },
  131. onClose() {
  132. this.setData({
  133. modalOpened: false
  134. });
  135. },
  136. chooseCard(e) {
  137. this.setData({
  138. clinicCard: e
  139. });
  140. }
  141. }
  142. });