<%@ page language="java" contentType="text/html;charset=UTF-8" trimDirectiveWhitespaces="true"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fastboot" prefix="fb"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro"%>
<fb:ui src="base/main">
    <fb:property name="title">批量发布任务</fb:property>
    <fb:css href="${base}/static/js/city-picker/city-picker.css"></fb:css>
    <fb:script src="${base}/static/js/city-picker/city-picker.data.js"></fb:script>
    <fb:script type="text/javascript">
        <script>
            layui.use([ 'tool', 'form', 'city' ], function() {
                var $ = layui.$, tool = layui.tool, form = layui.form, city= layui.city;

                let currentPicker = new city("#city-picker", {
                    getValListener: function(item){}});
                document.getElementById("file").onchange = function(){
                    let blob = document.getElementById("file").files[0];
                    $("#filename").val(blob.name)
                    let reader = new FileReader();
                    reader.readAsDataURL(blob);
                    reader.onload = function(){
                        console.log(reader.result); //获取到base64格式图片
                        $("#fileBase64").val(reader.result)
                    };
                }

                $("#select").on("click",function(){
                    document.getElementById("file").click()
                })
                $("#clean").on("click",function(){
                    document.getElementById("file").value = ""
                    $("#filename").val("")
                    $("#fileBase64").val("")
                })

                <%--tool.loadSelect("${base}/crop_class/list",{--%>
                <%--    id:"cropClassId",--%>
                <%--    data: {},--%>
                <%--    valueField: 'id',--%>
                <%--    textField: 'name',--%>
                <%--    defaultOption:'<option value="">请选择分类</option>'--%>
                <%--})--%>

                <%--form.on('select(cropClassId)', function (data) {--%>
                <%--    tool.loadSelect("${base}/crop_item/list",{--%>
                <%--        id:"cropItemId",--%>
                <%--        data: {classId: data.value},--%>
                <%--        valueField: 'id',--%>
                <%--        textField: 'name',--%>
                <%--        defaultOption:'<option value="">请选择作物</option>'--%>
                <%--    })--%>
                <%--});--%>
            });
            function publish(){
                let data = $("#form1").serializeArray();
                layui.tool.submit('${base}/crop/batchPublish', data);
            }
        </script>

    </fb:script>
    <fb:layout>
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>发布任务</legend>
        </fieldset>
        <form class="layui-form" id="form1" action="">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">地区</label>
                    <div class="layui-input-inline">
                        <input  id="city-picker"    class="layui-input">
                    </div>
                </div>
            </div>
<%--            <div class="layui-form-item">--%>
<%--                <label class="layui-form-label">作物种类</label>--%>
<%--                <div class="layui-input-inline">--%>
<%--                    <select lay-filter="cropClassId" id="cropClassId" name="cropClassId">--%>
<%--                    </select>--%>
<%--                </div>--%>
<%--                <div class="layui-input-inline">--%>
<%--                    <select id="cropItemId" name="cropItemId">--%>
<%--                    </select>--%>
<%--                </div>--%>
<%--            </div>--%>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">上传表格</label>
                    <div class="layui-input-inline">
                        <input type="text" id="filename"  readonly  autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <button type="button" class="layui-btn" id="select" >选择</button>
                        <button type="button" class="layui-btn layui-btn-primary" id="clean" >清除</button>
                    </div>
                </div>
            </div>
            <input type="hidden" id="fileBase64" name="fileBase64"   />
            <input type="file" id="file"  style="display: none"  />
            <input type="button" onclick="publish()" id="submit" style="display: none"  />
        </form>
    </fb:layout>
</fb:ui>