sysconfigCtrl.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. "use strict";
  2. app.controller("sysconfigCtrl", ["$parse", "$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "$window", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_sysinfo", "api_is_category","api_bpm_domain","api_simple", "FileUploader", "fileReader", "api_login", "api_wechatfile","api_user_data", function ($parse, t, a, n, e, i, s, r, o, l, u, d, c, g, api_is_category,api_bpm_domain, api_simple, FileUploader, fileReader, api_login, api_wechatfile,api_user_data) {
  3. a.langs = l.getAllLangs(), a.lang = "zh-cn", l.setCurrentLang(a.lang);
  4. var f = (t.user, r._, {
  5. idx: 0,
  6. sum: 1e3
  7. });
  8. // 当前所属院区或责任科室
  9. if(t.user.duty){
  10. a.branchId = t.user.duty.branch;
  11. }else if(t.user.branch){
  12. a.branchId = t.user.branch.id;
  13. }
  14. a.hospitalConfig = [];
  15. a.hospitalObj = {};
  16. // a.autoCloseIncidentHour = 24;//默认24小时自动关单
  17. a.changeAutoCloseIncidentHour = function(e){
  18. var v = parseFloat(e.target.value)?parseFloat(e.target.value):0;
  19. a.autoCloseIncidentHour.valueconfig = v > 0 ? v : 0;
  20. }
  21. //清除缓存
  22. a.refreshCache = function () {
  23. t.isMask = true;
  24. api_bpm_domain.refreshCache({}).then(function (result) {
  25. t.isMask = false;
  26. if (result.status == 200) {
  27. o.swal({
  28. title: "操作成功!",
  29. type: "success",
  30. confirmButtonColor: "#007AFF"
  31. })
  32. } else {
  33. o.swal({
  34. title: "操作异常!",
  35. text: "系统异常,请稍后重试,或者联系管理员!",
  36. type: "error"
  37. })
  38. }
  39. }).catch(function(err){
  40. t.isMask = false;
  41. })
  42. }
  43. //清除缓存-single
  44. a.refreshCacheSingle = function (type) {
  45. t.isMask = true;
  46. api_user_data.cacheFresh(type).then(function (result) {
  47. t.isMask = false;
  48. if (result.status == 200) {
  49. o.swal({
  50. title: "操作成功!",
  51. type: "success",
  52. confirmButtonColor: "#007AFF"
  53. })
  54. } else {
  55. o.swal({
  56. title: "操作异常!",
  57. text: "系统异常,请稍后重试,或者联系管理员!",
  58. type: "error"
  59. })
  60. }
  61. }).catch(function(err){
  62. t.isMask = false;
  63. })
  64. }
  65. // 切换三方设备
  66. a.changeCcType = function(type){
  67. a.hospitalObj.ccType.value = type;
  68. for (var key in a.hospitalObj) {
  69. if(key != 'ccType'){
  70. a.hospitalObj[key].value = '';
  71. }
  72. }
  73. }
  74. // 图片logo上传----start
  75. a.imgshows = [];
  76. a.uploadimgs = [];
  77. var model = $parse("upload_img");
  78. var modelSetter = model.assign;
  79. var uploader = (a.uploader = new FileUploader({
  80. url: "/uploader",
  81. }));
  82. a.getDetail = function(img){
  83. function getImageFileFromUrl(url, imageName, callback) {
  84. // imageName一定要带上后缀
  85. var blob = null
  86. var xhr = new XMLHttpRequest()
  87. xhr.open('GET', url)
  88. xhr.setRequestHeader('Accept', 'image/jpeg')
  89. xhr.responseType = 'blob'
  90. xhr.onload = () => {
  91. if (xhr.status === 200) {
  92. blob = xhr.response
  93. let imgFile = new File([blob], imageName, {type: 'image/jpeg'})
  94. console.log(imgFile)
  95. callback.call(this, imgFile)
  96. }
  97. }
  98. xhr.send()
  99. }
  100. getImageFileFromUrl(img, img.match(/[^\/\\]+$/) ? img.match(/[^\/\\]+$/)[0] : '',function(file){
  101. var dummy = new FileUploader.FileItem(uploader, file);
  102. uploader.queue = [dummy];
  103. getFile(file, a);
  104. })
  105. //获得预览图地址并且把file对象放入上传合集内
  106. function getFile(imgupload, a) {
  107. if (!imgupload) {
  108. return;
  109. }
  110. fileReader.readAsDataUrl(imgupload, a).then(function (result) {
  111. // console.log(result)
  112. a.imgshows = [result];
  113. var file = imgupload;
  114. a.uploadimgs = [file]; //这里是放着传给后台的数据file,下面controller的时候会有
  115. console.log(a.imgshows, a.uploadimgs);
  116. if (a.imgshows.length < 1) {
  117. $("#upupgogo").show();
  118. } else {
  119. $("#upupgogo").hide();
  120. }
  121. });
  122. }
  123. }
  124. // 添加
  125. a.change = function (event) {
  126. a.isEdit = true;
  127. var element = $(".upinp");
  128. modelSetter(a, element[0].files[0]);
  129. //附件预览
  130. a.imgupload = event.files[0];
  131. getFile(a.imgupload, a);
  132. //获得预览图地址并且把file对象放入上传合集内
  133. function getFile(imgupload, a) {
  134. if (!imgupload) {
  135. return;
  136. }
  137. fileReader.readAsDataUrl(imgupload, a).then(function (result) {
  138. // console.log(result)
  139. a.imgshows = [result];
  140. var file = document.querySelector("#upupgogo input[type=file]").files[0];
  141. a.uploadimgs = [file]; //这里是放着传给后台的数据file,下面controller的时候会有
  142. console.log(a.imgshows, a.uploadimgs);
  143. if (a.imgshows.length < 1) {
  144. $("#upupgogo").show();
  145. } else {
  146. $("#upupgogo").hide();
  147. }
  148. });
  149. }
  150. };
  151. // 删除
  152. a.uploadimg_del = function (index, imgs) {
  153. console.log(index, imgs);
  154. a.isEdit = true;
  155. a.imgshows.splice(index, 1);
  156. a.uploadimgs.splice(index, 1);
  157. a.uploader.queue.shift();
  158. if (a.imgshows.length < 1) {
  159. $("#upupgogo").show();
  160. } else {
  161. $("#upupgogo").hide();
  162. }
  163. document.querySelector("#upupgogo input[type=file]").value = null;
  164. };
  165. // 图片logo上传----end
  166. // 图片favicon上传----start
  167. a.isEdit1 = false;
  168. a.imgshows1 = [];
  169. a.uploadimgs1 = [];
  170. var model1 = $parse("upload_img1");
  171. var model1Setter = model1.assign;
  172. var uploader1 = (a.uploader1 = new FileUploader({
  173. url: "/uploader1",
  174. }));
  175. a.getDetail1 = function(img){
  176. function getImageFileFromUrl(url, imageName, callback) {
  177. // imageName一定要带上后缀
  178. var blob = null
  179. var xhr = new XMLHttpRequest()
  180. xhr.open('GET', url)
  181. xhr.setRequestHeader('Accept', 'image/jpeg')
  182. xhr.responseType = 'blob'
  183. xhr.onload = () => {
  184. if (xhr.status === 200) {
  185. blob = xhr.response
  186. let imgFile = new File([blob], imageName, {type: 'image/jpeg'})
  187. console.log(imgFile)
  188. callback.call(this, imgFile)
  189. }
  190. }
  191. xhr.send()
  192. }
  193. getImageFileFromUrl(img, img.match(/[^\/\\]+$/) ? img.match(/[^\/\\]+$/)[0] : '',function(file){
  194. var dummy = new FileUploader.FileItem(uploader1, file);
  195. uploader1.queue = [dummy];
  196. getFile(file, a);
  197. })
  198. //获得预览图地址并且把file对象放入上传合集内
  199. function getFile(imgupload, a) {
  200. if (!imgupload) {
  201. return;
  202. }
  203. fileReader.readAsDataUrl(imgupload, a).then(function (result) {
  204. // console.log(result)
  205. a.imgshows1 = [result];
  206. var file = imgupload;
  207. a.uploadimgs1 = [file]; //这里是放着传给后台的数据file,下面controller的时候会有
  208. console.log(a.imgshows1, a.uploadimgs1);
  209. if (a.imgshows1.length < 1) {
  210. $("#upupgogo1").show();
  211. } else {
  212. $("#upupgogo1").hide();
  213. }
  214. });
  215. }
  216. }
  217. // 添加
  218. a.change1 = function (event) {
  219. a.isEdit1 = true;
  220. var element = $(".upinp1");
  221. model1Setter(a, element[0].files[0]);
  222. //附件预览
  223. a.imgupload1 = event.files[0];
  224. getFile(a.imgupload1, a);
  225. //获得预览图地址并且把file对象放入上传合集内
  226. function getFile(imgupload, a) {
  227. if (!imgupload) {
  228. return;
  229. }
  230. fileReader.readAsDataUrl(imgupload, a).then(function (result) {
  231. // console.log(result)
  232. a.imgshows1 = [result];
  233. var file = document.querySelector("#upupgogo1 input[type=file]").files[0];
  234. a.uploadimgs1 = [file]; //这里是放着传给后台的数据file,下面controller的时候会有
  235. console.log(a.imgshows1, a.uploadimgs1);
  236. if (a.imgshows1.length < 1) {
  237. $("#upupgogo1").show();
  238. } else {
  239. $("#upupgogo1").hide();
  240. }
  241. });
  242. }
  243. };
  244. // 删除
  245. a.uploadimg_del1 = function (index, imgs) {
  246. console.log(index, imgs);
  247. a.isEdit1 = true;
  248. a.imgshows1.splice(index, 1);
  249. a.uploadimgs1.splice(index, 1);
  250. a.uploader1.queue.shift();
  251. if (a.imgshows1.length < 1) {
  252. $("#upupgogo1").show();
  253. } else {
  254. $("#upupgogo1").hide();
  255. }
  256. document.querySelector("#upupgogo1 input[type=file]").value = null;
  257. };
  258. //获取字典列表
  259. a.wxincident_degreeList = [];
  260. a.incident_degreeList = [];
  261. a.searchList = {
  262. autoIncidentDegree: null,
  263. autoWechatDegree: null,
  264. }
  265. a.getDictionary = function(type, v){
  266. api_wechatfile.getDictionary({ key: type, type: "list" }).then(res => {
  267. a[type + 'List'] = res || [];
  268. if(v){
  269. if (v.keyconfig == 'autoIncidentDegree') {
  270. a.searchList.autoIncidentDegree = a[type + 'List'].find(item => item.id == v.valueconfig);
  271. }
  272. if (v.keyconfig == 'autoWechatDegree') {
  273. a.searchList.autoWechatDegree = a[type + 'List'].find(item => item.id == v.valueconfig);
  274. }
  275. }
  276. })
  277. .catch(err => {
  278. console.log(err)
  279. })
  280. }
  281. // 图片favicon上传----end
  282. //保存
  283. a.savesystem = function () {
  284. var arr = {};
  285. arr.systemConfiguration = [];
  286. angular.forEach(a.baseConfig, function (v) {
  287. if (v.keyconfig == 'pwd' || v.keyconfig == 'conversationSeconds' || v.keyconfig == 'systemName' || v.keyconfig == 'largeScreenName') {
  288. arr.systemConfiguration.push(v);//用户默认密码,登录有效时长
  289. }
  290. })
  291. angular.forEach(a.linkConfig, function (v) {
  292. arr.systemConfiguration.push(v);
  293. })
  294. arr.systemConfiguration.push(a.repairMain);//报修主体
  295. arr.systemConfiguration.push(a.ifCreate);//自动建单
  296. arr.systemConfiguration.push(a.reqHasCategory);//是否选择故障现象
  297. arr.systemConfiguration.push(a.incidentWithConsumable);//是否需要绑定耗材
  298. let autoWechatDegree = a.myData.find(v => v.keyconfig == 'autoWechatDegree');
  299. if(a.searchList.autoWechatDegree){
  300. autoWechatDegree.valueconfig = a.searchList.autoWechatDegree.id.toString();
  301. }else{
  302. autoWechatDegree.valueconfig = '';
  303. }
  304. arr.systemConfiguration.push(autoWechatDegree);
  305. let autoIncidentDegree = a.myData.find(v => v.keyconfig == 'autoIncidentDegree');
  306. if(a.searchList.autoIncidentDegree){
  307. autoIncidentDegree.valueconfig = a.searchList.autoIncidentDegree.id.toString();
  308. }else{
  309. autoIncidentDegree.valueconfig = '';
  310. }
  311. arr.systemConfiguration.push(autoIncidentDegree);
  312. arr.systemConfiguration.push(a.wxIncidentWithCmdb);//是否需要绑定资产
  313. arr.systemConfiguration.push(a.ifWorking);//是否开通上下班
  314. arr.systemConfiguration.push(a.integralMechanism);//积分机制
  315. arr.systemConfiguration.push(a.ifRoom);//是否增加房间号选择
  316. arr.systemConfiguration.push(a.requesterLgoinType);//保修人登录方式
  317. arr.systemConfiguration.push(a.autoCloseIncidentHour);//自动关单小时
  318. console.log(arr,99999);
  319. t.isMask = true;
  320. var _t = t;
  321. var hospitalConfig = Object.values(a.hospitalObj);
  322. api_simple.addListData('hospitalConfig', hospitalConfig).then(function(result){
  323. if(result.status == 200){
  324. g.addData("systemConfiguration", arr).then(function (t) {
  325. if (t.status == 200) {
  326. //获取报修主体
  327. api_is_category.isCategory({ "idx": 0, "sum": 1000 })
  328. .then(function (res) {
  329. _t.isMask = false;
  330. if (res.status == 200) {
  331. //存储报修主体到缓存
  332. var list = res.list;
  333. list.forEach(v => {
  334. switch (v.keyconfig) {
  335. case "repairMain": //报修主体
  336. sessionStorage.setItem("repair_main", JSON.stringify(v));
  337. break;
  338. case "incidentWithConsumable": //是否绑定耗材
  339. sessionStorage.setItem("incidentWithConsumable", v.valueconfig);
  340. break;
  341. case "wxIncidentWithCmdb": //是否绑定资产
  342. sessionStorage.setItem("wxIncidentWithCmdb", v.valueconfig);
  343. break;
  344. case "ifRoom": //是否增加房间号选择
  345. sessionStorage.setItem("ifRoom", v.valueconfig);
  346. break;
  347. case "integralMechanism": //积分机制
  348. sessionStorage.setItem("integralMechanism", v.valueconfig);
  349. break;
  350. }
  351. });
  352. o.swal({
  353. title: "保存成功!",
  354. type: "success",
  355. confirmButtonColor: "#007AFF"
  356. })
  357. if (a.uploader && a.uploadimgs.length && a.isEdit) {
  358. // 有图片
  359. a.uploader.onBeforeUploadItem = function(item) {
  360. angular.extend(item.headers, _t.getSession());
  361. item.url = api_bpm_domain.uploadAttachmentJryModel('sysLogo', 777).getRequestedUrl();
  362. a.isEdit = false;
  363. item.formData = [{ 'fileName': item.file.name }];
  364. };
  365. a.uploader.uploadAll();
  366. a.uploader.onCompleteAll = function(){
  367. if (a.uploader1 && a.uploadimgs1.length && a.isEdit1) {
  368. // 有图片
  369. a.uploader1.onBeforeUploadItem = function(item) {
  370. angular.extend(item.headers, _t.getSession());
  371. item.url = api_bpm_domain.uploadAttachmentJryModel('faviconLogo', 777).getRequestedUrl();
  372. a.isEdit1 = false;
  373. item.formData = [{ 'fileName': item.file.name }];
  374. };
  375. a.uploader1.uploadAll();
  376. a.uploader1.onCompleteAll = function(){
  377. a.refreshData("expand-right", f);
  378. }
  379. }else{
  380. a.refreshData("expand-right", f);
  381. }
  382. }
  383. }else{
  384. if (a.uploader1 && a.uploadimgs1.length && a.isEdit1) {
  385. // 有图片
  386. a.uploader1.onBeforeUploadItem = function(item) {
  387. angular.extend(item.headers, _t.getSession());
  388. item.url = api_bpm_domain.uploadAttachmentJryModel('faviconLogo', 777).getRequestedUrl();
  389. a.isEdit1 = false;
  390. item.formData = [{ 'fileName': item.file.name }];
  391. };
  392. a.uploader1.uploadAll();
  393. a.uploader1.onCompleteAll = function(){
  394. a.refreshData("expand-right", f);
  395. }
  396. }else{
  397. a.refreshData("expand-right", f);
  398. }
  399. }
  400. }
  401. })
  402. .catch(function (err) {
  403. _t.isMask = false;
  404. console.log(err)
  405. })
  406. } else {
  407. _t.isMask = false;
  408. o.swal({
  409. title: "操作异常!",
  410. text: "系统异常,请稍后重试,或者联系管理员!",
  411. type: "error"
  412. })
  413. }
  414. })
  415. }else{
  416. _t.isMask = false;
  417. o.swal({
  418. title: "操作异常!",
  419. text: "系统异常,请稍后重试,或者联系管理员!",
  420. type: "error"
  421. })
  422. }
  423. })
  424. .catch(function (err) {
  425. _t.isMask = false;
  426. console.log(err)
  427. })
  428. }
  429. a.ldloading = {}
  430. a.refreshData = function (t, n) {
  431. a.ldloading[t.replace("-", "_")] = !0;
  432. angular.isUndefined(n) && (n = f);
  433. a.myData = [];
  434. g.fetchDataList("systemConfiguration", n).then(function (n) {
  435. if (n.status == 200) {
  436. var e = c.stripRestangular(n);
  437. a.myData = e.list, a.ldloading[t.replace("-", "_")] = !1
  438. console.log(a.myData);
  439. a.baseConfig = [];//基本配置
  440. a.cacheConfig = [];//缓存配置
  441. a.linkConfig = [];//链接配置
  442. a.repairMain = {};//报修主体
  443. console.log(a.myData,77777)
  444. angular.forEach(a.myData, function (v, i) {
  445. if (v.keyconfig == 'pwd' || v.keyconfig == 'conversationSeconds' || v.keyconfig == 'formUri' || v.keyconfig == 'localhost' || v.keyconfig == 'verificationPath' || v.keyconfig == 'docpath' || v.keyconfig == 'systemName' || v.keyconfig == 'largeScreenName') {
  446. a.baseConfig.push(v);//基本配置
  447. }
  448. if (v.keyconfig == 'userRedisIp' || v.keyconfig == 'userRedisPort') {
  449. a.cacheConfig.push(v);//缓存配置
  450. }
  451. if (v.keyconfig == 'wxBxQuestions' || v.keyconfig == 'wxGuide' || v.keyconfig == 'wxClQuestions') {
  452. a.linkConfig.push(v);//链接配置
  453. }
  454. if (v.keyconfig == 'repairMain') {
  455. a.repairMain = v;//报修主体
  456. }
  457. if (v.keyconfig == 'ifCreate') {
  458. a.ifCreate = v;//自动建单
  459. }
  460. if (v.keyconfig == 'reqHasCategory') {
  461. a.reqHasCategory = v;//是否选择故障现象
  462. }
  463. if (v.keyconfig == 'incidentWithConsumable') {
  464. a.incidentWithConsumable = v;//是否需要绑定耗材
  465. }
  466. if (v.keyconfig == 'autoIncidentDegree') {
  467. a.getDictionary('incident_degree', v);
  468. }
  469. if (v.keyconfig == 'autoWechatDegree') {
  470. a.getDictionary('wxincident_degree', v);
  471. }
  472. if (v.keyconfig == 'wxIncidentWithCmdb') {
  473. a.wxIncidentWithCmdb = v;//是否需要绑定资产
  474. }
  475. if (v.keyconfig == 'ifWorking') {
  476. a.ifWorking = v;//是否开通上下班
  477. }
  478. if (v.keyconfig == 'integralMechanism') {
  479. a.integralMechanism = v;//积分机制
  480. }
  481. if (v.keyconfig == 'ifRoom') {
  482. a.ifRoom = v;//是否增加房间号选择
  483. }
  484. if (v.keyconfig == 'requesterLgoinType') {
  485. a.requesterLgoinType = v;//报修人登录方式
  486. }
  487. if (v.keyconfig == 'autoCloseIncidentHour') {
  488. v.valueconfig = parseFloat(v.valueconfig)
  489. a.autoCloseIncidentHour = v;//自动关单小时
  490. }
  491. })
  492. }else{
  493. console.log(n.status);
  494. }
  495. }, function () {
  496. a.ldloading[t.replace("-", "_")] = !1
  497. });
  498. api_simple.fetchDataList("hospitalConfig", {"idx":0,"sum":100,"hospitalConfig":{"hosId":a.branchId}}).then(function (result) {
  499. if(result.status = 200){
  500. a.hospitalConfig = result.list || [];
  501. a.hospitalConfig.forEach(function(v){
  502. a.hospitalObj[v.key] = v;
  503. })
  504. console.log(a.hospitalObj);
  505. }
  506. })
  507. // 图片回显
  508. api_login.getSysNameAndLogo().then(function (res) {
  509. res.logo && a.getDetail(location.origin + '/file' + res.logo);
  510. res.favicon && a.getDetail1(location.origin + '/file' + res.favicon);
  511. });
  512. }
  513. a.refreshData("expand-right", f)
  514. }]);