setting_controller.js 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const tenderConst = require('../const/tender');
  10. const auditConst = require('../const/audit');
  11. const officeList = require('../const/cld_office').list;
  12. const settingConst = require('../const/setting.js');
  13. const scheduleConst = require('../const/schedule');
  14. const settingMenu = require('../../config/menu').settingMenu;
  15. const accountGroup = require('../const/account_group').group;
  16. const permission = require('../const/account_permission').permission;
  17. const noticeAgainConst = require('../const/account_permission').noticeAgain;
  18. const projectLog = require('../const/project_log');
  19. const imType = require('../const/tender').imType;
  20. const S2b = require('../lib/s2b');
  21. const measureType = require('../const/tender').measureType;
  22. const sendToWormhole = require('stream-wormhole');
  23. const path = require('path');
  24. const funSet = require('../const/fun_set');
  25. const projectSettingConst = require('../const/project_setting');
  26. const SpreadConst = require('../const/spread');
  27. const shenpiConst = require('../const/shenpi');
  28. const projectScreenConst = require('../const/project_screen');
  29. module.exports = app => {
  30. class SettingController extends app.BaseController {
  31. /**
  32. * 构造函数
  33. *
  34. * @param {Object} ctx - egg全局context
  35. * @return {void}
  36. */
  37. constructor(ctx) {
  38. super(ctx);
  39. ctx.subMenu = settingMenu;
  40. }
  41. async _checkMenu(pid) {
  42. const ctx = this.ctx;
  43. await this.ctx.service.s2bProj.refreshSessionS2b(pid);
  44. ctx.subMenu.s2b.display = !!ctx.session.sessionProject.gxby || !!ctx.session.sessionProject.dagl;
  45. }
  46. _checkProjectScreenAdmin(ctx) {
  47. if (!ctx.session.sessionUser.is_admin) throw '没有访问权限';
  48. if (!ctx.session.sessionProject || !ctx.session.sessionProject.id) throw '项目不存在';
  49. }
  50. async module(ctx) {
  51. try {
  52. this._checkProjectScreenAdmin(ctx);
  53. const projectId = ctx.session.sessionProject.id;
  54. await this._checkMenu(projectId);
  55. const screens = await ctx.service.projectScreen.getList(projectId);
  56. await this.layout('setting/module.ejs', {
  57. screens,
  58. templates: projectScreenConst.templates,
  59. projectScreenEnabled: ctx.session.sessionProject.page_show.openProjectScreen === 1,
  60. jsFiles: this.app.jsFiles.common.concat(['/public/js/project_screen_setting.js']),
  61. }, 'setting/module_modal.ejs');
  62. } catch (error) {
  63. ctx.log(error);
  64. ctx.redirect('/dashboard');
  65. }
  66. }
  67. async projectScreenSave(ctx) {
  68. let errorMessage = '项目大屏操作失败';
  69. try {
  70. this._checkProjectScreenAdmin(ctx);
  71. const data = JSON.parse(ctx.request.body.data);
  72. const projectId = ctx.session.sessionProject.id;
  73. const responseData = { err: 0, msg: '', data: null };
  74. switch (data.type) {
  75. case 'status': {
  76. errorMessage = '保存项目大屏开关失败';
  77. const enabled = parseInt(data.enabled) === 1 ? 1 : 0;
  78. ctx.session.sessionProject.page_show.openProjectScreen = enabled;
  79. await ctx.service.project.updatePageshow(projectId);
  80. responseData.data = { enabled };
  81. break;
  82. }
  83. case 'add': {
  84. errorMessage = '添加大屏失败';
  85. const screens = await ctx.service.projectScreen.addScreens(projectId, data.codes);
  86. responseData.data = { screens };
  87. break;
  88. }
  89. case 'delete': {
  90. errorMessage = '删除大屏失败';
  91. const screens = await ctx.service.projectScreen.deleteScreen(projectId, data.id);
  92. responseData.data = { screens };
  93. break;
  94. }
  95. case 'default': {
  96. errorMessage = '设置默认大屏失败';
  97. const screens = await ctx.service.projectScreen.setDefault(projectId, data.id);
  98. responseData.data = { screens };
  99. break;
  100. }
  101. case 'permissionload':
  102. errorMessage = '加载项目成员失败';
  103. responseData.data = await ctx.service.projectAccount.getProjectScreenPermissionAccounts(
  104. projectId,
  105. data
  106. );
  107. break;
  108. case 'permissionsave':
  109. errorMessage = '保存项目大屏权限失败';
  110. await ctx.service.projectAccount.saveProjectScreenPermissions(projectId, data.changes);
  111. break;
  112. default:
  113. throw '提交数据错误';
  114. }
  115. ctx.body = responseData;
  116. } catch (error) {
  117. ctx.log(error);
  118. ctx.ajaxErrorBody(error, errorMessage);
  119. }
  120. }
  121. /**
  122. * 项目信息页面(Get)
  123. *
  124. * @param {Object} ctx - egg全局变量
  125. * @return {void}
  126. */
  127. async info(ctx) {
  128. try {
  129. // 获取项目数据
  130. const projectId = ctx.session.sessionProject.id;
  131. await this._checkMenu(projectId);
  132. const projectData = await ctx.service.project.getDataById(projectId);
  133. if (projectData === null) {
  134. throw '没有对应的项目数据';
  135. }
  136. // 获取销售人员数据
  137. const salesmanData = await ctx.service.manager.getDataById(projectData.manager_id);
  138. // 数据规则
  139. const rule = ctx.service.project.rule('saveInfo');
  140. const jsValidator = await this.jsValidator.convert(rule).build();
  141. const officeName = officeList[salesmanData.office];
  142. const date = new Date(projectData.create_time * 1000);// 如果date为10位不需要乘1000
  143. const Y = date.getFullYear() + '-';
  144. const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  145. const D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
  146. const h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  147. const m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
  148. const s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
  149. const dateStr = Y + M + D + h + m + s;
  150. const renderData = {
  151. projectData,
  152. salesmanData,
  153. officeName,
  154. officeList,
  155. jsValidator,
  156. dateStr,
  157. };
  158. await this.layout('setting/info.ejs', renderData);
  159. } catch (error) {
  160. console.log(error);
  161. ctx.redirect('/dashboard');
  162. }
  163. }
  164. /**
  165. * 项目设置 -- 账号设置(Get)
  166. * @param ctx
  167. * @return {Promise<void>}
  168. */
  169. async user(ctx) {
  170. try {
  171. // 获取项目数据
  172. const projectId = ctx.session.sessionProject.id;
  173. await this._checkMenu(projectId);
  174. const projectData = await ctx.service.project.getDataById(projectId);
  175. if (projectData === null) {
  176. throw '没有对应的项目数据';
  177. }
  178. if (ctx.session.sessionUser.is_admin === 0) {
  179. throw '没有访问权限';
  180. }
  181. let keyword = '';
  182. if (ctx.query.keyword) {
  183. keyword = ctx.query.keyword;
  184. }
  185. let company = '';
  186. if (ctx.query.company) {
  187. company = ctx.query.company;
  188. }
  189. const page = ctx.page;
  190. const pageSize = ctx.pageSize;
  191. // 过滤数据
  192. ctx.service.projectAccount.searchFilter(ctx.request.query, projectId);
  193. ctx.sort = ['id', 'desc'];
  194. const total = await ctx.service.projectAccount.getCountWithBuilder();
  195. // 获取数据规则
  196. // const rule = ctx.service.projectAccount.rule('updateUser');
  197. // const frontRule = ctx.helper.validateConvert(rule);
  198. // const total = await ctx.service.projectAccount.count({ project_id: projectId });
  199. // 获取项目用户列表
  200. // const accountData = await ctx.service.projectAccount.getAllDataByCondition({
  201. // where: { project_id: projectId },
  202. // columns: ['id', 'account', 'name', 'company', 'role', 'mobile', 'auth_mobile', 'telephone', 'enable', 'is_admin', 'account_group'],
  203. // limit: (app.config.pageSize * (page - 1)),
  204. // offset: app.config.pageSize,
  205. // });
  206. // const columns = ['id', 'account', 'name', 'company', 'role', 'mobile', 'auth_mobile', 'telephone', 'enable', 'is_admin', 'account_group', 'bind'];
  207. // const accountData = await ctx.service.projectAccount.getListByProjectId(columns, projectId);
  208. const accountData = await ctx.service.projectAccount.getListWithBuilder();
  209. // 获取账号个数
  210. const user_total = await ctx.service.projectAccount.count({project_id: projectId});
  211. // 分页相关
  212. const pageInfo = {
  213. page,
  214. pageSizeSelect: 1,
  215. pageSize,
  216. total_num: total,
  217. total: Math.ceil(total / pageSize),
  218. queryData: JSON.stringify(ctx.urlInfo.query),
  219. };
  220. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({where: {pid: projectId}});
  221. const renderData = {
  222. projectData,
  223. accountData,
  224. accountGroup,
  225. permission,
  226. pageInfo,
  227. keyword,
  228. user_total,
  229. unitList,
  230. company,
  231. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.user),
  232. // rule: JSON.stringify(frontRule),
  233. };
  234. await this.layout('setting/user.ejs', renderData, 'setting/user_modal.ejs');
  235. } catch (error) {
  236. console.log(error);
  237. ctx.redirect('/dashboard');
  238. }
  239. }
  240. /**
  241. * 项目设置 -- 账号解绑设置(Post)
  242. * @param ctx
  243. * @return {Promise<void>}
  244. */
  245. async userUnbind(ctx) {
  246. const projectData = ctx.session.sessionProject;
  247. try {
  248. if (projectData.id === undefined) {
  249. throw '不存在对应的项目数据';
  250. }
  251. if (ctx.session.sessionUser.is_admin === 0) {
  252. throw '非管理员无权解绑账号';
  253. }
  254. const accountId = parseInt(ctx.request.body.id);
  255. const result = await ctx.service.projectAccount.update({bind: 0}, {id: accountId});
  256. if (!result) {
  257. throw '解绑失败';
  258. }
  259. this.setMessage('解绑成功', this.messageType.SUCCESS);
  260. } catch (error) {
  261. console.log(error);
  262. this.setMessage(error.toString(), this.messageType.ERROR);
  263. }
  264. ctx.redirect(ctx.request.header.referer);
  265. }
  266. /**
  267. * 项目权限 -- 账号设置(Get)
  268. * @param ctx
  269. * @return {Promise<void>}
  270. */
  271. async userPermissionSet(ctx) {
  272. try {
  273. // 获取项目数据
  274. const projectId = ctx.session.sessionProject.id;
  275. const projectData = await ctx.service.project.getDataById(projectId);
  276. if (projectData === null) {
  277. throw '没有对应的项目数据';
  278. }
  279. if (ctx.session.sessionUser.is_admin === 0) {
  280. throw '没有访问权限';
  281. }
  282. let keyword = '';
  283. if (ctx.query.keyword) {
  284. keyword = ctx.query.keyword;
  285. }
  286. let company = '';
  287. if (ctx.query.company) {
  288. company = ctx.query.company;
  289. }
  290. // 获取数据规则
  291. const page = ctx.page;
  292. const pageSize = ctx.pageSize;
  293. const columns = ['id', 'account', 'name', 'company', 'company_id', 'role', 'mobile', 'auth_mobile', 'telephone', 'enable', 'is_admin', 'bind', 'account_group', 'permission', 'cooperation', 'notice_again', 'unit_sign_path'];
  294. // 过滤数据
  295. ctx.service.projectAccount.searchFilter(ctx.request.query, projectId, columns);
  296. ctx.sort = ['id', 'desc'];
  297. const total = await ctx.service.projectAccount.getCountWithBuilder();
  298. const accountData = await ctx.service.projectAccount.getListWithBuilder();
  299. // 获取账号个数
  300. const user_total = await ctx.service.projectAccount.count({project_id: projectId});
  301. // 分页相关
  302. const pageInfo = {
  303. page,
  304. pageSizeSelect: 1,
  305. pageSize,
  306. total_num: total,
  307. total: Math.ceil(total / pageSize),
  308. queryData: JSON.stringify(ctx.urlInfo.query),
  309. };
  310. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({where: {pid: projectId}});
  311. const noticeSet = projectData.notice_setting ? JSON.parse(projectData.notice_setting) : ctx.helper._.cloneDeep(projectSettingConst.noticeSetting);
  312. const renderData = {
  313. projectData,
  314. accountData,
  315. accountGroup,
  316. permission,
  317. keyword,
  318. permissionStr: JSON.stringify(permission),
  319. pageInfo,
  320. user_total,
  321. unitList,
  322. company,
  323. noticeAgainConst,
  324. noticeSet,
  325. fujianOssPath: ctx.app.config.fujianOssPath,
  326. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.user),
  327. // rule: JSON.stringify(frontRule),
  328. };
  329. await this.layout('setting/user_permission.ejs', renderData, 'setting/user_permission_modal.ejs');
  330. } catch (error) {
  331. console.log(error);
  332. ctx.redirect('/dashboard');
  333. }
  334. }
  335. /**
  336. * 项目权限 -- 参建单位(Get)
  337. * @param ctx
  338. * @return {Promise<void>}
  339. */
  340. async userUnit(ctx) {
  341. try {
  342. // 获取项目数据
  343. const projectId = ctx.session.sessionProject.id;
  344. const projectData = await ctx.service.project.getDataById(projectId);
  345. if (projectData === null) {
  346. throw '没有对应的项目数据';
  347. }
  348. if (ctx.session.sessionUser.is_admin === 0) {
  349. throw '没有访问权限';
  350. }
  351. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({where: {pid: projectId}});
  352. for (const u of unitList) {
  353. const accountList = await ctx.service.projectAccount.getAllDataByCondition({
  354. where: {
  355. project_id: projectId,
  356. company: u.name
  357. }
  358. });
  359. u.account_num = accountList.length;
  360. }
  361. // 获取账号个数
  362. const user_total = await ctx.service.projectAccount.count({project_id: projectId});
  363. const renderData = {
  364. projectData,
  365. accountGroup,
  366. unitList,
  367. user_total,
  368. company: null,
  369. fujianOssPath: ctx.app.config.fujianOssPath,
  370. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.user),
  371. };
  372. await this.layout('setting/user_unit.ejs', renderData, 'setting/user_unit_modal.ejs');
  373. } catch (error) {
  374. console.log(error);
  375. ctx.redirect('/dashboard');
  376. }
  377. }
  378. /**
  379. * 项目设置 -- 单位新增设置(Post)
  380. * @param ctx
  381. * @return {Promise<void>}
  382. */
  383. async userUnitAdd(ctx) {
  384. const projectData = ctx.session.sessionProject;
  385. try {
  386. // 验证数据
  387. if (projectData.id === undefined) {
  388. throw '不存在对应的项目数据';
  389. }
  390. // 获取验证规则
  391. const rule = ctx.service.constructionUnit.rule('add');
  392. ctx.validate(rule);
  393. ctx.request.body.pid = projectData.id;
  394. const result = await ctx.service.constructionUnit.save(ctx.request.body);
  395. if (!result) {
  396. throw '保存单位失败';
  397. }
  398. this.setMessage('保存单位成功', this.messageType.SUCCESS);
  399. ctx.redirect('/' + ctx.controllerName + '/user/unit');
  400. } catch (error) {
  401. console.log(error);
  402. this.setMessage(error.toString(), this.messageType.ERROR);
  403. ctx.redirect(ctx.request.header.referer);
  404. }
  405. }
  406. /**
  407. * 项目设置 -- 单位编辑(Post)
  408. * @param ctx
  409. * @return {Promise<void>}
  410. */
  411. async userUnitSave(ctx) {
  412. const projectData = ctx.session.sessionProject;
  413. const responseData = {
  414. err: 0, msg: '', data: {},
  415. };
  416. try {
  417. // 验证数据
  418. if (projectData.id === undefined) {
  419. throw '不存在对应的项目数据';
  420. }
  421. const data = JSON.parse(ctx.request.body.data);
  422. switch (data.type) {
  423. case 'update':
  424. const post_data = {
  425. pid: projectData.id,
  426. id: data.id,
  427. };
  428. post_data[data.val_name] = data.val;
  429. if (data.name) post_data.name = data.name;
  430. const result = await ctx.service.constructionUnit.save(post_data);
  431. if (!result) {
  432. throw '保存单位失败';
  433. }
  434. if (post_data.name) {
  435. const accountList = await ctx.service.projectAccount.getAllDataByCondition({
  436. where: {
  437. project_id: projectData.id,
  438. company: post_data.name
  439. }
  440. });
  441. responseData.data = {account_num: accountList.length};
  442. }
  443. break;
  444. case 'delete':
  445. const accountList = await ctx.service.projectAccount.getAllDataByCondition({
  446. where: {
  447. project_id: projectData.id,
  448. company: data.name
  449. }
  450. });
  451. if (accountList.length > 0) {
  452. throw '该单位下还存在账号,无法删除';
  453. }
  454. await ctx.service.constructionUnit.del(data.id);
  455. break;
  456. case 'del-sign':
  457. const info = await ctx.service.constructionUnit.getDataById(data.id);
  458. let path = null;
  459. if (info.sign_path) {
  460. // 不删除地址,只删除数据库数据,防止已签章的报表丢失
  461. // await ctx.app.fujianOss.delete(ctx.app.config.fujianOssFolder + info.sign_path);
  462. const paths = info.sign_path.split('&%&');
  463. const newPath = paths.filter(item => item !== data.path);
  464. path = newPath.length !== 0 ? newPath.join('&%&') : null;
  465. }
  466. await ctx.service.constructionUnit.update({ sign_path: path }, { id: info.id });
  467. // 用户已选章也要判断,存在也要移除
  468. const userList = await ctx.service.projectAccount.getAllDataByCondition({ where: { company: info.name, project_id: projectData.id } });
  469. if (userList.length > 0) {
  470. for (const user of userList) {
  471. if (user.unit_sign_path && user.unit_sign_path.includes(data.path)) {
  472. const newSignPath = user.unit_sign_path.split('&%&').filter(item => item !== data.path).join('&%&');
  473. await ctx.service.projectAccount.update({ unit_sign_path: newSignPath ? newSignPath : null }, { id: user.id });
  474. }
  475. }
  476. }
  477. responseData.data = path;
  478. break;
  479. case 'import-users':
  480. responseData.data = await ctx.service.projectAccount.addUsers(projectData.id, data.users);
  481. break;
  482. default:
  483. break;
  484. }
  485. ctx.body = responseData;
  486. } catch (err) {
  487. this.log(err);
  488. ctx.body = {err: 1, msg: err.toString(), data: null};
  489. }
  490. }
  491. async userUnitUpload(ctx) {
  492. const responseData = {
  493. err: 0, msg: '', data: null,
  494. };
  495. let stream;
  496. try {
  497. const parts = ctx.multipart({ autoFields: true });
  498. const paths = [];
  499. let index = 0;
  500. while ((stream = await parts()) !== undefined) {
  501. const create_time = Date.parse(new Date()) / 1000;
  502. const fileInfo = path.parse(stream.filename);
  503. const filepath = `app/public/upload/sign/unit/qianzhang_${create_time + index.toString() + fileInfo.ext}`;
  504. await ctx.app.fujianOss.put(ctx.app.config.fujianOssFolder + filepath, stream);
  505. await sendToWormhole(stream);
  506. paths.push(filepath);
  507. ++index;
  508. }
  509. const unit = await ctx.service.constructionUnit.getDataById(parts.field.id);
  510. const sign_path = unit.sign_path ? unit.sign_path.split('&%&') : [];
  511. sign_path.push(...paths);
  512. const result = await ctx.service.constructionUnit.update({ sign_path: sign_path.join('&%&') }, { id: unit.id });
  513. if (result) {
  514. responseData.data = { sign_path: sign_path.join('&%&') };
  515. } else {
  516. throw '添加数据库失败';
  517. }
  518. } catch (err) {
  519. this.log(err);
  520. responseData.err = 1;
  521. responseData.msg = err;
  522. }
  523. ctx.body = responseData;
  524. }
  525. /**
  526. * 项目设置 -- 账号启用和停用设置(Post)
  527. * @param ctx
  528. * @return {Promise<void>}
  529. */
  530. async userSwitch(ctx) {
  531. const responseData = {
  532. err: 0, msg: '', data: null,
  533. };
  534. try {
  535. // 获取项目数据
  536. const projectId = ctx.session.sessionProject.id;
  537. const projectData = await ctx.service.project.getDataById(projectId);
  538. if (projectData === null) {
  539. throw '没有对应的项目数据';
  540. }
  541. if (ctx.session.sessionUser.is_admin === 0) {
  542. throw '没有访问权限';
  543. }
  544. const data = JSON.parse(ctx.request.body.data);
  545. const result = await ctx.service.projectAccount.update(data, {id: data.id});
  546. if (!result) {
  547. throw '提交数据失败';
  548. }
  549. } catch (err) {
  550. this.log(err);
  551. responseData.err = 1;
  552. responseData.msg = err;
  553. }
  554. ctx.body = responseData;
  555. }
  556. /**
  557. * 项目设置 -- 账号添加(Post)
  558. * @param ctx
  559. * @return {Promise<void>}
  560. */
  561. async addUser(ctx) {
  562. const projectData = ctx.session.sessionProject;
  563. try {
  564. // 验证数据
  565. if (projectData.id === undefined) {
  566. throw '不存在对应的项目数据';
  567. }
  568. // 获取验证规则
  569. const rule = ctx.service.projectAccount.rule('add');
  570. ctx.validate(rule);
  571. // 判断新密码的强度
  572. const reg = /^(?![0-9]+$)(?![a-zA-Z]+$).{6,16}$/;
  573. if (!reg.test(ctx.request.body.password)) {
  574. throw '请设置至少包含数字和字母的密码';
  575. }
  576. ctx.request.body.project_id = projectData.id;
  577. const result = await ctx.service.projectAccount.save(ctx.request.body);
  578. if (!result) {
  579. throw '保存账号数据失败';
  580. }
  581. this.setMessage('保存账号数据成功', this.messageType.SUCCESS);
  582. ctx.redirect('/' + ctx.controllerName + '/user');
  583. } catch (error) {
  584. console.log(error);
  585. ctx.session.postError = error.toString();
  586. this.setMessage(error.toString(), this.messageType.ERROR);
  587. ctx.redirect(ctx.request.header.referer);
  588. }
  589. }
  590. /**
  591. * 项目设置 -- 账号编辑(Post)
  592. * @param ctx
  593. * @return {Promise<void>}
  594. */
  595. async updateUser(ctx) {
  596. const projectData = ctx.session.sessionProject;
  597. try {
  598. // 验证数据
  599. if (projectData.id === undefined) {
  600. throw '不存在对应的项目数据';
  601. }
  602. // 获取验证规则
  603. const rule = ctx.service.projectAccount.rule('modify');
  604. ctx.validate(rule);
  605. const result = await ctx.service.projectAccount.save(ctx.request.body);
  606. if (!result) {
  607. throw '保存账号数据失败';
  608. }
  609. this.setMessage('保存账号数据成功', this.messageType.SUCCESS);
  610. ctx.redirect(ctx.request.header.referer);
  611. } catch (error) {
  612. console.log(error);
  613. this.setMessage(error.toString(), this.messageType.ERROR);
  614. ctx.redirect(ctx.request.header.referer);
  615. }
  616. }
  617. async resetUserPassword(ctx) {
  618. try {
  619. // 获取项目数据
  620. const projectId = ctx.session.sessionProject.id;
  621. const projectData = await ctx.service.project.getDataById(projectId);
  622. if (projectData === null) {
  623. throw '没有对应的项目数据';
  624. }
  625. if (ctx.session.sessionUser.is_admin === 0) {
  626. throw '没有访问权限';
  627. }
  628. const accountId = parseInt(ctx.request.body.id);
  629. let password = ctx.request.body.reset_password;
  630. password = password.toString();
  631. const account = ctx.request.body.account !== undefined ? ctx.request.body.account : '';
  632. if (isNaN(accountId) || accountId <= 0 || password.length < 6) {
  633. throw '参数错误';
  634. }
  635. // 判断新密码的强度
  636. const reg = /^(?![0-9]+$)(?![a-zA-Z]+$).{6,16}$/;
  637. if (!reg.test(password)) {
  638. throw '请设置至少包含数字和字母的密码';
  639. }
  640. const result = await ctx.service.projectAccount.resetPassword(accountId, password, account);
  641. if (!result) {
  642. throw '重置密码失败!';
  643. }
  644. this.setMessage('保存账号数据成功', this.messageType.SUCCESS);
  645. ctx.redirect(ctx.request.header.referer);
  646. } catch (error) {
  647. console.log(error);
  648. this.setMessage(error.toString(), this.messageType.ERROR);
  649. ctx.redirect(ctx.request.header.referer);
  650. }
  651. }
  652. /**
  653. * 项目设置 -- 账号权限编辑(Post)
  654. * @param ctx
  655. * @return {Promise<void>}
  656. */
  657. async permission(ctx) {
  658. const projectData = ctx.session.sessionProject;
  659. try {
  660. // 验证数据
  661. if (projectData.id === undefined) {
  662. throw '不存在对应的项目数据';
  663. }
  664. const accountId = parseInt(ctx.request.body.id);
  665. const accountInfo = await ctx.service.projectAccount.getDataById(accountId);
  666. if (accountInfo === null) {
  667. throw '不存在该客户';
  668. }
  669. const result = await ctx.service.projectAccount.permissionSave(accountId, ctx.request.body);
  670. if (!result) {
  671. throw '修改权限失败!';
  672. }
  673. this.setMessage('保存账号数据成功', this.messageType.SUCCESS);
  674. ctx.redirect(ctx.request.header.referer);
  675. } catch (error) {
  676. console.log(error);
  677. this.setMessage(error.toString(), this.messageType.ERROR);
  678. ctx.redirect(ctx.request.header.referer);
  679. }
  680. }
  681. // todo 暂时保留,如果支付审批不需要,则取消
  682. /**
  683. * 项目设置 -- 自定义标段分类(Get)
  684. *
  685. * @param ctx
  686. * @return {Promise<void>}
  687. */
  688. async category(ctx) {
  689. try {
  690. // 获取项目数据
  691. const projectId = ctx.session.sessionProject.id;
  692. await this._checkMenu(projectId);
  693. const projectData = await ctx.service.project.getDataById(projectId);
  694. if (projectData === null) {
  695. throw '没有对应的项目数据';
  696. }
  697. if (ctx.session.sessionUser.is_admin === 0) {
  698. throw '没有访问权限';
  699. }
  700. const categoryData = await ctx.service.category.getAllCategory(projectId);
  701. const tenderData = await ctx.service.tender.getList('', null, 1);
  702. const renderData = {
  703. projectData,
  704. categoryType: settingConst.cType,
  705. categoryData,
  706. tenderData,
  707. };
  708. await this.layout('setting/category.ejs', renderData, 'setting/category_modal.ejs');
  709. } catch (error) {
  710. console.log(error);
  711. ctx.redirect('/dashboard');
  712. }
  713. }
  714. /**
  715. * 新增分类(Ajax)
  716. *
  717. * @param ctx
  718. * @return {Promise<void>}
  719. */
  720. async addCategory(ctx) {
  721. try {
  722. const projectId = ctx.session.sessionProject.id;
  723. const responseData = {
  724. err: 0, msg: '', data: null,
  725. };
  726. const data = JSON.parse(ctx.request.body.data);
  727. if (!data.name) {
  728. throw '提交数据错误';
  729. }
  730. responseData.data = await ctx.service.category.addCategory(projectId, data.name, settingConst.cType.key.dropDown);
  731. ctx.body = responseData;
  732. } catch (err) {
  733. this.log(err);
  734. ctx.body = {err: 1, msg: err.toString(), data: null};
  735. }
  736. }
  737. /**
  738. * 编辑分类(Ajax)
  739. *
  740. * @param ctx
  741. * @return {Promise<void>}
  742. */
  743. async updateCategory(ctx) {
  744. try {
  745. const projectId = ctx.session.sessionProject.id;
  746. const responseData = {err: 0, msg: '', data: null};
  747. const data = JSON.parse(ctx.request.body.data);
  748. if (!data.id) {
  749. throw '提交数据错误';
  750. }
  751. if (data.name) {
  752. const count = await ctx.service.category.count({pid: projectId, name: data.name});
  753. if (count >= 1) {
  754. throw '存在同名类别';
  755. }
  756. }
  757. const result = await ctx.service.category.update(data, {id: data.id});
  758. if (!result) {
  759. throw '提交数据失败';
  760. }
  761. responseData.data = await ctx.service.category.getCategory(data.id);
  762. ctx.body = responseData;
  763. } catch (err) {
  764. this.log(err);
  765. ctx.body = {err: 1, msg: err.toString(), data: null};
  766. }
  767. }
  768. async setCategoryValue(ctx) {
  769. try {
  770. const responseData = {err: 0, msg: '', data: {}};
  771. const data = JSON.parse(ctx.request.body.data);
  772. if (!data.id) {
  773. throw '提交数据错误';
  774. }
  775. await ctx.service.categoryValue.setCategoryValue(data.id, data.updateValue);
  776. responseData.data.category = await ctx.service.category.getCategory(data.id);
  777. responseData.data.tenders = await ctx.service.tender.getList('', null, 1);
  778. ctx.body = responseData;
  779. } catch (err) {
  780. this.log(err);
  781. ctx.body = {err: 1, msg: err instanceof String ? err : '提交数据失败', data: null};
  782. }
  783. }
  784. /**
  785. * 删除分类(Ajax)
  786. *
  787. * @param ctx
  788. * @return {Promise<void>}
  789. */
  790. async deleteCategory(ctx) {
  791. try {
  792. const projectId = ctx.session.sessionProject.id;
  793. const responseData = {
  794. err: 0, msg: '', data: null,
  795. };
  796. const data = JSON.parse(ctx.request.body.data);
  797. if (!data.id) {
  798. throw '提交数据错误';
  799. }
  800. await ctx.service.category.deleteCategory(projectId, data.id);
  801. ctx.body = responseData;
  802. } catch (err) {
  803. this.log(err);
  804. ctx.body = {err: 1, msg: err.toString(), data: null};
  805. }
  806. }
  807. /**
  808. * 调整分类层次排序(Ajax)
  809. *
  810. * @param ctx
  811. * @return {Promise<void>}
  812. */
  813. async resetCategoryLevel(ctx) {
  814. try {
  815. const projectId = ctx.session.sessionProject.id;
  816. const responseData = {
  817. err: 0, msg: '', data: null,
  818. };
  819. const data = JSON.parse(ctx.request.body.data);
  820. await ctx.service.category.resetCategoryLevel(data);
  821. responseData.data = await ctx.service.category.getAllCategory(projectId);
  822. ctx.body = responseData;
  823. } catch (err) {
  824. this.log(err);
  825. ctx.body = {err: 1, msg: err.toString(), data: null};
  826. }
  827. }
  828. async selfCategoryLevel(ctx) {
  829. try {
  830. const data = JSON.parse(ctx.request.body.data);
  831. await ctx.service.projectAccount.defaultUpdate({
  832. id: ctx.session.sessionUser.accountId,
  833. self_category_level: data.self_category_level || ''
  834. });
  835. ctx.body = {
  836. err: 0, msg: '', data: null,
  837. };
  838. } catch (err) {
  839. ctx.log(err);
  840. ctx.ajaxErrorBody(err, '保存自定义分类失败');
  841. }
  842. }
  843. /** update porject info
  844. * @author wangfeng
  845. * @date 2018-10-12 15:48:05
  846. * @param ctx
  847. * @return {Promise<void>}
  848. */
  849. async updateinfo(ctx) {
  850. try {
  851. const projectId = ctx.params.id;
  852. const responseData = {
  853. err: 0, msg: '', data: null,
  854. };
  855. const conditionData = {
  856. id: projectId,
  857. };
  858. const data = ctx.request.body;
  859. const result = await ctx.service.project.update(data, conditionData);
  860. if (!result) {
  861. throw '提交数据失败';
  862. }
  863. ctx.redirect('/setting/info');
  864. } catch (err) {
  865. this.log(err);
  866. ctx.body = {err: 1, msg: err.toString(), data: null};
  867. }
  868. }
  869. async updateProjectSet(ctx) {
  870. try {
  871. const projectId = ctx.session.sessionProject.id;
  872. const data = JSON.parse(ctx.request.body.data);
  873. const allowField = ['notice_setting']; // 暂时只一个
  874. if (!ctx.helper._.includes(allowField, data.field)) {
  875. throw '非配置的字段无法使用本方法';
  876. }
  877. const result = await ctx.service.project.updateProjectSet(projectId, data.field, data.pData);
  878. if (!result) {
  879. throw '提交数据失败';
  880. }
  881. ctx.body = { err: 0, msg: '', data: result };
  882. } catch (err) {
  883. this.log(err);
  884. ctx.body = { err: 1, msg: err.toString(), data: null };
  885. }
  886. }
  887. /**
  888. * 检测账户是否存在
  889. *
  890. * @param {Object} ctx -egg全局变量
  891. * @return {void}
  892. */
  893. async accountExist(ctx) {
  894. const projectData = ctx.session.sessionProject;
  895. const responseData = {
  896. err: 0, msg: '', data: null,
  897. };
  898. try {
  899. const data = JSON.parse(ctx.request.body.data);
  900. const account = data.account;
  901. if (projectData.id === undefined) {
  902. throw '不存在对应项目';
  903. }
  904. responseData.data = await ctx.service.projectAccount.isAccountExist(account, projectData.id);
  905. ctx.body = responseData;
  906. } catch (error) {
  907. ctx.body = {err: 1, msg: error.toString(), data: null};
  908. }
  909. }
  910. /**
  911. * 显示设置(Get)
  912. * @param {Object} ctx -egg全局变量
  913. * @return {void}
  914. */
  915. async show(ctx) {
  916. try {
  917. // 获取项目数据
  918. const projectId = ctx.session.sessionProject.id;
  919. await this._checkMenu(projectId);
  920. const projectData = await ctx.service.project.getDataById(projectId);
  921. if (!projectData) {
  922. throw '没有对应的项目数据';
  923. }
  924. if (ctx.session.sessionUser.is_admin === 0) {
  925. throw '没有访问权限';
  926. }
  927. const showList = await ctx.service.settingShow.getList(projectData.page_path);
  928. const sjsRela = await ctx.service.project.getSjsRela(projectId);
  929. const projectSpread = await ctx.service.projectSpread.getProjectSpreadType(projectId);
  930. const renderData = {projectData, showList, sjsRela, settingConst, projectSpread};
  931. await this.layout('setting/show.ejs', renderData);
  932. } catch (error) {
  933. this.log(error);
  934. ctx.redirect('/dashboard');
  935. }
  936. }
  937. /**
  938. * 更新显示设置列表
  939. * @param {Object} ctx -egg全局变量
  940. * @return {void}
  941. */
  942. async showListUpdate(ctx) {
  943. try {
  944. // 获取项目id
  945. const projectId = ctx.session.sessionProject.id;
  946. const {data} = ctx.request.body;
  947. const {id} = JSON.parse(data);
  948. const result = await ctx.service.settingShow.setDefaultLabel(id, projectId);
  949. const responseData = {err: 0, msg: '', data: result};
  950. ctx.body = responseData;
  951. } catch (error) {
  952. this.log(error);
  953. ctx.body = {err: 1, msg: error.toString(), data: null};
  954. }
  955. }
  956. async showSjsUpdate(ctx) {
  957. try {
  958. const projectId = ctx.session.sessionProject.id;
  959. const data = JSON.parse(ctx.request.body.data);
  960. const result = await ctx.service.project.updateSjsRela(projectId, data.sub, data.field, data.key, data.value);
  961. ctx.body = {err: 0, msg: '', data: result};
  962. } catch (err) {
  963. this.log(err);
  964. this.ajaxErrorBody(err, '保存数据失败');
  965. }
  966. }
  967. async s2b(ctx) {
  968. try {
  969. const projectId = ctx.session.sessionProject.id;
  970. await this._checkMenu(projectId);
  971. const projectData = await ctx.service.project.getDataById(projectId);
  972. if (projectData === null) throw '没有对应的项目数据';
  973. if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
  974. const limitList = await ctx.service.multiLimit.getLimits(ctx.session.sessionProject.id);
  975. const tenders = await ctx.service.tender.getAllDataByCondition({where: {project_id: projectId}});
  976. for (const t of tenders) {
  977. t.measure_type_str = t.measure_type === measureType.tz.value ? measureType.tz.title : measureType.gcl.title;
  978. const stages = await ctx.service.stage.getAllDataByCondition({where: {tid: t.id}});
  979. t.stage_count_str = `第${stages.length || 0}期`;
  980. const user = await ctx.service.projectAccount.getAccountInfoById(t.user_id);
  981. t.user_str = user.name + '-' + user.company;
  982. t.show_time = stages.length > 0 ? stages[stages.length - 1].cache_time_r || stages[stages.length - 1].in_time : t.create_time;
  983. }
  984. await this.layout('setting/s2b.ejs', {
  985. projectData,
  986. tenders,
  987. limitList,
  988. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.s2b),
  989. }, 'setting/s2b_modal.ejs');
  990. } catch (error) {
  991. ctx.helper.log(error);
  992. ctx.redirect('/dashboard');
  993. }
  994. }
  995. async s2bUpdate(ctx) {
  996. try {
  997. const projectId = ctx.session.sessionProject.id;
  998. const projectData = await ctx.service.project.getDataById(projectId);
  999. if (projectData === null) throw '没有对应的项目数据';
  1000. if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
  1001. const data = JSON.parse(ctx.request.body.data);
  1002. if (!data.tid) throw '提交数据错误';
  1003. const updateData = {};
  1004. if (data.gxby_limit !== undefined) updateData.s2b_gxby_limit = data.gxby_limit;
  1005. if (data.gxby_check !== undefined) updateData.s2b_gxby_check = data.gxby_check;
  1006. if (data.dagl_limit !== undefined) updateData.s2b_dagl_limit = data.dagl_limit;
  1007. if (data.dagl_check !== undefined) updateData.s2b_dagl_check = data.dagl_check;
  1008. if (data.multi_limit !== undefined) updateData.s2b_multi_limit = data.multi_limit;
  1009. if (data.multi_check !== undefined) updateData.s2b_multi_check = data.multi_check;
  1010. await ctx.service.tender.saveApiRela(data.tid, updateData);
  1011. ctx.body = {err: 0, msg: '', data: null};
  1012. } catch (error) {
  1013. ctx.helper.log(error);
  1014. this.ajaxErrorBody(error, '保存数据失败');
  1015. }
  1016. }
  1017. async s2bUpdateStatus(ctx) {
  1018. try {
  1019. const projectId = ctx.session.sessionProject.id;
  1020. const projectData = await ctx.service.project.getDataById(projectId);
  1021. if (projectData === null) throw '没有对应的项目数据';
  1022. if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
  1023. const data = JSON.parse(ctx.request.body.data);
  1024. if (!data.type || data.status === undefined) throw '提交数据错误';
  1025. const responseData = {err: 0, msg: '', data: null};
  1026. switch (data.type) {
  1027. case 'gxby':
  1028. responseData.data = await this.ctx.service.s2bProj.updateGxbyStatus(projectId, data.status, data.limit, data.ratio);
  1029. break;
  1030. case 'dagl':
  1031. responseData.data = await this.ctx.service.s2bProj.updateDaglStatus(projectId, data.status, data.limit, data.ratio);
  1032. break;
  1033. default:
  1034. throw '提交数据错误';
  1035. }
  1036. ctx.body = responseData;
  1037. } catch (error) {
  1038. console.log(error);
  1039. ctx.helper.log(error);
  1040. this.ajaxErrorBody(error, '保存数据失败');
  1041. }
  1042. }
  1043. async saveLimit(ctx) {
  1044. try {
  1045. const data = JSON.parse(ctx.request.body.data);
  1046. const result = await ctx.service.multiLimit.saveLimit(data);
  1047. ctx.body = { err: 0, msg: '', data: result };
  1048. } catch (err) {
  1049. ctx.log(err);
  1050. ctx.ajaxErrorBody(err, '修改数据失败');
  1051. }
  1052. }
  1053. async saveLimitOption(ctx) {
  1054. try {
  1055. const data = JSON.parse(ctx.request.body.data);
  1056. const result = await ctx.service.multiLimit.saveLimitOption(data);
  1057. ctx.body = { err: 0, msg: '', data: result };
  1058. } catch (err) {
  1059. ctx.log(err);
  1060. ctx.ajaxErrorBody(err, '修改数据失败');
  1061. }
  1062. }
  1063. async tender(ctx) {
  1064. try {
  1065. const projectId = ctx.session.sessionProject.id;
  1066. await this._checkMenu(projectId);
  1067. const projectData = await ctx.service.project.getDataById(projectId);
  1068. if (projectData === null) throw '没有对应的项目数据';
  1069. if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
  1070. const limits = await this.ctx.service.multiLimit.getLimitList(this.ctx.session.sessionProject.id);
  1071. const renderData = {
  1072. projectData,
  1073. tender: ctx.tender.data,
  1074. limits,
  1075. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.tender),
  1076. };
  1077. await this.layout('setting/tender.ejs', renderData);
  1078. } catch (err) {
  1079. ctx.log(err);
  1080. }
  1081. }
  1082. async tenderLoad(ctx) {
  1083. try {
  1084. const data = JSON.parse(ctx.request.body.data);
  1085. if (!data.filter) throw '请求参数错误';
  1086. const filter = data.filter.split(';');
  1087. const result = {};
  1088. for (const f of filter) {
  1089. switch (f) {
  1090. case 'xmj':
  1091. result[f] = await this.ctx.service.ledger.getAllDataByCondition({
  1092. columns: ['id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf', 'code', 'name', 'unit'],
  1093. where: { tender_id: ctx.tender.id },
  1094. });
  1095. break;
  1096. case 'limit':
  1097. result[f] = await this.ctx.service.ledgerExtra.getAllDataByCondition({
  1098. columns: ['id', 'multi_limit'],
  1099. where: { tid: ctx.tender.id },
  1100. });
  1101. break;
  1102. default:
  1103. throw '未知数据类型';
  1104. }
  1105. }
  1106. ctx.body = { err: 0, msg: '', data: result };
  1107. } catch (err) {
  1108. ctx.log(err);
  1109. ctx.ajaxErrorBody(err, '加载数据错误');
  1110. }
  1111. }
  1112. async tenderUpdate(ctx) {
  1113. try {
  1114. const data = JSON.parse(ctx.request.body.data);
  1115. await this.ctx.service.ledgerExtra.updateMultiLimit(data.id, data.multi_limit);
  1116. ctx.body = {err: 0, msg: '', data };
  1117. } catch (err) {
  1118. ctx.log(err);
  1119. ctx.ajaxErrorBody(err, '保存数据错误');
  1120. }
  1121. }
  1122. async spread(ctx) {
  1123. try {
  1124. // 获取项目数据
  1125. const projectId = ctx.session.sessionProject.id;
  1126. await this._checkMenu(projectId);
  1127. const projectData = await ctx.service.project.getDataById(projectId);
  1128. if (!projectData) throw '没有对应的项目数据';
  1129. const sType = ctx.query.stype;
  1130. const code = ctx.query.code;
  1131. const projectSpread = await this.ctx.service.projectSpread.getProjectSpread(projectData.id, code);
  1132. const renderData = {
  1133. BaseSetCol: SpreadConst.BaseSetCol[sType],
  1134. sType,
  1135. code,
  1136. colSet: projectSpread[sType],
  1137. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.spread),
  1138. };
  1139. await this.layout('setting/spread.ejs', renderData, 'setting/spread_modal.ejs');
  1140. } catch (error) {
  1141. this.log(error);
  1142. ctx.redirect('/dashboard');
  1143. }
  1144. }
  1145. async saveSpread(ctx) {
  1146. try {
  1147. const projectId = ctx.session.sessionProject.id;
  1148. const data = JSON.parse(ctx.request.body.data);
  1149. await this.ctx.service.projectSpread.updateProjectSet(projectId, data.code, data.sType, data.colSet);
  1150. const projectSpread = await this.ctx.service.projectSpread.getProjectSpread(projectId, data.code);
  1151. ctx.body = { err: 0, msg: '', data: { colSet: projectSpread[data.sType] } };
  1152. } catch (error) {
  1153. ctx.log(error);
  1154. ctx.ajaxErrorBody(error, '保存列设置失败,请刷新后重试');
  1155. }
  1156. }
  1157. async previewSpread(ctx) {
  1158. try {
  1159. const data = JSON.parse(ctx.request.body.data);
  1160. const [billsSpread, posSpread] = this.ctx.service.projectSpread.generateRelaSpread(data.sType, data.colSet);
  1161. if (billsSpread.frozenField) billsSpread.frozenColCount = billsSpread.cols.findIndex(x => {return x.field === billsSpread.frozenField; }) + 1;
  1162. if (posSpread.frozenField) posSpread.frozenColCount = posSpread.cols.findIndex(x => {return x.field === posSpread.frozenField; }) + 1;
  1163. ctx.body = { err: 0, msg: '', data: { billsSpread, posSpread } };
  1164. } catch (error) {
  1165. ctx.log(error);
  1166. ctx.ajaxErrorBody(error, '保存列设置失败,请刷新后重试');
  1167. }
  1168. }
  1169. async resetSpread(ctx) {
  1170. try {
  1171. const projectId = ctx.session.sessionProject.id;
  1172. const data = JSON.parse(ctx.request.body.data);
  1173. const spreadTemplate = SpreadConst.ProjectSpreadTemplate.find(x => { return x.code === data.code; });
  1174. const colSet = spreadTemplate.template[data.sType];
  1175. await this.ctx.service.projectSpread.updateProjectSet(projectId, data.code, data.sType, colSet);
  1176. const projectSpread = await this.ctx.service.projectSpread.getProjectSpread(projectId, data.code);
  1177. ctx.body = { err: 0, msg: '', data: { colSet: projectSpread[data.sType] } };
  1178. } catch (error) {
  1179. ctx.log(error);
  1180. ctx.ajaxErrorBody(error, '保存列设置失败,请刷新后重试');
  1181. }
  1182. }
  1183. }
  1184. return SettingController;
  1185. };