Açıklama Yok

addOrEditResEntry.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /**
  2. * 增加或编辑 水电气信息
  3. * */
  4. $(function() {
  5. var editId = helper.request.queryString("editId");
  6. laydate.render({
  7. elem: '#pro_times',
  8. theme: '#249fea',
  9. value: helper.DateFormat.getNowDate()
  10. });
  11. if(editId) {
  12. getProlistDrop($('#pro_title')).then(function(){
  13. getDetail(editId);
  14. });
  15. } else {
  16. getProlistDrop($('#pro_title'));
  17. }
  18. $('#pro_title').on('change', changeProTitle)
  19. //添加编辑保存按钮点击
  20. $('#pro_save').on('click', saveProject);
  21. });
  22. //获取详情
  23. //function getDetail(eid){
  24. // $.getJSON(huayi.config.callcenter_url + "plcautomationapi/api/inputdata/getsingle", {
  25. // id: eid,
  26. // }, function(data) {
  27. // if(data.state == "success") {
  28. // var con = data.data;
  29. // if(con) {
  30. // $('#pro_times').val(con.inputtime);
  31. // $('#pro_title').selectpicker('val', con.projectname).trigger('change');
  32. //
  33. // $('#dic_remark').val(con.describe);
  34. // $('#dic_sort').val(con.sort);
  35. // }
  36. // }
  37. // });
  38. //}
  39. //项目切换
  40. function changeProTitle(){
  41. getEntryList($('#entryLists'), $(this).val());
  42. }
  43. //获取水电气 列表 @pt 项目名称
  44. function getEntryList(el, pt){
  45. if(!pt){
  46. el.empty();
  47. return;
  48. }
  49. var dtd = $.Deferred(); //在函数内部,新建一个Deferred对象
  50. $.ajax({
  51. type: "get",
  52. url: huayi.config.callcenter_url + "configurationapi/api/dictionary/getdicvaluelistdrop",
  53. dataType: 'json',
  54. async: true,
  55. data: {
  56. code: 'SDQFL',
  57. projectname: pt
  58. },
  59. success: function(data) {
  60. var res = data.data;
  61. el.empty();
  62. if(res && res.length > 0){
  63. for(var i = 0; i < res.length; i++) {
  64. $('<li class="form-group entryItem">'+
  65. '<label for="entryvalue_'+ i +'"id="entryname_'+ i +'" class="col-md-2 text-right">' + res[i].name + '</label>'+
  66. '<div class="col-md-10">'+
  67. '<input id="entryvalue_'+ i +'" class="form-control" type="text" placeholder="请输入用' + res[i].name + '总量" />'+
  68. '</div>'+
  69. '</li>').appendTo(el);
  70. }
  71. }else{
  72. $('<div class="alert alert-warning col-md-10 col-md-offset-2" role="alert">暂无数据,请联系管理员,添加数据。</div>').appendTo(el)
  73. }
  74. dtd.resolve(); // 改变Deferred对象的执行状态
  75. }
  76. });
  77. return dtd.promise(); // 返回promise对象
  78. }
  79. //获取值
  80. function getEntryValues(){
  81. var entryItem = $('#entryLists').find('.entryItem');
  82. var entryNames = [];
  83. var entryValues = [];
  84. for(var i = 0, len = entryItem.length; i < len; i++){
  85. var name = $(entryItem[i]).find('label[id*=entryname_]').text();
  86. var value = $(entryItem[i]).find('input[id*=entryvalue_]').val();
  87. entryNames.push(name);
  88. value = value === '' ? 0 : value;
  89. entryValues.push(value);
  90. }
  91. return {
  92. "name": entryNames,
  93. "value": entryValues
  94. }
  95. }
  96. //保存
  97. function saveProject() {
  98. var editId = helper.request.queryString("editId");
  99. var wUrl;
  100. if(!$.trim($('#pro_title').val())) {
  101. layer.confirm('你还没有选择所属项目', {
  102. icon: 2,
  103. btn: ['确定'] //按钮
  104. });
  105. return;
  106. }
  107. if(editId) {
  108. wUrl = "plcautomationapi/api/inputdata/update"; //修改
  109. } else {
  110. wUrl = "plcautomationapi/api/inputdata/add"; //添加
  111. }
  112. $.ajax({
  113. type: "post",
  114. url: huayi.config.callcenter_url + "plcautomationapi/api/inputdata/add",
  115. dataType: 'json',
  116. async: true,
  117. beforeSend: function() { //触发ajax请求开始时执行
  118. $('#pro_save').attr("disabled", true);
  119. $('#pro_save').text('保存中...');
  120. $(document).off('click', '#pro_save', saveProject);
  121. },
  122. data: {
  123. id: editId,
  124. inputtime: $('#pro_times').val(), //否 string 日期(不传时默认当天)
  125. projectname: $('#pro_title').val(),
  126. dataname: getEntryValues().name, //是 string[] 数据名称
  127. datavalue: getEntryValues().value //是 string[] 数据值
  128. },
  129. success: function(result) {
  130. if(result.state.toLowerCase() === "success") {
  131. var index = parent.layer.getFrameIndex(window.name);
  132. parent.layer.close(index);
  133. parent.$('#table_all').bootstrapTable('refresh');
  134. parent.layer.msg("保存成功");
  135. }
  136. },
  137. error: function(textStatus) {
  138. layer.confirm('网络繁忙,请稍后再试...', {
  139. icon: 7,
  140. closeBtn: 0,
  141. btn: ['确定'] //按钮
  142. });
  143. $('#pro_save').text('保存');
  144. $('#pro_save').attr("disabled", false);
  145. $(document).off('click', '#pro_save', saveProject);
  146. $(document).on('click', '#pro_save', saveProject);
  147. },
  148. complete: function(XMLHttpRequest, textStatus) {
  149. if(textStatus == 'timeout') {
  150. var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
  151. xmlhttp.abort();
  152. layer.confirm('网络超时,请稍后再试...', {
  153. icon: 7,
  154. closeBtn: 0,
  155. btn: ['确定'] //按钮
  156. });    
  157. }
  158. $('#pro_save').text('保存');
  159. $('#pro_save').attr("disabled", false);
  160. $(document).off('click', '#pro_save', saveProject);
  161. $(document).on('click', '#pro_save', saveProject);
  162. },
  163. });
  164. }
  165. //获取项目下拉
  166. function getProlistDrop(el){
  167. var dtd = $.Deferred(); //在函数内部,新建一个Deferred对象
  168. $.ajax({
  169. type: "get",
  170. url: huayi.config.callcenter_url + "equipmentapi/api/ProjectInfo/getlistdrop",
  171. dataType: 'json',
  172. async: true,
  173. data: {},
  174. success: function(data) {
  175. el.empty();
  176. el.append("<option value=''>请选择项目</option>");
  177. var res = data.data;
  178. if(res){
  179. for(var i = 0; i < res.length; i++) {
  180. $('<option value=' + res[i].text + '>' + res[i].text + '</option>').appendTo(el);
  181. }
  182. el.selectpicker('refresh');
  183. }
  184. dtd.resolve(); // 改变Deferred对象的执行状态
  185. }
  186. });
  187. return dtd.promise(); // 返回promise对象
  188. }