<script language="javascript">
var act = '{$act}';
$(function(){
	$("#addFormUser{$uniqid}").form('load',{
		'username':'<?php echo $info["username"] ?>',
		'email':'<?php echo $info["email"] ?>',
		'status':'<?php echo $info["status"] ?>',
		//'report':'<?php echo $info["report"] ?>',
		'company_id':'<?php echo $info["user_main"]["company_id"] ?>',
		'group_id':'<?php echo $info["user_main"]["group_id"] ?>'
	});
	
	$("#group_ids{$uniqid}").combobox({
		onLoadSuccess:function(){
			var act = '{$act}';
			if(act=='add'){
				//$("#group_ids{$uniqid}").combobox('setValue','5');
			}
		}
	});	
	
	$("#companyId{$uniqid}").combobox({
		url:'__ITEM__/__RUNTIME__/Data/Json/Comy_Client_data.json',
		editable:true,
		method:'get',
		required:true,
		valueField:'id',
		textField:'text',
		onLoadSuccess:function(){
			if(act=='edit'){
				var comyid = '<?php echo $info["user_main"]["company_id"] ?>';
				if(comyid){
					$("#partId{$uniqid}").combobox('reload','__ITEM__/__RUNTIME__/Data/Json/Part/'+comyid+'_data.json');
					$("#partId{$uniqid}").combobox('setValue','<?php echo $info["user_main"]["part_id"] ?>');
				}
				
			}
		},
		onSelect:function(e){
			var idd = e.id;
			var txt = e.text;
			var va = $("#partId{$uniqid}").combobox('setValue','');
			var pg = txt.match(/\s-\s/);
			if(pg){
				$("#partId{$uniqid}").combobox('reload','__ITEM__/__RUNTIME__/Data/Json/Part/-1_data.json');
			}else{
				$("#partId{$uniqid}").combobox('reload','__ITEM__/__RUNTIME__/Data/Json/Part/'+idd+'_data.json');
			}
		}
	});
});

var idd ='';
function onSubmitUser(idd){
	$.messager.progress();
	$("#addFormUser"+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');
			if(data==1){
				$.messager.alert('提示','新增数据成功！','info',function(){
					var sa = '{$TC.config.SUBMIT_ACTION}';
					$("#Users").datagrid('reload');
					if(sa==1){
						cancel['User'].dialog('close');
						cancel['User'] = null;
					}
				});
			}else if(data==0){
				$.messager.alert('提示','新增数据失败！','warning');
			}else if(data==2){
				$.messager.alert('提示','无法发送邮件，请检查邮箱设置！','warning');
			}else{
				$.messager.alert('提示','您没有新增权限！','warning',function(){
					var sa = '{$TC.config.SUBMIT_ACTION}';
					if(sa==1){
						cancel['User'].dialog('close');
						cancel['User'] = null;
					}
				});
			}
		}
	});
}

function onUploadUser(idd){
	$.messager.progress();
	var ids = $("#ids"+idd).val();
	$("#addFormUser"+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');
			if(data==1){
				$.messager.alert('提示','更新数据成功！','info',function(){
					var sa = '{$TC.config.SUBMIT_ACTION}';
					$("#Users").datagrid('reload');
					if(sa==1){
						cancel['User'].dialog('close');
						cancel['User'] = null;
					}
				});
			}else if(data==0){
				$.messager.alert('提示','数据没有变动或更新失败！','warning');
			}else{
				$.messager.alert('提示','您没有修改权限！','warning',function(){
					var sa = '{$TC.config.SUBMIT_ACTION}';
					if(sa==1){
						cancel['User'].dialog('close');
						cancel['User'] = null;
					}
				});
			}
		}
	});
}

function onRepwd(idd){
	$.messager.progress();
	var ids = $("#ids"+idd).val();
	$("#addFormUser"+idd).form('submit',{
		url:'__APP__?g=<?php echo GROUP_NAME; ?>&m=<?php echo MODULE_NAME; ?>&a=rspwd&id='+ids,
		onSubmit: function(){
			var isValid = $(this).form('validate');
			if (!isValid){
				$.messager.progress('close');
			}
			return isValid;
		},
		success:function(data){
			$.messager.progress('close');
			if(data==1){
				$.messager.alert('提示','重置密码成功！','info',function(){
					var sa = '{$TC.config.SUBMIT_ACTION}';
					if(sa==1){
						cancel['User'].dialog('close');
						cancel['User'] = null;
					}
				});
			}else if(data==0){
				$.messager.alert('提示','重置密码失败！','warning');
			}else if(data==2){
				$.messager.alert('提示','无法发送邮件，请检查邮箱设置！','warning');
			}else{
				
				$.messager.alert('提示','您没有重置密码权限！','warning',function(){
					var sa = '{$TC.config.SUBMIT_ACTION}';
					if(sa==1){
						cancel['User'].dialog('close');
						cancel['User'] = null;
					}
				});
			}
		}
	});
}

