<!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">
        .layui-form-select dl{max-height: 120px;}
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" pad15>
            <form class="layui-form" action="" lay-filter="component-form-element">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-xs12 layui-col-sm5 layui-col-md4">
                        <label class="layui-form-label"><font color='red' size="4">*</font>仓别：</label>
                        <div class="layui-col-xs5 layui-col-sm7 layui-col-md8">
                            <select id="id_warehouse" name="warehouse" lay-verify="required">
                                <option value=""></option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="layui-row layui-col-space10">
                    <label class="layui-form-label">备注：</label>
                    <div class="layui-col-xs8 layui-col-sm7 layui-col-md8">
                        <input id="notes" name="notes" autocomplete="off" class="layui-input"/>
                    </div>
                </div>
                <button class="layui-btn" id="goods-submit" lay-submit lay-filter="component-form-element" style="display: none"></button>
                <button class="layui-btn" type="button" id="goods-import" style="display: none"></button>
            </form>
        </div>
    </div>
</div>

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

    admin.req({
      url: '/warehouse/select/?type=2',
      done: function(res){
        var data = res.data;
        var warehouse_node = $('#id_warehouse');
        for (var i in data) {
            var pid = data[i].id;
            var value = data[i].value;
            warehouse_node.append("<option value='"+pid+"'>"+value+"</option>");
        }
        form.render();
     }
    });

     var form_data = {field:{}};
     upload.render({
            elem: '#goods-import',
             url: '/goods/godownentry/import/'
            , accept: 'file'
            , acceptMime: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
            , exts: 'xlsx'
            , field: 'excel_file'
            , multiple: false
            , data:{main_data: function(){return JSON.stringify(form_data.field);}}
            , done: function (res) {
                if (res.code != 0) {
                    layer.msg(res.msg);
                }else {
                    parent.layui.onSubmitChild(res.data);
                }
            }
            , error: function () {
                layer.msg('导入失败');
            }
        });
    form.on('submit(component-form-element)', function (data) {
        form_data = data;
        $('#goods-import').click();
        return false;
    });

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


})
  </script>
</body>
</html>