$('.DicSelect').on('click', function () {
    var rootCode = $(this).find("input").eq(1).attr("diccode");
    var code1 = document.getElementsByName("F_DeviceCount")[0].value;
    var name1 = document.getElementsByName("F_Fax")[0].value;

    var code2 = document.getElementsByName("F_AfterSaleNameID")[0].value;
    var name2 = document.getElementsByName("F_Email")[0].value;

    var code3 = document.getElementsByName("F_WORKORDERLEVELID")[0].value;
    var name3 = document.getElementsByName("F_WORKORDERNAME")[0].value;


    layer.open({
        type: 2,
        scrollbar: false,
        content: '/WXInterFace/GetDicSelect/?diccode=' + rootCode + "&code1=" + code1 + "&name1=" + name1 + "&code2=" + code2 + "&name2=" + name2 + "&code3=" + code3 + "&name3=" + name3,
        area: ['700px', '500px'],
        id: 'goodNameSelect',
        title: '选择'

    })
});

function saveParams(code1, name1, code2, name2, code3, name3) {
    document.getElementsByName("F_DeviceCount")[0].value = code1;
    document.getElementsByName("F_Fax")[0].value = name1;

    document.getElementsByName("F_AfterSaleNameID")[0].value = code2;
    document.getElementsByName("F_Email")[0].value = name2;

    document.getElementsByName("F_WORKORDERLEVELID")[0].value = code3;
    document.getElementsByName("F_WORKORDERNAME")[0].value = name3;
}




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

    //日期
    laydate.render({
        elem: '#date'
    });
    //日期
    laydate.render({
        elem: '#date1'
    });
    //日期
    laydate.render({
        elem: '#date2'
    });
    //监听保存
    form.on('submit(SubmitSaveData)', function (data) {
        //所有表单数据
        var dataArr = new Array();
        dataArr = data.field;
    
        //是否回访
        if (dataArr["F_RETURNVISITFLAG"] == "on") {
            dataArr["F_RETURNVISITFLAG"] = 1;
        }
        else {
            dataArr["F_RETURNVISITFLAG"] = 0;
        }
        //业务类型名称
        dataArr["F_ADSLACCOUNT"] = $("#F_ADSLACCOUNT").find("option:selected").text();
        //业务类别
        dataArr["F_FILEFLAG"] = $("#F_ADSLACCOUNT").find("option:selected").attr("parentid");
        //业务类别名称
        dataArr["F_HOUSING"] = $("#F_ADSLACCOUNT").find("option:selected").attr("parentname");
        //来电号码
        dataArr["F_CUSTOMERTELEPHONE"] = $("#F_Telephone").html().trim();

        //客户信息
        var costomInfoModle = {
            F_CustomerId: $("#F_CustomerId").val(),
            F_CustomerName: $("#F_CustomerName").val(),
            F_CustomerPym: $('.sexParam input[name="F_CustomerPym"]:checked ').val(),
            F_CustomerCode: $("#F_CustomerCode").val(),
            F_Telephone: $("#F_Telephone").html().trim(),
            F_Mobile: $("#F_Mobile").val().trim(),
            F_DeviceCount: $("#F_DeviceCount").val(),
            F_Fax: $("#F_Fax").val(),
            F_AfterSaleNameID: $("#F_AfterSaleNameID").val(),
            F_Email: $("#F_Email").val()
        }
        dataArr["CustomerBaseModel"] = costomInfoModle;
        $.ajax({
            url: "/CallRecord/workOrderEditData",
            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: '保存成功'
                        ,offset: '40%'
                         , 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 {
                    layui.layer.alert("保存失败!", {
                        icon: 2
                        ,offset: '40%'
                    });

                    return false;
                }

            },
            error: function (error) {
                return false;
            }
        });
        return false;
    });
     //.监听当前 select，动态改变子项
  form.on('select(searchLabel)', function (d) {
    if (d.value) {
      var data = {
        id: d.value
      }
      $.ajax({
        url: "/Tag/GetData",
        type: "post",
        async: false,//同步请求
        contentType: "application/json",
        dataType: "text",
        cache: false,
        data: JSON.stringify(data),
        success: function (thisResult) {
          if (eval('(' + thisResult + ')').msg == "成功") {
            var data = eval('(' + thisResult + ')')
            $('#bussContent').val(data.data.F_About)
            $("#nrContent").val(data.data.F_Content);
          } else {
            layer.msg('失败');

          }

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

  });
})


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