js連線小票印表機

呂建奎發表於2015-05-28
var div = dojo.create("div");
            var table = dojo.create("table", {cellpadding: "3", cellspacing: "5", style: "min-width:250px; max-width:300px; font:15px arial,sans-serif;"}, div);
                var tBody = dojo.create("tbody", {style: {verticalAlign: "initial"}}, table);
                      var tr = dojo.create("tr", null, tBody);
                          var td = dojo.create("td", {align: "left", colspan: "3"}, tr);
                          dojo.create("span", {style: "font:bold 18px arial,sans-serif;", innerHTML: app.gym.name}, td);
                      if(app.gym.phone && app.gym.phone.length>0)
                      {
                          tr = dojo.create("tr", null, tBody);
                              var td = dojo.create("td", {align: "left", style: "font:15px arial,sans-serif;", colspan: "3"}, tr);
                              dojo.create("span", {style: "margin-right:10px;", innerHTML: "電話"}, td);
                              dojo.create("span", {innerHTML: app.gym.phone}, td);
                      }
                      tr = dojo.create("tr", null, tBody);
                          dojo.create("td", {align: "left", style: "border-bottom:1px solid black; width:100%; height:5px; margin-bottom:5px; ", colspan: "3"}, tr);
                      tr = dojo.create("tr", null, tBody);
                          var td = dojo.create("td", {align: "left", style: "font:15px arial,sans-serif;", colspan: "3"}, tr);
                          dojo.create("span", {style: "margin-right:10px;", innerHTML: "收款員"}, td);
                          dojo.create("span", {innerHTML: app.user.displayName}, td);
                      tr = dojo.create("tr", null, tBody);
                          dojo.create("td", {align: "left", style: "border-bottom:1px solid black; width:100%; height:5px; margin-bottom:5px; ", colspan: "3"}, tr);
                      tr = dojo.create("tr", null, tBody);
                          td = dojo.create("td", {style: "width:50%;", innerHTML: "單價"}, tr);
                          td = dojo.create("td", {style: "width:20%;", innerHTML: "數量"}, tr);
                          td = dojo.create("td", {style: "width:30%;", innerHTML: "金額"}, tr);
                      tr = dojo.create("tr", null, tBody);
                          dojo.create("td", {align: "left", style: "border-bottom:1px solid black; width:100%; height:5px; margin-bottom:5px; ", colspan: "3"}, tr);
                      var conPrice = 0;
                      var sumPrice = 0;
                      for(var i=0; i<this.app.shoppingCart.products.length; i++)
                      {
                          var product = this.app.shoppingCart.products[i];
                          tr = dojo.create("tr", null, tBody);
                              td = dojo.create("td", {align: "left", colspan: "3", innerHTML: product.name}, tr);
                          tr = dojo.create("tr", {style: "margin-bottom:5px;"}, tBody);
                              td = dojo.create("td", {style: "width:50%;", innerHTML: isCardPay?product.memberPrice:product.retailPrice}, tr);
                              td = dojo.create("td", {style: "width:20%;", innerHTML: isCardPay?(product.cardPrice/product.memberPrice):(product.price/product.retailPrice)}, tr);
                              td = dojo.create("td", {style: "width:30%;", innerHTML: isCardPay?product.cardPrice:product.price}, tr);
                              conPrice += isCardPay?product.cardPrice:product.price;
                              sumPrice += product.price;
                      }
                      tr = dojo.create("tr", null, tBody);
                          dojo.create("td", {align: "left", style: "border-bottom:1px solid black; width:100%; height:5px; margin-bottom:5px; ", colspan: "3"}, tr);
                      tr = dojo.create("tr", null, tBody);
                          td = dojo.create("td", {align: "left", innerHTML: "原價"}, tr);
                              dojo.create("span", {innerHTML: sumPrice}, td);
                          td = dojo.create("td", {align: "left", colspan: "2", innerHTML: "折扣"}, tr);
                              dojo.create("span", {innerHTML: String(10/parseFloat(sumPrice/conPrice)).substring(0,3)}, td);
                      tr = dojo.create("tr", null, tBody);
                          dojo.create("td", {align: "left", style: "border-bottom:1px solid black; width:100%; height:5px; margin-bottom:5px; ", colspan: "3"}, tr);
                      tr = dojo.create("tr", null, tBody);
                          td = dojo.create("td", {align: "left", style: "font:bold 18px arial,sans-serif;", colspan: "3", innerHTML: "實收金額: &nbsp;"}, tr);
                              dojo.create("span", {innerHTML: conPrice}, td);
                      tr = dojo.create("tr", null, tBody);
                          dojo.create("td", {align: "left", style: "border-bottom:1px solid black; width:100%; height:5px; margin-bottom:5px; ", colspan: "3"}, tr);
                      tr = dojo.create("tr", null, tBody);
                          td = dojo.create("td", {align: "left", colspan: "3", innerHTML: "日期"}, tr);
                              dojo.create("span", {innerHTML: dojo.date.locale.format(new Date(), {datePattern: "yyyy-MM-dd", timePattern:'hh:mm:ss'})}, td);
                      tr = dojo.create("tr", null, tBody);
                          dojo.create("td", {align: "left", style: "border-bottom:1px solid black; width:100%; height:5px; margin-bottom:5px; ", colspan: "3"}, tr);
                      tr = dojo.create("tr", null, tBody);     
                          td = dojo.create("td", {align: "left", colspan: "3", innerHTML: "謝謝光臨!"}, tr);
                      tr = dojo.create("tr", null, tBody);     
                          td = dojo.create("td", {align: "left", colspan: "3", innerHTML: "www.didayuandong.com"}, tr);
        var content = div.innerHTML;
             var fea = "location=no,toobar=no,resizable=no,status=no,menubar=no,scrollbars=no,dependent=no,width=230px,height=530px,dialog=yes";
             var newWin = window.open(window.location.protocol+"//"+window.location.host+"/gris/print.html","購買商品",fea);
          newWin.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'+
                      '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Print</title>'+
                      '<style media="print">.noprint { display: none }.PageNext{ PAGE-BREAK-AFTER: always }</style>'+
                      '<script>function doPrint(){if(document.all){document.execCommand(\'print\');window.close();}else{window.print();window.close();}}</script>'+
                      '<br>'+content + '<br><form><input class="noprint" type="button" value="列印" onclick="doPrint()"></form>');
          newWin.focus();

相關文章