AddFileDialog.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <uni-popup ref="fileRef" type="center" background-color="#fff">
  3. <view class="dialog-container">
  4. <view class="dialog-header">
  5. <text class="dialog-title">{{ form.title }}</text>
  6. <view class="dialog-close" @click="close">
  7. <text>×</text>
  8. </view>
  9. </view>
  10. <uni-forms ref="formRef" :rules="rules" :model="form" labelWidth="200" label-position="top"
  11. class="crm-form">
  12. <uni-row class="form-row uni-row1">
  13. <template v-if="form.type === 1">
  14. <uni-col :xs="24">
  15. <uni-forms-item :label="t('PersonalManagement.Title.ProofOfIdentity') + 1">
  16. <cwg-file-picker v-model="form.file1" :editable="editingId === form.id" :limit="1"
  17. uploadUrl="/custom/file/upload/1" :baseUrl="updateUrl" :imageWidth="150"
  18. :imageHeight="150" uploadText="点击上传" replaceText="点击替换" noImageText="暂无图片"
  19. :showPreviewDelete="editingId === form.id"
  20. @update:modelValue="(val) => handleFileUpdate(val, form, 'file1')" />
  21. </uni-forms-item>
  22. </uni-col>
  23. <uni-col :xs="24">
  24. <uni-forms-item :label="t('PersonalManagement.Title.ProofOfIdentity') + 2">
  25. <cwg-file-picker v-model="form.file2" :editable="editingId === form.id" :limit="1"
  26. uploadUrl="/custom/file/upload/2" :baseUrl="updateUrl" :imageWidth="150"
  27. :imageHeight="150" uploadText="点击上传" replaceText="点击替换" noImageText="暂无图片"
  28. :showPreviewDelete="editingId === form.id"
  29. @update:modelValue="(val) => handleFileUpdate(val, form, 'file2')" />
  30. </uni-forms-item>
  31. </uni-col>
  32. </template>
  33. <template v-if="form.type === 2">
  34. <uni-col :xs="24">
  35. <uni-forms-item :label="t('PersonalManagement.Title.ProofOfAddress')">
  36. <cwg-file-picker v-model="form.file3" :editable="editingId === form.id" :limit="1"
  37. uploadUrl="/custom/file/upload/3" :baseUrl="updateUrl" :imageWidth="150"
  38. :imageHeight="150" uploadText="点击上传" replaceText="点击替换" noImageText="暂无图片"
  39. :showPreviewDelete="editingId === form.id"
  40. @update:modelValue="(val) => handleFileUpdate(val, form, 'file3')" />
  41. </uni-forms-item>
  42. </uni-col>
  43. </template>
  44. <template v-if="form.type === 3">
  45. <uni-col :xs="24">
  46. <uni-forms-item :label="t('PersonalManagement.Title.AttachedFile')">
  47. <cwg-file-picker v-model="form.file4" :editable="editingId === form.id" :limit="9"
  48. uploadUrl="/custom/file/upload/10" :baseUrl="updateUrl" :imageWidth="150"
  49. :imageHeight="150" uploadText="点击上传" replaceText="点击替换" noImageText="暂无图片"
  50. :showPreviewDelete="editingId === form.id"
  51. @update:modelValue="(val) => handleFileUpdate(val, form, 'file4')" />
  52. </uni-forms-item>
  53. </uni-col>
  54. </template>
  55. </uni-row>
  56. </uni-forms>
  57. <view class="dialog-footer">
  58. <view class="btn btn-cancel" @click="close">{{ t('Btn.Cancel') }}</view>
  59. <view class="btn btn-confirm" @click="submit">{{ t('Btn.Confirm') }}</view>
  60. </view>
  61. </view>
  62. </uni-popup>
  63. </template>
  64. <script setup lang="ts">
  65. import { ref, nextTick, computed, onMounted } from 'vue';
  66. import { useI18n } from 'vue-i18n';
  67. import { Validators } from '@/utils/validators';
  68. import { personalApi } from '@/service/personal';
  69. const { t, locale } = useI18n();
  70. interface AddBankForm {
  71. addressName: string;
  72. address: string;
  73. checkboxGroup: string[];
  74. }
  75. const hobbys = computed(() => [
  76. { value: 1, text: t('blockchain.item8') }
  77. ]);
  78. const emit = defineEmits(["success"]);
  79. const fileRef = ref<any>(null);
  80. const formRef = ref<any>(null);
  81. const form = ref<AddBankForm>({});
  82. const rules = {
  83. addressName: [Validators.required(t('blockchain.item3') + t('common.cannotbeempty'))],
  84. address: [Validators.required(t('blockchain.item4') + t('common.cannotbeempty'))]
  85. };
  86. // 打开弹窗
  87. const open = async (item) => {
  88. form.value = {}
  89. await nextTick();
  90. console.log(item, 23123);
  91. form.value = item;
  92. let files = []
  93. item?.tableData.forEach(file => {
  94. if (file.type === 1) {
  95. form.value.file1 = file.path
  96. } else if (file.type === 2) {
  97. form.value.file2 = file.path
  98. } else if (file.type === 3) {
  99. form.value.file3 = file.path
  100. } else if (file.type === 10) {
  101. files.push(file.path)
  102. }
  103. })
  104. getBankList()
  105. fileRef.value?.open();
  106. };
  107. // 关闭弹窗
  108. const close = () => {
  109. fileRef.value?.close();
  110. resetForm();
  111. };
  112. // 重置表单
  113. const resetForm = () => {
  114. form.value = {};
  115. formRef.value?.clearValidate();
  116. };
  117. // 提交表单
  118. const submit = async () => {
  119. close();
  120. emit('success');
  121. };
  122. const bankList = ref([])
  123. const isZh = computed(() => ['cn', 'zh', 'zhHant'].includes(locale.value));
  124. const getLangName = (item: any) => (isZh.value ? item.name : item.enName);
  125. const createOptions = (list: any[], valueKey = 'code') => {
  126. return list.map((item) => ({
  127. text: getLangName(item),
  128. value: getLangName(item)
  129. }));
  130. };
  131. const bankOptions = computed(() => createOptions(bankList.value, 'name'));
  132. // 获取银行列表
  133. const getBankList = async () => {
  134. const res = await personalApi.BankList({})
  135. if (res.code === 200) {
  136. bankList.value = res.data
  137. }
  138. }
  139. // 文件更新处理
  140. const handleFileUpdate = (newValue, item, field) => {
  141. item[field] = newValue
  142. }
  143. // 暴露方法
  144. defineExpose({
  145. open,
  146. close
  147. });
  148. </script>
  149. <style scoped lang="scss">
  150. @import "@/uni.scss";
  151. .dialog-container {
  152. width: 80vw;
  153. max-width: px2rpx(800);
  154. max-height: 85vh;
  155. padding: px2rpx(24);
  156. overflow: hidden;
  157. border-radius: px2rpx(12);
  158. .dialog-header {
  159. display: flex;
  160. justify-content: space-between;
  161. align-items: center;
  162. margin-bottom: px2rpx(24);
  163. padding-bottom: px2rpx(16);
  164. border-bottom: 1px solid #f3f4f6;
  165. .dialog-title {
  166. font-size: px2rpx(18);
  167. font-weight: 600;
  168. color: #1f2937;
  169. }
  170. .dialog-close {
  171. width: px2rpx(32);
  172. height: px2rpx(32);
  173. display: flex;
  174. align-items: center;
  175. justify-content: center;
  176. font-size: px2rpx(28);
  177. color: #9ca3af;
  178. cursor: pointer;
  179. transition: all 0.3s;
  180. &:hover {
  181. color: #1f2937;
  182. }
  183. }
  184. }
  185. .dialog-footer {
  186. display: flex;
  187. gap: px2rpx(12);
  188. justify-content: space-around;
  189. padding: px2rpx(16) 0 0;
  190. border-top: 1px solid #f3f4f6;
  191. .btn {
  192. min-width: px2rpx(120);
  193. padding: px2rpx(12) px2rpx(24);
  194. border-radius: px2rpx(6);
  195. font-size: px2rpx(14);
  196. font-weight: 600;
  197. box-sizing: border-box;
  198. border: none;
  199. cursor: pointer;
  200. text-align: center;
  201. transition: all 0.3s;
  202. display: flex;
  203. align-items: center;
  204. justify-content: center;
  205. &.btn-cancel {
  206. background: #f3f4f6;
  207. color: #6b7280;
  208. &:hover {
  209. background: #e5e7eb;
  210. }
  211. &:active {
  212. background: #d1d5db;
  213. }
  214. }
  215. &.btn-confirm {
  216. background: #ea2027;
  217. color: var(--bs-emphasis-color);
  218. &:hover {
  219. background: #d11920;
  220. }
  221. &:active {
  222. background: #c01819;
  223. }
  224. }
  225. }
  226. }
  227. .crm-form {
  228. overflow-y: auto;
  229. max-height: 70vh;
  230. }
  231. }
  232. </style>