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

  //点击细类打开页面
  $('.layui-card-header').on('click','.clickpanle a', function () {
    console.log("点击了")
    //置忙
    top.AgentBusy();

    var data = {
      F_CustomerId: $("#F_CustomerId").val(),
      F_CustomerName: $("#F_CustomerName").val(),
      F_CustomerPym: $('.sexParam input[name="F_CustomerPym"]:checked ').val(),
      F_CustomerEName: $("#F_CustomerEName").val(),
      F_PostCode: $("#F_PostCode").val(),
      F_CustomerLayer: $("#F_CustomerLayer").html().trim(),
      F_CustomerCode: $("#F_CustomerCode").val(),
      F_Telephone: $("#F_Telephone").html().trim(),
      F_ScaleResume: $("#F_ScaleResume").val(),
      F_CustomerClass: $("#F_CustomerClass").val()


    }

    //工单编号
    var workOrderNum = $("#workOrderNum").val();
    var flowid = $(this).attr("data-url");
    var flowType = $(this).attr("data-type");
    var flowValue = $(this).attr("data-value");
    
    //特殊类处理
    if (flowType != null && flowType != "" && flowType == "ZX" && flowid != 39) {
      //所有表单数据

      var dataArr = {
        F_WORKORDERSTATEID: 5,
        F_REPAIRREQUEST: "已处理",
        F_FILEFLAG: "6",
        F_HOUSING: "咨询",
        F_REPAIRLEVEL: flowid,
        F_ADSLACCOUNT: flowValue,
        CustomerBaseModel: data,
        F_WORKORDERID: workOrderNum,
        F_REPAIRMANID: 1,
        F_WORKORDERFROM: "语音工单",
        F_CUSTOMERNAME: $("#F_CustomerName").val(),
        F_CUSTOMERTELEPHONE: $("#F_Telephone").html().trim(),
        F_WORKORDERTYPEID: 3//处理方式

      }

      $.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("提交成功");
            try {
              //置闲
              top.AgentFree();
            }
            catch (e) { }
            try {
              layer.msg('提交成功', {
                icon: 1,
                time: 10 //2秒关闭（如果不配置，默认是3秒）
              }, function () {

                $(".callScreen").hide()

                //top.document.getElementById("mainframe").src = "/Main/IndexCenter";
              });
              //        layer.open({
              //            content: '提交成功'
              //     , btn: ['确定']
              //     , yes: function (index, layero) {

              //         layer.close(index);
              //         top.document.getElementById("mainframe").src = "/Main/IndexCenter";

              //     }
              //        , cancel: function () {

              //            top.document.getElementById("mainframe").src = "/Main/IndexCenter";

              //        }
              //});
              //parent.document.getElementById("mainframe").src = "/Main/IndexCenter";
              //var thisindex = parent.layer.getFrameIndex(window.name); //获取窗口索引
              //parent.layer.close(thisindex);
              //top.CloseLayerNow();
            }
            catch (e) { }
            return false;
          } else {
            alert("提交失败");

            return false;
          }

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

      $.ajax({
        url: "/CallRecord/SaveCunInfo",
        type: "post",
        async: false,//同步请求
        contentType: "application/json",
        dataType: "text",
        cache: false,
        data: JSON.stringify(data),
        // data: dataArr,
        success: function (thisResult, result) {
        },
        error: function (error) {
          return false;
        }
      });

      layer.open({
        type: 2,
        anim: 4,
        scrollbar: false,
        zIndex: layer.zIndex,
        content: '/CallRecord/CallWorkFolw/?workOrderNum=' + workOrderNum + '&flowid=' + flowid,
        area: ['90%', '90%'],
        id: 'CallWorkFolw',
        title: '服务监督热线系统业务工单'
        , success: function (layero) {
          layer.setTop(layero); //重点2
        }
        , end: function () {
          try {
            //置闲
            top.AgentFree();
          }
          catch (e) { }
          try {
            $(".callScreen").hide()
            //top.document.getElementById("mainframe").src = "/Main/IndexCenter";
            //var thisindex = parent.layer.getFrameIndex(window.name); //获取窗口索引
            //parent.layer.close(thisindex);
            //top.CloseLayerNow();
          }
          catch (e) { }
        }

      });
    }
  });







  //特别关注
  $('.layui-btn-group .careCustom').on('click', function () {


    var cusType = $("#F_ScaleResume").val();
    if (cusType == 1) {
      $("#F_ScaleResume").val("2");
      $("#F_CustomerClass").val("特别关注");

      //改变特别关注样式
      $(".layui-btn-group .careCustom").removeClass("layui-btn-primary");
      $(".layui-btn-group .careCustom").addClass("layui-btn-warm");

    }
    else if (cusType == 2) {
      $("#F_ScaleResume").val("1");
      $("#F_CustomerClass").val("一般用户");
      //改变特别关注样式
      $(".layui-btn-group .careCustom").removeClass("layui-btn-warm");
      $(".layui-btn-group .careCustom").addClass("layui-btn-primary");

    }
    else if (cusType == 3) {
      $("#F_ScaleResume").val("2");
      $("#F_CustomerClass").val("特别关注");
      //改变特别关注样式
      $(".layui-btn-group .careCustom").removeClass("layui-btn-primary");
      $(".layui-btn-group .careCustom").addClass("layui-btn-warm");

      //改变黑名单样式
      $(".layui-btn-group .blackCustom").removeClass("layui-btn-warm");
      $(".layui-btn-group .blackCustom").addClass("layui-btn-primary");
    }


  });
  //黑名单
  $('.layui-btn-group .blackCustom').on('click', function () {

    var cusType = $("#F_ScaleResume").val();
    if (cusType == 1 || cusType == 2) {
      $("#F_ScaleResume").val("3");
      $("#F_CustomerClass").val("黑名单");
      //改变特别关注样式
      $(".layui-btn-group .careCustom").removeClass("layui-btn-warm");
      $(".layui-btn-group .careCustom").addClass("layui-btn-primary");

      //改变黑名单样式
      $(".layui-btn-group .blackCustom").removeClass("layui-btn-primary");
      $(".layui-btn-group .blackCustom").addClass("layui-btn-warm");

    }
    else if (cusType == 3) {
      $("#F_ScaleResume").val("1");
      $("#F_CustomerClass").val("一般用户");

      //改变黑名单样式
      $(".layui-btn-group .blackCustom").removeClass("layui-btn-warm");
      $(".layui-btn-group .blackCustom").addClass("layui-btn-primary");
    }

  });

})