setting_company_usepowertime.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="X-UA-Compatible" content="IE=8" />
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <link rel="stylesheet" type="text/css" href="http://static.vbdsm.com/js/lib/easyui/themes/vber/easyui.css" />
  7. <link rel="stylesheet" type="text/css" href="http://static.vbdsm.com/js/lib/easyui/themes/icon.css" />
  8. <script type="text/javascript" src="http://static.vbdsm.com/js/lib/jquery-1.8.0.min.js"></script>
  9. <script type="text/javascript" src="http://static.vbdsm.com/js/lib/highcharts/highcharts.js"></script>
  10. <script type="text/javascript" src="http://static.vbdsm.com/js/lib/easyui/jquery.easyui.min.js"></script>
  11. <script type="text/javascript" src="http://static.vbdsm.com/js/lib/easyui/locale/easyui-lang-zh_CN.js"></script>
  12. <script type="text/javascript" src="http://static.vbdsm.com/js/lib/loadmask/jquery.loadmask.min.js"></script>
  13. <script type="text/javascript" src="http://static.vbdsm.com/js/static.support.js"></script>
  14. <script type="text/javascript" src="http://static.vbdsm.com/js/easyui.support.js"></script>
  15. <script type="text/javascript" src="http://static.vbdsm.com/js/common.tools.js"></script>
  16. <script type="text/javascript" src="http://static.vbdsm.com/js/util.js"></script>
  17. <script type="text/javascript" src="http://static.vbdsm.com/js/lib/layer/layer/layer.js"></script>
  18. <title>企业峰谷平时段管理</title>
  19. <script type="text/javascript" charset="UTF-8"></script>
  20. </head>
  21. <body style="margin: 0">
  22. <div style="width: 100%; height: 100%">
  23. <table class="easyui-datagrid" border="0" style="height: 100%" id="company_usepower"></table>
  24. </div>
  25. <script>
  26. //类型数据源
  27. var timeType = [
  28. { value: "1", text: "峰" },
  29. { value: "2", text: "谷" },
  30. { value: "3", text: "平" },
  31. { value: "4", text: "尖" },
  32. ]
  33. //数据格式化
  34. function unitformatter(value, rowData, rowIndex) {
  35. if (value == 0) {
  36. return
  37. }
  38. for (var i = 0; i < timeType.length; i++) {
  39. if (timeType[i].value == value) {
  40. return timeType[i].text
  41. }
  42. }
  43. }
  44. //状态数据源
  45. var stateData = [
  46. { value: "1", text: "启用" },
  47. { value: "0", text: "关闭" },
  48. ]
  49. //时段数据源
  50. var timeData = [
  51. { value: "00:00", text: "00:00" },
  52. { value: "00:30", text: "00:30" },
  53. { value: "01:00", text: "01:00" },
  54. { value: "01:30", text: "01:30" },
  55. { value: "02:00", text: "02:00" },
  56. { value: "02:30", text: "02:30" },
  57. { value: "03:00", text: "03:00" },
  58. { value: "03:30", text: "03:30" },
  59. { value: "04:00", text: "04:00" },
  60. { value: "04:30", text: "04:30" },
  61. { value: "05:00", text: "05:00" },
  62. { value: "05:30", text: "05:30" },
  63. { value: "06:00", text: "06:00" },
  64. { value: "06:30", text: "06:30" },
  65. { value: "07:00", text: "07:00" },
  66. { value: "07:30", text: "07:30" },
  67. { value: "08:00", text: "08:00" },
  68. { value: "08:30", text: "08:30" },
  69. { value: "09:00", text: "09:00" },
  70. { value: "09:30", text: "09:30" },
  71. { value: "10:00", text: "10:00" },
  72. { value: "10:30", text: "10:30" },
  73. { value: "11:00", text: "11:00" },
  74. { value: "11:30", text: "11:30" },
  75. { value: "12:00", text: "12:00" },
  76. { value: "12:30", text: "12:30" },
  77. { value: "13:00", text: "13:00" },
  78. { value: "13:30", text: "13:30" },
  79. { value: "14:00", text: "14:00" },
  80. { value: "14:30", text: "14:30" },
  81. { value: "15:00", text: "15:00" },
  82. { value: "15:30", text: "15:30" },
  83. { value: "16:00", text: "16:00" },
  84. { value: "16:30", text: "16:30" },
  85. { value: "17:00", text: "17:00" },
  86. { value: "17:30", text: "17:30" },
  87. { value: "18:00", text: "18:00" },
  88. { value: "18:30", text: "18:30" },
  89. { value: "19:00", text: "19:00" },
  90. { value: "19:30", text: "19:30" },
  91. { value: "20:00", text: "20:00" },
  92. { value: "20:30", text: "20:30" },
  93. { value: "21:00", text: "21:00" },
  94. { value: "21:30", text: "21:30" },
  95. { value: "22:00", text: "22:00" },
  96. { value: "22:30", text: "22:30" },
  97. { value: "23:00", text: "23:00" },
  98. { value: "23:30", text: "23:30" },
  99. { value: "24:00", text: "24:00" },
  100. ]
  101. var tableObj = $("#company_usepower")
  102. $(function () {
  103. initGridData()
  104. })
  105. //表格数据查询
  106. function initGridData() {
  107. ajax({
  108. url: "/web/companyusepower/getList.json",
  109. type: "post",
  110. dataType: "json",
  111. success: function (data) {
  112. tableObj.datagrid("loadData", data)
  113. },
  114. })
  115. }
  116. tableObj.datagrid({
  117. columns: [
  118. [
  119. {
  120. field: "timeType",
  121. title: "类型",
  122. width: 120,
  123. formatter: unitformatter,
  124. align: "center",
  125. editor: {
  126. type: "combobox",
  127. options: {
  128. data: timeType,
  129. valueField: "value",
  130. textField: "text",
  131. required: true,
  132. editable: false,
  133. panelHeight: 100,
  134. },
  135. },
  136. },
  137. {
  138. field: "startDate",
  139. title: "开始日期",
  140. width: 120,
  141. align: "center",
  142. editor: { type: "datebox", options: { required: true } },
  143. },
  144. {
  145. field: "endDate",
  146. title: "结束日期",
  147. width: 120,
  148. align: "center",
  149. editor: { type: "datebox", options: { required: true } },
  150. },
  151. {
  152. field: "startTime",
  153. title: "开始时间",
  154. width: 120,
  155. align: "center",
  156. editor: {
  157. type: "combobox",
  158. options: {
  159. data: timeData,
  160. valueField: "value",
  161. textField: "text",
  162. required: true,
  163. editable: false,
  164. },
  165. },
  166. },
  167. {
  168. field: "endTime",
  169. title: "结束时间",
  170. width: 120,
  171. align: "center",
  172. editor: {
  173. type: "combobox",
  174. options: {
  175. data: timeData,
  176. valueField: "value",
  177. textField: "text",
  178. required: true,
  179. editable: false,
  180. },
  181. },
  182. },
  183. {
  184. field: "state",
  185. title: "状态",
  186. width: 120,
  187. align: "center",
  188. formatter: function (value, rec) {
  189. if (0 == rec.state) {
  190. return '<font color="red">关闭</font>'
  191. } else if (1 == rec.state) {
  192. return '<font color="green">启用</font>'
  193. }
  194. },
  195. editor: {
  196. type: "combobox",
  197. options: {
  198. data: stateData,
  199. valueField: "value",
  200. textField: "text",
  201. required: true,
  202. editable: false,
  203. panelHeight: 60,
  204. },
  205. },
  206. },
  207. ],
  208. ],
  209. toolbar: [
  210. {
  211. text: "新增",
  212. iconCls: "icon-add",
  213. handler: append,
  214. },
  215. "-",
  216. {
  217. text: "删除",
  218. iconCls: "icon-remove",
  219. handler: remove,
  220. },
  221. "-",
  222. {
  223. text: "修改",
  224. iconCls: "icon-edit",
  225. handler: update,
  226. },
  227. "-",
  228. {
  229. text: "保存",
  230. iconCls: "icon-save",
  231. handler: save,
  232. },
  233. "-",
  234. {
  235. text: "取消",
  236. iconCls: "icon-undo",
  237. handler: undo,
  238. },
  239. ],
  240. singleSelect: true,
  241. rownumbers: false,
  242. onDblClickRow: onClickRow, //双击事件(启动编辑功能)
  243. /* onLoadSuccess:function(data){
  244. if(0 == data.rows.length){
  245. $(".datagrid-view2 .datagrid-body tbody").append('<tr ><td align="center" colspan="6"><font color="red">暂无记录</font></td></tr>');
  246. }
  247. }, */
  248. onLoadError: function () {
  249. alert("载入数据发生错误,请重试。")
  250. },
  251. })
  252. var editFlag = true,
  253. appendFlag = true,
  254. editIndex = undefined
  255. function endEditing() {
  256. if (typeof editIndex == "undefined") {
  257. return true
  258. }
  259. if (tableObj.datagrid("validateRow", editIndex)) {
  260. tableObj.datagrid("endEdit", editIndex)
  261. editIndex = undefined
  262. return true
  263. } else {
  264. return false
  265. }
  266. }
  267. //启动编辑功能
  268. function onClickRow(index) {
  269. if (editIndex != index) {
  270. if (endEditing()) {
  271. tableObj.datagrid("selectRow", index).datagrid("beginEdit", index)
  272. editIndex = index
  273. editFlag = true
  274. } else {
  275. tableObj.datagrid("selectRow", editIndex)
  276. }
  277. }
  278. }
  279. //新增
  280. function append() {
  281. if (!appendFlag || !editFlag) {
  282. layer.msg("请先保存正在修改或者新增的行!", {
  283. icon: 4,
  284. })
  285. return
  286. }
  287. if (endEditing()) {
  288. tableObj.datagrid("appendRow", { status: "P" })
  289. editIndex = tableObj.datagrid("getRows").length - 1
  290. tableObj.datagrid("selectRow", editIndex).datagrid("beginEdit", editIndex)
  291. appendFlag = false
  292. }
  293. }
  294. //修改
  295. function update() {
  296. if (!appendFlag || !editFlag) {
  297. layer.msg("请先取消正在更改或者新增的行!", {
  298. icon: 4,
  299. })
  300. return
  301. }
  302. //获取行号
  303. var rowIndex = tableObj.datagrid("getRowIndex", tableObj.datagrid("getSelected"))
  304. onClickRow(rowIndex)
  305. }
  306. //保存
  307. function save() {
  308. if (typeof editIndex != "undefined") {
  309. if (endEditing()) {
  310. tableObj.datagrid("acceptChanges") //确认修改的数据
  311. var row = tableObj.datagrid("getSelected") //获取修改后的数据
  312. var jsonData = {}
  313. var id = row.id
  314. if (id == undefined) {
  315. id = 0 //表示新增
  316. }
  317. //企业id
  318. var companyId = row.companyId
  319. if (companyId == undefined) {
  320. companyId = $("#companyId").val()
  321. }
  322. jsonData.id = id
  323. jsonData.companyId = companyId
  324. jsonData.timeType = row.timeType
  325. jsonData.startDate = row.startDate
  326. jsonData.endDate = row.endDate
  327. jsonData.startTime = row.startTime
  328. jsonData.endTime = row.endTime
  329. jsonData.state = row.state
  330. ajax({
  331. type: "POST",
  332. dataType: "json",
  333. url: "/web/companyusepower/addOrModify.json",
  334. data: jsonData,
  335. success: function (result) {
  336. if (result.status == 1) {
  337. layer.msg(result.msg)
  338. initGridData()
  339. appendFlag = true
  340. } else {
  341. alert(result.msg)
  342. }
  343. },
  344. })
  345. }
  346. }
  347. }
  348. //取消
  349. function undo() {
  350. tableObj.datagrid("rejectChanges")
  351. editIndex = undefined
  352. appendFlag = true
  353. editFlag = true
  354. }
  355. //删除
  356. function remove() {
  357. if (!appendFlag || !editFlag) {
  358. layer.msg("请先取消正在更改或者新增的行!", {
  359. icon: 4,
  360. })
  361. return
  362. }
  363. var row = tableObj.datagrid("getSelected")
  364. if (row != null) {
  365. confirm("警告", "确认删除选定的行?", function (data) {
  366. if (data) {
  367. var id = row.id
  368. ajax({
  369. url: "/web/companyusepower/realDel/" + id + ".json",
  370. success: function (json) {
  371. if (json.status == 1) {
  372. layer.msg(json.msg)
  373. initGridData()
  374. appendFlag = true
  375. } else {
  376. alert(json.msg)
  377. }
  378. },
  379. error: function () {
  380. alert("删除失败,请重试!")
  381. },
  382. })
  383. }
  384. })
  385. } else {
  386. alert("请选择要删除的项!")
  387. }
  388. }
  389. </script>
  390. </body>
  391. </html>