用 JS 验证工作状态

页面效果展示:

HTML  主要就是在onclick事件上加上参数传至JS:onclick="state('recover','1')

<td>
	<@ifAuthority path="/personal/transfer">
	<a href="javascript:void(0)" class="easyui-linkbutton"
		iconCls="icon-reload" plain="true" onclick="transfer();">转交</a>
	</@ifAuthority>
</td>
<td>
	<@ifAuthority path="/personal/pause">
	<a href="javascript:void(0)" class="easyui-linkbutton"
		iconCls="icon-clear" plain="true" onclick="state('pause','2');">暂停</a>
	</@ifAuthority>
</td>
<td>
	<@ifAuthority path="/personal/recover">
	<a href="javascript:void(0)" class="easyui-linkbutton"
		iconCls="icon-undo" plain="true" onclick="state('recover','1');">恢复</a>
	</@ifAuthority>
</td>
<td>
	<@ifAuthority path="/personal/complete">
	<a href="javascript:void(0)" class="easyui-linkbutton"
		iconCls="icon-ok" plain="true" onclick="state('complete','3');">完成</a>
	</@ifAuthority>
</td>

JS:

// 更改工作状态
function state(type, num) {// type,num 为ftl传入的参数
	var row = $('#dg').datagrid("getSelections");
	var text = "";
	var flag = "";
	var title = "提示";
	var show = "";
	if (row.length == 1) {
		if (row[0].state == "2") {// 现在状态为 暂停 点击的同为 暂停 按钮
			show = '该任务已暂停!';
		} else if (row[0].state == "3") {// 现在状态为 完成 点击的同为 完成 按钮
			show = "该任务已完成";
		} else { // 另外一按钮
			show = "新任务不可恢复";
		}
		if (num == "1") {// 点击恢复时 存入 text flag 信息
			text = "确认要恢复任务吗?";
			flag = "1";
		} else if (num == "2") {// 点击暂停 时 存入 text flag 信息
			text = "确认要暂停任务吗?";
			flag = "2";
		} else {// 点击完成 时 存入 text flag 信息
			text = "确认已经完成任务了吗?";
			flag = "3";
		}
		if (row[0].state == num) {// 现在 状态 与点击按钮 状态 相同时
			showMsg(title, show);
		} else {
			operate(row[0], text, flag);
		}
	} else {
		$.messager.show({
			title : '提示:',
			msg : '请选择一行操作!'
		});
	}
}

function operate(row, text, flag) {
	$.messager.confirm('提示信息111', text, function(r) {
		if (r) {
			$.post(URL_PREFIX + '/personal/queryStatus', {
				id : row.id,
				isOpen : flag,
				table : 'internalwork_personal'
			}, function(result) {
				if (result == "0") {
					$.messager.show({
						title : '错误提示:',
						msg : '操作失败!',
						timeout : 2000,
						showType : 'slide'
					});
				} else {
					$.messager.show({
						title : '提示:',
						msg : '操作成功!',
						timeout : 2000,
						showType : 'slide'
					});
					datagridReload('dg'); // 重新加载数据
				}
			}, 'json');
		}
	});
}

JAVA :

controller:

// controller	
@ResponseBody
@RequestMapping("/queryStatus")
public String changeState(String id, String isOpen, String table) {
	String result = ConstantUtil.SUCCESS;
		try {
			personalservice.changeState(id, isOpen, table);
		} catch (BusinessException e) {
			logger.info(e);
			result = ConstantUtil.FAILURE;
		}
		return result;
}

// service

	@Override
	public void changeState(String id, String isOpen, String table) throws BusinessException {
		if (StrUtil.isBlank(id)) {// id不为空
			throw new BusinessException("设置工作状态,参数为空!");
		}
		try {// 修改工作状态 isOpen 1新工作,2暂停,3已完成,
			StringBuffer sb = new StringBuffer();
			sb.append("UPDATE " + table + " SET state = '").append(isOpen).append("' WHERE ID = '").append(id)
					.append("' ");
			personalDao.changeState(sb.toString());
		} catch (TransFailException e) {
			throw (e);
		}
	}
// dao 
	@Override
	public void changeState(String sql) throws TransFailException {
		try {
			sqlMapper.update(sql);
		} catch (RuntimeException e) {
			e.printStackTrace();
			throw new TransFailException("更新工作状态失败!", e);
		}
	}

猜你喜欢

转载自blog.csdn.net/weixin_40627398/article/details/81359466