| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- /**
- * 增加或编辑 水电气信息
- * */
- $(function() {
- var editId = helper.request.queryString("editId");
- laydate.render({
- elem: '#pro_times',
- theme: '#249fea',
- value: helper.DateFormat.getNowDate()
- });
- if(editId) {
- getProlistDrop($('#pro_title')).then(function(){
- getDetail(editId);
- });
- } else {
- getProlistDrop($('#pro_title'));
- }
- $('#pro_title').on('change', changeProTitle)
- //添加编辑保存按钮点击
- $('#pro_save').on('click', saveProject);
- });
- //获取详情
- //function getDetail(eid){
- // $.getJSON(huayi.config.callcenter_url + "plcautomationapi/api/inputdata/getsingle", {
- // id: eid,
- // }, function(data) {
- // if(data.state == "success") {
- // var con = data.data;
- // if(con) {
- // $('#pro_times').val(con.inputtime);
- // $('#pro_title').selectpicker('val', con.projectname).trigger('change');
- //
- // $('#dic_remark').val(con.describe);
- // $('#dic_sort').val(con.sort);
- // }
- // }
- // });
- //}
- //项目切换
- function changeProTitle(){
- getEntryList($('#entryLists'), $(this).val());
- }
- //获取水电气 列表 @pt 项目名称
- function getEntryList(el, pt){
- if(!pt){
- el.empty();
- return;
- }
- var dtd = $.Deferred(); //在函数内部,新建一个Deferred对象
- $.ajax({
- type: "get",
- url: huayi.config.callcenter_url + "configurationapi/api/dictionary/getdicvaluelistdrop",
- dataType: 'json',
- async: true,
- data: {
- code: 'SDQFL',
- projectname: pt
- },
- success: function(data) {
- var res = data.data;
- el.empty();
- if(res && res.length > 0){
- for(var i = 0; i < res.length; i++) {
- $('<li class="form-group entryItem">'+
- '<label for="entryvalue_'+ i +'"id="entryname_'+ i +'" class="col-md-2 text-right">' + res[i].name + '</label>'+
- '<div class="col-md-10">'+
- '<input id="entryvalue_'+ i +'" class="form-control" type="text" placeholder="请输入用' + res[i].name + '总量" />'+
- '</div>'+
- '</li>').appendTo(el);
- }
- }else{
- $('<div class="alert alert-warning col-md-10 col-md-offset-2" role="alert">暂无数据,请联系管理员,添加数据。</div>').appendTo(el)
- }
-
- dtd.resolve(); // 改变Deferred对象的执行状态
- }
- });
- return dtd.promise(); // 返回promise对象
- }
- //获取值
- function getEntryValues(){
- var entryItem = $('#entryLists').find('.entryItem');
- var entryNames = [];
- var entryValues = [];
- for(var i = 0, len = entryItem.length; i < len; i++){
- var name = $(entryItem[i]).find('label[id*=entryname_]').text();
- var value = $(entryItem[i]).find('input[id*=entryvalue_]').val();
- entryNames.push(name);
- value = value === '' ? 0 : value;
- entryValues.push(value);
- }
- return {
- "name": entryNames,
- "value": entryValues
- }
- }
- //保存
- function saveProject() {
- var editId = helper.request.queryString("editId");
- var wUrl;
- if(!$.trim($('#pro_title').val())) {
- layer.confirm('你还没有选择所属项目', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- if(editId) {
- wUrl = "plcautomationapi/api/inputdata/update"; //修改
- } else {
- wUrl = "plcautomationapi/api/inputdata/add"; //添加
- }
- $.ajax({
- type: "post",
- url: huayi.config.callcenter_url + "plcautomationapi/api/inputdata/add",
- dataType: 'json',
- async: true,
- beforeSend: function() { //触发ajax请求开始时执行
- $('#pro_save').attr("disabled", true);
- $('#pro_save').text('保存中...');
- $(document).off('click', '#pro_save', saveProject);
- },
- data: {
- id: editId,
- inputtime: $('#pro_times').val(), //否 string 日期(不传时默认当天)
- projectname: $('#pro_title').val(),
- dataname: getEntryValues().name, //是 string[] 数据名称
- datavalue: getEntryValues().value //是 string[] 数据值
- },
- success: function(result) {
- if(result.state.toLowerCase() === "success") {
- var index = parent.layer.getFrameIndex(window.name);
- parent.layer.close(index);
- parent.$('#table_all').bootstrapTable('refresh');
- parent.layer.msg("保存成功");
- }
- },
- error: function(textStatus) {
- layer.confirm('网络繁忙,请稍后再试...', {
- icon: 7,
- closeBtn: 0,
- btn: ['确定'] //按钮
- });
- $('#pro_save').text('保存');
- $('#pro_save').attr("disabled", false);
- $(document).off('click', '#pro_save', saveProject);
- $(document).on('click', '#pro_save', saveProject);
- },
- complete: function(XMLHttpRequest, textStatus) {
- if(textStatus == 'timeout') {
- var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
- xmlhttp.abort();
- layer.confirm('网络超时,请稍后再试...', {
- icon: 7,
- closeBtn: 0,
- btn: ['确定'] //按钮
- });
- }
- $('#pro_save').text('保存');
- $('#pro_save').attr("disabled", false);
- $(document).off('click', '#pro_save', saveProject);
- $(document).on('click', '#pro_save', saveProject);
- },
- });
- }
- //获取项目下拉
- function getProlistDrop(el){
- var dtd = $.Deferred(); //在函数内部,新建一个Deferred对象
- $.ajax({
- type: "get",
- url: huayi.config.callcenter_url + "equipmentapi/api/ProjectInfo/getlistdrop",
- dataType: 'json',
- async: true,
- data: {},
- success: function(data) {
- el.empty();
- el.append("<option value=''>请选择项目</option>");
- var res = data.data;
- if(res){
- for(var i = 0; i < res.length; i++) {
- $('<option value=' + res[i].text + '>' + res[i].text + '</option>').appendTo(el);
- }
- el.selectpicker('refresh');
- }
- dtd.resolve(); // 改变Deferred对象的执行状态
- }
- });
- return dtd.promise(); // 返回promise对象
- }
|