<script language="javascript">
var role = '{$role}';
if(role==-2){
	cancel['Report'].dialog('close');
	cancel['Report'] = null;
	$.messager.alert('提示','您没有新增权限！','warning');
}else if(role==-3){
	cancel['Report'].dialog('close');
	cancel['Report'] = null;
	$.messager.alert('提示','您没有编辑权限！','warning');
}

var act = '{$act}';
$(function(){
	$("#addFormReport{$uniqid}").form('load',{
		'type':'<?php echo $info["type"] ?>',
		'pid':'<?php echo $info["pid"] ?>',
		'level':'<?php echo $info["level"] ?>',
		'hertz':'<?php echo $info["hertz"] ?>',
		'priority':'<?php echo $info["priority"] ?>',
		'comy':'<?php echo $info["comy"] ?>',
		'user_id':'<?php echo $info["user_id"] ?>',
		'os':'<?php echo $info["os"] ?>',
		'title':'<?php echo $info["title"] ?>',
		'comment':'<?php echo $info["baseinfo"]["comment"] ?>'
	});
	
	var pid = '{$pid}';
	$("#pid{$uniqid}").combobox({
		url:'__APP__?g=<?php echo GROUP_NAME; ?>&m=Project&a=getProject&act=json',
		editable:true,
		method:'get',
		valueField:'id',
		textField:'text',
		required:true,
		filter: function(q,r){
			var opts = $(this).combobox('options');
			var v = r[opts.textField];
			var vp = ','+String(getPinYin(v));
			var qp = ','+q.toUpperCase();
			if(vp.indexOf(qp)>=0 || v.indexOf(q) == 0){
				return r[opts.textField];
			}
		},
		onLoadSuccess:function(){
			if(act=='add'){
				$("#pid{$uniqid}").combobox('setValue',pid);
			}
		}
	});
	
	$("#priority{$uniqid}").combobox({
		url:'__ITEM__/__RUNTIME__/Data/Json/Linkage/youxianji_data.json',
		editable:false,
		method:'get',
		required:true,
		valueField:'id',
		textField:'text',
		onLoadSuccess:function(){
			if(act=='add'){
				$("#priority{$uniqid}").combobox('setValue',1);
			}
		}
	});
	
	$("#hertz{$uniqid}").combobox({
		url:'__ITEM__/__RUNTIME__/Data/Json/Linkage/chuxianpinlv_data.json',
		editable:false,
		method:'get',
		required:true,
		valueField:'id',
		textField:'text',
		onLoadSuccess:function(){
			if(act=='add'){
				$("#hertz{$uniqid}").combobox('setValue','未知');
			}
		}
	});
	
	$("#type{$uniqid}").combobox({
		url:'__ITEM__/__RUNTIME__/Data/Json/Linkage/chuxianweizhi_data.json',
		editable:false,
		method:'get',
		required:true,
		valueField:'id',
		textField:'text'
	});
	
	$("#level{$uniqid}").combobox({
		url:'__ITEM__/__RUNTIME__/Data/Json/Linkage/yanzhongxing_data.json',
		editable:false,
		method:'get',
		required:true,
		valueField:'id',
		textField:'text',
		onLoadSuccess:function(){
			if(act=='add'){
				$("#level{$uniqid}").combobox('setValue','小调整');
			}
		}
	});
	
	$("#user_id{$uniqid}").combobox({
		url:'__ITEM__/__RUNTIME__/Data/Json/User_2_data.json',
		editable:true,
		method:'get',
		valueField:'id',
		textField:'text',
		required:false,
		filter: function(q,r){
			var opts = $(this).combobox('options');
			var v = r[opts.textField];
			var vp = ','+String(getPinYin(v));
			var qp = ','+q.toUpperCase();
			if(vp.indexOf(qp)>=0 || v.indexOf(q) == 0){
				return r[opts.textField];
			}
		},
	});
	
	var mc = Number('<?php echo C("MORE_COMY") ?>');
	if(mc){
		$("#comy{$uniqid}").combotree({
			url:'__ITEM__/__RUNTIME__/Data/Json/Comy_Part_data.json',
			editable:false,
			method:'get',
			required:false,
			valueField:'id',
			textField:'text',
			onSelect:function(c){
				$("#user_id{$uniqid}").combobox('setValue',0);
				$("#user_id{$uniqid}").combobox('reload','__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=getUser&id='+c['id']);
			},
			onLoadSuccess:function(){
				if(act=='edit'){
					$("#user_id{$uniqid}").combobox('reload','__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=getUser&id=<?php echo $info["comy"] ?>');
				}
			}
		});
	}else{
		$("#comy{$uniqid}").combobox({
			url:'__ITEM__/__RUNTIME__/Data/Json/Part_2_data.json',
			editable:false,
			method:'get',
			required:false,
			valueField:'id',
			textField:'text',
			onSelect:function(c){
				$("#user_id{$uniqid}").combobox('setValue',0);
				$("#user_id{$uniqid}").combobox('reload','__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=getUser&id='+c['id']);
			},
			onLoadSuccess:function(){
				if(act=='edit'){
					$("#user_id{$uniqid}").combobox('reload','__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=getUser&id=<?php echo $info["comy"] ?>');
				}
			}
		});
	}
	
	if(act=='add'){
		$("#pro_creatdate{$uniqid}").datepicker('setValue','<?php echo date("Y-m-d",time()) ?>');
	}
});

