var m_businessstatecache = "";//业务状态
var m_FansCheckStatus = "";
var m_SystemFansStateCache = [];
var m_BusinessCheckStstus = "";//当前选中状态集合
var m_NowBusinessCheck = "";//当前提交状态集合
//--------------------------------------------业务状态--------------------------------------------
var m_SystemFansGgStateCache = [];//所有广告系统业务状态
var m_BusinessCheckGgStstus = "";//当前选中状态集合
//业务状态
function ShowBusiness() {
    var strParaJson = $.toJSON({
        key: "g_business_state"
    });
    talkObj.getbusinessstauts(strParaJson);

}
//获取业务状态回调
function AsyncGetBusinessStautsResult(jsonResult) {
    $("#selectFansStateModel").modal({ backdrop: 'static', keyboard: false });
    if (jsonResult.success) {
        if (jsonResult.wechats == null || jsonResult.wechats == "undefined"
            || jsonResult.wechats[0].valus == null || jsonResult.wechats[0].valus == "undefined"
            ) {
            $("#divFansStateList").html("暂无数据！");
            return;
        }
       
        for (var i = 0; i < jsonResult.wechats.length; i++) {
        	if (jsonResult.wechats[i].key == "g_business_state") {
        		m_SystemFansStateCache = $.parseJSON(jsonResult.wechats[i].valus);
        	} else if (jsonResult.wechats[i].key == "gg_business_state") {
        		m_SystemFansGgStateCache = $.parseJSON(jsonResult.wechats[i].valus);
        	}
        }
        
        var htmlContent = "";
    	//微客多多状态遍历
        for (var i = 0; i < m_SystemFansStateCache.length; i++) {
            htmlContent += "<a id=\"btnFansState" + $.trim(m_SystemFansStateCache[i]) + "\" href=\"javascript:void(0);\"";
            htmlContent += "class=\"btn btn-default\"";
            htmlContent += "onclick=\"CheckFansState('" + encodeURI($.trim(m_SystemFansStateCache[i])) + "');\">" + m_SystemFansStateCache[i] + "</a>";
            if ((i + 1) < m_SystemFansStateCache.length) {
                htmlContent += "<i class=\"fa fa-long-arrow-right\" aria-hidden=\"true\"></i>";
            }
        }
        var htmlGgContent = "";
    	//广告系统业务状态遍历
        for (var j = 0; j < m_SystemFansGgStateCache.length; j++) {
        	htmlGgContent += "<a id=\"btnFansGgState" + $.trim(m_SystemFansGgStateCache[j]) + "\" href=\"javascript:void(0);\"";
        	htmlGgContent += "class=\"btn btn-default\"";
        	htmlGgContent += "onclick=\"CheckFansGgState('" + encodeURI($.trim(m_SystemFansGgStateCache[j])) + "');\">" + m_SystemFansGgStateCache[j] + "</a>";
        	if ((j + 1) < m_SystemFansGgStateCache.length) {
        		htmlGgContent += "<i class=\"fa fa-long-arrow-right\" aria-hidden=\"true\"></i>";
        	}
        }
		//End
        $("#divFansStateList").html(htmlContent);
        var strbusiness = SuperReplace(m_BusinessCheckStstus, "|", "#");
        var Statusitem = strbusiness.split("#");

        for (var i = 0; i < Statusitem.length - 1; i++) {
            CheckFansState($.trim(Statusitem[i]))
        }
    }
}
//更改粉丝业务状态
function CheckFansState(val) {
    var status = decodeURIComponent(val);
    var btn = $("#btnFansState" + status);
    if (btn.length > 0) {
        if (btn.attr("class") == "btn btn-default") {
            btn.attr("class", "btn btn-success");
        } else {
            btn.attr("class", "btn btn-default");
        }
    }
}
//提交
function ResetFansMark() {

    var objhidDocWechatKey = $("#hidDocWechatKey");
    var objhidDocPid = $("#hidDocPid");
    var objtxtDocName = $("#txtDocName");
    var objtxtDocAge = $("#txtDocAge");
    var objtxtDocMobile = $("#txtDocMobile");
    var objtxtDocWXCode = $("#txtDocWXCode");
    //var objtxtTagVal = $("#txtTagVal");
    //var objtxtBisVal = $("#txtBisVal");
    var objtxtDocRemark = $("#txtDocRemark");
    var objselectPersonDept = $("#selectPersonDept");
    var objhidDocUin = $("#hidDocUin");
    objtxtDocAge.val($.trim(objtxtDocAge.val()));
    objtxtDocName.val($.trim(objtxtDocName.val()));
    objtxtDocMobile.val($.trim(objtxtDocMobile.val()));
    objtxtDocWXCode.val($.trim(objtxtDocWXCode.val()));
    //objtxtTagVal.val($.trim(objtxtTagVal.val()));
    //objtxtBisVal.val($.trim(objtxtBisVal.val()));
    objtxtDocRemark.html($.trim(objtxtDocRemark.html()));


    var selectVal = "";
    for (var i = 0; i < m_SystemFansStateCache.length; i++) {
        var btn = $("#btnFansState" + $.trim(m_SystemFansStateCache[i]));
        if (btn.length > 0) {
            if (btn.attr("class") == "btn btn-success") {
                selectVal += "|" + $.trim(m_SystemFansStateCache[i]) + "|";
            }
        }
    }
	//广告系统状态
    var selectGgVal = "";
    for (var i = 0; i < m_SystemFansGgStateCache.length; i++) {
    	var btn = $("#btnFansGgState" + $.trim(m_SystemFansGgStateCache[i]));
    	if (btn.length > 0) {
    		if (btn.attr("class") == "btn btn-success") {
    			selectGgVal += "|" + $.trim(m_SystemFansGgStateCache[i]) + "|";
    		}
    	}
    }
    var bisbusiness = SuperReplace(selectVal, "||", "|");
    var ggbisbusiness = SuperReplace(selectGgVal, "||", "|")
    var strParaJson = $.toJSON({
    	wechatkey: objhidDocWechatKey.val(),
    	pid: objhidDocPid.val(),
    	age: objtxtDocAge.val(),
    	name: objtxtDocName.val(),
    	fmobile: objtxtDocMobile.val(),
    	wxcode: objtxtDocWXCode.val(),
    	remark: objtxtDocRemark.html(),
    	tagval: m_NowSelectFriendTags,
    	ggtagval: m_NowSelectFriendggTags,
    	bisval: bisbusiness,
    	ggbisval: ggbisbusiness,
    	groupname: objselectPersonDept.html(),
    	uin: objhidDocUin.val()
    });
    talkObj.setfrienddoc(strParaJson);
    ResetFriendTagList()
    m_BusinessCheckStstus = bisbusiness;
    m_BusinessCheckGgStstus = ggbisbusiness;
}
//回调
function AsyncSetFriendDocResult(jsonResult) {
    if (jsonResult.success) {
        if (m_BusinessCheckStstus.length > 0) {
            var showstatus = SuperReplace(m_BusinessCheckStstus, "|", "<span>-<span>");
            $("#divDocFriendsSelectStatus").html(showstatus.substr(0, showstatus.length - 2));
        } else {
            $("#divDocFriendsSelectStatus").html("暂无状态");
        }
    }
}

//--------------------------------------------业务状态--------------------------------------------End
