| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="X-UA-Compatible" content="IE=8" />
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <link rel="stylesheet" type="text/css" href="http://static.vbdsm.com/js/lib/easyui/themes/vber/easyui.css" />
- <link rel="stylesheet" type="text/css" href="http://static.vbdsm.com/js/lib/easyui/themes/icon.css" />
- <script type="text/javascript" src="http://static.vbdsm.com/js/lib/jquery-1.8.0.min.js"></script>
- <script type="text/javascript" src="http://static.vbdsm.com/js/lib/highcharts/highcharts.js"></script>
- <script type="text/javascript" src="http://static.vbdsm.com/js/lib/easyui/jquery.easyui.min.js"></script>
- <script type="text/javascript" src="http://static.vbdsm.com/js/lib/easyui/locale/easyui-lang-zh_CN.js"></script>
- <script type="text/javascript" src="http://static.vbdsm.com/js/lib/loadmask/jquery.loadmask.min.js"></script>
- <script type="text/javascript" src="http://static.vbdsm.com/js/static.support.js"></script>
- <script type="text/javascript" src="http://static.vbdsm.com/js/easyui.support.js"></script>
- <script type="text/javascript" src="http://static.vbdsm.com/js/common.tools.js"></script>
- <script type="text/javascript" src="http://static.vbdsm.com/js/util.js"></script>
- <script type="text/javascript" src="http://static.vbdsm.com/js/lib/layer/layer/layer.js"></script>
- <title>企业峰谷平时段管理</title>
- <script type="text/javascript" charset="UTF-8"></script>
- </head>
- <body style="margin: 0">
- <div style="width: 100%; height: 100%">
- <table class="easyui-datagrid" border="0" style="height: 100%" id="company_usepower"></table>
- </div>
- <script>
- //类型数据源
- var timeType = [
- { value: "1", text: "峰" },
- { value: "2", text: "谷" },
- { value: "3", text: "平" },
- { value: "4", text: "尖" },
- ]
- //数据格式化
- function unitformatter(value, rowData, rowIndex) {
- if (value == 0) {
- return
- }
- for (var i = 0; i < timeType.length; i++) {
- if (timeType[i].value == value) {
- return timeType[i].text
- }
- }
- }
- //状态数据源
- var stateData = [
- { value: "1", text: "启用" },
- { value: "0", text: "关闭" },
- ]
- //时段数据源
- var timeData = [
- { value: "00:00", text: "00:00" },
- { value: "00:30", text: "00:30" },
- { value: "01:00", text: "01:00" },
- { value: "01:30", text: "01:30" },
- { value: "02:00", text: "02:00" },
- { value: "02:30", text: "02:30" },
- { value: "03:00", text: "03:00" },
- { value: "03:30", text: "03:30" },
- { value: "04:00", text: "04:00" },
- { value: "04:30", text: "04:30" },
- { value: "05:00", text: "05:00" },
- { value: "05:30", text: "05:30" },
- { value: "06:00", text: "06:00" },
- { value: "06:30", text: "06:30" },
- { value: "07:00", text: "07:00" },
- { value: "07:30", text: "07:30" },
- { value: "08:00", text: "08:00" },
- { value: "08:30", text: "08:30" },
- { value: "09:00", text: "09:00" },
- { value: "09:30", text: "09:30" },
- { value: "10:00", text: "10:00" },
- { value: "10:30", text: "10:30" },
- { value: "11:00", text: "11:00" },
- { value: "11:30", text: "11:30" },
- { value: "12:00", text: "12:00" },
- { value: "12:30", text: "12:30" },
- { value: "13:00", text: "13:00" },
- { value: "13:30", text: "13:30" },
- { value: "14:00", text: "14:00" },
- { value: "14:30", text: "14:30" },
- { value: "15:00", text: "15:00" },
- { value: "15:30", text: "15:30" },
- { value: "16:00", text: "16:00" },
- { value: "16:30", text: "16:30" },
- { value: "17:00", text: "17:00" },
- { value: "17:30", text: "17:30" },
- { value: "18:00", text: "18:00" },
- { value: "18:30", text: "18:30" },
- { value: "19:00", text: "19:00" },
- { value: "19:30", text: "19:30" },
- { value: "20:00", text: "20:00" },
- { value: "20:30", text: "20:30" },
- { value: "21:00", text: "21:00" },
- { value: "21:30", text: "21:30" },
- { value: "22:00", text: "22:00" },
- { value: "22:30", text: "22:30" },
- { value: "23:00", text: "23:00" },
- { value: "23:30", text: "23:30" },
- { value: "24:00", text: "24:00" },
- ]
- var tableObj = $("#company_usepower")
- $(function () {
- initGridData()
- })
- //表格数据查询
- function initGridData() {
- ajax({
- url: "/web/companyusepower/getList.json",
- type: "post",
- dataType: "json",
- success: function (data) {
- tableObj.datagrid("loadData", data)
- },
- })
- }
- tableObj.datagrid({
- columns: [
- [
- {
- field: "timeType",
- title: "类型",
- width: 120,
- formatter: unitformatter,
- align: "center",
- editor: {
- type: "combobox",
- options: {
- data: timeType,
- valueField: "value",
- textField: "text",
- required: true,
- editable: false,
- panelHeight: 100,
- },
- },
- },
- {
- field: "startDate",
- title: "开始日期",
- width: 120,
- align: "center",
- editor: { type: "datebox", options: { required: true } },
- },
- {
- field: "endDate",
- title: "结束日期",
- width: 120,
- align: "center",
- editor: { type: "datebox", options: { required: true } },
- },
- {
- field: "startTime",
- title: "开始时间",
- width: 120,
- align: "center",
- editor: {
- type: "combobox",
- options: {
- data: timeData,
- valueField: "value",
- textField: "text",
- required: true,
- editable: false,
- },
- },
- },
- {
- field: "endTime",
- title: "结束时间",
- width: 120,
- align: "center",
- editor: {
- type: "combobox",
- options: {
- data: timeData,
- valueField: "value",
- textField: "text",
- required: true,
- editable: false,
- },
- },
- },
- {
- field: "state",
- title: "状态",
- width: 120,
- align: "center",
- formatter: function (value, rec) {
- if (0 == rec.state) {
- return '<font color="red">关闭</font>'
- } else if (1 == rec.state) {
- return '<font color="green">启用</font>'
- }
- },
- editor: {
- type: "combobox",
- options: {
- data: stateData,
- valueField: "value",
- textField: "text",
- required: true,
- editable: false,
- panelHeight: 60,
- },
- },
- },
- ],
- ],
- toolbar: [
- {
- text: "新增",
- iconCls: "icon-add",
- handler: append,
- },
- "-",
- {
- text: "删除",
- iconCls: "icon-remove",
- handler: remove,
- },
- "-",
- {
- text: "修改",
- iconCls: "icon-edit",
- handler: update,
- },
- "-",
- {
- text: "保存",
- iconCls: "icon-save",
- handler: save,
- },
- "-",
- {
- text: "取消",
- iconCls: "icon-undo",
- handler: undo,
- },
- ],
- singleSelect: true,
- rownumbers: false,
- onDblClickRow: onClickRow, //双击事件(启动编辑功能)
- /* onLoadSuccess:function(data){
- if(0 == data.rows.length){
- $(".datagrid-view2 .datagrid-body tbody").append('<tr ><td align="center" colspan="6"><font color="red">暂无记录</font></td></tr>');
- }
- }, */
- onLoadError: function () {
- alert("载入数据发生错误,请重试。")
- },
- })
- var editFlag = true,
- appendFlag = true,
- editIndex = undefined
- function endEditing() {
- if (typeof editIndex == "undefined") {
- return true
- }
- if (tableObj.datagrid("validateRow", editIndex)) {
- tableObj.datagrid("endEdit", editIndex)
- editIndex = undefined
- return true
- } else {
- return false
- }
- }
- //启动编辑功能
- function onClickRow(index) {
- if (editIndex != index) {
- if (endEditing()) {
- tableObj.datagrid("selectRow", index).datagrid("beginEdit", index)
- editIndex = index
- editFlag = true
- } else {
- tableObj.datagrid("selectRow", editIndex)
- }
- }
- }
- //新增
- function append() {
- if (!appendFlag || !editFlag) {
- layer.msg("请先保存正在修改或者新增的行!", {
- icon: 4,
- })
- return
- }
- if (endEditing()) {
- tableObj.datagrid("appendRow", { status: "P" })
- editIndex = tableObj.datagrid("getRows").length - 1
- tableObj.datagrid("selectRow", editIndex).datagrid("beginEdit", editIndex)
- appendFlag = false
- }
- }
- //修改
- function update() {
- if (!appendFlag || !editFlag) {
- layer.msg("请先取消正在更改或者新增的行!", {
- icon: 4,
- })
- return
- }
- //获取行号
- var rowIndex = tableObj.datagrid("getRowIndex", tableObj.datagrid("getSelected"))
- onClickRow(rowIndex)
- }
- //保存
- function save() {
- if (typeof editIndex != "undefined") {
- if (endEditing()) {
- tableObj.datagrid("acceptChanges") //确认修改的数据
- var row = tableObj.datagrid("getSelected") //获取修改后的数据
- var jsonData = {}
- var id = row.id
- if (id == undefined) {
- id = 0 //表示新增
- }
- //企业id
- var companyId = row.companyId
- if (companyId == undefined) {
- companyId = $("#companyId").val()
- }
- jsonData.id = id
- jsonData.companyId = companyId
- jsonData.timeType = row.timeType
- jsonData.startDate = row.startDate
- jsonData.endDate = row.endDate
- jsonData.startTime = row.startTime
- jsonData.endTime = row.endTime
- jsonData.state = row.state
- ajax({
- type: "POST",
- dataType: "json",
- url: "/web/companyusepower/addOrModify.json",
- data: jsonData,
- success: function (result) {
- if (result.status == 1) {
- layer.msg(result.msg)
- initGridData()
- appendFlag = true
- } else {
- alert(result.msg)
- }
- },
- })
- }
- }
- }
- //取消
- function undo() {
- tableObj.datagrid("rejectChanges")
- editIndex = undefined
- appendFlag = true
- editFlag = true
- }
- //删除
- function remove() {
- if (!appendFlag || !editFlag) {
- layer.msg("请先取消正在更改或者新增的行!", {
- icon: 4,
- })
- return
- }
- var row = tableObj.datagrid("getSelected")
- if (row != null) {
- confirm("警告", "确认删除选定的行?", function (data) {
- if (data) {
- var id = row.id
- ajax({
- url: "/web/companyusepower/realDel/" + id + ".json",
- success: function (json) {
- if (json.status == 1) {
- layer.msg(json.msg)
- initGridData()
- appendFlag = true
- } else {
- alert(json.msg)
- }
- },
- error: function () {
- alert("删除失败,请重试!")
- },
- })
- }
- })
- } else {
- alert("请选择要删除的项!")
- }
- }
- </script>
- </body>
- </html>
|