huangbin 4 anos atrás
pai
commit
e2f045216b

+ 12 - 13
src/common/setup/upload/index.ts

@@ -12,6 +12,14 @@ function getBase64(file: File) {
     });
 }
 
+function handleIsJSON(val: string) {
+    try {
+        const str = JSON.parse(val)
+        return str
+    } catch (e) {
+        return val
+    }
+}
 
 function getImg(imgURl: string) {
     let result = '';
@@ -113,20 +121,11 @@ export function handlePreviewImg() {
     async function previewImg(file: FileItem | string) {
         if (typeof file === 'string') {
             if (file && file !== '--') {
-                const fn = (val: string) => {
-                    const temp = val.replace(/\"/g, "")
-                    previewImage.value = getImg(temp)
-                    previewVisible.value = true;
-                }
                 // 处理服务的脏数据,时而反而JSON格式,时而返回string格式,
                 // fuck
-                try {
-                    const str = JSON.parse(file)
-                    fn(str)
-                } catch (e) {
-                    fn(file)
-                }
-
+                const temp = handleIsJSON(file).replace(/\"/g, "")
+                previewImage.value = getImg(temp)
+                previewVisible.value = true;
             }
         } else {
             if (!file.url && !file.preview) {
@@ -156,7 +155,7 @@ export function getUploadImg() {
     function handleImg(value: string) {
         const arr = value.split(',')
         return arr.map((e, i) => {
-            const str = JSON.parse(e);
+            const str = handleIsJSON(e);
             return {
                 uid: i.toString(),
                 name: getImgName(e),

+ 41 - 27
src/views/information/custom/compoments/modify/index.vue

@@ -102,13 +102,9 @@
           </a-col>
           <a-col :span="12">
             <a-form-item label="营业执照">
-              <div class="upload">
-                <a-upload action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
-                          :transform-file="transformFile">
-                  <a-button class="uploadBtn">上传</a-button>
-                </a-upload>
-                <div class="look">查看附件</div>
-              </div>
+              <UploadImg :visible="visible"
+                         :imgList="attachmentImgList"
+                         @upload="attachmentUpload" />
             </a-form-item>
           </a-col>
           <a-col :span="12">
@@ -170,13 +166,9 @@
           <a-col :span="12">
             <a-form-item label="身份证正面照"
                          name="cardbackphotourl">
-              <div class="upload">
-                <a-upload action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
-                          :transform-file="transformFile">
-                  <a-button class="uploadBtn">上传</a-button>
-                </a-upload>
-                <div class="look">查看附件</div>
-              </div>
+              <UploadImg :visible="visible"
+                         :imgList="cardfrontImgList"
+                         @upload="cardfrontUpload" />
             </a-form-item>
           </a-col>
           <a-col :span="12">
@@ -191,13 +183,9 @@
           <a-col :span="24">
             <a-form-item label="身份证反面照"
                          name="cardfrontphotourl">
-              <div class="upload">
-                <a-upload action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
-                          :transform-file="transformFile">
-                  <a-button class="uploadBtn">上传</a-button>
-                </a-upload>
-                <div class="look">查看附件</div>
-              </div>
+              <UploadImg :visible="visible"
+                         :imgList="cardbackImgList"
+                         @upload="cardbackUpload" />
             </a-form-item>
           </a-col>
           <a-col :span="12">
@@ -288,10 +276,12 @@ import { QueryModifyUserInfoApply } from '@/services/go/ermcp/customInfo';
 import { mergeTwoObj } from '@/utils/objHandle';
 import { validateAction } from '@/common/setup/form';
 import { delAddress } from '@/services/socket/address';
+import UploadImg from '@/common/components/uploadImg/index.vue';
+import { getUploadImg } from '@/common/setup/upload';
 
 export default defineComponent({
     name: 'modify-custom',
-    components: {},
+    components: { UploadImg },
     props: {
         selectedRow: {
             default: initFormState,
@@ -307,6 +297,12 @@ export default defineComponent({
         const { formRef, formState, rules } = handleForm();
         // 地址
         const { cityList, districtList, provinceList, getCityList, getDistrictList } = getAddress();
+        // 营业执照
+        const { uploadImgAction: attachmentUpload, uploadImgList: attachmentImgList, handleImg: attachmentHandle } = getUploadImg();
+        // 背面证件照地址
+        const { uploadImgAction: cardbackUpload, uploadImgList: cardbackImgList, handleImg: cardbackHandle } = getUploadImg();
+        // 正面证件照地址
+        const { uploadImgAction: cardfrontUpload, uploadImgList: cardfrontImgList, handleImg: cardfrontHandle } = getUploadImg();
 
         function isPersonal(): boolean {
             return formState.userinfotype === '1';
@@ -319,14 +315,26 @@ export default defineComponent({
                 userid.value = props.selectedRow.userid;
                 countryid.value = props.selectedRow.countryid;
                 mergeTwoObj(formState, props.selectedRow);
-                if(isPersonal()) {
-                  formState.username = props.selectedRow.customername
+                if (isPersonal()) {
+                    formState.username = props.selectedRow.customername;
                 }
-                const { provinceid, cityid, address, mobile } = props.selectedRow;
-                formState.cardaddress = address
-                formState.mobilephone = mobile
+                const { provinceid, cityid, address, mobile, attachment1, cardfrontphotourl, cardbackphotourl } = props.selectedRow;
+                formState.cardaddress = address;
+                formState.mobilephone = mobile;
                 provinceid ? getCityList(provinceid) : (formState.provinceid = undefined);
                 cityid ? getDistrictList(cityid) : ((formState.cityid = undefined), (formState.districtid = undefined));
+                if (attachment1) {
+                    // 营业执照
+                    attachmentImgList.value = attachmentHandle(attachment1);
+                }
+                if (cardbackphotourl) {
+                    // 背面证件照地址
+                    cardbackImgList.value = cardbackHandle(cardbackphotourl);
+                }
+                if (cardbackphotourl) {
+                    // 正面证件照地址
+                    cardfrontImgList.value = cardfrontHandle(cardbackphotourl);
+                }
             }
         });
         function submit(OperateType: 1 | 2) {
@@ -376,6 +384,12 @@ export default defineComponent({
             provinceList,
             getCityList,
             getDistrictList,
+            attachmentUpload,
+            attachmentImgList,
+            cardbackUpload,
+            cardbackImgList,
+            cardfrontUpload,
+            cardfrontImgList,
         };
     },
 });