浏览代码

241004-1820-Kim

hokky 1 月之前
父节点
当前提交
bd20ec6600

+ 191 - 8
resources/views/front/dabory/myapp/popup/popup-form1/form-a/member-seller-edit-form.blade.php

@@ -77,12 +77,14 @@
 
                         <div class="form-group d-flex flex-column mb-2">
                             <label class="m-0">신분증사본</label>
+                            <input type="file" id="upload-file1" name="ssn_card_img" value="{{ old('ssn_card_img') }}" class="cursor-pointer rounded w-100 form-control-uniform-custom" required style="text-indent: 0;">
                             <input type="text" id="ssn-card-img-txt"
                                    onclick="PopupPopupForm1FormAMemberSellerEditForm.show_image(this)"
                                    class="w-100 rounded mb-1 tooltip-show-img" readonly>
                         </div>
                         <div class="form-group d-flex flex-column mb-2">
                             <label class="m-0">통장사본</label>
+                            <input type="file" id="upload-file2" name="bank_account_img" value="{{ old('bank_account_img') }}" class="cursor-pointer rounded w-100 form-control-uniform-custom" required style="text-indent: 0;">
                             <input type="text" id="bank-account-img-txt"
                                    onclick="PopupPopupForm1FormAMemberSellerEditForm.show_image(this)"
                                    class="w-100 rounded mb-1 tooltip-show-img" readonly>
