@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}



<script>
     layui.use(['jquery','upload', 'form', 'laydate', 'common','optimizeSelectOption'], function () {
         var form = layui.form,
             $ = layui.$,
             upload = layui.upload,
             common = layui.common,
             laydate = layui.laydate;
         var keyValue = $.request("keyValue");
         //权限字段
         common.authorizeFields('adminform');

         var uploadInst = upload.render({
            elem: '#uploader'
            , url: '/FileManage/Uploadfile/Upload' //改成您自己的上传接口
            , size: 1024
            , accept: 'file'
            , data: { filetype: 3, fileby: '客户订单' }
            , auto: true//不自动提交
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    //失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                    common.modalMsg(res.msg, "warning");
                    return false;
                }
                $('#F_Attachment').val(res.data[0].src);
                $('.myDownloader').show();
                $('#downloader').attr('href',res.data[0].src);
                // $('#F_Attachment').text(res.data[0].src);
                // $('#F_Attachment').attr('src',res.data[0].src);
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });

         //此处需修改
         //类型为时间时
         //laydate.render({
             //elem: '#F_Birthday'
             //, btns: ['clear', 'now']
             //, trigger: 'click',
             //format: 'yyyy-MM-dd',
         //});

          var dataCfg=[{
              elem:'#F_CooperationTime',
              btns: ['clear', 'now'],
              trigger: 'click',
              format: 'yyyy-MM-dd'
            },{
                elem:'#F_PostTime',
               btns: ['clear', 'now'],
               trigger: 'click',
               format: 'yyyy-MM-dd'
            },
          ];

          $(function () {


             dataCfg.forEach(function(config) { laydate.render(config);});
             if (!!keyValue) {
                  common.ajax({
                    url: '/OrderManagement/OrderCustomer/GetFormJson',
                    dataType: 'json',
                    data: { keyValue: keyValue },
                    async: false,
                    success: function (data) {
                        common.val('adminform', data);
                     }
                });
            }
            form.render();
            var _fileVal = $('#F_Attachment').val();
              if(_fileVal.length<5){
                  //没有上传文件
                  $('.myDownloader').hide();
              }else{
                  $('.myDownloader').show();
                  $('#downloader').attr('href',_fileVal);
              }
        });
        wcLoading.close();


        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var postData = data.field;
            common.submitForm({
                url: '/OrderManagement/OrderCustomer/SubmitForm?keyValue=' + keyValue,
                param: postData,
                success: function () {
                    common.parentreload('data-search-btn');
                }
            })
            return false;
        });
    });
</script>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">

            <style>

                .layui-form-select > .layui-select-title > input {
                    margin-left: 10px;
                }

                #downloader {
                    color: dodgerblue;
                    cursor: pointer;
                }
            </style>

            <div class="layui-form layuimini-form" lay-filter="adminform">

                <div class="layui-form-item">
                    <label style="margin-left:-10px" class="layui-form-label required">客户名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="F_Name" name="F_Name" autocomplete="off" lay-verify="required" placeholder="请输入" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6">
                        <label class="layui-form-label required">开始合作时间</label>
                        <div class="layui-input-block">
                            <input style="margin-left:10px" type="text" id="F_CooperationTime" name="F_CooperationTime" autocomplete="off" lay-verify="required" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-col-md6 layui-col-sm6">
                        <label class="layui-form-label required">发帖时间</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_PostTime" name="F_PostTime" autocomplete="off" lay-verify="required" class="layui-input">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6">
                        <label class="layui-form-label required">合作进展</label>
                        <div class="layui-input-block">
                            <select id="F_OrderState" name="F_OrderState" lay-verify="required">
                                <option value="">===请选择===</option>
                                <option value="1">持续合作</option>
                                <option value="0">断续</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-col-md6 layui-col-sm6">
                        <label class="layui-form-label">联系方式</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_Contact" name="F_Contact" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6">
                        <label class="layui-form-label required">对接人</label>
                        <div class="layui-input-block">
                            <input style="margin-left:10px" type="text" id="F_ContactPerson" name="F_ContactPerson" autocomplete="off" lay-verify="required" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-col-md6 layui-col-sm6">
                        <label class="layui-form-label required">对接情况</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_Docking" name="F_Docking" autocomplete="off" lay-verify="required" class="layui-input">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">附件</label>
                    <div class="layui-input-block" style="padding-right: 70px;">
                        <input type="text" id="F_Attachment" name="F_Attachment" readonly disabled class="layui-input">
                        @* <a class="layui-input" id="F_Attachment" name="F_Attachment"></a> *@
                        <button class="layui-btn" style="position: absolute;top: 0;right: 6px;cursor: pointer;" id="uploader">上传</button>
                    </div>
                </div>
                <div class="layui-form-item myDownloader" style="display:none">
                    <label class="layui-form-label"></label>
                    <a target="_blank" id="downloader">下载附件</a>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea id="F_Remark" name="F_Remark" value="" autocomplete="off" class="layui-textarea"></textarea>
                    </div>
                </div>

                <div class="layui-form-item layui-hide">
                    <button class="layui-btn site-demo-active" lay-submit id="submit" lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</body>

