$('.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;

  console.log(1111)
  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', '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;
  console.log()
  //日期
  laydate.render({
    elem: '#date',
    min: 0,
    type: 'datetime',
    calendar: true,
    ready: function (date) {
      $(".layui-laydate-footer [lay-type='datetime'].laydate-btns-time").click();
      $(".laydate-main-list-0 .layui-laydate-content li ol li:last-child").click();
      $(".layui-laydate-footer [lay-type='date'].laydate-btns-time").click();
    }
  });
  //日期
  laydate.render({
    elem: '#date1',
    min: 0,
    type: 'datetime',
    calendar: true,
    ready: function (date) {
      $(".layui-laydate-footer [lay-type='datetime'].laydate-btns-time").click();
      $(".laydate-main-list-0 .layui-laydate-content li ol li:last-child").click();
      $(".layui-laydate-footer [lay-type='date'].laydate-btns-time").click();
    }
  });
    //#region 202212
  //if(document.getElementById("checkVisit").checked){
  //  $('#date1').attr('disabled',false)
  //}else{
  //  $('#date1').attr('disabled',true)
  //}
  //console.log(document.getElementById("checkVisit").checked)
     //#endregion 202212
    form.on('checkbox(statue)', function (obj) {
    console.log(obj)
    var check = obj.elem.checked;
    console.log(check)
    if (!check) {
      $('#date1').attr('disabled',true)
      $('#date1').val('')
    }else{
      $('#date1').attr('disabled',false)
    }
  });
  upload.render({
    elem: '#test3'
    , url: '/Upload/UploadFile/' //改成您自己的上传接口
    , accept: 'file' //普通文件
    , done: function (res) {
      layer.msg('上传成功');
      $(".test3File").text(res.src.split('/')[4])
      $("#F_INSTALLADDRESS").val(res.src)
    }
  });
  
  form.on('radio(sexCheck)', function (data) {
    var value = data.value;   //  当前选中的value值
    if (value == "3") {
      $(".huifangDIV").hide()
      if ($("#F_ADSLACCOUNT").find("option:selected").attr("parentname")=="表扬") {
        $(".workTypeDiv").show()
      } else {
        $(".workTypeDiv").hide()
      }
      

    } else if ((value == "1")) {
      $(".workTypeDiv").show()
      $(".huifangDIV").show()
    }


    

  });


  //监听提交
  form.on('submit(SubmitData)', function (data) {
    //所有表单数据
      //#region 202212注释
    //var searchOfficeId = $("#searchOfficeId").val();
    //var officeName = $("#officeName").val();
    HistoryOrderList = []

    //for (var i = 0; i < searchOfficeId.split(",").length; i++) {
    //  console.log(i)
    //  if(searchOfficeId.split(",")[i]){
    //    var obj = {}
    //    obj.F_OPTUSERID = searchOfficeId.split(",")[i]
    //    obj.F_UserName = officeName.split(",")[i]
    //    console.log(obj)
    //    HistoryOrderList.push(obj)
    //  }     

    //}#endregion 202212注释
    var dataArr = new Array();
    dataArr = data.field;
    //console.log(HistoryOrderList) //处理人员

    if(helper.cookies.get('F_REPAIRMANID')=="4"){
        //202212if($("#F_CustomerEName").val()==""){
        //  layui.layer.alert("请输入微博号", {
        //    icon: 2
        //    ,offset: '40%'
        //  });
        //  return false;
        //}202212
        
        //来电号码
        dataArr["F_REPAIRMANID"] = helper.cookies.get('F_REPAIRMANID');
    }else{
      //来电号码
      dataArr["F_CUSTOMERTELEPHONE"] = $("#F_Telephone").html().trim();
    }
    //转办   $('input:radio[name="F_WORKORDERTYPEID"]:checked').val()=="1"

      // //#region  202212 这个是转发的 隐藏掉
      if ($('input:radio[name="F_WORKORDERTYPEID"]:checked').val() == 1 || $("#F_ADSLACCOUNT").find("option:selected").attr("parentname") == "表扬") {
          dataArr["F_WORKORDERSTATEID"] = 5;
          dataArr["F_REPAIRREQUEST"] = "已转办";
      }
      else {
          dataArr["F_WORKORDERSTATEID"] = 5;
          dataArr["F_REPAIRREQUEST"] = "已处理";
      }
        //if (HistoryOrderList.length==0) {
      //  layui.layer.alert("请选择转发人员", {
      //    icon: 2
      //    ,offset: '40%'
      //  });
      //  return false;
      //}  
   
                
        //if($("#F_ADSLACCOUNT").find("option:selected").attr("parentname")!="表扬"){
      //  if ($("#date").val() == "") {
      //    layui.layer.alert("请选择回复时间", {
      //      icon: 2
      //      ,offset: '40%'
      //    });
      //    return false;
      //  }
      //}

      
      //dataArr["F_WORKORDERSTATEID"] = 1;
      //dataArr["F_REPAIRREQUEST"] = "处理中";
      //}
      ////
   // else {#endregion  202212 这个是转发的 隐藏掉
        //2021 8 20 号改成 已处理
      //dataArr["F_WORKORDERSTATEID"] = 2;
      //dataArr["F_REPAIRREQUEST"] = "已办结";

   
   // }#202212
    dataArr["HistoryOrderList"] = HistoryOrderList;
    dataArr["F_INSTALLADDRESS"] = $("#F_INSTALLADDRESS").val();
    //业务类型名称
    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");
    //投诉类回复时间不能为空
    //if (dataArr["F_FILEFLAG"] != null && dataArr["F_FILEFLAG"] != "" && dataArr["F_FILEFLAG"] == 3) {
       
    //}

    //转办部门
    dataArr["F_DEPTCODE"] = $("#F_DEPTID").find("option:selected").text();
    //转办人员
    dataArr["F_USERNAME"] = $("#F_CREATEBY").find("option:selected").text();

    //是否回访
    if (dataArr["F_RETURNVISITFLAG"] == "on") {
      dataArr["F_RETURNVISITFLAG"] = 1;
      if (dataArr["F_RETURNVISITTIME"] == null || dataArr["F_RETURNVISITTIME"] == "") {
        if($('.huifangDIV').css('display') == 'block') {
          layui.layer.alert("计划回访时间不能为空!", {
            icon: 2
          });
          return false;
        }
      }
    }
    else {
      dataArr["F_RETURNVISITFLAG"] = 0;
    }
    //客户信息
    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_CustomerEName: $("#F_CustomerEName").val(),

      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;

    console.log(dataArr["CustomerBaseModel"])
    console.log(dataArr)
    $.ajax({
      url: "/CallRecord/workOrderAddData",
      type: "post",
      async: false,//同步请求
      contentType: "application/json",
      dataType: "text",
      cache: false,
      data: JSON.stringify(dataArr),
      // data: dataArr,
      success: function (thisResult, result) {

        if (thisResult == "True") {
          //alert("提交成功");
          //top.document.getElementById("mainframe").src = "/Main/IndexCenter";
          try {
            var thisindex = parent.layer.getFrameIndex(window.name); //获取窗口索引
            parent.layer.close(thisindex);
          }
          catch (e) { }
          return false;
        } else {
          alert("提交失败");
          //layui.layer.alert("提交失败!", {
          //    icon: 2
          //});

          return false;
        }

      },
      error: function (error) {
        return false;
      }
    });
    return false;
  });
  //监听保存
  form.on('submit(SubmitSaveData)', function (data) {
    debugger
    HistoryOrderList = new Array()
    //所有表单数据
    var dataArr = new Array();
    dataArr = data.field;
      console.log(data.F_REPAIRMANID)
    if (data.F_REPAIRMANID == 3) {
      helper.cookies.set('F_REPAIRMANID', "")
    }
    if(helper.cookies.get('F_REPAIRMANID')=="4"){
      debugger
      //if($("#F_CustomerEName").val()==""){
      //  layui.layer.alert("请输入微博号", {
      //    icon: 2
      //  });
      //  return false;
      //}
      //来电号码
      dataArr["F_REPAIRMANID"] = helper.cookies.get('F_REPAIRMANID');
      console.log(helper.cookies.get('F_REPAIRMANID'))
    }
    
    var zbbm = $("#F_DEPTID").find("option:selected").val();
    var zbry = $("#F_CREATEBY").find("option:selected").val();
    dataArr["F_WORKORDERSTATEID"] = 0;
    dataArr["F_REPAIRREQUEST"] = "待处理";

    dataArr["F_INSTALLADDRESS"] = $("#F_INSTALLADDRESS").val();
    //业务类型名称
    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_DEPTCODE"] = $("#F_DEPTID").find("option:selected").text();
    //转办人员
    dataArr["F_USERNAME"] = $("#F_CREATEBY").find("option:selected").text();

    //是否回访
    if (dataArr["F_RETURNVISITFLAG"] == "on") {
      dataArr["F_RETURNVISITFLAG"] = 1;
    }
    else {
      dataArr["F_RETURNVISITFLAG"] = 0;
    }
    //来电号码
    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_CustomerEName: $("#F_CustomerEName").val(),
      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/workOrderAddData",
      type: "post",
      async: false,//同步请求
      contentType: "application/json",
      dataType: "text",
      cache: false,
      data: JSON.stringify(dataArr),
      // data: dataArr,
      success: function (thisResult, result) {
        if (thisResult == "True") {
          //top.document.getElementById("mainframe").src = "/Main/IndexCenter";
          try {
            var thisindex = parent.layer.getFrameIndex(window.name); //获取窗口索引
            parent.layer.close(thisindex);
          }
          catch (e) { }

          //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 {
          alert("提交失败");
          //layui.layer.alert("保存失败!", {
          //    icon: 2
          //});

          return false;
        }

      },
      error: function (error) {
        return false;
      }
    });
    return false;
  });
  //.监听当前 select，动态改变子项
  form.on('select(busstype)', function (d) {
    var F_ADSLACCOUNT = $("#F_ADSLACCOUNT").find("option:selected").attr("parentname");
    if(F_ADSLACCOUNT=="表扬"||F_ADSLACCOUNT=="咨询"||F_ADSLACCOUNT=="挂失"){
      if(F_ADSLACCOUNT=="表扬"){
        $(".workTypeDiv").show()
        $(".huifangDIV").hide()
        $(".F_WORKORDERTYPEID").attr("disabled","disabled")
      }else{
        $(".F_WORKORDERTYPEID").removeAttr("disabled")
        $(".huifangDIV").show()
      }
      if ($('input:radio[name="F_WORKORDERTYPEID"]:checked').val()=="3") {
        $(".huifangDIV").hide()
      } else{
        $(".huifangDIV").show()
      }
    }else{
      $(".F_WORKORDERTYPEID").removeAttr("disabled")
      if ($('input:radio[name="F_WORKORDERTYPEID"]:checked').val()=="3") {
        $(".huifangDIV").hide()
      } else{
        $(".huifangDIV").show()
      }
    }
    $.ajax({
      url: "/CallRecord/GetTypeContenet",
      type: "get",
      contentType: "application/json",
      dataType: "text",
      cache: false,
      data: { "bussnessType": d.value, "creatDateTime": $("#creatDateTime").val() },
      success: function (result, status) {
        if (status) {

          $("#bussContent").text(result);

        }


      }
    });
  });
  //.监听当前 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
            ,offset: '40%'
          });
        }

      }
    });
  });
  //.监听当前 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;
        }
      });
    }

  });
  //.监听当前 select，动态改变子项
  form.on('select(accepttype)', 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_OPTUSERID").empty();
          $(".F_OPTUSERID").append("<option value='' ></option>");
          var list = eval("(" + result + ")");
          if (list.length > 0) {
            for (var i = 0; i < list.length; i++) {


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

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

      }
    });
  });
})

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





