accountTransfer.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view class="edit-container">
  3. <uni-forms ref="transferForm" :modelValue="transferFormData" :label-width="250" label-position="top"
  4. :rules="transferFormRules">
  5. <uni-forms-item label="转出账户" required name="senderAccountId">
  6. <uni-data-select :localdata="accountSelectedData" v-model="transferFormData.senderAccountId"></uni-data-select>
  7. </uni-forms-item>
  8. <uni-forms-item label="转入账户" required name="recipientAccountId">
  9. <uni-data-select :localdata="accountSelectedData"
  10. v-model="transferFormData.recipientAccountId"></uni-data-select>
  11. </uni-forms-item>
  12. <uni-forms-item label="转账积分" required name="transferPoints">
  13. <uni-easyinput v-model="transferFormData.transferPoints" placeholder="请输入转账积分" type="digit" />
  14. </uni-forms-item>
  15. <!-- 按钮组 -->
  16. <view class="button-container">
  17. <button type="default" style="width:300rpx;" @click="cancel()">取消</button>
  18. <button type="primary" style="color:#ffffff;backgroundColor:#2A82E4;width:300rpx;"
  19. @click="transfer()">转账</button>
  20. </view>
  21. </uni-forms>
  22. </view>
  23. </template>
  24. <script setup>
  25. import { ref } from 'vue';
  26. import { onShow } from '@dcloudio/uni-app';
  27. import { accountApi } from '@/apis/apis';
  28. // 组件
  29. /**
  30. * 账户表单
  31. */
  32. const transferForm = ref(null);
  33. // 属性
  34. /**
  35. * 账户表单数据
  36. */
  37. const transferFormData = ref({});
  38. /**
  39. * 账户下拉框数据
  40. */
  41. const accountSelectedData = ref([]);
  42. /**
  43. * 打卡任务表单规则
  44. */
  45. const transferFormRules = ref({
  46. senderAccountId: {
  47. rules: [{
  48. required: true,
  49. errorMessage: '转出账户不能为空'
  50. }]
  51. },
  52. recipientAccountId: {
  53. rules: [{
  54. required: true,
  55. errorMessage: '转入账户不能为空'
  56. }]
  57. },
  58. transferPoints: {
  59. rules: [{
  60. required: true,
  61. errorMessage: '转出积分不能为空'
  62. }, {
  63. format: 'number',
  64. errorMessage: "请输入有效数字"
  65. }, {
  66. minimum: 1,
  67. errorMessage: "最小值{minimum}"
  68. }]
  69. }
  70. });
  71. // 方法
  72. /**
  73. * 保存奖励
  74. */
  75. const transfer = () => {
  76. transferForm.value.validate(['id']).then(() => {
  77. return accountApi.transfer(transferFormData.value)
  78. }).then(datt => {
  79. uni.showToast({
  80. title: '转账成功',
  81. icon: 'success',
  82. duration: 2000
  83. });
  84. setTimeout(() => {
  85. uni.navigateBack();
  86. }, 2000);
  87. });
  88. }
  89. /**
  90. * 后退
  91. */
  92. const cancel = () => {
  93. uni.navigateBack();
  94. }
  95. /**
  96. * 获取账户数据
  97. */
  98. const loadAccountData = async () => {
  99. let res = await accountApi.queryAccountList();
  100. if (!res) {
  101. accountSelectedData.value = [];
  102. return;
  103. }
  104. accountSelectedData.value = res.map(item => {
  105. let text = `${item.accountName}(${item.points}积分)`;
  106. return {
  107. text,
  108. value: item.id
  109. }
  110. });
  111. }
  112. // 生命周期
  113. onShow(() => {
  114. loadAccountData();
  115. });
  116. </script>
  117. <style lang="scss" scoped>
  118. .edit-container {
  119. margin: 16rpx;
  120. .button-container {
  121. background-color: #FFFFFF;
  122. display: flex;
  123. /* 使用Flexbox布局 */
  124. justify-content: space-between;
  125. /* 按钮之间的空间分布 */
  126. padding: 20rpx;
  127. /* 容器两侧的空白填充 */
  128. }
  129. }
  130. </style>