recharge.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <Theme>
  3. <view class="wrap">
  4. <Navbar fixed border title="充值">
  5. <template #right>
  6. <navMenu :options="{ icon: 'icon-home', text: '主页' }" />
  7. <view class="nav_right" @click.stop="handleTo">
  8. <trans _t="记录" />
  9. </view>
  10. </template>
  11. </Navbar>
  12. <view class="content">
  13. <view>
  14. <view class="recharge_top">
  15. <view class="label">
  16. <trans _t="余额" />
  17. </view>
  18. <view class="value"
  19. >{{ symbol.symbol }} <text>{{ Moneyhtml(userInfo.money) }}</text>
  20. </view>
  21. </view>
  22. <view class="recharge_money">
  23. <view class="money">
  24. <view class="label">
  25. <trans _t="充值金额" />
  26. </view>
  27. <view class="value">
  28. <text class="currency">{{ symbol.symbol }}</text>
  29. <Input
  30. shape="square"
  31. v-model="money"
  32. :placeholder="t('请输入金额')"
  33. />
  34. </view>
  35. </view>
  36. <view class="money_list">
  37. <view
  38. class="_list"
  39. :class="money == item ? 'active' : ''"
  40. v-for="(item, index) in moneyList"
  41. :key="index"
  42. @click="listActive(item)"
  43. >
  44. <text>{{ symbol.symbol }} </text>{{ item }}
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. <!-- <view class="bank_list">
  50. <view class="label">
  51. <trans _t="选择充值方式" />
  52. </view>
  53. <view class="value">
  54. <view
  55. class="_list_"
  56. v-for="(item, index) in bankList"
  57. :key="index"
  58. @click="paySubmit(item)"
  59. >
  60. <view class="_list_left">
  61. <view class="bank_title">{{ item.title }}</view>
  62. <view class="desc">{{ item.desc }}</view>
  63. </view>
  64. <i class="icon-font icon-left"></i>
  65. </view>
  66. </view>
  67. </view> -->
  68. <view class="footer" @click="paySubmit">
  69. <trans _t="充值" />
  70. </view>
  71. </view>
  72. </view>
  73. </Theme>
  74. </template>
  75. <script setup>
  76. import { computed, ref, onMounted } from "vue";
  77. import Navbar from "@/components/navbar";
  78. import navMenu from "@/components/nav_menu";
  79. import { useSystemStore, useUserStore } from "@/store";
  80. import Input from "@/components/input";
  81. import { t } from "@/locale";
  82. import { PAY_LISTS, PAY_SUBMIT } from "@/api";
  83. import { openUrl, Toast, Moneyhtml } from "@/utils";
  84. const useUser = useUserStore();
  85. const useSystem = useSystemStore();
  86. const money = ref("");
  87. const moneyList = [500, 1000, 2000, 3000];
  88. const bankList = ref([]);
  89. const currency = computed(() => useSystem.getCurrency);
  90. const symbol = computed(() => useSystem.getSymbol);
  91. const userInfo = computed(() => useUser.getuserInfo);
  92. const listActive = (item) => {
  93. if (money.value == item) return (money.value = "");
  94. money.value = item;
  95. };
  96. const handleTo = () => {
  97. uni.navigateTo({ url: "/pages/bank/recharge_list" });
  98. };
  99. const getPayList = async () => {
  100. try {
  101. const res = await PAY_LISTS();
  102. const bankData = res.data;
  103. let arr = [];
  104. bankData.forEach((item) => {
  105. if (item.lists.length) {
  106. arr = [...arr, ...item.lists];
  107. }
  108. });
  109. bankList.value = arr;
  110. } catch (error) {}
  111. };
  112. const paySubmit = async () => {
  113. if (!money.value) return Toast(t("请输入金额"));
  114. let recharge_money = money.value;
  115. if (symbol.value.code != "CNY") {
  116. recharge_money = (Number(money.value) * Number(symbol.value.rate)).toFixed(
  117. 2
  118. );
  119. }
  120. try {
  121. const res = await PAY_SUBMIT({
  122. money: recharge_money,
  123. });
  124. uni.navigateTo({
  125. url: `/pages/shop/payment?oid=${res.data.orderid}&type=recharge`,
  126. });
  127. } catch (error) {
  128. if (error.ret) {
  129. uni.navigateTo({
  130. url: `/pages/shop/payment?oid=${error.data.orderid}&type=recharge`,
  131. });
  132. } else {
  133. Toast(error.msg);
  134. }
  135. }
  136. };
  137. onMounted(() => {
  138. useUser.getUserInfo();
  139. getPayList();
  140. });
  141. </script>
  142. <style lang="less" scoped>
  143. @import url("@/style.less");
  144. .wrap {
  145. min-height: 100vh;
  146. display: flex;
  147. flex-direction: column;
  148. background-color: var(--bg);
  149. .nav_right {
  150. color: var(--text);
  151. .size(28rpx);
  152. margin-left: 16rpx;
  153. }
  154. .content {
  155. flex-grow: 1;
  156. display: flex;
  157. flex-direction: column;
  158. justify-content: space-between;
  159. padding: 24rpx;
  160. padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
  161. box-sizing: border-box;
  162. .recharge_top {
  163. background-color: var(--light);
  164. border-radius: 16rpx;
  165. padding: 24rpx;
  166. .size(28rpx);
  167. .flex_position(space-between);
  168. column-gap: 24rpx;
  169. .value {
  170. .size(40rpx);
  171. text {
  172. margin-left: 6rpx;
  173. }
  174. }
  175. }
  176. .recharge_money {
  177. margin-top: 24rpx;
  178. background-color: var(--light);
  179. padding: 24rpx;
  180. border-radius: 16rpx;
  181. .money {
  182. .label {
  183. color: var(--text);
  184. .size(28rpx);
  185. font-weight: 700;
  186. }
  187. .value {
  188. margin-top: 24rpx;
  189. .ver();
  190. .currency {
  191. // .size();
  192. // color: var(--text-02);
  193. margin-right: 18rpx;
  194. }
  195. }
  196. }
  197. .money_list {
  198. margin-top: 24rpx;
  199. .flex();
  200. gap: 24rpx;
  201. background-color: var(--light);
  202. ._list {
  203. height: 76rpx;
  204. padding: 8rpx;
  205. background-color: var(--light);
  206. color: var(--text);
  207. border: 1px solid var(--black);
  208. border-radius: 8rpx;
  209. .flex_center();
  210. flex: 1;
  211. .size(28rpx);
  212. }
  213. .active {
  214. background-color: var(--black);
  215. color: var(--light);
  216. }
  217. }
  218. }
  219. .bank_list {
  220. margin-top: 24rpx;
  221. background-color: var(--light);
  222. padding: 24rpx;
  223. border-radius: 16rpx;
  224. .label {
  225. color: var(--text);
  226. .size(28rpx);
  227. font-weight: 700;
  228. }
  229. .value {
  230. ._list_ {
  231. .flex_position(space-between);
  232. padding: 20rpx 0;
  233. border-bottom: 1px solid var(--borderColor);
  234. ._list_left {
  235. .bank_title {
  236. .size(28rpx);
  237. color: var(--text);
  238. }
  239. .desc {
  240. color: var(--text-01);
  241. margin-top: 16rpx;
  242. .size(24rpx);
  243. }
  244. }
  245. .icon-left {
  246. color: var(--text-01);
  247. .size();
  248. transform: rotate(180deg);
  249. }
  250. &:last-child {
  251. border-bottom: none;
  252. }
  253. }
  254. }
  255. }
  256. .footer {
  257. padding: 0 24rpx 24rpx;
  258. background-color: var(--black);
  259. color: var(--light);
  260. padding: 16rpx 30rpx;
  261. height: 96rpx;
  262. .flex_center();
  263. border-radius: 16rpx;
  264. font-weight: 700;
  265. .size(28rpx);
  266. }
  267. }
  268. }
  269. </style>