<!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>
      h3, td, th{color: #000000}
      .layui-table td, .layui-table th {border-color: #000000;height: 1px}
  </style>
</head>
<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="supplier_name" class="cell">供应商</td>
                        <td id="supplier_account" class="cell">供应商账号</td>
                    </tr>
                    <tr>
                        <td id="supplier_bank" class="cell">供应商开户行</td>
                        <td id="status_text" class="cell">状态</td>
                        <td id="amount" class="cell">应付金额</td>
                    </tr>
                    <tr>
                        <td id="amount_CNY" class="cell">应付金额大写</td>
                        <td id="apply_amount" class="cell">申请金额</td>
                        <td id="apply_amount_CNY" class="cell">申请金额大写</td>

                    </tr>
                    <tr>
                        <td id="actual_amount" class="cell">实付金额</td>
                        <td id="actual_amount_CNY" class="cell" colspan="2">实付金额大写</td>
                    </tr>
                    <tr>
                        <td id="notes" class="cell" colspan="3">备注</td>
                    </tr>
                </table>
                <table class="layui-table">
                     <tr>
                        <td>序号</td>
                        <td>产品名称</td>
                        <td>产品代码</td>
                        <td>合同号</td>
                        <td align="right">数量</td>
                        <td align="right">单价</td>
                        <td align="right">历史成本</td>
                        <td align="right">金额</td>
                    </tr>

                    <tr id="tr_total">
                        <td colspan="7" align="right">合计：</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" width="25%">申请人：<span id="create_user"></span></td>
                        <td align="center" width="25%">审核人：<span id="check_user"></span></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));

    $('#create_user').html(data.create_user_text + ',' + data.create_time);
    if (data.check_user_text) {
        $('#check_user').html(data.check_user_text+ ',' + data.check_time);
    }

    $('.cell').each(function (index, element) {
        element.innerHTML += '：' + (data[element.id]||'')
    });

    admin.req({
        url: '/purchase/purchase_payment/detail/?id='+data.id
        ,done: function(data){
            var company = data.data.company;
            var data = data.data.data;
            var  amount = 0;
            for(var n in data){
                var m = parseInt(n) + 1;
                amount += parseFloat(data[n].amount);
                $('#tr_total').before("<tr>\n" +
                    "                        <td>"+m+"</td>\n" +
                    "                        <td>"+data[n].name+"</td>\n" +
                    "                        <td>"+data[n].model+"</td>\n" +
                    "                        <td>"+data[n].order_no+"</td>\n" +
                    "                        <td>"+data[n].count+"</td>\n" +
                    "                        <td>"+data[n].price+"</td>\n" +
                    "                        <td>"+data[n].avg_cost_price+"</td>\n" +
                    "                        <td align=\"right\">"+data[n].amount+"</td>\n" +
                    "                    </tr>");
            }
            $('#td_amount').html(amount.toFixed(2));
            $('#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>

