rechargeMoney.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <view class="container">
  3. <userInfo
  4. :is-show-switch-patient="true"
  5. :is-show-balance="true"
  6. :is-show-recharge="false"
  7. @refresh-data="refreshData"
  8. ></userInfo>
  9. <view class="recharge-money">
  10. <view class="recharge-money-title">充值金额</view>
  11. <view class="recharge-money-input">
  12. <text class="recharge-money-symbol">¥</text>
  13. <input
  14. class="recharge-money-input-val"
  15. type="digit"
  16. placeholder="请输入充值金额"
  17. placeholder-class="placeholder-class"
  18. v-model="rechargeMoney"
  19. @input="bindKeyInput"
  20. />
  21. </view>
  22. <view class="recharge-money-list">
  23. <view
  24. class="recharge-money-item"
  25. :class="{ active: item === rechargeMoney }"
  26. v-for="(item, index) in moneyList"
  27. :key="index"
  28. @click="selectMoney(item)"
  29. >
  30. <text class="recharge-money-item-val">{{ item }}元</text>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="recharge-btn">
  35. <button class="btn" @click="jumpConfirmaPay">立即充值</button>
  36. </view>
  37. <view class="recharge-tips">
  38. <view class="recharge-tips-title">温馨提示</view>
  39. <view class="recharge-tips-content">
  40. <view class="recharge-tips-item">1. 充值金额将存入您的就诊卡账户中,可用于门诊缴费、住院缴费等。</view>
  41. <view class="recharge-tips-item">2. 请仔细核对充值金额,充值成功后无法撤销。</view>
  42. <view class="recharge-tips-item" v-if="frontPayLimit.MinPayMoney">3. 每次充值最低{{ frontPayLimit.MinPayMoney }}元。</view>
  43. <view class="recharge-tips-item" v-if="frontPayLimit.MaxPayMoney">4. 每次充值最高{{ frontPayLimit.MaxPayMoney }}元。</view>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. <script setup lang="ts">
  49. import { ref, computed } from 'vue';
  50. import { onShow, onLoad } from '@dcloudio/uni-app';
  51. import { useOnLoad } from '@/hook';
  52. import { queryFrontPayLimit } from '@/pagesPatient/service/recharge';
  53. import { queryCardBalance_V3, addOrderLocal } from '@/pagesPatient/service/pay';
  54. import { pagesPatientFn } from '@/utils';
  55. import { common } from '@/utils';
  56. import userInfo from '@/pagesPersonal/st1/components/userInfo/userInfo.vue';
  57. const rechargeMoney = ref('');
  58. const currentUser = ref<any>({});
  59. const pageType = ref('mzjf');
  60. const balance = ref(0);
  61. const frontPayLimit = ref<any>({});
  62. const moneyList = [100, 200, 500, 1000];
  63. useOnLoad((options: any) => {
  64. if (options.pageType) {
  65. pageType.value = options.pageType;
  66. }
  67. const app = getApp();
  68. if (app.globalData.defaultMember) {
  69. currentUser.value = app.globalData.defaultMember;
  70. }
  71. });
  72. onShow(async () => {
  73. await getFrontPayLimit();
  74. await getCardBalance();
  75. });
  76. const refreshData = (user: any) => {
  77. currentUser.value = user;
  78. getCardBalance();
  79. };
  80. const getFrontPayLimit = async () => {
  81. try {
  82. const res = await queryFrontPayLimit();
  83. if (res.Code === 10000 && res.Data) {
  84. frontPayLimit.value = res.Data;
  85. }
  86. } catch (e) {
  87. console.error(e);
  88. }
  89. };
  90. const getCardBalance = async () => {
  91. if (!currentUser.value || !currentUser.value.MemberId) return;
  92. try {
  93. const res = await queryCardBalance_V3({
  94. MemberId: currentUser.value.MemberId,
  95. CardType: currentUser.value.CardType,
  96. CardNo: currentUser.value.CardNo,
  97. });
  98. if (res.Code === 10000 && res.Data) {
  99. balance.value = res.Data.Balance;
  100. }
  101. } catch (e) {
  102. console.error(e);
  103. }
  104. };
  105. const bindKeyInput = (e: any) => {
  106. let val = e.detail.value;
  107. // Limit to 2 decimal places
  108. val = val.replace(/[^\d.]/g, "");
  109. val = val.replace(/\.{2,}/g, ".");
  110. val = val.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
  111. val = val.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
  112. if (val.indexOf(".") < 0 && val != "") {
  113. val = parseFloat(val);
  114. }
  115. rechargeMoney.value = val;
  116. };
  117. const selectMoney = (money: number) => {
  118. rechargeMoney.value = money.toString();
  119. };
  120. const jumpConfirmaPay = async () => {
  121. if (!rechargeMoney.value) {
  122. common.showToast('请输入充值金额');
  123. return;
  124. }
  125. if (parseFloat(rechargeMoney.value) <= 0) {
  126. common.showToast('充值金额必须大于0');
  127. return;
  128. }
  129. if (frontPayLimit.value.MinPayMoney && parseFloat(rechargeMoney.value) < frontPayLimit.value.MinPayMoney) {
  130. common.showToast(`充值金额不能小于${frontPayLimit.value.MinPayMoney}元`);
  131. return;
  132. }
  133. if (frontPayLimit.value.MaxPayMoney && parseFloat(rechargeMoney.value) > frontPayLimit.value.MaxPayMoney) {
  134. common.showToast(`充值金额不能大于${frontPayLimit.value.MaxPayMoney}元`);
  135. return;
  136. }
  137. // Check pending orders
  138. let serviceId = pageType.value == 'mzjf' ? '006' : pageType.value == 'zyjf' ? '007' : '';
  139. if (await pagesPatientFn.hasOrderToBePaid(serviceId)) return;
  140. const app = getApp();
  141. // Construct order data
  142. let data = {
  143. PayMoney: rechargeMoney.value,
  144. MemberId: currentUser.value.MemberId,
  145. CardType: currentUser.value.CardType,
  146. CardNo: currentUser.value.CardNo,
  147. MemberName: currentUser.value.MemberName,
  148. ServiceId: serviceId,
  149. PayType: '2', // WeChat Pay
  150. };
  151. try {
  152. common.showLoading();
  153. const res = await addOrderLocal(data);
  154. common.hideLoading();
  155. if (res.Code === 10000 && res.Data) {
  156. // Navigate to payment page
  157. // Assuming rechargePay is the next page.
  158. // Need to check where to go. rechargeMoney.js says:
  159. // wx.navigateTo({ url: '../rechargePay/rechargePay?orderId=' + res.Data.OrderId + '&payMoney=' + this.data.rechargeMoney + '&pageType=' + this.data.pageType });
  160. // Or rechargePayZy if pageType is zyjf.
  161. let url = '';
  162. if (pageType.value === 'mzjf') {
  163. url = `../rechargePay/rechargePay?orderId=${res.Data.OrderId}&payMoney=${rechargeMoney.value}&pageType=${pageType.value}`;
  164. } else {
  165. // Assuming rechargePayZy exists or logic is similar
  166. // rechargeMoney.js:
  167. // if (this.data.pageType == 'mzjf') url = '../rechargePay/rechargePay?orderId=' + res.Data.OrderId ...
  168. // else url = '../rechargePayZy/rechargePayZy?orderId=' + res.Data.OrderId ...
  169. url = `../rechargePayZy/rechargePayZy?orderId=${res.Data.OrderId}&payMoney=${rechargeMoney.value}&pageType=${pageType.value}`;
  170. }
  171. common.goToUrl(url);
  172. } else {
  173. common.showToast(res.Message || '创建订单失败');
  174. }
  175. } catch (e) {
  176. common.hideLoading();
  177. common.showToast('网络异常,请稍后重试');
  178. }
  179. };
  180. </script>
  181. <style lang="scss" scoped>
  182. .container {
  183. min-height: 100vh;
  184. background-color: #f5f5f5;
  185. padding-bottom: 40upx;
  186. }
  187. .recharge-money {
  188. background-color: #fff;
  189. margin-top: 20upx;
  190. padding: 30upx;
  191. &-title {
  192. font-size: 32upx;
  193. font-weight: bold;
  194. color: #333;
  195. margin-bottom: 30upx;
  196. }
  197. &-input {
  198. display: flex;
  199. align-items: center;
  200. border-bottom: 1upx solid #eee;
  201. padding-bottom: 20upx;
  202. margin-bottom: 30upx;
  203. &-val {
  204. flex: 1;
  205. font-size: 60upx;
  206. height: 80upx;
  207. margin-left: 10upx;
  208. }
  209. }
  210. &-symbol {
  211. font-size: 40upx;
  212. color: #333;
  213. font-weight: bold;
  214. }
  215. &-list {
  216. display: flex;
  217. flex-wrap: wrap;
  218. justify-content: space-between;
  219. }
  220. &-item {
  221. width: 48%;
  222. height: 100upx;
  223. display: flex;
  224. align-items: center;
  225. justify-content: center;
  226. border: 1upx solid #ddd;
  227. border-radius: 8upx;
  228. margin-bottom: 20upx;
  229. color: #333;
  230. font-size: 32upx;
  231. &.active {
  232. border-color: #007aff;
  233. color: #007aff;
  234. background-color: rgba(0, 122, 255, 0.1);
  235. }
  236. }
  237. }
  238. .recharge-btn {
  239. margin: 60upx 30upx;
  240. .btn {
  241. width: 100%;
  242. height: 90upx;
  243. line-height: 90upx;
  244. background-color: #007aff;
  245. color: #fff;
  246. font-size: 32upx;
  247. border-radius: 45upx;
  248. &:active {
  249. opacity: 0.8;
  250. }
  251. }
  252. }
  253. .recharge-tips {
  254. padding: 0 30upx;
  255. &-title {
  256. font-size: 28upx;
  257. color: #666;
  258. margin-bottom: 20upx;
  259. }
  260. &-item {
  261. font-size: 24upx;
  262. color: #999;
  263. line-height: 1.5;
  264. margin-bottom: 10upx;
  265. }
  266. }
  267. .placeholder-class {
  268. font-size: 32upx;
  269. color: #ccc;
  270. }
  271. </style>