
layui.use(['form', 'upload', 'layer', 'jquery', 'laydate'], function () {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : parent.layer,
        $ = layui.jquery,
        laydate = layui.laydate
     , upload = layui.upload;

    //日期
    laydate.render({
        elem: '#date'
    });


    //绑定原始文件域
    upload.render({
        elem: '#test10'
      , url: '/LostGoods/UploadFile/'
      , done: function (res) {
          //如果上传失败
          if (res.code > 0) {
              return layer.msg(res.msg);
          } else {
              console.log(res.src)
              $("#imgShow").attr('src', res.src);
              $("#F_OwerCardPath").val(res.src);
              $(".mengban").css('z-index', '-1');
          }
          //上传成功
      }
    });



    //监听提交
    form.on('submit(SubmitData)', function (data) {
        //所有表单数据
        var dataArr = new Array();
        dataArr = data.field;
        if (dataArr["types"] == 0) {

            if (dataArr["F_RecivedUserID"] == null || dataArr["F_RecivedUserID"] == "") {
                layui.layer.alert("接收人不能为空!", {
                    icon: 3
                });
                return false;

            }
            //存放地点
            dataArr["F_RecivedUserName"] = $("#F_RecivedUserID").find("option:selected").text();

        }
        else if (dataArr["types"] == 1) {
            if (dataArr["F_OtherDeptName"] == null || dataArr["F_OtherDeptName"] == "") {
                layui.layer.alert("单位名称不能为空!", {
                    icon: 3
                });
                return false;
            }
        }

        $.ajax({
            url: "/LostGoods/SaveLostTransferData",
            type: "post",
            async: false,//同步请求
            contentType: "application/json",
            dataType: "text",
            cache: false,
            data: JSON.stringify(dataArr),
            // data: dataArr,
            success: function (thisResult, result) {
                if (thisResult == "True") {
                    layer.open({
                        content: '保存成功'
                         , btn: ['确定']
                         , yes: function (index, layero) {
                             layer.close(index);
                             ////刷新父窗体

                             var thisindex = parent.layer.getFrameIndex(window.name); //获取窗口索引
                             parent.layer.close(thisindex);
                         }
                            , cancel: function () {
                                var thisindex = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                parent.layer.close(thisindex);
                            }
                    });

                    return false;
                } else {

                    layer.open({
                        title: '提示'
, content: '保存失败!'
                    });
                    return false;
                }

            },
            error: function (error) {
                return false;
            }
        });
        return false;
    });

    form.on('radio(defaultSelect)', function (data) {
        if (data.value == 0) {
            $(".outdept").css("display", "none");
            $(".indept").css("display", "block");
        }
        else {
            $(".outdept").css("display", "block");
            $(".indept").css("display", "none");
        }
    });

    //.监听当前 select，动态改变子项
    form.on('select(fcoptype)', function (d) {
        $.ajax({
            url: "/CallRecord/GetDeptUsers",
            type: "get",
            contentType: "application/json",
            dataType: "text",
            cache: false,
            data: { "deptId": d.value },
            success: function (result, status) {
                if (status) {
                    $("#F_RecivedUserID").empty();
                    $("#F_RecivedUserID").append("<option value='' ></option>");
                    var list = eval("(" + result + ")");
                    if (list.length > 0) {
                        for (var i = 0; i < list.length; i++) {


                            $("#F_RecivedUserID").append("<option  value='" + list[i].F_UserId + "'>" + list[i].F_UserName + "</option>");

                        }
                    }

                    form.render('select');
                }
                else {
                    layui.layer.alert("获取该部门下用户信息失败!", {
                        icon: 2
                    });
                }

            }
        });
    });

})

$('.DicSelect').on('click', function () {

    layer.open({
        type: 2,
        scrollbar: false,
        content: '/LostGoods/GetPathInfo',
        area: ['700px', '500px'],
        id: 'GetPathInfo',
        title: '选择'

    })
});

function saveParams(code1, name1) {
    $("#F_PlaceId").val(code1);
    $("#F_PlaceName").val(name1);
}
//关闭当前页
$('.closeThisPage').on('click', function () {
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.close(index);
});
