let category = document.getElementById("category-select"); let num = document.getElementById("num-select"); let productname = document.getElementById("productname-select"); let category_data = ""; let num_data = ""; let productname_data = ""; let productname_data_infos = ""; let basic_repair = document.getElementById("basic_repair"); // 通常製品時の修理料金表 let send_repair = document.getElementById("send_repair"); // 送込み修理のみ対応時の表 let visit_repair = document.getElementById("visit_repair"); // 送込み修理と出張修理両方対応時の表 let parts_repair = document.getElementById("parts_repair"); // 部品代が別途必要な製品の修理料金表 let visitService = document.getElementById("visitService"); // 出張修理サービスの案内 let result_end = document.getElementById("result_end"); let result_no = document.getElementById("result_no"); let result_supportend = document.getElementById("result_supportend"); let result_price = document.getElementById("result_price"); function format_with_regex(number) { return !(number + '').includes('.') ? (number + '').replace(/\d{1,3}(?=(\d{3})+$)/g, (match) => { return match + ','; }) : (number + '').replace(/\d{1,3}(?=(\d{3})+(\.))/g, (match) => { return match + ','; }); } function showResult(obj, isShow) { isShow ? (obj.classList.remove('tag_hide'), obj.classList.add('tag_display')) : (obj.classList.remove('tag_display'), obj.classList.add('tag_hide')) } async function setSelectOption(select_num, selected_key, select_obj) { let filename = ""; let data = ""; let isfetch = false; switch (select_num) { case 1: category_data == "" ? (isfetch = true, filename = "TypeNum1.json") : data = category_data; break; case 2: num_data == "" ? (isfetch = true, filename = "TypeNum2.json") : data = num_data; break; case 3: productname_data == "" ? (isfetch = true, filename = "ProductName.json") : data = productname_data; break; } if (isfetch) { let current_domain = location.hostname; let protocol = location.protocol; let port = location.port && location.port != '80' ? ':' + location.port : ''; fetch(protocol + "//" + current_domain + port + "/-/media/cojp/product/support_info/json/repair_serv/ptouch/" + filename) .then((response) => response.json()) .then((data) => { addOption(select_num, selected_key, select_obj, data); }).catch((error) => console.error(error)); } else { addOption(select_num, selected_key, select_obj, data); } } function addOption(select_num, selected_key, select_obj, data) { let option_groups = data.option_groups; let option_group = null; if (select_num == 1) { option_group = option_groups; } else { option_group = option_groups.filter((value) => { return value.option_parent === selected_key; }); } let options = option_group[0].options; options.forEach(option => { select_obj.add(new Option(option.value, option.key)); }); if (select_num == 3) { productname_data_infos = options; } } function initSelectObj(n) { if (n == 0) { category.options.length = 0; category.add(new Option("--", "00", true)); // 型番内容の設定 setSelectOption(1, "", category) } if (n == 0 || n == 1) { num.options.length = 0; num.add(new Option("項目1回答後、ご選択ください", "00_00", true)); } if (n == 0 || n == 1 || n == 2) { productname.options.length = 0; productname.add(new Option("項目1,2回答後、ご選択ください", "00_00_00", true)); } showResult(result_end, false); showResult(result_no, true); showResult(result_supportend, false); showResult(result_price, false); showResult(visitService, false); } document.addEventListener("DOMContentLoaded", (event) => { // 初期設定 initSelectObj(0); // changeイベントリスナー category.addEventListener("change", (e) => { initSelectObj(1); let index = e.target.selectedIndex; let key = e.target.options[index].value; setSelectOption(2, key, num); }); num.addEventListener("change", (e) => { initSelectObj(2); let index = e.target.selectedIndex; let key = e.target.options[index].value; setSelectOption(3, key, productname); }); productname.addEventListener("change", (e) => { initSelectObj(3); let index = e.target.selectedIndex; let key = e.target.options[index].value; let option = productname_data_infos.filter((value) => { return value.key === key; }) let info = option[0].info; // 修理が終了している場合は、終了している旨のメッセージだけ表示 if (info.period == "end") { showResult(result_end, false); showResult(result_no, false); showResult(result_supportend, true); showResult(result_price, false); showResult(visitService, false); // 修理がまだ続いている場合は、料金一覧表を表示 } else { let a = document.getElementsByClassName("repair_cost_a"); // 調整のみ(★基本工賃) let b = document.getElementsByClassName("repair_cost_b"); // 一般部品交換修理 let c = document.getElementsByClassName("repair_cost_c"); // 特定部品交換修理 let d = document.getElementsByClassName("repair_cost_d"); // 出張費 let e = document.getElementsByClassName("repair_cost_e"); // 送料 let f = document.getElementsByClassName("repair_cost_f"); // 合計額:調整のみ(引取)(★送込修理合計額) let g = document.getElementsByClassName("repair_cost_g"); // 合計額:一般部品交換修理(引取) let h = document.getElementsByClassName("repair_cost_h"); // 合計額:特定部品交換修理(引取) let i = document.getElementsByClassName("repair_cost_i"); // 合計額:調整のみ(出張)(★出張修理合計額) let j = document.getElementsByClassName("repair_cost_j"); // 合計額:一般部品交換修理(出張) let k = document.getElementsByClassName("repair_cost_k"); // 合計額:特定部品交換修理(出張) if (info.RepairType == "typeC") { a[0].innerHTML = a[1].innerHTML = a[2].innerHTML = a[3].innerHTML = info.RepairCostA == "対象外" || info.RepairCostA == "サポート終了" ? info.RepairCostA : "¥" + format_with_regex(parseInt(info.RepairCostA)).toString() + "+部品代"; } else { a[0].innerHTML = a[1].innerHTML = a[2].innerHTML = a[3].innerHTML = info.RepairCostA == "対象外" || info.RepairCostA == "サポート終了" ? info.RepairCostA : "¥" + format_with_regex(parseInt(info.RepairCostA)).toString(); } b[0].innerHTML = b[1].innerHTML = info.RepairCostB == "対象外" || info.RepairCostB == "サポート終了" ? info.RepairCostB : "¥" + format_with_regex(parseInt(info.RepairCostB)).toString(); c[0].innerHTML = c[1].innerHTML = info.RepairCostC == "対象外" || info.RepairCostC == "サポート終了" ? info.RepairCostC : "¥" + format_with_regex(parseInt(info.RepairCostC)).toString(); d[0].innerHTML = d[1].innerHTML = d[2].innerHTML = d[3].innerHTML = info.travelexpenses == "対象外" ? info.travelexpenses : "¥" + format_with_regex(parseInt(info.travelexpenses)).toString(); info.travelexpenses; e[0].innerHTML = e[1].innerHTML = e[2].innerHTML = e[3].innerHTML = e[4].innerHTML = e[5].innerHTML = info.shipping == "対象外" ? info.shipping : "¥" + format_with_regex(parseInt(info.shipping)).toString(); info.shipping; if (info.RepairType == "typeC") { f[0].innerHTML = f[1].innerHTML = f[2].innerHTML = f[3].innerHTML = f[4].innerHTML = f[5].innerHTML = info.SumCostA == "対象外" || info.SumCostA == "サポート終了" ? info.SumCostA : "¥" + format_with_regex(parseInt(info.SumCostA)).toString() + "+部品代"; } else { f[0].innerHTML = f[1].innerHTML = f[2].innerHTML = f[3].innerHTML = f[4].innerHTML = f[5].innerHTML = info.SumCostA == "対象外" || info.SumCostA == "サポート終了" ? info.SumCostA : "¥" + format_with_regex(parseInt(info.SumCostA)).toString(); } g[0].innerHTML = g[1].innerHTML = g[2].innerHTML = g[3].innerHTML = info.SumCostB == "対象外" || info.SumCostB == "サポート終了" ? info.SumCostB : "¥" + format_with_regex(parseInt(info.SumCostB)).toString(); h[0].innerHTML = h[1].innerHTML = h[2].innerHTML = h[3].innerHTML = info.SumCostC == "対象外" || info.SumCostC == "サポート終了" ? info.SumCostC : "¥" + format_with_regex(parseInt(info.SumCostC)).toString(); if (info.RepairType == "typeC") { i[0].innerHTML = i[1].innerHTML = i[2].innerHTML = i[3].innerHTML = info.SumTCostA == "対象外" || info.SumTCostA == "サポート終了" ? info.SumTCostA : "¥" + format_with_regex(parseInt(info.SumTCostA)).toString() + "+部品代"; } else { i[0].innerHTML = i[1].innerHTML = i[2].innerHTML = i[3].innerHTML = info.SumTCostA == "対象外" || info.SumTCostA == "サポート終了" ? info.SumTCostA : "¥" + format_with_regex(parseInt(info.SumTCostA)).toString(); } j[0].innerHTML = j[1].innerHTML = info.SumTCostB == "対象外" || info.SumTCostB == "サポート終了" ? info.SumTCostB : "¥" + format_with_regex(parseInt(info.SumTCostB)).toString(); k[0].innerHTML = k[1].innerHTML = info.SumTCostC == "対象外" || info.SumTCostC == "サポート終了" ? info.SumTCostC : "¥" + format_with_regex(parseInt(info.SumTCostC)).toString(); showResult(result_end, false); showResult(result_no, false); showResult(result_supportend, false); showResult(result_price, true); } // 修理タイプによって表示項目を変更 if (info.RepairType == "typeA") { showResult(parts_repair, false); showResult(basic_repair, true); showResult(send_repair, true); showResult(visit_repair, false); showResult(visitService, false); } else if (info.RepairType == "typeB") { showResult(parts_repair, false); showResult(basic_repair, true); showResult(send_repair, false); showResult(visit_repair, true); showResult(visitService, true); } else if (info.RepairType == "typeC") { showResult(parts_repair, true); showResult(basic_repair, false); showResult(send_repair, false); showResult(visit_repair, false); showResult(visitService, true); } else { showResult(visitService, false); } // 修理サービスの終了が近づいているとき if (info.period == "soon") { showResult(result_end, true); } }); });