<!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;}
    </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-xs6 layui-col-sm4">
                                <label class="layui-form-label"><font color='red' size="4">*</font>合同号：</label>
                                <div class="layui-input-block">
                                    <input id="id_no" type="text" name="no" lay-verify="required" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-col-xs6 layui-col-sm4">
                                <label class="layui-form-label"><font color='red' size="4">*</font>供应商：</label>
                                <div class="layui-input-block">
                                    <select id="id_supplier" name="supplier" lay-verify="required" lay-search>
                                        <option value=""></option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-col-xs6 layui-col-sm4">
                                <label class="layui-form-label">付款方式：</label>
                                <div class="layui-input-block">
                                    <!--<input id="id_payment_type" type="text" name="payment_type" autocomplete="off"
                                           class="layui-input">-->
                                    <input type="text" name="payment_type" id="id_payment_type" class="layui-input" style="position:absolute;z-index:2;width:80%;" autocomplete="off">
                                    <select lay-filter="hc_select">
                                        <option value="票到付款">票到付款</option>
                                        <option value="预付">预付</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-row layui-col-space10">
                            <div class="layui-col-xs6 layui-col-sm4">
                                <label class="layui-form-label"><font color='red' size="4">*</font>收货人：</label>
                                <div class="layui-input-block">
                                    <input id="id_consignee_name" type="text" name="consignee_name" lay-verify="required" autocomplete="off"
                                           class="layui-input">
                                </div>
                            </div>

                            <div class="layui-col-xs6 layui-col-sm4">
                                <label class="layui-form-label"><font color='red' size="4">*</font>收货电话：</label>
                                <div class="layui-input-block">
                                    <input id="id_consignee_tel" type="text" name="consignee_tel" lay-verify="required" autocomplete="off"
                                           class="layui-input">
                                </div>
                            </div>

                            <div class="layui-col-xs6 layui-col-sm4">
                                <label class="layui-form-label">交货时间：</label>
                                <div class="layui-input-block">
                                    <input id="id_deliver_time" type="text" name="deliver_time" autocomplete="off"
                                           class="layui-input">
                                </div>
                            </div>
                        </div>

                        <div class="layui-row layui-col-space10">

                            <div class="layui-col-xs12">
                                <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>

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

    var id = layui.view.getParameterByName('id');
    var supplier_type = layui.view.getParameterByName('type');
    var supplier_option = '';

    admin.req({
        url: '/foundation/search_options/?type=4',
        done: function(res){
            _options = res.data;
        }
    });

    admin.req({
        url: '/supplier/supplier/select/?type=' + supplier_type,
        done: function(res){
            var suppliers = res.data;
            for (var i in suppliers) {
                 supplier_option += "<option value="+ suppliers[i].id+">"+ suppliers[i].value+"</option>";
            }
            $("#id_supplier").append(supplier_option);
            form.render();
            var orderData = JSON.parse(JSON.stringify(parent.layui.table.editdata));
             form.val("component-form-element", orderData);
        }
    });


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

    form.on('select(hc_select)', function (data) {   // 赋值给input框
                $("#id_payment_type").val(data.value);
                form.render();
            });

    form.on('submit(component-form-element)', function(data){

        var supplier = $('#id_supplier').val();
        var payment_type = $('#id_payment_type').val();
        var notes = $('#id_notes').val();
        var deliver_time = $('#id_deliver_time').val();
        var no = $('#id_no').val();
        var consignee_name = $('#id_consignee_name').val();
        var consignee_tel = $('#id_consignee_tel').val();


        var order_data = {
            'supplier': supplier,
            'notes': notes,
            'no': no,
            'count': 0,
            'amount': 0,
            'payment_type': payment_type,
            'deliver_time':deliver_time,
            'consignee_name': consignee_name,
            'consignee_tel': consignee_tel
        };

        data.field.order_data = order_data;
        admin.req({
            url: '/purchase/purchase_order/edit/?id='+id
            ,data: JSON.stringify(data.field)
            ,type: 'post'
            , done: function (res) {
                parent.layui.onSubmitChild();
            }
        });
        return false;
    });

    $('#btn_close').on('click', function() {
        parent.layer.closeAll('iframe');
    });

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

  });

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