<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!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">
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/static/css/reset.css" />
    <style>html{background-color: #fff;padding-bottom: 50px;}</style>
</head>
<body>
<div class="layui-form">
    <div class="layui-card-body">

        <div id="textDiv">
            <div class="layui-form-item">
                <div class="contentBody ">
                    <div class="layui-col-lg12 layui-col-sm12">
                        <label class="layui-form-label"><i class="mark">*</i>物料代码：</label>
                        <div class="layui-input-block">
                            <div id="materialCode"></div>
                            <input type="hidden" id="code">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="operate-footer">
        <input type="button" value="确定" class="layui-btn " onclick="confirm()">
        <input type="button" value="取消" class="layui-btn layui-btn-primary" onclick="cancel()">
    </div>
</div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/xm-select.js"></script>
<script>
    var materialCode = null;
    var materialCodeVal = null;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['form','jquery','layedit'], function () {
        $ = layui.jquery,
            form = layui.form,
            layer = layui.layer;

         materialCodeVal = xmSelect.render({
            el: '#materialCode',
            name: 'materialCode',
            // radio: true,
            tips: '请输入查询',
            // clickClose: true,
            filterable: true,
            remoteSearch: true,
            remoteMethod: function (val, cb, show) {
                if (!isBlank(val)) {
                    $.ajax({
                        type: 'post',
                        url: '${ctx}/material/getMaterialCodeList',
                        async: false,
                        dataType: 'json',
                        data:{
                            materialCode:val
                        },
                        success: function (d) {
                            var arr = [];
                            for (var i = 0; i < d.length; i++) {
                                var data = {};
                                data.name = d[i].code;
                                data.value = d[i].id;
                                data.origin = d[i];
                                arr.push(data);
                            }
                            cb(arr);
                        }
                    });
                } else {
                    cb([]);
                }
            },
            // on: function (data) {
            //     if (data.isAdd && data.arr.length > 0) {
            //         var d = data.arr[0].origin;
            //         materialCode = d.code;
            //         $("#code").val(materialCode);
            //     }
            // }
        });


    });

    function confirm(){
        let code =  materialCodeVal.getValue('nameStr');
        if (isBlank(code)) {
            layer.msg("请选择物料!",{time:1000});
            return false;
        }
        parent.addMaterialInfo(code);
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }

    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }

    function cancel(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
</script>
</body>
</html>
