AddFileDialog.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <cwg-popup :title="form.title" :visible="visible" @close="onPopupClose" @confirm="submit" >
  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" :offset="2">
  15. <uni-forms-item :label="t('PersonalManagement.Title.ProofOfIdentity') + 1">
  16. <cwg-file-picker-wrapper 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" :offset="2">
  24. <uni-forms-item :label="t('PersonalManagement.Title.ProofOfIdentity') + 2">
  25. <cwg-file-picker-wrapper 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" :offset="2">
  35. <uni-forms-item :label="t('PersonalManagement.Title.ProofOfAddress')">
  36. <cwg-file-picker-wrapper 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" :offset="2">
  46. <uni-forms-item :label="t('PersonalManagement.Title.AttachedFile')">
  47. <cwg-file-picker-wrapper 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. </cwg-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 visible = ref(false);
  82. const form = ref<AddBankForm>({});
  83. const rules = {
  84. addressName: [Validators.required(t('blockchain.item3') + t('common.cannotbeempty'))],
  85. address: [Validators.required(t('blockchain.item4') + t('common.cannotbeempty'))]
  86. };
  87. // 打开弹窗
  88. const open = async (item) => {
  89. form.value = {}
  90. await nextTick();
  91. console.log(item, 23123);
  92. form.value = item;
  93. let files = []
  94. item?.tableData.forEach(file => {
  95. if (file.type === 1) {
  96. form.value.file1 = file.path
  97. } else if (file.type === 2) {
  98. form.value.file2 = file.path
  99. } else if (file.type === 3) {
  100. form.value.file3 = file.path
  101. } else if (file.type === 10) {
  102. files.push(file.path)
  103. }
  104. })
  105. getBankList()
  106. visible.value = true
  107. // fileRef.value?.open();
  108. };
  109. // 关闭弹窗
  110. const close = () => {
  111. visible.value = false
  112. };
  113. // 弹窗真正关闭后清空表单
  114. const onPopupClose = () => {
  115. resetForm();
  116. };
  117. // 重置表单
  118. const resetForm = () => {
  119. form.value = {};
  120. formRef.value?.clearValidate();
  121. };
  122. // 提交表单
  123. const submit = async () => {
  124. close();
  125. emit('success');
  126. };
  127. const bankList = ref([])
  128. const isZh = computed(() => ['cn', 'zh', 'zhHant'].includes(locale.value));
  129. const getLangName = (item: any) => (isZh.value ? item.name : item.enName);
  130. const createOptions = (list: any[], valueKey = 'code') => {
  131. return list.map((item) => ({
  132. text: getLangName(item),
  133. value: getLangName(item)
  134. }));
  135. };
  136. const bankOptions = computed(() => createOptions(bankList.value, 'name'));
  137. // 获取银行列表
  138. const getBankList = async () => {
  139. const res = await personalApi.BankList({})
  140. if (res.code === 200) {
  141. bankList.value = res.data
  142. }
  143. }
  144. // 文件更新处理
  145. const handleFileUpdate = (newValue, item, field) => {
  146. item[field] = newValue
  147. }
  148. // 暴露方法
  149. defineExpose({
  150. open,
  151. close
  152. });
  153. </script>
  154. <style scoped lang="scss">
  155. @import "@/uni.scss";
  156. .dialog-container {
  157. width: 80vw;
  158. max-width: px2rpx(800);
  159. max-height: 85vh;
  160. padding: px2rpx(24);
  161. overflow: hidden;
  162. border-radius: px2rpx(12);
  163. .dialog-header {
  164. display: flex;
  165. justify-content: space-between;
  166. align-items: center;
  167. margin-bottom: px2rpx(24);
  168. padding-bottom: px2rpx(16);
  169. border-bottom: 1px solid #f3f4f6;
  170. .dialog-title {
  171. font-size: px2rpx(18);
  172. font-weight: 600;
  173. color: #1f2937;
  174. }
  175. .dialog-close {
  176. width: px2rpx(32);
  177. height: px2rpx(32);
  178. display: flex;
  179. align-items: center;
  180. justify-content: center;
  181. font-size: px2rpx(28);
  182. color: #9ca3af;
  183. cursor: pointer;
  184. transition: all 0.3s;
  185. &:hover {
  186. color: #1f2937;
  187. }
  188. }
  189. }
  190. .dialog-footer {
  191. display: flex;
  192. gap: px2rpx(12);
  193. justify-content: space-around;
  194. padding: px2rpx(16) 0 0;
  195. border-top: 1px solid #f3f4f6;
  196. .btn {
  197. min-width: px2rpx(120);
  198. padding: px2rpx(12) px2rpx(24);
  199. border-radius: px2rpx(6);
  200. font-size: px2rpx(14);
  201. font-weight: 600;
  202. box-sizing: border-box;
  203. border: none;
  204. cursor: pointer;
  205. text-align: center;
  206. transition: all 0.3s;
  207. display: flex;
  208. align-items: center;
  209. justify-content: space-around;
  210. &.btn-cancel {
  211. background: #f3f4f6;
  212. color: #6b7280;
  213. &:hover {
  214. background: #e5e7eb;
  215. }
  216. &:active {
  217. background: #d1d5db;
  218. }
  219. }
  220. &.btn-confirm {
  221. background: #ea2027;
  222. color: var(--bs-emphasis-color);
  223. &:hover {
  224. background: #d11920;
  225. }
  226. &:active {
  227. background: #c01819;
  228. }
  229. }
  230. }
  231. }
  232. .crm-form {
  233. overflow-y: auto;
  234. max-height: 70vh;
  235. }
  236. }
  237. </style>