quotaConfig.js 3.76 KB
/**
 * 权益分配
 */

var quotaConfig = function() {
	return {

		search : function() {
			$("#data-grid").datagrid({
				url : "/quota/config/list?" + $('#search-form').serialize(),
			});
		},

		beforeAdd : function() {
			$("#add-form").form("clear");
			$("#add-dialog").dialog('open');
		},

		add : function() {
			$("#add-form").form('submit', {
				url : "/quota/config/add",
				onSubmit : function(param) {
					return $(this).form('validate');
				},
				success : function(data) {
					var result = $.parseJSON(data);
					if (result.success == true) {
						$.messager.show({
							title : '信息',
							msg : '设置成功'
						});
						$('#data-grid').datagrid('reload');
						$("#add-dialog").dialog("close");
					} else {
						$.messager.alert("错误", result.data);
					}
				}
			});
		},

		beforeUpdate : function() {
			var row = $('#data-grid').datagrid('getSelected');
			if (row) {
				if (row.allot == "0") {
					$('#add-dialog').dialog('open')
							.dialog('setTitle', '编辑权益分配');
					$('#add-form').form('load',
							"/quota/config/queryById?id=" + row.id);
				} else {
					$.messager.alert("错误提示", "仅未分配设置可以修改");
				}
			} else {
				$.messager.alert("错误提示", "请选择数据");
			}
		},

		/** 分配权益 */
		allot : function() {
			var row = $('#data-grid').datagrid('getSelected');
			if (!row) {
				$.messager.alert("错误提示", "请选择数据");
				return;
			}
			if (row.allot != '0') {
				$.messager.alert("错误提示", "只能分配状态为未分配的任务");
				return;
			}
			$.messager.confirm("提示框", "确认要开始分配吗?", function(ok) {
				if (ok) {
					$.ajax({
						url : "/quota/config/allot",
						dataType : "json",
						type : "POST",
						data : {
							id : row.id
						},
						success : function(data) {
							if (data.success == true) {
								$.messager.show({
									title : '信息',
									msg : '操作完毕'
								});
								$('#data-grid').datagrid('reload');
							} else {
								$.messager.alert("错误提示", data.data);
							}
						}
					});
				}
			});
		},

		/** 作废 */
		invalid : function(actId) {
			var row = $('#data-grid').datagrid('getSelected');
			if (!row) {
				$.messager.alert("错误提示", "请选择数据");
				return;
			}
			if (row.allot != '0') {
				$.messager.alert("错误提示", "只能作废状态为未分配的任务");
				return;
			}
			$.messager.confirm("提示框", "确认要作废此记录吗?", function(ok) {
				if (ok) {
					$.ajax({
						url : "/quota/config/invalid",
						dataType : "json",
						type : "POST",
						data : {
							id : row.id
						},
						success : function(data) {
							$.messager.show({
								title : '信息',
								msg : '操作完毕'
							});
							$('#data-grid').datagrid('reload');
						}
					});
				}
			});
		},

		otcCodeChange : function(newValue, oldValue) {
			if (newValue.length == 6) {
				$.ajax({
					url : '/quota/config/getOtcName',
					type : 'post',
					dataType : 'json',
					data : {
						otcCode : newValue
					},
					success : function(data) {
						$("#otcName").textbox('setValue', data.otcName);
					}
				});
			}
		},

		trustOtcCodeChange : function(newValue, oldValue) {
			if (newValue.length == 6) {
				$.ajax({
					url : '/quota/config/getOtcName',
					type : 'post',
					dataType : 'json',
					data : {
						otcCode : newValue
					},
					success : function(data) {
						$("#trustOtcName").textbox('setValue', data.otcName);
					}
				});
			}
		},

		formatStatus : function(value, row, index) {
			var status;
			switch (value) {
			case 0:
				status = '未分配';
				break;
			case 1:
				status = '已分配';
				break;
			case 2:
				status = '作废';
				break;
			}
			return status;
		}
	}

}();