function onResetUser(idd){
	cancel['User'].dialog('close');
	cancel['User'] = null;
}
</script>
<div class="con-tb">
<form id="addFormUser{$uniqid}" method="post">
 <table class="infobox" width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="23%"><label for="username">帐号</label></td>
    <td width="77%">
    <input name="username" class="easyui-validatebox"  size="22" data-options="required:true" /><input id="ids{$uniqid}" type="hidden" value="{$id}" /></td>
  </tr>
  <if condition="C('MORE_COMY')">
  <tr>
    <td width="23%"><label for="company_id">公司</label></td>
    <td width="77%">
    <input name="company_id" class="relo" id="companyId{$uniqid}" size="28" />
    </td>
  </tr>
  <tr>
    <td width="23%"><label for="part_id">部门</label></td>
    <td width="77%">
    <input name="part_id" class="easyui-combobox relo" id="partId{$uniqid}" size="28" data-options="url:'__ITEM__/__RUNTIME__/Data/Json/Empty_data.json',editable:true,method:'get',required:true,valueField:'id',textField:'text'" />
    </td>
  </tr>
  <else />
  <tr>
    <td width="23%"><label for="part_id">部门</label></td>
    <td width="77%">
    <input name="part_id" class="easyui-combobox relo" id="partId{$uniqid}" size="28" data-options="url:'__ITEM__/__RUNTIME__/Data/Json/Part_data.json',editable:true,method:'get',required:true,valueField:'id',textField:'text'" />
    </td>
  </tr>
  </if>
  <tr>
    <td width="23%"><label for="group_id">角色</label></td>
    <td width="77%">
   <input name="group_id" class="easyui-combobox relo" id="group_ids{$uniqid}" size="28" data-options="url:'__ITEM__/__RUNTIME__/Data/Json/Group_data.json',editable:true,method:'get',required:true,valueField:'id',textField:'text'" />
    </td>
  </tr>
  <tr>
    <td width="23%"><label for="password">密码</label></td>
    <td width="77%"> <input name="password" type="password" class="easyui-validatebox"  size="22" /><if condition="$act=='add'">(留空时自动生成随机密码)</if></td>
  </tr>
  <tr>
    <td width="23%"><label for="email">邮箱</label></td>
    <td width="77%"><input name="email" type="text" class="easyui-validatebox" value="" size="42" data-options="required:true,validType:'email'" /></td>
  </tr>
  <tr>
    <td width="23%"><label for="status">状态</label></td>
    <td width="77%">
    <select class="easyui-combobox" name="status">  
        <option value="1">开启</option>  
        <option  value="0">关闭</option>  
    </select>
   </td>
  </tr>
  <!--
  <tr>
    <td width="23%"><label for="report">周报</label></td>
    <td width="77%">
    <select class="easyui-combobox" name="report">  
        <option value="0">是</option>  
        <option  value="1">否</option>  
    </select>
   </td>
  </tr>
  -->
  <tr>
    <td height="38" colspan="2" align="center"><if condition="$act=='add'"><a href="javascript:void(0);" onclick="javascript:onSubmitUser('{$uniqid}')" id="su" class="easyui-linkbutton" data-options="iconCls:'icon-save'">保存</a><else /><a href="javascript:void(0);" onclick="javascript:return onUploadUser('{$uniqid}')" id="sue" class="easyui-linkbutton" data-options="iconCls:'icon-save'">保存</a></if> &nbsp; <a href="javascript:void(0);" onclick="javascript:onResetUser('{$uniqid}')" id="re" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">关闭</a> &nbsp; <if condition="$act=='edit'"><a href="javascript:void(0);" onclick="javascript:return onRepwd('{$uniqid}')" id="sur" class="easyui-linkbutton" data-options="iconCls:'icon-save'">重置密码</a></if></td>
  </tr>
 </table>
</form>
</div>