function onSubmitReport(idd){
	$.messager.progress();
	$("#toUser"+idd+" option").attr("selected",true);
	$("#addFormReport"+idd).form('submit',{
		url:'__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=add&act=add&go=1',
		onSubmit: function(){
			var isValid = $(this).form('validate');
			if (!isValid){
				$.messager.progress('close');
			}
			return isValid;
		},
		success:function(data){
			$.messager.progress('close');
			$("#toUser"+idd+" option").attr("selected",false);
			if(data==1){
				$.messager.alert('提示','新增数据成功！','info',function(){
					var sa = '{$TC.config.SUBMIT_ACTION}';
					$("#Report").datagrid('reload');
					if(sa==1){
						cancel['Report'].dialog('close');
						cancel['Report'] = null;
					}
				});
			}else if(data==0){
				$.messager.alert('提示','新增数据失败！','warning');
			}else if(data<0){
				$.messager.alert('提示','您没有新增权限！','warning',function(){
					var sa = '{$TC.config.SUBMIT_ACTION}';
					if(sa==1){
						cancel['Report'].dialog('close');
						cancel['Report'] = null;
					}
				});
			}else{
				$.messager.alert('提示',data,'warning');
			}
		}
	});
}

function onUploadReport(idd){
	$.messager.progress();
	$("#toUser"+idd+" option").attr("selected",true);
	var ids = $("#ids"+idd).val();
	$("#addFormReport"+idd).form('submit',{
		url:'__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=add&act=edit&go=1&id='+ids,
		onSubmit: function(){
			var isValid = $(this).form('validate');
			if (!isValid){
				$.messager.progress('close');
			}
			return isValid;
		},
		success:function(data){
			$.messager.progress('close');
			$("#toUser"+idd+" option").attr("selected",false);
			if(data==1){
				$.messager.alert('提示','更新数据成功！','info',function(){
					var sa = '{$TC.config.SUBMIT_ACTION}';
					$("#Report").datagrid('reload');
					$("#ReportDetail").panel('refresh');
					if(sa==1){
						cancel['Report'].dialog('close');
						cancel['Report'] = null;
					}
				});
			}else if(data==0){
				$.messager.alert('提示','更新数据失败！','warning');
			}else if(data==2){
				$.messager.alert('提示','只能更新自己所新增的数据！','warning');
			}else if(data<0){
				$.messager.alert('提示','您没有更新权限','warning',function(){
					var sa = '{$TC.config.SUBMIT_ACTION}';
					if(sa==1){
						cancel['Report'].dialog('close');
						cancel['Report'] = null;
					}
				});
			}else{
				$.messager.alert('提示',data,'warning');
			}
		}
	});
}

