PageSourceSearch

https://luckyway.com.hk/ClientResources/Script/regnpay-2.0.js

js luckyway.com.hk collected 2026-10-09 00:06:42 UTC 35,555 bytes, 907 lines download raw bytes

1/*
2 * 用于前台regnpay
3 * Edition:2019-12-4
4 * By JOJO
5 * 
6 * var jsData = {
7            id: '@ViewBag.id',
8            returnUrl: '@WS.Utility.PathUtil.GetSiteRoot()',
9            IsLogin: '@ViewBag.IsLogin',
10            IsMobile: false,
11            HasPreview: true,
12            UploadButtonText: "Upload files(jpg, png, pdf)",
13            UploadingText: "Uploading...",
14            UploadSuccessfulText: "Upload Successful",           
15            UploadFailText: "上传失败",
16            NoFileText: "没有选中文件",
17            UploadLengthText: "最多只能上传{0}个文件",
18            UploadSizeText: "最多只能上传{0}个文件",
19            BackText: "返回",
20            ConfirmText: "确认",
21            PleaseSelect:"请选择",
22            Version:"1.0"or"2.0",
23            HasRNPConfirm:true,
24            FormatErrorText:"格式错误",
25            RequiredText: "必填",
26            PreviewTitleText:"請再次確認頁面",
27    }
28 */
29var _jsData = {
30    id: "",
31    returnUrl:"",
32    IsLogin: false,
33    IsMobile: false,
34    HasPreview: true,
35    Version: "1.0",
36    HasRNPConfirm: false,
37    UploadButtonText: "點擊上傳文件",
38    UploadingText: "上傳中……",
39    UploadSuccessfulText: "上傳成功",
40    UploadFailText: "上傳失敗",
41    NoFileText: "抱歉,您沒有選擇文件",
42    UploadLengthText: "抱歉,最多只能上傳{0}個文件",
43    UploadSizeText: "抱歉,最多只能上傳{0}的文件",
44    BackText: "返回",
45    ConfirmText: "確認",
46    PleaseSelect: "請選擇",
47    FormatErrorText: "格式錯誤,請檢查",
48    RequiredText: "必填", 
49    PreviewTitleText: "請再次確認頁面",
50}
51function save(tag) {
52    var content = $(tag).parents("#content:first");
53    if (checkForm(content) === true) {
54        if (jsData.HasPreview) {
55            preview(content);
56        }
57        else {
58            if (jsData.HasRNPConfirm) {
59                rnpConfirm(content);
60            }
61            else {
62                confirm(content);
63            }
64           
65        }
66    }
67}
68function uploadFile(id) {
69    var file = $("#" + id);
70    var length = file[0].files.length;
71    var size = file[0].files.size;
72    var maxLength = file.data("maxl");
73    var maxSize = Number(file.data("maxs")) * 1024 * 1024;
74    var lis = $("#" + id).parent().find('.box').find("li");
75    var tempLength = lis.length;
76    var tempSize = 0;
77    var tempHtml = "";
78    lis.each(function (i, li) {
79        tempSize += Number($(li).data("size"));
80    });
81    if (size + tempSize > maxSize) {
82        tempHtml = "<i class='uploadicon3'></i><span class='upload_text3'>" + String.format(jsData.UploadSizeText, maxSize) + "</span>";
83        $("#" + id).parent().find('.uploadMain').html(tempHtml);
84    }
85    else {
86        if (length + tempLength > maxLength) {
87            tempHtml = "<i class='uploadicon3'></i><span class='upload_text3'>" + String.format(jsData.UploadLengthText, maxLength) + "</span>";
88            $("#" + id).parent().find('.uploadMain').html(tempHtml);
89        }
90        else if (length > 0 && length + tempLength <= maxLength) {
91            $("#save").attr("disabled", true);
92            tempHtml = "<i class='uploadicon2'></i><span class='upload_text2'>" + jsData.UploadingText + "</span>";
93            $("#" + id).parent().find('.uploadMain').html(tempHtml);
94            var formData = new FormData();
95            var files = $("#" + id).get(0).files;
96            if (files.length > 0) {
97                for (var i = 0; i < files.length; i++) {
98                    formData.append(i,files[i]);
99                }
100            }
101            formData.append("key", jsData.id);
102            if (jsData.Version == "2.0") {
103                window.regAndPay.uploadMultiFile(formData).then(result => {
104                    updateFileResult(result.data, id, maxLength);
105                    file.val('');
106
107                });
108                //window.regAndPay.uploadMultiFile(formData, function (result) {
109                //    updateFileResult(result, id, maxLength);
110
111                //}, function () { });
112            }
113            else {
114                InstoreSdk.api.regnpay.uploadMultiFile(formData, function (result) {
115                    updateFileResult(result, id, maxLength);
116                    file.val('');
117                }, function () { });
118            }
119            
120        }
121        else if (length === 0) {
122            alert(jsData.NoFileText);
123        }
124       
125    }
126}
127function updateFileResult(result, id, maxLength) {
128    console.log("ok");
129    if (result.length > 0) {//上传成功
130        var htmlString = "";
131        $.each(result, function (i, val) {
132
133            htmlString += "<li class='pic' data-id='" + id + "' data-path='" + val.Path + "' data-size='" + val.Size + "'><span>" + val.OriginalName + "</span><span class='closeX'>刪除</span></li>";
134        });
135        $("#" + id).parent().find('.box').append(htmlString);
136        if ($("#" + id).parent().find('.box').find("li").length < maxLength) {
137            $("#" + id).parent().find('.uploadMain').html("<i class='uploadicon1'></i><span class='upload_text1' >" + jsData.UploadButtonText + "</span > ");
138        }
139        else {
140            // $("#" + id).parent().find('.uploadMain').css("display", "none;");
141            $("#" + id).parent().find('.uploadMain').html("<span class='upload_text2'>" + jsData.UploadSuccessfulText + "</span>");
142        }
143    } else {
144        alert(jsData.UploadFailText);
145    }
146    $("#save").removeAttr("disabled");
147}
148function ActivateRequired(tag, num, bool) {
149    var _this = $(tag).parents(".form-group ");
150    for (var i = 0; i < num; i++) {
151        if (bool === 1) {
152            _this.next().addClass("required");
153            _this.next().children(".control-label").append("<span style='color:red;'> *</span>");
154        }
155        else {
156            _this.next().removeClass("required");
157            _this.next().children(".control-label").find('span').remove();
158        }
159        _this = _this.next();
160    }
161}
162function getMinPriceTotal() {
163    var qty = 1;
164    var price = parseFloat('0.00');
165    if (!isNaN(parseFloat($('#minPrice').html()))) {
166        price = parseFloat($('#minPrice').html());
167    }
168    if (!isNaN(Number($('#totalQty').val()))) {
169        price = Number($('#totalQty').val());
170    }
171    return qty * price;
172}
173function getPrice() {
174    var total = getMinPriceTotal();
175    var obj = $(".pay").find(":checked");
176    obj.each(function (i, item) {
177        var id = $(item).data("id");
178        var num = $('#qty_' + id);
179        var qty = Number(num.val());
180        if (isNaN(qty) || qty == 0) {
181            qty = Number(num.attr("min"));
182            if (isNaN(qty)) {
183                qty = 1;
184            }
185            num.val(qty);
186        }
187        var id = $(item).data("id");
188        var price = parseFloat($(item).data("price"));
189        if (price < 0) {
190            price = 0;
191        }
192        total = accAdd(total, parseFloat(price * qty));
193    });
194    var rebate = parseFloat($('#discount').data("rebate"));
195    if (rebate > 0) {
196        var discount = 0;
197        var isPer = $('#discount').data("isper");
198        var meetAmount = parseFloat($('#discount').data("meetamount"));
199        if (total > meetAmount) {
200            if (isPer === "true") {
201                discount = total * rebate / 100;
202            }
203            else {
204                var noLimit = $('#discount').data("nolimit");
205                if (noLimit === "False") {
206
207                    discount = rebate;
208                }
209                else {
210                    discount = parseInt(total / meetAmount) * rebate;
211                }
212            }
213            total = total - discount;
214        }
215        $('#discount').html(discount);
216    }
217    $('#total').html(total);
218}
219function getScore() {
220    var total = 0;
221    $("select option:selected").each(function (i, option) {
222        if ($(option).data("score") != undefined) {
223            total = total + parseFloat($(option).data("score"));
224        }
225
226    });
227    $(".radio").find(":checked").each(function (i, checked) {
228        total = total + parseFloat($(checked).data("score"));
229    });
230    $(".checkbox").find(":checked").each(function (i, checked) {
231        total = total + parseFloat($(checked).data("score"));
232    });
233    $(".radio_qty").find(":checked").each(function (i, checked) {
234        var num = $('#qty_' + id);
235        var qty = Number(num.val());
236        if (isNaN(qty) || qty == 0) {
237            qty = Number(num.attr("min"));
238            num.val(qty);
239        }
240        total = total + parseFloat($(checked).data("score")) * qty;
241    });
242    $(".checkbox_qty").find(":checked").each(function (i, checked) {
243        var num = $('#qty_' + id);
244        var qty = Number(num.val());
245        if (isNaN(qty) || qty == 0) {
246            qty = Number(num.attr("min"));
247            num.val(qty);
248        }
249        total = total + parseFloat($(checked).data("score")) * qty;
250    });
251    $(".radio_nest_panel").children(".option").find(":checked").each(function (i, checked) {
252        total = total + parseFloat($(checked).data("score"));
253    });
254    $(".checkbox_nest_panel").children(".option").find(":checked").each(function (i, checked) {
255        total = total + parseFloat($(checked).data("score"));
256    });
257    $('#score').data("total", total);
258    $('#score').html(total);
259}
260function checkForm(content) {
261   
262    var check = true;
263    var requireds = $(content).find('#Anwers:first').find('.required');
264    requireds.each(function (i, required) {
265        var fieldset = $(required).find('.fieldset').first();
266        if ($(fieldset).hasClass('text') || $(fieldset).hasClass('email') || $(fieldset).hasClass('date') || $(fieldset).hasClass("textWithDropdown")) {
267            if ($(fieldset).find('input').val() === '') {
268                errmsg = jsData.RequiredText;
269                $(fieldset).next().text(errmsg);
270                if (check) {
271                    check = false;
272                    $(fieldset).find('input').focus();
273                }
274            }
275            
276        }
277        else if ($(fieldset).hasClass("files") || $(fieldset).hasClass("images")) {
278            var lis = $(fieldset).find('.box li');
279            if (lis.length < 1) {
280                errmsg = jsData.RequiredText;
281                $(fieldset).next().text(errmsg);
282                if (check) {
283                    check = false;
284                    $(window).scrollTop($(fieldset).parent().offset().top - $(fieldset).parent().height());
285                }
286            }
287        }
288        else if ($(fieldset).hasClass('dropdown')) {
289            if ($(fieldset).find('select').val() === '') {
290                errmsg = jsData.RequiredText;
291                $(fieldset).next().text(errmsg);
292                if (check) {
293                    check = false;
294                    $(window).scrollTop($(fieldset).parent().offset().top - $(fieldset).parent().height());
295                }
296            }
297        }
298        else if ($(fieldset).hasClass("textarea")) {
299            if ($(fieldset).children("textarea").val() === '') {
300                errmsg = jsData.RequiredText;
301                $(fieldset).next().text(errmsg);
302                if (check) {
303                    check = false;
304                    $(fieldset).find('input').focus();
305                }
306            }
307        }
308        else if ($(fieldset).hasClass('multi_connected_dropdown')) {
309            $(fieldset).find('select').each(function (i, dropdown_op) {
310                if ($(dropdown_op).val() == '0') {
311                    errmsg = jsData.RequiredText;
312                    $(fieldset).next().text(errmsg);
313                    if (check) {
314                        check = false;
315                        $(window).scrollTop($(fieldset).prev().offset().top);
316                    }
317                }
318
319            });
320        }
321        else {
322            checked = false;
323            var name = $(fieldset).find('input').first().val();
324            $('input[name=' + name + ']').each(function () {
325                if ($(this).is(':checked')) {
326                    checked = true;
327                }
328            });
329            if (!checked) {
330                errmsg = jsData.RequiredText;
331                $(fieldset).next().text(errmsg);
332                if (check) {
333                    check = false;
334                    $(window).scrollTop($(fieldset).parent().offset().top - $(fieldset).parent().height());
335                }
336            }
337        }
338    });
339    if ($("#Signature").length > 0) {
340        saveSign();
341        if ($(Signature).attr("src") == "") {
342            $("#Sign").addClass("focus");
343            if (check) {
344                check = false;
345                $("#Sign").focus();
346            }
347            
348        }
349    }
350    var errors = $(content).find('p[name=error]');
351    if (check) {
352        errors.each(function (i, error) {
353            if ($(error).html() != '') {
354                check = false;
355                $(window).scrollTop($(error).parent().offset().top - $(error).parent().height());
356                return ture;
357            }
358        });
359    }
360   
361    return check;
362}
363function changePrice(id) {
364    var price = $('#price_' + id).val();
365    $('#price_' + id).prev().data('price', price);
366    getPrice();
367}
368function changeDisplay(id) {
369    var display = $('#display_' + id).val();
370    $('#display_' + id).prev().data('display', display);
371}
372function getAnswers(content) {
373    var list = [];
374    var obj = {};   
375    var questions = $('#Anwers').find('.form-group');
376    if (content != undefined) {
377        questions = $(content).find('#Anwers:first').find('.form-group');
378        console.log(questions.length);
379    }
380    questions.each(function (i, question) {
381        var fieldset = $(question).children("fieldset");
382        var questionId = $(fieldset).find("[name$='qId']").val();
383        if ($(fieldset).hasClass("radio") || $(fieldset).hasClass("checkbox") || $(fieldset).hasClass("radio_nest_panel") || $(fieldset).hasClass("checkbox_nest_panel")) {
384            var checked = $(fieldset).children('.option').find(":checked");
385            checked.each(function (t, item) {
386                obj = {};
387                obj.QuestionId = $(item).attr("name");
388                obj.AnswerId = $(item).data("id");
389                obj.Display = $(item).data("display");
390                obj.Qty = $('#qty_' + obj.AnswerId).val();
391                obj.Price = $(item).data("price");
392                obj.Result = $(item).data("score");
393                list.push(obj);
394            });
395        }
396        else if ($(fieldset).hasClass("radio_qty") || $(fieldset).hasClass("checkbox_qty") || $(fieldset).hasClass("radio_pay") || $(fieldset).hasClass("checkbox_pay") || $(fieldset).hasClass("radio_pay_qty") || $(fieldset).hasClass("checkbox_pay_qty") || $(fieldset).hasClass("radio_pay_qty_pic") || $(fieldset).hasClass("checkbox_pay_qty_pic") || $(fieldset).hasClass("activateOption")) {
397            var checkeds = $(fieldset).find('div').find(":checked");
398            checkeds.each(function (t, item) {
399                obj = {};
400                obj.QuestionId = $(item).attr("name");
401                obj.AnswerId = $(item).data("id");
402                obj.Display = $(item).data("display");
403                obj.Qty = $('#qty_' + obj.AnswerId).val();
404                obj.Price = $(item).data("price");
405                obj.Result = $(item).data("score");
406                list.push(obj);
407            });
408        }
409        else if ($(fieldset).hasClass("files") || $(fieldset).hasClass("images")) {
410            var lis = $(fieldset).find('.box li');
411            lis.each(function (t, item) {
412                obj = {};
413                obj.QuestionId = $(item).data("id");
414                obj.Display = $(item).children(":first").html();
415                obj.Result = $(item).data("path");
416                obj.Qty = $(item).data("size");
417                list.push(obj);
418            });
419        }
420        else if ($(fieldset).hasClass("dropdown")) {
421            obj = {};
422            obj.QuestionId = $(fieldset).children("select").attr("id");
423            obj.Display = $(fieldset).children("select").val();
424            obj.Result = $(fieldset).children("select").find("option:selected").data("score");
425            list.push(obj);
426        }
427        else if ($(fieldset).hasClass("multi_connected_dropdown")) {
428            obj = {};
429            obj.QuestionId = $(fieldset).children("select").attr("id");
430            obj.Result = $(fieldset).children("select").data("display");
431            list.push(obj);
432        }
433        else if ($(fieldset).hasClass("textWithDropdown")) {
434            obj = {};
435            obj.QuestionId = $(fieldset).children(".text").attr("id");
436            obj.Result = $(fieldset).children(".text").val() + $(fieldset).children(".text").attr("option");
437            list.push(obj);
438        }
439        else if ($(fieldset).hasClass("textarea")) {
440            obj = {};
441            obj.QuestionId = $(fieldset).children("textarea").attr("id");
442            obj.Result = $(fieldset).children("textarea").val();
443            list.push(obj);
444        }
445        else if ($(fieldset).hasClass("text") || $(fieldset).hasClass("date") || $(fieldset).hasClass("email")) {
446            obj = {};
447            obj.QuestionId = $(fieldset).children("input").attr("id");
448            obj.Result = $(fieldset).children("input").val();
449            list.push(obj);
450        }
451    });
452    console.log(list);
453    return list;
454   
455}
456function preview(content) {
457    var html = "<div class='title'>" + jsData.PreviewTitleText + "</div>";
458    var Anwers = $(content).find('#Anwers:first');
459    var preview = $(content).next('#preview:first');
460    var questions = $(Anwers).find('.form-group');
461    questions.each(function (i, question) {
462        var fieldset = $(question).children("fieldset");
463        if (fieldset.length > 0) {
464            html += "<div>";            
465            html += "<div class='question'>" + $(question).children('.control-label').text() + "</div>";
466            html += "<div class='anwer'>";
467            if ($(fieldset).hasClass("radio") || $(fieldset).hasClass("checkbox") || $(fieldset).hasClass("radio_nest_panel") || $(fieldset).hasClass("checkbox_nest_panel")) {
468                var checkeds = $(fieldset).children('.option').find(":checked");
469                checkeds.each(function (t, item) {
470                    html += "<p >" + $(item).data("display");
471                    html += "</p>";
472                });
473            }
474            else if ($(fieldset).hasClass("radio_qty") || $(fieldset).hasClass("checkbox_qty") || $(fieldset).hasClass("radio_pay") || $(fieldset).hasClass("checkbox_pay") || $(fieldset).hasClass("radio_pay_qty") || $(fieldset).hasClass("checkbox_pay_qty") || $(fieldset).hasClass("radio_pay_qty_pic") || $(fieldset).hasClass("checkbox_pay_qty_pic") || $(fieldset).hasClass("activateOption")) {
475                checkeds = $(fieldset).children('div').find(":checked");
476                checkeds.each(function (t, item) {
477                    html += "<p >" + $(item).data("display");
478                    if ($(item).data("price") > 0) {
479                        if ($(item).data("price").toString().indexOf(".") > 0) {
480                            html += "(" + $('#Currency').text() + " " + $(item).data("price").toString().substring(0, $(item).data("price").toString().indexOf(".") + 3) + ")";
481                        }
482                        else {
483                            html += "(" + $('#Currency').text() + " " + $(item).data("price").toString()+ ")";
484                        }
485                    }
486                    if ($('#qty_' + $(item).data("id")).val() > 0) {
487                        html += "X" + $('#qty_' + $(item).data("id")).val();
488                    }
489                    html += "</p>";
490                });
491            }
492            else if ($(fieldset).hasClass("files") || $(fieldset).hasClass("images")) {
493                var lis = $(fieldset).find('.box li');
494                lis.each(function (t, item) {
495                    html += "<p><a href='" + $(item).data("path") + "' target='_blank'>" + $(item).children(":first").html() + "</a></p>";
496                });
497            }
498            else if ($(fieldset).hasClass("dropdown")) {
499                html += "<p>" + $(fieldset).children("select").val() + "</p>";
500            }
501            else if ($(fieldset).hasClass("multi_connected_dropdown")) {
502                html += "<p>" + $(fieldset).children("select").data("display") + "</p>";
503            }
504            else if ($(fieldset).hasClass("textWithDropdown")) {
505                html += "<p>" + $(fieldset).children(".text").val() + $(fieldset).children(".text").attr("option") + "</p>";
506            }
507            else if ($(fieldset).hasClass("textarea")) {
508                html += "<p>" + $(fieldset).children("textarea").val() + "</p>";
509            }
510            else if ($(fieldset).hasClass("text") || $(fieldset).hasClass("date") || $(fieldset).hasClass("email")) {
511                html += "<p>" + $(fieldset).children("input").val() + "</p>";
512            }
513            html += "</div>";
514            html += "</div>";       
515        }
516    });
517    if (jsData.IsPay) {
518        html += "<div class='total'>total:" + Number($('#total').html()) + "</div>";
519    }
520    if ($('#score').length > 0) {
521        html += "<div class='score'>score:" + Number($('#score').html()) + "</div>";
522    }
523    if ($("#Signature").length > 0) {
524        html += "<div class='sign'><img src='" + $(Signature).attr("src") + "'</div>";
525    }
526   
527
528    
529    if (jsData.HasRNPConfirm) {
530        html += "<input type='button' value='" + jsData.ConfirmText + "' class='confirm' onclick='rnpConfirm($(this).parents(\"#preview\").prev())'/>";
531    }
532    else {
533        html += "<input type='button' value='" + jsData.ConfirmText + "' class='confirm' onclick='confirm($(this).parents(\"#preview\").prev())'/>";
534    }
535    html += "<input type='button' value='" + jsData.BackText + "' class='back' onclick='back($(this).parents(\"#preview\").prev());'/>";
536    $(preview).html(html);
537    $(content).css("display", "none");
538    $(preview).css("display", "block");  
539    $(window).scrollTop($(preview).offset().top-200);
540}
541function back(content) {
542    $(content).css("display", "block");
543    $(content).next('#preview').html("");
544}
545function getPanels(tag) {
546    var type = $(tag).attr("type");
547    var id = $(tag).data("id");
548    var panelId = "panel_" + $(tag).attr("name");
549    if ($(tag).prop('checked')) {
550        if (type == "radio") {
551            $('#' + panelId).html("");
552        }
553        
554        if (jsData.Version == "2.0") {
555            window.regAndPay.getPanel(id).then(result => {
556                if (result.data.Succeeded) {
557                    htmlString = "<div  class='option_panel' id='option_panel_" + id + "'>";
558                    htmlString = htmlString + result.data.ReturnValue;
559                    htmlString = htmlString + "</div>";
560                    $('#' + panelId).append(htmlString);
561                }
562            });
563        }
564        else {
565            InstoreSdk.api.regnpay.getPanel(id, function (data) {
566                if (data.Succeeded) {
567                    htmlString = "<div  class='option_panel' id='option_panel_" + id + "'>";
568                    htmlString = htmlString + data.ReturnValue;
569                    htmlString = htmlString + "</div>";
570                    $('#' + panelId).append(htmlString);
571                }
572            }, function () { });
573        }
574    }
575    else {
576        if (type == "checkbox") {
577            $('#option_panel_' + id).remove();
578        }
579    }
580
581}
582function getNextSelectList(id) {
583    var display = "";
584    $('#' + id).nextAll().remove();
585    var optionId = $('#' + id).val();
586    if (optionId != "0") {
587        display = $('#' + id).find("option:selected").text();
588        var selectid = $('#' + id).data("selectid");
589        if (jsData.Version == "2.0") {
590            window.regAndPay.getSubOptionList(optionId).then(result => {
591                if (result.data.ReturnValue.length > 0) {
592                    var selectStr = "<select id='" + optionId + "' data-selectid='" + selectid + "' onchange=\"getNextSelectList('" + optionId + "')\" class='dropdown_op'>";
593                    selectStr += "<option value='0'>" + jsData.PleaseSelect + "</option>";
594                    $.each(result.data.ReturnValue, function (i, val) {
595
596                        selectStr += "<option value='" + val.Id + "'>" + val.Display + "</option>";
597                    });
598                    selectStr += "</select>";
599                    $('#' + id).parent().append(selectStr);
600                }
601            });
602        }
603        else {
604            InstoreSdk.api.regnpay.getSubOptionList(optionId, function (data) {
605                if (data.ReturnValue.length > 0) {
606                    var selectStr = "<select id='" + optionId + "' data-selectid='" + selectid + "' onchange=\"getNextSelectList('" + optionId + "')\" class='dropdown_op'>";
607                    selectStr += "<option value='0'>" + jsData.PleaseSelect + "</option>";
608                    $.each(data.ReturnValue, function (i, val) {
609
610                        selectStr += "<option value='" + val.Id + "'>" + val.Display + "</option>";
611                    });
612                    selectStr += "</select>";
613                    $('#' + id).parent().append(selectStr);
614
615                }
616
617            }, function () { });
618        }
619        
620
621
622    }
623    $('#' + id).prevAll().each(function (i, sel) {
624        display = $(sel).find("option:selected").text() + " " + display;
625    });
626    $('#' + selectid).data("display", display);
627    console.log($('#' + selectid).data("display"));
628
629}
630function checkInventory(oid) {
631    var max = parseInt($('#qty_' + oid).attr("max"));
632    var qty = parseInt($('#qty_' + oid).val());
633    var inventory = 0;
634    if (jsData.Version == "2.0") {
635        window.regAndPay.checkOptionInventory(oid).then(result => {
636            inventory = result.data;
637            $('#qty_' + oid).next().find([name = "inventory"]).text(inventory);
638            if (inventory < max || isNaN(max)) {
639                max = inventory;
640            }
641            if (max < qty) {
642                qty = max;
643                if (qty <= 0) {
644                    qty = 0;
645                }
646                $('#qty_' + oid).val(qty);
647            }
648            getPrice();
649            getScore();
650        });
651    }
652    else {
653        InstoreSdk.api.regnpay.checkOptionInventory(oid, function (data) {
654            inventory = data;
655            $('#qty_' + oid).next().find([name = "inventory"]).text(inventory);
656            if (inventory < max || isNaN(max)) {
657                max = inventory;
658            }
659            if (max < qty) {
660                qty = max;
661                if (qty <= 0) {
662                    qty = 0;
663                }
664                $('#qty_' + oid).val(qty);
665            }
666            getPrice();
667            getScore();
668        }, function () { });
669    }
670    
671
672}
673function checkQtyAndPrice(inputId) {
674    var max = parseInt($('#' + inputId).attr("max"));
675     var min = parseInt($('#' + inputId).attr("min"));
676    var qty = parseInt($('#' + inputId).val());
677    if (min > qty) {
678        qty = min;
679        $('#' + inputId).val(qty);
680    }
681    if (max < qty) {
682        qty = max;
683        $('#' + inputId).val(qty);
684    }
685    getPrice();
686    getScore();
687}
688function checkIdentification(id) {
689    var checkStr = $('#' + id).val();
690    var qId = id;
691    if (jsData.Version == '2.0') {
692
693        window.regAndPay.checkIdentification(checkStr, qId).then(result => {
694            if (!result.data.Succeeded) {
695                $('#' + id).val("");
696                $('#' + id).parent().next().text(data.Message);
697            }
698        });
699    }
700    else {
701        InstoreSdk.api.regnpay.checkIdentification(checkStr, qId, function (data) {
702            if (!data.Succeeded) {
703                $('#' + id).val("");
704                $('#' + id).parent().next().text(data.Message);
705            }
706        }, function () { });
707    }
708   
709}
710function saveSign() {
711    if (!isCanvasBlank(document.getElementById("NewSignCanvas"))) {
712        var signature = Signer.export();
713        var obj = new Object();
714        obj.Base64str = signature;
715        obj.key = jsData.id;
716        if (jsData.Version == '2.0') {
717
718            window.regAndPay.base64StringToImageURL(obj).then(result => {
719                if (result.data.Succeeded) {
720                    $('#Signature').attr("src", result.data.ReturnValue);
721                    $("#Sign").removeClass("focus");
722                    return true;
723                }
724                else {
725                    Signer.initCanvas();
726                    alert("簽署失敗");
727                    $("#Sign").addClass("focus");
728                    $("#Sign").focus();
729                    return false;
730                }
731            });
732        }
733        else {
734            InstoreSdk.api.regnpay.base64StringToImageURL(obj, function (data) {
735                if (data.Succeeded) {
736                    $('#Signature').attr("src", data.ReturnValue);
737                    $("#Sign").removeClass("focus");
738                    return true;
739                }
740                else {
741                    Signer.initCanvas();
742                    alert("簽署失敗");
743                    $("#Sign").addClass("focus");
744                    $("#Sign").focus();
745                    return false;
746                }
747            }, function () { });
748        }
749       
750    }  
751    return false;
752}
753function bindOnMouseOut() {
754    $("#NewSignCanvas").removeAttr("onMouseDown");
755    $("#NewSignCanvas").attr("OnMouseOut", "saveSign()");
756}
757function clearSign() {
758    Signer.initCanvas();
759    $('#Signature').attr("src", "");
760   // $("#NewSignCanvas").attr("onMouseDown", "bindOnMouseOut()");
761}
762function isCanvasBlank(canvas) {
763    var blank = document.createElement('canvas');//系统获取一个空canvas对象
764    blank.width = canvas.width;
765    blank.height = canvas.height;
766    console.log(canvas.toDataURL());
767    console.log(blank.toDataURL());
768    return canvas.toDataURL() == blank.toDataURL();//比较值相等则为空
769}
770function propertychange(tag) {
771    if ($(tag).val() != "") {
772        $(tag).parents('fieldset').next().html("");
773        if ($(tag).attr("type") == "email") {
774            var reg1 = /([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/;
775            if (reg1.test($(tag).val()) == false) {
776                errmsg = jsData.FormatErrorText;
777                $(tag).parents('fieldset').next().text(errmsg);
778                $(tag).focus();
779            }
780        }
781    }
782    
783}
784$('#SignButton').bind('click', function () {
785    var signature = Signer.export();
786    var obj = new Object();
787    obj.Base64str = signature;
788    obj.key = jsData.id;
789
790    InstoreSdk.api.regnpay.base64StringToImageURL(obj, function (data) {
791        if (data.Succeeded) {
792            $('#SignArea').fadeOut();
793            //$('#Signature').unbind('click');
794            //$('#SignValue').attr('value', data.ReturnValue);
795            $('#Signature').attr("src", data.ReturnValue);
796        }
797        else {
798            Signer.initCanvas();
799            alert("簽署失敗");
800        }
801
802    }, function () { });
803});
804$("body").on("click", ".upload_text1", function () {
805    $(this).parent().prev().click();
806});
807$("body").on("click", ".closeX", function () {
808    $(this).parent().remove();
809    var tempLength = $(this).parent().siblings().length;
810    var maxLength = $(this).parent().next().data("max");
811    if (tempLength < maxLength) {
812        $(this).parent().find('.uploadMain').html("<i class='uploadicon1'></i><span class='upload_text1' >" + jsData.UploadButtonText + "</span > ");
813    }
814});
815$("body").on("input propertychange", "input", function () {
816    $(this).parents('fieldset').next().html("");
817    if ($(this).attr("type") == "email" && $(this).val() != "") {
818        var reg1 = /([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/;
819        if (reg1.test($(this).val()) == false) {
820            errmsg = jsData.FormatErrorText;
821            $(this).parents('fieldset').next().text(errmsg);
822            $(this).focus();
823        }
824    }
825	if ($(this).attr("placeholder") == "填寫內容請勿超過10個中文字") {
826		var pattern = /^.{1,10}$/;
827		if (pattern.test($(this).val()) == false) {
828			errmsg = "填寫內容請勿超過10個中文字 ";
829			$(this).parents('fieldset').next().text(errmsg);
830			$(this).focus();
831		}
832	}
833});
834/**
835 * 乘法
836 * @param arg1
837 * @param arg2
838 * @returns {Number}
839 */
840function accMul(arg1, arg2) {
841    var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
842    try { m += s1.split(".")[1].length } catch (e) { }
843    try { m += s2.split(".")[1].length } catch (e) { }
844    return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
845}
846/**
847 * 除法
848 * @param arg1
849 * @param arg2
850 * @returns {Number}
851 */
852function accDiv(arg1, arg2) {
853    var t1 = 0, t2 = 0, r1, r2;
854    try { t1 = arg1.toString().split(".")[1].length } catch (e) { }
855    try { t2 = arg2.toString().split(".")[1].length } catch (e) { }
856    with (Math) {
857        r1 = Number(arg1.toString().replace(".", ""))
858        r2 = Number(arg2.toString().replace(".", ""))
859        return (r1 / r2) * pow(10, t2 - t1);
860    }
861}
862/**
863 * 加法
864 * @param arg1
865 * @param arg2
866 * @returns {Number}
867 */
868function accAdd(arg1, arg2) {
869    var r1, r2, m, c;
870    try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
871    try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
872    c = Math.abs(r1 - r2);
873    m = Math.pow(10, Math.max(r1, r2))
874    if (c > 0) {
875        var cm = Math.pow(10, c);
876        if (r1 > r2) {
877            arg1 = Number(arg1.toString().replace(".", ""));
878            arg2 = Number(arg2.toString().replace(".", "")) * cm;
879        }
880        else {
881            arg1 = Number(arg1.toString().replace(".", "")) * cm;
882            arg2 = Number(arg2.toString().replace(".", ""));
883        }
884    }
885    else {
886        arg1 = Number(arg1.toString().replace(".", ""));
887        arg2 = Number(arg2.toString().replace(".", ""));
888    }
889    return (arg1 + arg2) / m
890}
891/**
892 * 减法
893 * @param arg1
894 * @param arg2
895 * @returns
896 */
897function accSub(arg1, arg2) {
898    var r1, r2, m, n;
899    try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
900    try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
901    m = Math.pow(10, Math.max(r1, r2));
902    //last modify by deeka
903    //动态控制精度长度
904    n = (r1 >= r2) ? r1 : r2;
905    return ((arg1 * m - arg2 * m) / m).toFixed(n);
906}
907

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.