<!DOCTYPE html>
<html>
<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">
        .table-overlay .layui-table-view,
        .table-overlay .layui-table-header,
        .table-overlay .layui-table-box,
        .table-overlay .layui-table-body{overflow: visible;}
        .table-overlay .layui-table-cell{height: auto; overflow: visible;}
        .layui-form-select dl{max-height: 150px;}
    </style>
</head>
<body>

<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">

                    <form class="layui-form" action="" lay-filter="component-form-element">
                        <div class="layui-row layui-col-space10">
                            <div class="layui-col-xs12 layui-col-sm4 layui-col-md4">
                                <label class="layui-form-label">应付金额：</label>
                                <div class="layui-input-block" style="line-height: 36px;">
                                    <span id="id_amount"></span>
                                </div>
                            </div>
                            <div class="layui-col-xs12 layui-col-sm4 layui-col-md4">
                                <label class="layui-form-label">已付金额：</label>
                                <div class="layui-input-block" style="line-height: 36px;">
                                    <span id="id_pay_amount"></span>
                                </div>
                            </div>
                        </div>

                        <div class="layui-row layui-col-space10">
                            <div class="layui-col-xs12 layui-col-sm4 layui-col-md4">
                                <label class="layui-form-label"><font color='red' size="4">*</font>结算账户：</label>
                                <div class="layui-input-block">
                                    <select id="id_payment_account" name="account" lay-verify="required">
                                        <option value="">请选择结算账户</option>
                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="layui-row layui-col-space10">
                            <div class="layui-col-xs12 layui-col-sm4 layui-col-md4">
                                <label class="layui-form-label"><font color='red' size="4">*</font>付款金额：</label>
                                <div class="layui-input-block">
                                    <input id="id_actual_amount" type="text" name="actual_amount"  autocomplete="off" lay-verify="required|numberGtZ" class="layui-input">
                                </div>
                            </div>
                        </div>

                        <div class="layui-row layui-col-space10">
                            <div class="layui-col-xs12 layui-col-sm4 layui-col-md4">
                                <label class="layui-form-label">备注：</label>
                                <div class="layui-input-block">
                                    <input id="id_notes" type="text" name="notes"  autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <button class="layui-btn" id="purchase-order-submit" lay-submit lay-filter="component-form-element" style="display: none">保存</button>
                    </form>

                </div>
            </div>
        </div>
    </div>
</div>

  <script src="../../layuiadmin/layui/layui.js"></script>
  <script>

  layui.link('../../../layuiadmin/style/autocomplete.css');
  layui.config({
    base: '../../../layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index',
    autocomplete: 'autocomplete'
  }).use(['index', 'utils','form', 'element'], function(){
    var $ = layui.$
    ,admin = layui.admin
    ,element = layui.element
    ,form = layui.form;

    var editdata = JSON.parse(JSON.stringify(parent.layui.table.editdata));
    $('#id_amount').html(editdata.total_amount);
    $('#id_pay_amount').html(editdata.pay_amount);

    var payment_type_option = '';

     admin.req({
        url: '/foundation/search_options/?type=5',
        done: function(res){
            var payment_types = res.data;
            for (var i in payment_types) {
                 payment_type_option += "<option value="+ payment_types[i].id+">"+ payment_types[i].name+"</option>";
            }
            $("#id_payment_account").append(payment_type_option);
            form.render();
        }
    });


    form.render(null, 'component-form-element');
    element.render('breadcrumb', 'breadcrumb');

    form.on('submit(component-form-element)', function(data){
        var actual_amount = $('#id_actual_amount').val();
        var amount = parseFloat(editdata.total_amount);
        actual_amount = parseFloat(actual_amount);
        var actual_amount_old = parseFloat(editdata.pay_amount);
        if (actual_amount + actual_amount_old > amount) {
            layer.confirm('实收金额大于应收金额, 确定要付款吗？', function(index){
                layer.close(index);
                admin.req({
                    url: '/order/sale_order/pay/?id='+editdata.id
                    ,data: JSON.stringify(data.field)
                    ,type: 'post'
                    ,done: function(res){
                         parent.layui.onSubmitChild();
                    }
                });
            });
        }else{
            admin.req({
            url: '/order/sale_order/pay/?id='+editdata.id
                ,data: JSON.stringify(data.field)
                ,type: 'post'
                , done: function (res) {
                    parent.layui.onSubmitChild();
                }
            });
        }

        return false;
    });

    parent.layui.submitChild = function () {
      $("#purchase-order-submit").click();
    };

  });

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