123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- 'use strict';
- var app = angular.module('app', [
- ]);
- app.controller("formeditCtrl", ["$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.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
- self.get_id = sp.getUrlName("id");
- self.get_lastReturnPageno = sp.getUrlName("lastReturnPageno");
- self.get_lastReturnPage = sp.getUrlName("lastReturnPage");
- self.return = "workList.html?lastReturnPageno=" + self.get_lastReturnPageno
- self.deviceType = localStorage.getItem("tjJxtGoldenlinkWork-deviceType");
- self.read = sp.getUrlName("read");
- var postCfg = {
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': "Bearer " + self.get_AccessToken
- }
- };
- var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]
- self.beforeUpload = function () {
- if (self.data.ID == 0) {
- var data = {
- tablename: "SX_ZHIBANGZRZ",
- data: {
- GLRQ: self.data.GLRQ,
- XINGQI: self.data.XINGQI,
- TIANQI: self.data.TIANQI,
- QIWEN: self.data.QIWEN,
- DBLDZW: self.data.DBLDZW,
- ZBYBB: self.data.ZBYBB,
- ZBYYB: self.data.ZBYYB,
- ZBJL: self.data.ZBJL,
- USERID: self.userId,
- 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) {
- self.get_id = res.data;
- self.upload()
- $timeout(function () {
- sp.dialoghide();
- }, 1000)
- } else {
- sp.dialog(res.message);
- }
- })
- } else {
- self.upload()
- }
- }
- self.upload = function () {
- var acceptFileTypes = /(jpg|png)$/i
- $('#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_ZHIBANGZRZ,column=ATTACHLIST,routeinfoid=" + self.get_id + ",loaded=" + data.loaded + ",total=" + data.total));
- },
- add: function (e, data) {
- var num = 0;
- //文件类型判断
- $.each(data.originalFiles, function (index, item) {
- if (item['type'] != null && item['type'] != undefined && !acceptFileTypes.test(item['name'])) {
- sp.dialog("您好,请上传JPG、PNG格式的文件!");
- return;
- } else {
- num++
- }
- })
- if (num == data.originalFiles.length) {
- data.submit();
- }
- },
- // 上传完成后的执行逻辑
- 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;
- self.arrayFile.forEach(function (item) {
- item.FILEURL1 = $sce.trustAsResourceUrl(apiurljs.login + "g2work" + item.FILEURL)
- })
- $scope.$apply();//绑定数据局部刷新
- }
- })
- $timeout(function () {
- $("#fileupload").trigger("click")
- }, 1)
- }
- self.getDBLD = function () {
- var data = {
- tablename: "SX_ZHIBANRYGL",
- colums: "*",
- order: "ID",
- sqlwhere: { "MANMARK": "C01" },
- 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.DBLD = res.data;
- self.getData()
- })
- }
- self.getDBLD()
- //获取数据
- self.getData = function () {
- if (self.get_id == 0) {
- self.data = {
- ID: 0,
- GLRQ: sp.format(sp.getLocalDate()),
- XINGQI: weeks[new Date(sp.getLocalDate()).getDay()],
- TIANQI: "",
- QIWEN: "",
- DBLDZW: "",
- ZBYBB: "",
- ZBYYB: "",
- ZBJL: ""
- }
- self.arrayFile = [];
- } else {
- var data = {
- tablename: "SX_ZHIBANGZRZ",
- colums: "*",
- order: "ID desc",
- sqlwhere: { ID: self.get_id },
- 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,
- GLRQ: res.data[0].GLRQ ? sp.format(res.data[0].GLRQ) : sp.format(sp.getLocalDate()),
- XINGQI: res.data[0].XINGQI ? res.data[0].XINGQI : weeks[new Date(sp.getLocalDate()).getDay()],
- TIANQI: res.data[0].TIANQI ? res.data[0].TIANQI : "",
- QIWEN: res.data[0].QIWEN ? res.data[0].QIWEN : "",
- DBLDZW: res.data[0].DBLDZW ? res.data[0].DBLDZW : "",
- ZBYBB: res.data[0].ZBYBB ? res.data[0].ZBYBB : "",
- ZBYYB: res.data[0].ZBYYB ? res.data[0].ZBYYB : "",
- ZBJL: res.data[0].ZBJL ? res.data[0].ZBJL : "",
- };
- if (res.data[0].ATTACHLIST) {
- self.arrayFile = JSON.parse(res.data[0].ATTACHLIST)
- self.arrayFile.forEach(function (item) {
- item.FILEURL1 = $sce.trustAsResourceUrl(apiurljs.login + "g2work" + item.FILEURL)
- })
- console.log(self.arrayFile)
- } else {
- self.arrayFile = [];
- }
- })
- }
- }
- self.seePic = function (obj) {
- self.seePicUrl = obj.FILEURL1
- $('.sp-bgMask').fadeIn(200);
- $(".sp-bgMask").bind("click", function () {
- $(this).fadeOut(200);
- if ($("#seePic").is(":visible")) { //若对话框显示则淡出
- $("#seePic").fadeOut(200);
- }
- });
- $timeout(function () {
- sp.setCenter("#seePic")
- }, 1)
- }
- //删除附件
- self.deleteFile = function (item) {
- var data = {
- tablename: "SX_ZHIBANGZRZ",
- column: "ATTACHLIST",
- routeinfoid: self.get_id,
- fileid: item.FILEID,
- filenames: item.FILEOLDNAME
- }
- $http.post(apiurljs.login + "g2app/abase/deleteUploadFileName", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- if (res.success == true) {
- self.arrayFile = res.data;
- self.arrayFile.forEach(function (item) {
- item.FILEURL1 = $sce.trustAsResourceUrl(apiurljs.login + "g2work" + item.FILEURL)
- })
- } else {
- sp.dialog(res.message)
- }
- })
- }
- self.changeDate = function () {
- self.data.XINGQI = weeks[new Date(self.data.GLRQ).getDay()]
- }
- //保存提交
- self.btnSave = function (n) {
- if (self.get_id == 0) {
- var data = {
- tablename: "SX_ZHIBANGZRZ",
- data: {
- GLRQ: self.data.GLRQ,
- XINGQI: self.data.XINGQI,
- TIANQI: self.data.TIANQI,
- QIWEN: self.data.QIWEN,
- DBLDZW: self.data.DBLDZW,
- ZBYBB: self.data.ZBYBB,
- ZBYYB: self.data.ZBYYB,
- ZBJL: self.data.ZBJL,
- USERID: self.userId,
- 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_ZHIBANGZRZ",
- data: {
- GLRQ: self.data.GLRQ,
- XINGQI: self.data.XINGQI,
- TIANQI: self.data.TIANQI,
- QIWEN: self.data.QIWEN,
- DBLDZW: self.data.DBLDZW,
- ZBYBB: self.data.ZBYBB,
- ZBYYB: self.data.ZBYYB,
- ZBJL: self.data.ZBJL,
- }
- }
- $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);
- }
- })
- }
- }
- //头部下滚冻结
- $(function () {
- $(".sp-page-center").css("max-height", $(window).height() - 58).css("height", $(window).height() - 58)
- //页面高度撑满
- setTimeout(function () {
- if ($(".ibox-content").height() < $(window).height() - 31) {
- $(".ibox-content").css("height", $(window).height() - 31)
- }
- }, 1)
- })
- }])
|