account-info-modal.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <su-popup :show="show" class="add-bank-wrap" @close="hideModal">
  3. <view class="ss-modal-box bg-white ss-flex-col">
  4. <view class="modal-header ss-flex-col ss-col-left">
  5. <text v-if="props.modelValue.type === 'bank'" class="modal-title ss-m-b-20">
  6. 绑定银行卡
  7. </text>
  8. <text v-if="props.modelValue.type === 'wechat'" class="modal-title ss-m-b-20">
  9. 绑定微信
  10. </text>
  11. <text v-if="props.modelValue.type === 'alipay'" class="modal-title ss-m-b-20">
  12. 绑定支付宝
  13. </text>
  14. </view>
  15. <view class="modal-content ss-flex-1 ss-p-b-100">
  16. <block v-if="props.modelValue.type === 'bank'">
  17. <uni-forms
  18. ref="form"
  19. :model="state.bank.model"
  20. :rules="state.bank.rules"
  21. validateTrigger="bind"
  22. labelWidth="160"
  23. labelAlign="center"
  24. border
  25. :labelStyle="{ fontWeight: 'bold' }"
  26. >
  27. <uni-forms-item name="account_name" label="持卡人">
  28. <uni-easyinput
  29. :inputBorder="false"
  30. placeholder="请输入持卡人"
  31. v-model="state.bank.model.account_name"
  32. />
  33. </uni-forms-item>
  34. <uni-forms-item name="account_header" label="开户行">
  35. <uni-easyinput
  36. :inputBorder="false"
  37. placeholder="请输入开户行"
  38. v-model="state.bank.model.account_header"
  39. />
  40. </uni-forms-item>
  41. <uni-forms-item name="account_no" label="银行卡号">
  42. <uni-easyinput
  43. type="number"
  44. :inputBorder="false"
  45. placeholder="请输入银行卡号"
  46. v-model="state.bank.model.account_no"
  47. />
  48. </uni-forms-item>
  49. </uni-forms>
  50. </block>
  51. <block v-if="props.modelValue.type === 'wechat'">
  52. <uni-forms
  53. ref="form"
  54. :model="state.wechat.model"
  55. :rules="state.wechat.rules"
  56. validateTrigger="bind"
  57. labelWidth="160"
  58. labelAlign="center"
  59. border
  60. :labelStyle="{ fontWeight: 'bold' }"
  61. >
  62. <uni-forms-item name="account_name" label="真实姓名">
  63. <uni-easyinput
  64. :inputBorder="false"
  65. placeholder="请输入您的真实姓名"
  66. v-model="state.wechat.model.account_name"
  67. />
  68. </uni-forms-item>
  69. </uni-forms>
  70. </block>
  71. <block v-if="props.modelValue.type === 'alipay'">
  72. <uni-forms
  73. ref="form"
  74. :model="state.alipay.model"
  75. :rules="state.alipay.rules"
  76. validateTrigger="bind"
  77. labelWidth="160"
  78. labelAlign="center"
  79. border
  80. :labelStyle="{ fontWeight: 'bold' }"
  81. >
  82. <uni-forms-item name="account_name" label="真实姓名">
  83. <uni-easyinput
  84. :inputBorder="false"
  85. placeholder="请输入您的真实姓名"
  86. v-model="state.alipay.model.account_name"
  87. />
  88. </uni-forms-item>
  89. <uni-forms-item name="account_no" label="支付宝">
  90. <uni-easyinput
  91. :inputBorder="false"
  92. placeholder="请输入支付宝 邮箱/手机号"
  93. v-model="state.alipay.model.account_no"
  94. />
  95. </uni-forms-item>
  96. </uni-forms>
  97. </block>
  98. </view>
  99. <view class="modal-footer ss-flex ss-row-center ss-col-center">
  100. <button class="ss-reset-button save-btn" @tap="onSave">保存</button>
  101. </view>
  102. </view>
  103. </su-popup>
  104. </template>
  105. <script setup>
  106. import { ref, reactive, unref, watchPostEffect, watch } from 'vue';
  107. import sheep from '@/sheep';
  108. import { realName, bankName, bankCode, alipayAccount } from '@/sheep/validate/form';
  109. const form = ref(null);
  110. const props = defineProps({
  111. modelValue: {
  112. type: Object,
  113. default() {},
  114. },
  115. show: {
  116. type: Boolean,
  117. default: false,
  118. },
  119. });
  120. watch(
  121. () => props.modelValue,
  122. (newValue, oldValue) => {
  123. setModelValue(newValue);
  124. },
  125. );
  126. function setModelValue(modelValue) {
  127. Object.keys(state[modelValue.type].model).forEach((key) => {
  128. state[modelValue.type].model[key] = modelValue[key];
  129. });
  130. }
  131. const emits = defineEmits(['update:modelValue', 'close']);
  132. // 数据
  133. const state = reactive({
  134. bank: {
  135. model: {
  136. account_name: '',
  137. account_header: '',
  138. account_no: '',
  139. },
  140. rules: {
  141. account_name: realName,
  142. account_header: bankName,
  143. account_no: bankCode,
  144. },
  145. },
  146. alipay: {
  147. model: {
  148. account_name: '',
  149. account_no: '',
  150. },
  151. rules: {
  152. account_name: realName,
  153. account_no: alipayAccount,
  154. },
  155. },
  156. wechat: {
  157. model: {
  158. account_name: '',
  159. },
  160. rules: {
  161. account_name: realName,
  162. },
  163. },
  164. });
  165. setModelValue(props.modelValue);
  166. const hideModal = () => {
  167. emits('close');
  168. };
  169. const onSave = async () => {
  170. const validate = await unref(form)
  171. .validate()
  172. .catch((error) => {
  173. 'error: ', error;
  174. });
  175. if (!validate) return;
  176. let data = {
  177. type: props.modelValue.type,
  178. account_header: state[props.modelValue.type].model.account_header,
  179. account_name: state[props.modelValue.type].model.account_name,
  180. account_no: state[props.modelValue.type].model.account_no,
  181. };
  182. let res = await sheep.$api.user.account.save(data);
  183. if (res.error === 0) {
  184. emits('update:modelValue', res.data);
  185. hideModal();
  186. }
  187. };
  188. </script>
  189. <style lang="scss" scoped>
  190. .ss-modal-box {
  191. border-radius: 30rpx 30rpx 0 0;
  192. max-height: 1000rpx;
  193. .modal-header {
  194. position: relative;
  195. padding: 60rpx 40rpx 40rpx;
  196. .modal-title {
  197. font-size: 32rpx;
  198. font-weight: bold;
  199. }
  200. .close-icon {
  201. position: absolute;
  202. top: 10rpx;
  203. right: 20rpx;
  204. font-size: 46rpx;
  205. opacity: 0.2;
  206. }
  207. }
  208. .modal-content {
  209. overflow-y: auto;
  210. }
  211. .modal-footer {
  212. height: 120rpx;
  213. .save-btn {
  214. width: 710rpx;
  215. height: 80rpx;
  216. border-radius: 40rpx;
  217. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  218. color: $white;
  219. }
  220. }
  221. }
  222. </style>