@@ -106,6 +108,20 @@
         <script src="//t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js"></script>
         <script>
             $(document).ready(async function() {
+                $('#upload-file1').on('change', function() {
+                    const input = $(this);
+                    const media_input = input.closest('.form-group').find('input[type="text"]');
+                    PopupPopupForm1FormAMemberSellerEditForm.file_upload(this.files[0], media_input);
+                });
+
+                $('#upload-file2').on('change', function() {
+                    const input = $(this);
+                    const media_input = input.closest('.form-group').find('input[type="text"]');
+                    PopupPopupForm1FormAMemberSellerEditForm.file_upload(this.files[0], media_input);
+                });
+                $('#upload-file1').fileselect();
+                $('#upload-file2').fileselect();
+
                 $('.member-company-act').on('click', function () {
                     // console.log($(this).data('value'))
 
@@ -120,11 +136,24 @@
 
             (function( PopupPopupForm1FormAMemberSellerEditForm, $, undefined ) {
                 PopupPopupForm1FormAMemberSellerEditForm.formA = {!! json_encode($formA) !!};
-
+                PopupPopupForm1FormAMemberSellerEditForm.setup;
                 PopupPopupForm1FormAMemberSellerEditForm.show_image = function ($this) {
                     window.open(window.env['MEDIA_URL']  + $($this).val())
                 }
 
+                PopupPopupForm1FormAMemberSellerEditForm.get_setup = async function () {
+                    const response = await get_api_data('setup-page', {
+                        PageVars: {
+                            Query: "setup_code = 'media-body' and is_on_use = '1' and brand_code='post'",
+                            Limit: 9999999, Offset: 0
+                        }
+                    })
+                    const setupJson = JSON.parse(response.data['Page'][0]['SetupJson']);
+                    setupJson['BrandCode']= 'post';
+                    console.log('setupJson : ', setupJson);
+                    return setupJson;
+                }
+
                 PopupPopupForm1FormAMemberSellerEditForm.btn_act_new = function () {
                     $('#modal-select-popup .modal-body button').removeClass('bg-grey-700 border-grey-700 bg-grey-700-hover')
                     $('#modal-select-popup .modal-body thead th').removeClass('bg-grey-700')
@@ -138,7 +167,6 @@
                     Atype.btn_act_new('#member-company-form #frm');
                 }
 
-
                 PopupPopupForm1FormAMemberSellerEditForm.parameter = function () {
                     const member_company_form = $('#member-company-form')
                     let id = Number($(member_company_form).find('#Id').val());
@@ -150,12 +178,14 @@
                         AccountHolder: $(member_company_form).find('#holder-name-txt').val(),
                         Ssn1: $(member_company_form).find('#ssn1-txt').val(),
                         Ssn2: $(member_company_form).find('#ssn2-txt').val(),
+                        SsnCardImg: $(member_company_form).find('#ssn-card-img-txt').val()
                     }
                     if (id < 0) {
                         parameter = { Id: id }
                     }
 
-                    // console.log(parameter)
+                    console.log(parameter)
+
                     return parameter;
                 }
 
@@ -173,12 +203,165 @@
                     }, 'PopupPopupForm1FormAMemberSellerEditForm');
                 }
 
+                PopupPopupForm1FormAMemberSellerEditForm.get_file_path_list = function (file_url, page) {
+                    let file_path_list = [];
+
+                    if (file_url) {
+                        console.log('file_url : ', file_url);
+                        file_path_list.push(PopupPopupForm1FormAMemberSellerEditForm.get_media_data(file_url))
+                    }
+
+                    return file_path_list;
+                }
+
+                PopupPopupForm1FormAMemberSellerEditForm.get_media_data = async function (file_url) {
+                    const path_list = file_url.split('/')
+                    const file_name = path_list[path_list.length - 1]
+                    const file_path = file_url.split(file_name)[0]
+
+                    return {
+                        name: file_name,
+                        path: file_path,
+                        setup: await PopupPopupForm1FormAMemberSellerEditForm.get_setup(),
+                        type: "post",
+                    }
+                }
+
+                PopupPopupForm1FormAMemberSellerEditForm.get_current_setup = function () {
+                    return PopupPopupForm1FormAMemberSellerEditForm.setup['post'];
+                }
+
+                PopupPopupForm1FormAMemberSellerEditForm.check_file = function (file){
+                    const allowed_extensions = ['jpg', 'jpeg', 'png', 'bmp', 'webp'];
+                    const file_extension = file.name.split('.').pop().toLowerCase();
+
+                    if (!allowed_extensions.includes(file_extension)) {
+                        iziToast.error({
+                            title: 'Error',
+                            message: '이미지파일만 가능합니다.',
+                        });
+                        input_box_reset_for('#member-company-form');
+                        return;
+                    }
+                }
+
+                PopupPopupForm1FormAMemberSellerEditForm.change_file_url = async function (file_name, input) {
+                    console.log('change_file_url : ', file_name);
+                    console.log('change_file_url : ', input);
+                    const setup = await PopupPopupForm1FormAMemberSellerEditForm.get_setup()
+                    input.val(get_curr_setup_file_path(setup, file_name))
+                }
+
+                PopupPopupForm1FormAMemberSellerEditForm.file_upload = async function (file, input){
+                    PopupPopupForm1FormAMemberSellerEditForm.check_file(file);
+                    if (isEmpty(file)) {
+                        input_box_reset_for('#member-company-form')
+                        return;
+                    }
+                    const original_file_path = input.val();
+                    await PopupPopupForm1FormAMemberSellerEditForm.change_file_url(file.name, input);
+                    const id = Number($('#member-company-form').find('#Id').val())
+                    const mediaValue = input.val();
+                    const media = await PopupPopupForm1FormAMemberSellerEditForm.get_media_data(mediaValue);
+
+                    // 화열 선택을 했을 때 파일존재 여부 체크
+                    if (! isEmpty(file)) {
+                        // $('.media-btn-group button').prop('disabled', true);
+                        const response = await axios.post('/file-exists', {file_path: media['path'] + media['name']});
+                        console.log('response : ', response);
+                        // $('.media-btn-group button').prop('disabled', false);
+                        if (response.data) {
+                            const split_media_name = media['name'].split('.')
+                            const change_file_name = media['path'] + split_media_name[0] + '-change.' + split_media_name[1]
+
+                            $('#media-form').find('#file-url-txt').focus()
+
+                            iziToast.error({
+                                title: 'Error',
+                                message: `화일주소에 화일이 존재합니다. 저장을 원하시면 화일주소 입력창에서 ${media['name']} 이름을 직접 변경해주세요. Ex: ${change_file_name}`,
+                            });
+                            return;
+                        }
+                    }
+
+
+                    let formData = new FormData();
+                    formData.append('_token', $('meta[name="csrf-token"]').attr('content'))
+                    formData.append('file', file);
+                    formData.append('media', JSON.stringify(media));
+
+                    $.ajax({
+                        url: "/file-upload",
+                        type:'POST',
+                        data: formData,
+                        processData: false,
+                        contentType: false,
+                        success: function(data) {
+                            // console.log('upload succes : ', data);
+                            PopupPopupForm1FormAMemberSellerEditForm.callback_success(original_file_path)
+
+                        },
+                        error: function(jqXHR, textStatus, errorThrown) {
+                            console.error(jqXHR.responseText);
+                            iziToast.error({
+                                title: 'Error',
+                                message: '파일 업로드 중 오류가 발생했습니다: ' + errorThrown,
+                            });
+                        }
+                    });
+                }
+
+                PopupPopupForm1FormAMemberSellerEditForm.callback_success = function (filePath) {
+                    // const test = PopupPopupForm1FormAMemberSellerEditForm.get_file_path_list(mediaValue)
+                    console.log('filePath : ', filePath);
+                    PopupPopupForm1FormAMemberSellerEditForm.delete_file(filePath)
+                    // const file_delete = await call_local_api('/file-delete', {
+                    //     file_path_list: filePath
+                    // })
+                    // $('#pace-progress-panel').attr('hidden', true)
+                    iziToast.success({
+                        title: 'Success', message: $('#action-completed').text(),
+                    });
+                }
+
+                PopupPopupForm1FormAMemberSellerEditForm.delete_file = function (filePath) {
+                    if (!confirm(`${filePath} 이전 파일을 삭제합니다.`)) {
+                        return;
+                    }
+                    $.ajax({
+                    url: "/file-delete",
+                    type: 'POST',
+                    data: {
+                        _token: $('meta[name="csrf-token"]').attr('content'),
+                        file_path_list: JSON.stringify([filePath])
+                    },
+                    success: function(response) {
+                        // $(`#file-row${safeFileName}`).remove();
+                        // PopupPopupForm1FormAMemberSellerEditForm.file_list();
+                        iziToast.success({
+                            title: 'Success', message: '이전파일이 삭제되었습니다.',
+                        });
+                    },
+                    error: function(error) {
+                        console.log(error.responseJSON)
+                        iziToast.error({
+                            title: 'Error', message: '파일 삭제에 실패했습니다.',
+                        });
+                    }
+                });
+
+                }
+
                 PopupPopupForm1FormAMemberSellerEditForm.companyParameter = function () {
                     const member_company_form = $('#member-company-form')
                     let id = Number($(member_company_form).find('#BuyerId').val());
                     let parameter = {
                         Id: id,
                         CompanyName: $(member_company_form).find('#company-name-txt').val(),
+                        BankName: $(member_company_form).find('#bank-name-txt').val(),
+                        AccountNo: $(member_company_form).find('#account-no-txt').val(),
+                        HolderName: $(member_company_form).find('#holder-name-txt').val(),
+                        AccountImg: $(member_company_form).find('#bank-account-img-txt').val(),
                     }
 
                     console.log(parameter)
@@ -215,19 +398,19 @@
 
                     const member_ext = member_ext_page.data.Page[0]
                     const company = company_page.data.Page[0]
-
+                    console.log('company : ', company);
                     $(member_company_form).find('#Id').val(member.Id)
                     $(member_company_form).find('#BuyerId').val(member.BuyerId)
                     $(member_company_form).find('#company-name-txt').val(company.CompanyName)
                     $(member_company_form).find('#email-txt').val(member.Email)
                     $(member_company_form).find('#mobile-no-txt').val(member_ext.MobileNo)
-                    $(member_company_form).find('#bank-name-txt').val(member_ext.BankName)
-                    $(member_company_form).find('#account-no-txt').val(member_ext.BankAccountNo)
-                    $(member_company_form).find('#holder-name-txt').val(member_ext.AccountHolder)
+                    $(member_company_form).find('#bank-name-txt').val(company.BankName)
+                    $(member_company_form).find('#account-no-txt').val(company.AccountNo)
+                    $(member_company_form).find('#holder-name-txt').val(company.HolderName)
                     $(member_company_form).find('#ssn1-txt').val(member_ext.Ssn1)
                     $(member_company_form).find('#ssn2-txt').val(member_ext.Ssn2)
                     $(member_company_form).find('#ssn-card-img-txt').val(member_ext.SsnCardImg)
-                    $(member_company_form).find('#bank-account-img-txt').val(member_ext.BankAccountImg)
+                    $(member_company_form).find('#bank-account-img-txt').val(company.AccountImg)
                 }