'use strict'; var app = angular.module('app', [ ]); app.controller("detailCtrl", ["$scope", "$http", "$timeout", '$sce', function ($scope, $http, $timeout, $sce) { var self = this; var s4 = new SM4Util(); self.userId = $.cookie("GlWorkPlatform-userid"); self.userName = $.cookie("GlWorkPlatform-chineseName"); self.userCName = $.cookie("GlWorkPlatform-chineseName"); self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken"); self.get_lastReturnPageno = sp.getUrlName("lastReturnPageno"); self.get_id = sp.getUrlName("id"); self.return = "list.html?lastReturnPageno=" + self.get_lastReturnPageno var postCfg = { headers: { 'Content-Type': 'application/json', 'Authorization': "Bearer " + self.get_AccessToken } }; //上传附件 self.beforeUpload = function () { if (self.data.ID == 0) { var data = { tablename: "SX_SJPSWJTZ", data: { LWDW: self.data.LWDW, WJMC: self.data.WJMC, SJPS: self.data.SJPS, QPSJ: self.data.QPSJ, BLJD: self.data.BLJD, DBTX: self.data.DBTX, DBTXTIME: self.data.DBTXTIME, REMARK: self.data.REMARK, FLOWROUTEINFOID: "", USERID: self.userId, SECTCODE: self.userDpCode, CDATE: sp.getLocalDate() } } $http.post(apiurljs.login + "g2app/DangJian/insertFormData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.code == 0) { self.get_id = res.data; self.getData(); self.upload() } else { sp.dialog(res.message) } }) } else { self.upload() } } self.upload = function () { $('#fileupload').fileupload({ url: apiurljs.login + 'g2app/abase/saveUploadFileName', dataType: 'json', beforeSend: function (xhr, data) { xhr.setRequestHeader("Authorization", "Bearer " + self.get_AccessToken); xhr.setRequestHeader("File-Argument", s4.encryptData_CBC("tablename=SX_SJPSWJTZ,column=FILEATTACH,id=" + self.get_id + ",routeinfoid=" + self.get_id + ",loaded=" + data.loaded + ",total=" + data.total)); }, // 上传完成后的执行逻辑 done: function (e, data) { var arrayFile = strToJson(s4.decryptData_CBC(data.result.data).slice(0, s4.decryptData_CBC(data.result.data).lastIndexOf("}") + 1)) self.arrayFile = arrayFile.data; $scope.$apply();//绑定数据局部刷新 } }) $timeout(function () { $("#fileupload").trigger("click") }, 1) } self.getDP = function () { var data = { userid: self.userId } $http.post(apiurljs.login + "g2app/richang/queryDpInfo", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.userDpName = res.data.length == 0 ? "" : res.data[0].SECTION; self.userDpCode = res.data.length == 0 ? "" : res.data[0].CODE; self.getData(); }) } self.getData = function () { if (self.get_id == 0) { self.data = { ID: 0, LWDW: "", WJMC: "", SJPS: "", QPSJ: sp.format(sp.getLocalDate()), BLJD: "", DBTX: "", DBTXTIME: sp.format(sp.getLocalDate()), REMARK: "" } self.arrayFile = []; } else { var data = { tablename: "SX_SJPSWJTZ", colums: "*", order: "ID", sqlwhere: { ID: self.get_id }, sqlorwhere: "", sqlinwhere: "", sqllikewhere: "" } $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.data = { ID: res.data[0].ID, LWDW: res.data[0].LWDW ? res.data[0].LWDW : "", WJMC: res.data[0].WJMC ? res.data[0].WJMC : "", SJPS: res.data[0].SJPS ? res.data[0].SJPS : "", QPSJ: res.data[0].QPSJ ? sp.format(res.data[0].QPSJ) : sp.format(sp.getLocalDate()), BLJD: res.data[0].BLJD ? res.data[0].BLJD : "", DBTX: res.data[0].DBTX ? res.data[0].DBTX : "", DBTXTIME: res.data[0].DBTXTIME ? sp.format(res.data[0].DBTXTIME) : sp.format(sp.getLocalDate()), REMARK: res.data[0].REMARK ? res.data[0].REMARK : "" } if (res.data[0].FILEATTACH && res.data[0].FILEATTACH != "") { self.arrayFile = JSON.parse(res.data[0].FILEATTACH); } }) } } self.getDP() self.btnSave = function () { if (self.data.ID == 0) { var data = { tablename: "SX_SJPSWJTZ", data: { LWDW: self.data.LWDW, WJMC: self.data.WJMC, SJPS: self.data.SJPS, QPSJ: self.data.QPSJ, BLJD: self.data.BLJD, DBTX: self.data.DBTX, DBTXTIME: self.data.DBTXTIME, REMARK: self.data.REMARK, FLOWROUTEINFOID: "", USERID: self.userId, SECTCODE: self.userDpCode, CDATE: sp.getLocalDate() } } $http.post(apiurljs.login + "g2app/dataabase/insertFormData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.success) { sp.dialog("保存成功!"); self.get_id = res.data; self.getData(); $timeout(function () { sp.dialoghide(); }, 1000) } else { sp.dialog(res.message); } }) } else { var data = { id: self.data.ID, tablename: "SX_SJPSWJTZ", data: { LWDW: self.data.LWDW, WJMC: self.data.WJMC, SJPS: self.data.SJPS, QPSJ: self.data.QPSJ, BLJD: self.data.BLJD, DBTX: self.data.DBTX, DBTXTIME: self.data.DBTXTIME, REMARK: self.data.REMARK, } } $http.post(apiurljs.login + "g2app/dataabase/upFormData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.success) { sp.dialog("保存成功!"); self.getData(); $timeout(function () { sp.dialoghide(); }, 1000) } else { sp.dialog(res.message); } }) } } }])