var csrfToken = "58428d89291d8252ffc1d6d64abed461fa42566cfb6cba411e678c6b56e62192"; var store = { inquiry_name : "", inquiry_yomi : "", inquiry_email : "", inquiry_confirmationemail: "", inquiry_tel : "", inquiry_company : "", inquiry_company_tel : "", inquiry_zip : "", inquiry_pref : "", inquiry_city : "", inquiry_street : "", inquiry_bldg : "", inquiry_msg : "" }; var ViewMode = { EDIT: "edit", CONF: "conf", WAIT: "wait" }; var prefs = "北海道,青森県,岩手県,宮城県,秋田県,山形県,福島県,茨城県,栃木県,群馬県,埼玉県,千葉県,東京都,神奈川県,山梨県,新潟県,富山県,石川県,福井県,長野県,岐阜県,静岡県,愛知県,三重県,滋賀県,京都府,大阪府,兵庫県,奈良県,和歌山県,鳥取県,島根県,岡山県,広島県,山口県,徳島県,香川県,愛媛県,高知県,福岡県,佐賀県,長崎県,熊本県,大分県,宮崎県,鹿児島県,沖縄県".split( "," ); new Vue({ el: "#wrapper", data: { store: store, viewMode: ViewMode.EDIT, prefs: prefs, validator: null, noVlidationTargets: [ "inquiry_bldg" ], }, mounted: function() { this.validator = new Validator( this.store, this.noVlidationTargets ); }, methods: { // -------------------------------------------- // Validation // -------------------------------------------- validation: function() { if( this.validator.validation() ) { this.showConf(); return; } return false; }, valueChange: function() { this.validator.clearAllValidity(); }, // -------------------------------------------- // Page // -------------------------------------------- showEdit: function() { console.log( "EDIT" ); this.scrollToTop(); this.viewMode = ViewMode.EDIT; }, showConf: function() { console.log( "CONF" ); this.scrollToTop(); this.viewMode = ViewMode.CONF; }, showWait: function() { console.log( "WAIT" ); this.scrollToTop(); this.viewMode = ViewMode.WAIT; this.entry(); }, // ---------------------------------------------------- // Entry // ---------------------------------------------------- entry: function() { var _this = this; var fd = new FormData(); fd.append( "data", JSON.stringify( this.store ) ); fd.append( "csrfToken", csrfToken ); // @see form.php axios.post( 'apis/entry_form/send_data_2022_1_2.php', fd ) .then( function( resp ) { console.log( "ENTRY FINISH", resp ); if( ! resp.data.status ) { alert( resp.data.error ); if( resp.data.code == "csrf" ) { // 対CSRFトークン検証違反:トップに移動 location.href = "./lectureship_1_2.html"; return; } else if( resp.data.code == "send-fail-admin" ) { // 管理メール送信エラー:確認ページに移動 _this.showConf(); return; } else if( resp.data.code == "send-fail-user" ) { // ユーザーメール送信エラー:入力フォームに移動 _this.showEdit(); return; } // その他のエラー:確認ページに移動 _this.showConf(); return; } // 正常終了:Thanksページに移動 location.href = "lectureship_1_2_thanks.html"; }) .catch( function( error ) { console.log( "Ajax error:", error ) }); }, // -------------------------------------------- // Utils // -------------------------------------------- scrollToTop: function() { var offset = $( "#content div.main_content" ).offset(); window.scrollTo( 0, offset.top ); }, multiLineStr: function( str ) { return str .replace( /&/g, '&') .replace( //g, '>') .replace( /"/g, '"') .replace( /'/g, ''') .replace( /[\\n]/g, "
" ); }, toHankaku: function( val ) { return val == "" ? "" : ( val.replace( /[!-~]/g, function(s) { return String.fromCharCode(s.charCodeAt(0) - 0xFEE0); } ) ); }, zipUpdate: function() { this.store.inquiry_zip = this.toHankaku( this.store.inquiry_zip ); var zipArray = this.store.inquiry_zip.match( /^([0-9]{3})-?([0-9]{4})$/ ); if( ! zipArray || zipArray.length < 3 ) { return; } var _this = this; axios.get( 'https://madefor.github.io/postal-code-api/api/v1/' + zipArray[ 1 ] + "/" + zipArray[ 2 ] + ".json" ) .then( function( resp ) { console.log( "RESP ADDRESS", resp ); if( resp.status != "200" ) { // alert( "申し訳ございません。郵便番号から住所が特定できませんでした。\\n手動にて住所の入力をしてください。" ); return; } var d = resp.data.data[ 0 ].ja; _this.store.inquiry_pref = d.prefecture; _this.store.inquiry_city = d.address1; _this.store.inquiry_street = d.address2; }) .catch( function( error ) { console.log( "Ajax error:", error ); }); }, }, computed: { isEditMode: function() { return this.viewMode === ViewMode.EDIT; }, isConfMode: function() { return this.viewMode === ViewMode.CONF; }, isWaitMode: function() { return this.viewMode === ViewMode.WAIT; }, mainContentClass: function() { return this.viewMode === ViewMode.WAIT ? "main_content main-wait" : "main_content"; }, } });