<!DOCTYPE html>
<html style="height: 100%;min-height: 100%;">
<head>
  <meta charset="utf-8">
  <title>　</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
    <style type="text/css">
        .layui-table td{border-color:#000;}
    </style>
</head>
<style>
      h3, td, th{color: #000000}
      .layui-table td, .layui-table th {border-color: #000000;height: 1px}
  </style>
<body style="background-color: #fff;height: 100%;min-height: 100%;">

  <div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" pad15>
        <div class="layui-row layui-col-space15">
          <div class="layui-col-md12">

            <div id="print_div">
                <h3 align="center" style="font-weight: bold;letter-spacing:8px;"><span id="company"></span></br>销售订单</h3>
                <table class="layui-table">
                    <tr>
                        <td id="no" class="cell">订单号</td>
                        <td id="customer_name" class="cell">客户姓名</td>
                        <td id="customer_tel" class="cell">客户电话</td>
                    </tr>
                    <tr>
                        <td id="create_user_text" class="cell">下单人员</td>
                        <td id="create_time" class="cell">下单时间</td>
                        <td id="notes" class="cell">备注</td>
                    </tr>
                </table>
                <table class="layui-table">
                    <tr>
                        <td>产品名称</td>
                        <td>产品代码</td>
                        <td>质量标准</td>
                        <td align="right" width="70">单价</td>
                        <td align="right" width="70">数量</td>
                        <td align="right" width="70">金额</td>
                    </tr>

                    <tr id="tr_total">
                        <td colspan="4" align="right">合计：</td>
                        <td align="right" id="td_count"></td>
                        <td align="right" id="td_amount"></td>
                    </tr>
                </table>
                <table class="table-embed" border='0' width='100%' height="50px">
                    <tr style="height: 80px;">
                        <td align="center">制单人签字：__________</td>
                        <td align="center">审核人签字：__________</td>
                        <td align="center">财务签字：__________</td>
                        <td align="center">总经理签字：__________</td>
                    </tr>
                </table>
            </div>
          </div>
        </div>
        </div>
    </div>
  </div>

  <script src="../../layuiadmin/layui/layui.js?t=1"></script>
  <script>
  layui.config({
    base: '../../../layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table'], function(){
    var $ = layui.$
    ,admin = layui.admin;

    var data = JSON.parse(JSON.stringify(parent.layui.table.editdata));
    $('.cell').each(function (index, element) {
        element.innerHTML += '：' + (data[element.id]||'')
    });

    admin.req({
        url: '/order/sale_order/detail/?id='+data.id
        ,done: function(data){
            var company = data.data.company;
            var items_data = data.data.items_data;
            var count = 0
                ,amount = 0;
            for(var n in items_data){
                count += parseFloat(items_data[n].count);
                amount += parseFloat(items_data[n].amount);
                $('#tr_total').before("<tr>\n" +
                    "                        <td>"+items_data[n].name+"</td>\n" +
                    "                        <td>"+items_data[n].model+"</td>\n" +
                    "                        <td>"+items_data[n].quality_request_text+"</td>\n" +
                    "                        <td align=\"right\">"+items_data[n].price+"</td>\n" +
                    "                        <td align=\"right\">"+items_data[n].count+"</td>\n" +
                    "                        <td align=\"right\">"+items_data[n].amount+"</td>\n" +
                    "                    </tr>");
            }
            $('#td_count').html(parseFloat(count).toFixed(2));
            $('#td_amount').html(parseFloat(amount).toFixed(4));
            $('#company').html(company);
        }
    });

      parent.layui.submitChild = function () {
          window.scrollTo(0,0);
          doPrint();
          parent.layui.onSubmitChild();
      };

      function doPrint() {
          var $ = layui.$;
        document.body.innerHTML=$('#print_div').html();
          window.print();
      }
  });

  </script>
</body>
</html>

