From 13a9152564983b787067df8bbe5b5fc99ddfc450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=98=89=E7=A5=A5=20=E8=A9=B9?= Date: Tue, 20 Aug 2024 19:09:28 +0800 Subject: [PATCH] updates --- Views/Home/ModalList.cshtml | 61 ++++ wwwroot/assets/javascript/custom/modallist.js | 327 ++++++++++++++++++ 2 files changed, 388 insertions(+) diff --git a/Views/Home/ModalList.cshtml b/Views/Home/ModalList.cshtml index a2d41333..91714695 100644 --- a/Views/Home/ModalList.cshtml +++ b/Views/Home/ModalList.cshtml @@ -377,6 +377,8 @@ + +
+
+ + +
+
\ No newline at end of file diff --git a/wwwroot/assets/javascript/custom/modallist.js b/wwwroot/assets/javascript/custom/modallist.js index 1c4dc5ca..c145b715 100644 --- a/wwwroot/assets/javascript/custom/modallist.js +++ b/wwwroot/assets/javascript/custom/modallist.js @@ -8,6 +8,15 @@ var modelQuotationRowID; var mainItem_items = []; var mainItem_map = {}; + +var subItem_items = []; +var subItem_map = {}; + +var deledMainItems = []; +var deledSubItems = []; + +var preSubItem_name = ''; + $(document).ready(function () { deptList(); loadModelQuotationDataTable(); @@ -16,13 +25,160 @@ $(document).ready(function () { $('#dt-responsive').DataTable().ajax.reload(); }); + //新增次項目對話框儲存鈕 + $('#modelSubItemDialogSaveBtn').on('click', function () { + var method = $('#modelSubItem_method').val(); + var subItem_uid = $('#modelSubItem_uid').val(); + var modelSubItem_uid = $('#parent_Item_uid').val(); + var modelSubItem_name = $('#modelSubItem_name').val(); + var modelSubItem_descript = $('#modelSubItem_descript').val(); + var modelSubItem_price = $('#modelSubItem_price').val(); + var modelSubItem_unitType = $('#modelSubItem_unitType').val(); + var modelSubItem_number = $('#modelSubItem_number').val(); + var modelSubItem_hasAC = 'N'; + var parent_data_uid = $('#model_parent_data_uid').val(); + + if ($('#modelSubItem_hasAC').prop("checked")) { + modelSubItem_hasAC = 'Y'; + } else { + modelSubItem_hasAC = 'N'; + } + + var msg = ''; + + if (modelSubItem_price == '') { + msg += '請輸入單價!\n'; + } else { + if (modelSubItem_price.isNumber() == false) { + msg += '單價必須為數字!\n'; + } + } + + if (modelSubItem_number == '') { + msg += '請輸入數量!\n'; + } else { + if (modelSubItem_number.isNumber() == false) { + msg += '數量必須為數字!\n'; + } + } + + if (msg != '') { + alert(msg); + return; + } + + var modelSubItem_subTotal = modelSubItem_price * modelSubItem_number; + + + + if (method == 'add') { + var datauid = Math.floor(Math.random() * 999999999); + var htmlCode = ''; + + htmlCode += '
  • '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += '
    '; + htmlCode += '
    '; + htmlCode += '
    '; + htmlCode += ' '; + htmlCode += '
    '; + htmlCode += '
    '; + htmlCode += '
    '; + htmlCode += '

    '; + htmlCode += ' ' + modelSubItem_name + '\r\n'; + htmlCode += '


    '; + htmlCode += '

    '; + htmlCode += ' ' + modelSubItem_descript + '\r\n'; + htmlCode += '


    '; + htmlCode += '

    '; + htmlCode += ' 單價 NT$' + AppendComma(modelSubItem_price) + ', 數量 ' + modelSubItem_number + ', 單位 ' + modelSubItem_unitType + '\r\n'; + htmlCode += ' 小計 NT$' + AppendComma(modelSubItem_subTotal) + '\r\n'; + htmlCode += ' AC(' + modelSubItem_hasAC + ')'; + htmlCode += '

    '; + htmlCode += '
    '; + htmlCode += '
    '; + htmlCode += '
    '; + htmlCode += '
    '; + htmlCode += ' '; + htmlCode += '
    '; + htmlCode += '
    '; + htmlCode += '
  • '; + + var htmlObj = $('#modelItem_div').find('[data-uid="' + parent_data_uid + '"]').find('ol'); + + //var htmlObj = $('#' + parent_data_uid).find('ol'); + htmlObj.append(htmlCode); + + $('#modelSubItemModal').modal('toggle'); + } + + }); + //新增主項目對話框儲存鈕 $('#modelMainItemDialogSaveBtn').on('click', function () { + var modelMainItem_uid = $('#modelMainItem_uid').val(); + var mainItem_uid = $('#parent_mainItem_uid').val(); + var method = $('#modelMainItem_method').val(); + var modelMainItem_name = $('#modelMainItem_name').val(); + if (modelMainItem_name == "") { + alert('主項目名稱不得為空白!'); + return; + } + + if (method == 'edit') { + var obj = $('#modelItem_div').find("[data-uid='" + modelMainItem_uid + "']"); + $(obj).prop('data-main-uid', mainItem_uid); + $(obj).find("[data-name='mainItem_name']").val(modelMainItem_name); + $(obj).find("[data-span='mainItem_name']").text(modelMainItem_name); + + $('#modelMainItemModal').modal('toggle'); + } + + if (method == 'add') { + var datauid = Math.floor(Math.random() * 99999999); + + var htmlCode = ''; + htmlCode += ''; + htmlCode += '
    '; + htmlCode += '
    '; + htmlCode += ' '; + htmlCode += ' ' + modelMainItem_name + ''; + htmlCode += '
    '; + htmlCode += ' '; + htmlCode += '
    '; + htmlCode += ' '; + htmlCode += '
    '; + htmlCode += ' '; + htmlCode += '
      '; + htmlCode += ' '; + htmlCode += '
    '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += '
    '; + + $('#modelItem_div').append(htmlCode); + + $('#modelMainItemModal').modal('toggle'); + } + + }); //新增主項目鈕 $('#addModelMainItemBtn').on('click', function () { + + $('#modelMainItem_name').typeahead('destroy'); loadMainItemTypeahead(); @@ -32,6 +188,9 @@ $(document).ready(function () { //新增報價單範本視窗 $('#modelQuotationListNewBtn').on('click', function () { + deledMainItems = []; + deledSubItems = []; + $('#clientModelQuotationPreviewModal').modal('toggle'); }); @@ -101,6 +260,167 @@ $(document).ready(function () { }); }); +function addSubItem(obj) { + var modelMainItem_uid = $(obj).parent().parent().attr("data-uid"); + var modelMainItem_name = $(obj).parent().parent().find("[data-name='mainItem_name']").val(); + var parent_mainItem_uid = $(obj).parent().parent().attr("data-main-uid"); + + $('#modelSubItem_name').typeahead('destroy'); + + loadSubItemTypeahead(parent_mainItem_uid); + + + $('#modelSubItem_method').val('add'); + $('#modelSubItem_uid').val(''); + $('#parent_Item_uid').val(''); + $('#model_parent_data_uid').val(modelMainItem_uid); + + $('#modelSubItem_hasAC').prop("checked", "checked").trigger("change"); + + $('#modelSubItemModal').modal('toggle'); +} + +function delModelMainItem(obj) { + if (confirm('確定刪除此主項目資料? 所有子項目也會一併刪除~')) { + if (confirm('再次確認是否刪除所有此項目與子項目?')) { + var modelMainItem_uid = $(obj).parent().parent().parent().attr("data-uid"); + + var delItem = { + modelMainItem_uid: modelMainItem_uid + } + + deledMainItems.push(delItem); + + $(obj).parent().parent().parent().remove(); + + alert('預定刪除完成! 記得按下下方儲存鈕才是真的刪除喔~'); + } + } +} + +function editModelMainItem(obj) { + var modelMainItem_name = $(obj).parent().parent().find("[data-name='mainItem_name']").val(); + var parent_mainItem_uid = $(obj).parent().parent().parent().attr("data-main-uid"); + var modelMainItem_uid = $(obj).parent().parent().parent().attr("data-uid"); + $('#modelMainItem_name').typeahead('destroy'); + + loadMainItemTypeahead(); + $('#modelMainItem_method').val('edit'); + $('#modelMainItem_uid').val(modelMainItem_uid); + $('#modelMainItem_name').val(modelMainItem_name); + $('#parent_mainItem_uid').val(parent_mainItem_uid); + $('#modelMainItemModal').modal('toggle'); +} + +function loadSubItemTypeahead(mainItem_uid) { + var formData = { + dept_uid: $('#dept_select').val(), + mainItem_uid: mainItem_uid + } + + $.ajax({ + url: "/AuthApi/authSubItemList", + type: "post", + data: formData, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + var obj = data.subItems; + + subItem_items = []; + subItem_map = {}; + + $.each(obj, function (i, item) { + var id = item.subItem_uid; + var name = item.subItem_name; + var descript = item.subItem_descript; + var price = item.subItem_price; + var unitType = item.subItem_unitType; + + subItem_map[name] = { id: id, name: name, descript: descript, price: price, unitType: unitType }; + subItem_items.push(name); + }); + + var bh = new Bloodhound({ + local: subItem_items, + queryTokenizer: Bloodhound.tokenizers.whitespace, + datumTokenizer: Bloodhound.tokenizers.whitespace + }); + + var nflTeamsWithDefaults = function nflTeamsWithDefaults(q, sync) { + if (q === '') { + sync(bh.index.all()); + } else { + bh.search(q, sync); + } + }; + + $('#modelSubItem_name').typeahead( + { + minLength: 0, + highlight: false + }, + { + source: nflTeamsWithDefaults + } + + ); + + preSubItem_name = ''; + $('#modelSubItem_name').bind('typeahead:select', function (ev, suggestion) { + var modelSubItem_descript = $('#modelSubItem_descript').val(); + + if (preSubItem_name != '') { + if (suggestion != preSubItem_name) { + if (confirm('確定要用新項目覆蓋目前資料?')) { + $('#parent_Item_uid').val(subItem_map[suggestion].id); + preSubItem_name = suggestion; + + $('#modelSubItem_price').val(subItem_map[suggestion].price).trigger('change'); + $('#modelSubItem_unitType').val(subItem_map[suggestion].unitType).trigger('change'); + $('#modelSubItem_descript').val(subItem_map[suggestion].descript).trigger('change'); + } else { + $('#modelSubItem_name').typeahead('val', preSubItem_name); + //suggestion = preSubItem_name; + //$('#modelSubItem_name').val(preSubItem_name).trigger('change');; + } + } + } else { + $('#parent_Item_uid').val(subItem_map[suggestion].id); + preSubItem_name = suggestion; + + $('#modelSubItem_price').val(subItem_map[suggestion].price).trigger('change'); + $('#modelSubItem_unitType').val(subItem_map[suggestion].unitType).trigger('change'); + $('#modelSubItem_descript').val(subItem_map[suggestion].descript).trigger('change'); + + } + + + + console.log('Selection: ' + suggestion); + console.log('Selection key: ' + subItem_map[suggestion].id); + + }); + + //$('#modelMainItem_name').bind('typeahead:autocomplete', function (ev, suggestion) { + // console.log('Selection: ' + suggestion); + // console.log('Selection key: ' + mainItem_map[suggestion].id); + // $('#parent_mainItem_uid').val(mainItem_map[suggestion].id); + //}); + + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); +} + function loadMainItemTypeahead() { var formData = { dept_uid: $('#dept_select').val() @@ -152,6 +472,13 @@ function loadMainItemTypeahead() { $('#modelMainItem_name').bind('typeahead:select', function (ev, suggestion) { console.log('Selection: ' + suggestion); console.log('Selection key: ' + mainItem_map[suggestion].id); + $('#parent_mainItem_uid').val(mainItem_map[suggestion].id); + }); + + $('#modelMainItem_name').bind('typeahead:autocomplete', function (ev, suggestion) { + console.log('Selection: ' + suggestion); + console.log('Selection key: ' + mainItem_map[suggestion].id); + $('#parent_mainItem_uid').val(mainItem_map[suggestion].id); }); } else {