AddFileDialog.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <cwg-popup :title="form.title" :visible="visible" @close="close" @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 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 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 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 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. // fileRef.value?.close();
  112. visible.value = false
  113. resetForm();
  114. };
  115. // 重置表单
  116. const resetForm = () => {
  117. form.value = {};
  118. formRef.value?.clearValidate();
  119. };
  120. // 提交表单
  121. const submit = async () => {
  122. close();
  123. emit('success');
  124. };
  125. const bankList = ref([])
  126. const isZh = computed(() => ['cn', 'zh', 'zhHant'].includes(locale.value));
  127. const getLangName = (item: any) => (isZh.value ? item.name : item.enName);
  128. const createOptions = (list: any[], valueKey = 'code') => {
  129. return list.map((item) => ({
  130. text: getLangName(item),
  131. value: getLangName(item)
  132. }));
  133. };
  134. const bankOptions = computed(() => createOptions(bankList.value, 'name'));
  135. // 获取银行列表
  136. const getBankList = async () => {
  137. const res = await personalApi.BankList({})
  138. if (res.code === 200) {
  139. bankList.value = res.data
  140. }
  141. }
  142. // 文件更新处理
  143. const handleFileUpdate = (newValue, item, field) => {
  144. item[field] = newValue
  145. }
  146. // 暴露方法
  147. defineExpose({
  148. open,
  149. close
  150. });
  151. </script>
  152. <style scoped lang="scss">
  153. @import "@/uni.scss";
  154. .dialog-container {
  155. width: 80vw;
  156. max-width: px2rpx(800);
  157. max-height: 85vh;
  158. padding: px2rpx(24);
  159. overflow: hidden;
  160. border-radius: px2rpx(12);
  161. .dialog-header {
  162. display: flex;
  163. justify-content: space-between;
  164. align-items: center;
  165. margin-bottom: px2rpx(24);
  166. padding-bottom: px2rpx(16);
  167. border-bottom: 1px solid #f3f4f6;
  168. .dialog-title {
  169. font-size: px2rpx(18);
  170. font-weight: 600;
  171. color: #1f2937;
  172. }
  173. .dialog-close {
  174. width: px2rpx(32);
  175. height: px2rpx(32);
  176. display: flex;
  177. align-items: center;
  178. justify-content: center;
  179. font-size: px2rpx(28);
  180. color: #9ca3af;
  181. cursor: pointer;
  182. transition: all 0.3s;
  183. &:hover {
  184. color: #1f2937;
  185. }
  186. }
  187. }
  188. .dialog-footer {
  189. display: flex;
  190. gap: px2rpx(12);
  191. justify-content: space-around;
  192. padding: px2rpx(16) 0 0;
  193. border-top: 1px solid #f3f4f6;
  194. .btn {
  195. min-width: px2rpx(120);
  196. padding: px2rpx(12) px2rpx(24);
  197. border-radius: px2rpx(6);
  198. font-size: px2rpx(14);
  199. font-weight: 600;
  200. box-sizing: border-box;
  201. border: none;
  202. cursor: pointer;
  203. text-align: center;
  204. transition: all 0.3s;
  205. display: flex;
  206. align-items: center;
  207. justify-content: space-around;
  208. &.btn-cancel {
  209. background: #f3f4f6;
  210. color: #6b7280;
  211. &:hover {
  212. background: #e5e7eb;
  213. }
  214. &:active {
  215. background: #d1d5db;
  216. }
  217. }
  218. &.btn-confirm {
  219. background: #ea2027;
  220. color: var(--bs-emphasis-color);
  221. &:hover {
  222. background: #d11920;
  223. }
  224. &:active {
  225. background: #c01819;
  226. }
  227. }
  228. }
  229. }
  230. .crm-form {
  231. overflow-y: auto;
  232. max-height: 70vh;
  233. }
  234. }
  235. </style>