function onResetReport(idd){
	cancel['Report'].dialog('close');
	cancel['Report'] = null;
}
</script>
<div class="con-tb">
<form method="post" enctype="multipart/form-data" id="addFormReport{$uniqid}">
    <table class="infobox" width="100%" border="0" cellspacing="0" cellpadding="0" style="border-collapse: collapse;">
      <tbody>
      <tr>
        <td width="11%"><label for="bugno">问题编号</label><input id="ids{$uniqid}" type="hidden" value="{$id}" /></td>
        <td width="23%">{$bugno}<input name="bugno" type="hidden" value="{$bugno}" /></td>
        <td width="11%"><label for="type">出现位置</label></td>
        <td width="22%"><input name="type" id="type{$uniqid}" class="relo" size="24" /></td>
        <td width="11%"><label for="pid">所属项目</label></td>
        <td width="22%"><input name="pid" id="pid{$uniqid}" class="relo" size="24" /></td>
      </tr>
      <tr>
        <td width="11%"><label for="level">严重性</label></td>
        <td width="23%"><input name="level" id="level{$uniqid}" class="relo" size="26" /></td>
        <td width="11%"><label for="hertz">频率</label></td>
        <td width="22%"><input name="hertz" id="hertz{$uniqid}" class="relo" size="24" /></td>
        <td width="11%"><label for="priority">优先级</label></td>
        <td width="22%"><input name="priority" id="priority{$uniqid}" class="relo" size="24" /></td>
      </tr>
      <tr>
        <td><label for="user_id">指派给</label></td>
        <td colspan="3"><input name="comy" id="comy{$uniqid}" class="relo" style="width:280px;" />&nbsp;-->&nbsp;<input name="user_id" id="user_id{$uniqid}" class="relo" style="width:180px;" /><input name="olduser" type="hidden" value="{$info.user_id}" /></td>
        <td><label for="os">平台</label></td>
        <td><input name="os" id="os{$uniqid}" size="24" class="easyui-validatebox" data-options="validType:'ptext'" /></td>
        </tr>
      <tr>
        <td><label for="title">摘要</label></td>
        <td colspan="3"><input name="title" type="text" id="title{$uniqid}" class="easyui-validatebox" data-options="validType:'ptext'" style="width:99%" /></td>
        <td><label for="creator">创建人</label></td>
        <td>{$username}</td>
        </tr>
      <tr>
        <td><label for="notes">详细现象</label></td>
        <td height="225" colspan="5"><textarea name="notes" id="notes{$uniqid}"  rows="18" data-options="uploadJson:'__APP__?g=Public&m=Upload&a=save&act=Report'" class="easyui-kindeditor" style="width:99%; height:220px;">{$info.baseinfo.notes}</textarea></td>
      </tr>
      <tr>
        <td><label for="comment">备注</label></td>
        <td colspan="5"><input name="comment" type="text" id="comment{$uniqid}" class="easyui-validatebox" data-options="validType:'ptext'" style="width:99%" /></td>
        </tr>
      <if condition="$act=='add'">
      <tr>
        <td><label for="path">附件</label></td>
        <td colspan="5">
         <input name="path" type="file" />&nbsp;<span class="up-font-over">(文件类型：rar、zip)</span>
        </td>
      </tr> 
     </if>
      </tbody>
      <tr>
        <td height="38" colspan="6" align="center"><if condition="$act=='add'">
        <a href="javascript:void(0);" onclick="javascript:onSubmitReport('{$uniqid}')" id="su" class="easyui-linkbutton" data-options="iconCls:'icon-save'">保存</a><else /><a href="javascript:void(0);" onclick="javascript:return onUploadReport('{$uniqid}')" id="sue" class="easyui-linkbutton" data-options="iconCls:'icon-save'">保存</a></if> &nbsp; <a href="javascript:void(0);" onclick="javascript:onResetReport('{$uniqid}')" id="re" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">关闭</a></td>
        </tr>
     </table> 
</form>
</div>
<div id="addApp"></div>