
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'
        , type: 'datetime'
    });


    //绑定原始文件域
    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_GoodsImg").val(res.src);
              $(".mengban").css('z-index', '-1');
          }
          //上传成功
      }
    });

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

        //属性
        if (dataArr["F_PropertyId"] != null && dataArr["F_PropertyId"] != "") {
            dataArr["F_PropertyName"] = $("#F_PropertyId").find("option:selected").text();
        }
        //种类
        if (dataArr["F_KindsId"] != null && dataArr["F_KindsId"] != "") {

            dataArr["F_KindsName"] = $("#F_KindsId").find("option:selected").text();
        }

        $.ajax({
            url: "/LostGoods/SaveRegistInfoEdit",
            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;
    });



    //.监听当前 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_CREATEBY").empty();
                    $("#F_CREATEBY").append("<option value='' ></option>");
                    var list = eval("(" + result + ")");
                    if (list.length > 0) {
                        for (var i = 0; i < list.length; i++) {


                            $("#F_CREATEBY").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);
});
