<%@ 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-lg4 layui-col-sm4">
                        <label class="layui-form-label"><i class="mark">*</i>条码：</label>
                        <div class="layui-input-block">
                            <div id="newBarcode"></div>
                            <input type="hidden" id="materialCode" value="${materialCode}">
                            <input type="hidden" id="uniqueId" value="${uniqueId}">
                            <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 newBarcode = 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;

        var newBarcode = xmSelect.render({
            el: '#newBarcode',
            name: 'newBarcode',
            radio: true,
            tips: '请输入查询',
            clickClose: true,
            filterable: true,
            remoteSearch: true,
            remoteMethod: function (val, cb, show) {
                if (!isBlank(val)) {
                    $.ajax({
                        type: 'post',
                        url: '${ctx}/entryChanges/materialInformationChange/getChangeBarCodeList',
                        async: false,
                        dataType: 'json',
                        data:{
                            materialCode:`${materialCode}`,
                            newBarcode:val
                        },
                        success: function (d) {
                            var arr = [];
                            for (var i = 0; i < d.length; i++) {
                                var data = {};
                                data.name = d[i].material_barcode;
                                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;
                    newBarcode = d.material_barcode;
                    $("#code").val(newBarcode);
                }
            }
        });


    });

    function confirm(){
        parent.setValue($("#uniqueId").val(),$("#code").val());
        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>