123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date
- * @version
- */
- const tenderConst = require('../const/tender');
- const auditConst = require('../const/audit');
- const officeList = require('../const/cld_office').list;
- const settingConst = require('../const/setting.js');
- const scheduleConst = require('../const/schedule');
- const settingMenu = require('../../config/menu').settingMenu;
- const accountGroup = require('../const/account_group').group;
- const permission = require('../const/account_permission').permission;
- const noticeAgainConst = require('../const/account_permission').noticeAgain;
- const projectLog = require('../const/project_log');
- const imType = require('../const/tender').imType;
- const S2b = require('../lib/s2b');
- const measureType = require('../const/tender').measureType;
- const sendToWormhole = require('stream-wormhole');
- const path = require('path');
- const funSet = require('../const/fun_set');
- const projectSettingConst = require('../const/project_setting');
- const SpreadConst = require('../const/spread');
- module.exports = app => {
- class SettingController extends app.BaseController {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局context
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- ctx.subMenu = settingMenu;
- }
- async _checkMenu(pid) {
- const ctx = this.ctx;
- await this.ctx.service.s2bProj.refreshSessionS2b(pid);
- ctx.subMenu.s2b.display = !!ctx.session.sessionProject.gxby || !!ctx.session.sessionProject.dagl;
- ctx.subMenu.datacollect.display = ctx.session.sessionProject.page_show.openDataCollect;
- // this.ctx.subMenu.s2b.display = false;
- }
- /**
- * 项目信息页面(Get)
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- async info(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- // 获取销售人员数据
- const salesmanData = await ctx.service.manager.getDataById(projectData.manager_id);
- // 数据规则
- const rule = ctx.service.project.rule('saveInfo');
- const jsValidator = await this.jsValidator.convert(rule).build();
- const officeName = officeList[salesmanData.office];
- const date = new Date(projectData.create_time * 1000);// 如果date为10位不需要乘1000
- const Y = date.getFullYear() + '-';
- const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
- const D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
- const h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
- const m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
- const s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
- const dateStr = Y + M + D + h + m + s;
- const renderData = {
- projectData,
- salesmanData,
- officeName,
- officeList,
- jsValidator,
- dateStr,
- };
- await this.layout('setting/info.ejs', renderData);
- } catch (error) {
- console.log(error);
- ctx.redirect('/dashboard');
- }
- }
- /**
- * 项目设置 -- 账号设置(Get)
- * @param ctx
- * @return {Promise<void>}
- */
- async user(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- let keyword = '';
- if (ctx.query.keyword) {
- keyword = ctx.query.keyword;
- }
- let company = '';
- if (ctx.query.company) {
- company = ctx.query.company;
- }
- const page = ctx.page;
- const pageSize = ctx.pageSize;
- // 过滤数据
- ctx.service.projectAccount.searchFilter(ctx.request.query, projectId);
- ctx.sort = ['id', 'desc'];
- const total = await ctx.service.projectAccount.getCountWithBuilder();
- // 获取数据规则
- // const rule = ctx.service.projectAccount.rule('updateUser');
- // const frontRule = ctx.helper.validateConvert(rule);
- // const total = await ctx.service.projectAccount.count({ project_id: projectId });
- // 获取项目用户列表
- // const accountData = await ctx.service.projectAccount.getAllDataByCondition({
- // where: { project_id: projectId },
- // columns: ['id', 'account', 'name', 'company', 'role', 'mobile', 'auth_mobile', 'telephone', 'enable', 'is_admin', 'account_group'],
- // limit: (app.config.pageSize * (page - 1)),
- // offset: app.config.pageSize,
- // });
- // const columns = ['id', 'account', 'name', 'company', 'role', 'mobile', 'auth_mobile', 'telephone', 'enable', 'is_admin', 'account_group', 'bind'];
- // const accountData = await ctx.service.projectAccount.getListByProjectId(columns, projectId);
- const accountData = await ctx.service.projectAccount.getListWithBuilder();
- // 获取账号个数
- const user_total = await ctx.service.projectAccount.count({project_id: projectId});
- // 分页相关
- const pageInfo = {
- page,
- pageSizeSelect: 1,
- pageSize,
- total_num: total,
- total: Math.ceil(total / pageSize),
- queryData: JSON.stringify(ctx.urlInfo.query),
- };
- const unitList = await ctx.service.constructionUnit.getAllDataByCondition({where: {pid: projectId}});
- const renderData = {
- projectData,
- accountData,
- accountGroup,
- permission,
- pageInfo,
- keyword,
- user_total,
- unitList,
- company,
- // rule: JSON.stringify(frontRule),
- };
- await this.layout('setting/user.ejs', renderData, 'setting/user_modal.ejs');
- } catch (error) {
- console.log(error);
- ctx.redirect('/dashboard');
- }
- }
- /**
- * 项目设置 -- 账号解绑设置(Post)
- * @param ctx
- * @return {Promise<void>}
- */
- async userUnbind(ctx) {
- const projectData = ctx.session.sessionProject;
- try {
- if (projectData.id === undefined) {
- throw '不存在对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '非管理员无权解绑账号';
- }
- const accountId = parseInt(ctx.request.body.id);
- const result = await ctx.service.projectAccount.update({bind: 0}, {id: accountId});
- if (!result) {
- throw '解绑失败';
- }
- this.setMessage('解绑成功', this.messageType.SUCCESS);
- } catch (error) {
- console.log(error);
- this.setMessage(error.toString(), this.messageType.ERROR);
- }
- ctx.redirect(ctx.request.header.referer);
- }
- /**
- * 项目权限 -- 账号设置(Get)
- * @param ctx
- * @return {Promise<void>}
- */
- async userPermissionSet(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- let keyword = '';
- if (ctx.query.keyword) {
- keyword = ctx.query.keyword;
- }
- let company = '';
- if (ctx.query.company) {
- company = ctx.query.company;
- }
- // 获取数据规则
- const page = ctx.page;
- const pageSize = ctx.pageSize;
- const columns = ['id', 'account', 'name', 'company', 'role', 'mobile', 'auth_mobile', 'telephone', 'enable', 'is_admin', 'bind', 'account_group', 'permission', 'cooperation', 'notice_again'];
- // 过滤数据
- ctx.service.projectAccount.searchFilter(ctx.request.query, projectId, columns);
- ctx.sort = ['id', 'desc'];
- const total = await ctx.service.projectAccount.getCountWithBuilder();
- const accountData = await ctx.service.projectAccount.getListWithBuilder();
- // 获取账号个数
- const user_total = await ctx.service.projectAccount.count({project_id: projectId});
- // 分页相关
- const pageInfo = {
- page,
- pageSizeSelect: 1,
- pageSize,
- total_num: total,
- total: Math.ceil(total / pageSize),
- queryData: JSON.stringify(ctx.urlInfo.query),
- };
- const unitList = await ctx.service.constructionUnit.getAllDataByCondition({where: {pid: projectId}});
- const noticeSet = projectData.notice_setting ? JSON.parse(projectData.notice_setting) : ctx.helper._.cloneDeep(projectSettingConst.noticeSetting);
- const renderData = {
- projectData,
- accountData,
- accountGroup,
- permission,
- keyword,
- permissionStr: JSON.stringify(permission),
- pageInfo,
- user_total,
- unitList,
- company,
- noticeAgainConst,
- noticeSet,
- // rule: JSON.stringify(frontRule),
- };
- await this.layout('setting/user_permission.ejs', renderData, 'setting/user_permission_modal.ejs');
- } catch (error) {
- console.log(error);
- ctx.redirect('/dashboard');
- }
- }
- /**
- * 项目权限 -- 参建单位(Get)
- * @param ctx
- * @return {Promise<void>}
- */
- async userUnit(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const unitList = await ctx.service.constructionUnit.getAllDataByCondition({where: {pid: projectId}});
- for (const u of unitList) {
- const accountList = await ctx.service.projectAccount.getAllDataByCondition({
- where: {
- project_id: projectId,
- company: u.name
- }
- });
- u.account_num = accountList.length;
- }
- // 获取账号个数
- const user_total = await ctx.service.projectAccount.count({project_id: projectId});
- const renderData = {
- projectData,
- accountGroup,
- unitList,
- user_total,
- fujianOssPath: ctx.app.config.fujianOssPath,
- };
- await this.layout('setting/user_unit.ejs', renderData, 'setting/user_unit_modal.ejs');
- } catch (error) {
- console.log(error);
- ctx.redirect('/dashboard');
- }
- }
- /**
- * 项目设置 -- 单位新增设置(Post)
- * @param ctx
- * @return {Promise<void>}
- */
- async userUnitAdd(ctx) {
- const projectData = ctx.session.sessionProject;
- try {
- // 验证数据
- if (projectData.id === undefined) {
- throw '不存在对应的项目数据';
- }
- // 获取验证规则
- const rule = ctx.service.constructionUnit.rule('add');
- ctx.validate(rule);
- ctx.request.body.pid = projectData.id;
- const result = await ctx.service.constructionUnit.save(ctx.request.body);
- if (!result) {
- throw '保存单位失败';
- }
- this.setMessage('保存单位成功', this.messageType.SUCCESS);
- ctx.redirect('/' + ctx.controllerName + '/user/unit');
- } catch (error) {
- console.log(error);
- this.setMessage(error.toString(), this.messageType.ERROR);
- ctx.redirect(ctx.request.header.referer);
- }
- }
- /**
- * 项目设置 -- 单位编辑(Post)
- * @param ctx
- * @return {Promise<void>}
- */
- async userUnitSave(ctx) {
- const projectData = ctx.session.sessionProject;
- const responseData = {
- err: 0, msg: '', data: null,
- };
- try {
- // 验证数据
- if (projectData.id === undefined) {
- throw '不存在对应的项目数据';
- }
- const data = JSON.parse(ctx.request.body.data);
- switch (data.type) {
- case 'update':
- const post_data = {
- pid: projectData.id,
- id: data.id,
- };
- post_data[data.val_name] = data.val;
- if (data.name) post_data.name = data.name;
- const result = await ctx.service.constructionUnit.save(post_data);
- if (!result) {
- throw '保存单位失败';
- }
- if (post_data.name) {
- const accountList = await ctx.service.projectAccount.getAllDataByCondition({
- where: {
- project_id: projectData.id,
- company: post_data.name
- }
- });
- responseData.data = {account_num: accountList.length};
- }
- break;
- case 'delete':
- const accountList = await ctx.service.projectAccount.getAllDataByCondition({
- where: {
- project_id: projectData.id,
- company: data.name
- }
- });
- if (accountList.length > 0) {
- throw '该单位下还存在账号,无法删除';
- }
- await ctx.service.constructionUnit.del(data.id);
- break;
- case 'del-sign':
- const info = await ctx.service.constructionUnit.getDataById(data.id);
- if (info.sign_path) {
- // 不删除地址,只删除数据库数据,防止已签章的报表丢失
- // await ctx.app.fujianOss.delete(ctx.app.config.fujianOssFolder + info.sign_path);
- }
- await ctx.service.constructionUnit.update({sign_path: null}, {id: info.id});
- break;
- default:
- break;
- }
- ctx.body = responseData;
- } catch (err) {
- this.log(err);
- ctx.body = {err: 1, msg: err.toString(), data: null};
- }
- }
- async userUnitUpload(ctx) {
- const responseData = {
- err: 0, msg: '', data: null,
- };
- try {
- const stream = await ctx.getFileStream();
- const create_time = Date.parse(new Date()) / 1000;
- const fileInfo = path.parse(stream.filename);
- const filepath = `app/public/upload/sign/unit/qianzhang_${create_time + fileInfo.ext}`;
- await ctx.app.fujianOss.put(ctx.app.config.fujianOssFolder + filepath, stream);
- await sendToWormhole(stream);
- const result = await ctx.service.constructionUnit.update({sign_path: filepath}, {id: stream.fields.id});
- if (result) {
- responseData.data = {sign_path: filepath};
- } else {
- throw '添加数据库失败';
- }
- } catch (err) {
- this.log(err);
- responseData.err = 1;
- responseData.msg = err;
- }
- ctx.body = responseData;
- }
- /**
- * 项目设置 -- 账号启用和停用设置(Post)
- * @param ctx
- * @return {Promise<void>}
- */
- async userSwitch(ctx) {
- const responseData = {
- err: 0, msg: '', data: null,
- };
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const data = JSON.parse(ctx.request.body.data);
- const result = await ctx.service.projectAccount.update(data, {id: data.id});
- if (!result) {
- throw '提交数据失败';
- }
- } catch (err) {
- this.log(err);
- responseData.err = 1;
- responseData.msg = err;
- }
- ctx.body = responseData;
- }
- /**
- * 项目设置 -- 账号添加(Post)
- * @param ctx
- * @return {Promise<void>}
- */
- async addUser(ctx) {
- const projectData = ctx.session.sessionProject;
- try {
- // 验证数据
- if (projectData.id === undefined) {
- throw '不存在对应的项目数据';
- }
- // 获取验证规则
- const rule = ctx.service.projectAccount.rule('add');
- ctx.validate(rule);
- // 判断新密码的强度
- const reg = /^(?![0-9]+$)(?![a-zA-Z]+$).{6,16}$/;
- if (!reg.test(ctx.request.body.password)) {
- throw '请设置至少包含数字和字母的密码';
- }
- ctx.request.body.project_id = projectData.id;
- const result = await ctx.service.projectAccount.save(ctx.request.body);
- if (!result) {
- throw '保存账号数据失败';
- }
- this.setMessage('保存账号数据成功', this.messageType.SUCCESS);
- ctx.redirect('/' + ctx.controllerName + '/user');
- } catch (error) {
- console.log(error);
- ctx.session.postError = error.toString();
- this.setMessage(error.toString(), this.messageType.ERROR);
- ctx.redirect(ctx.request.header.referer);
- }
- }
- /**
- * 项目设置 -- 账号编辑(Post)
- * @param ctx
- * @return {Promise<void>}
- */
- async updateUser(ctx) {
- const projectData = ctx.session.sessionProject;
- try {
- // 验证数据
- if (projectData.id === undefined) {
- throw '不存在对应的项目数据';
- }
- // 获取验证规则
- const rule = ctx.service.projectAccount.rule('modify');
- ctx.validate(rule);
- const result = await ctx.service.projectAccount.save(ctx.request.body);
- if (!result) {
- throw '保存账号数据失败';
- }
- this.setMessage('保存账号数据成功', this.messageType.SUCCESS);
- ctx.redirect(ctx.request.header.referer);
- } catch (error) {
- console.log(error);
- this.setMessage(error.toString(), this.messageType.ERROR);
- ctx.redirect(ctx.request.header.referer);
- }
- }
- async resetUserPassword(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const accountId = parseInt(ctx.request.body.id);
- let password = ctx.request.body.reset_password;
- password = password.toString();
- const account = ctx.request.body.account !== undefined ? ctx.request.body.account : '';
- if (isNaN(accountId) || accountId <= 0 || password.length < 6) {
- throw '参数错误';
- }
- // 判断新密码的强度
- const reg = /^(?![0-9]+$)(?![a-zA-Z]+$).{6,16}$/;
- if (!reg.test(password)) {
- throw '请设置至少包含数字和字母的密码';
- }
- const result = await ctx.service.projectAccount.resetPassword(accountId, password, account);
- if (!result) {
- throw '重置密码失败!';
- }
- this.setMessage('保存账号数据成功', this.messageType.SUCCESS);
- ctx.redirect(ctx.request.header.referer);
- } catch (error) {
- console.log(error);
- this.setMessage(error.toString(), this.messageType.ERROR);
- ctx.redirect(ctx.request.header.referer);
- }
- }
- /**
- * 项目设置 -- 账号权限编辑(Post)
- * @param ctx
- * @return {Promise<void>}
- */
- async permission(ctx) {
- const projectData = ctx.session.sessionProject;
- try {
- // 验证数据
- if (projectData.id === undefined) {
- throw '不存在对应的项目数据';
- }
- const accountId = parseInt(ctx.request.body.id);
- const accountInfo = await ctx.service.projectAccount.getDataById(accountId);
- if (accountInfo === null) {
- throw '不存在该客户';
- }
- const result = await ctx.service.projectAccount.permissionSave(accountId, ctx.request.body);
- if (!result) {
- throw '修改权限失败!';
- }
- this.setMessage('保存账号数据成功', this.messageType.SUCCESS);
- ctx.redirect(ctx.request.header.referer);
- } catch (error) {
- console.log(error);
- this.setMessage(error.toString(), this.messageType.ERROR);
- ctx.redirect(ctx.request.header.referer);
- }
- }
- /**
- * 项目设置 -- 自定义标段分类(Get)
- *
- * @param ctx
- * @return {Promise<void>}
- */
- async category(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const categoryData = await ctx.service.category.getAllCategory(projectId);
- const tenderData = await ctx.service.tender.getList('', null, 1);
- const renderData = {
- projectData,
- categoryType: settingConst.cType,
- categoryData,
- tenderData,
- };
- await this.layout('setting/category.ejs', renderData, 'setting/category_modal.ejs');
- } catch (error) {
- console.log(error);
- ctx.redirect('/dashboard');
- }
- }
- /**
- * 新增分类(Ajax)
- *
- * @param ctx
- * @return {Promise<void>}
- */
- async addCategory(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const responseData = {
- err: 0, msg: '', data: null,
- };
- const data = JSON.parse(ctx.request.body.data);
- if (!data.name) {
- throw '提交数据错误';
- }
- responseData.data = await ctx.service.category.addCategory(projectId, data.name, settingConst.cType.key.dropDown);
- ctx.body = responseData;
- } catch (err) {
- this.log(err);
- ctx.body = {err: 1, msg: err.toString(), data: null};
- }
- }
- /**
- * 编辑分类(Ajax)
- *
- * @param ctx
- * @return {Promise<void>}
- */
- async updateCategory(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const responseData = {err: 0, msg: '', data: null};
- const data = JSON.parse(ctx.request.body.data);
- if (!data.id) {
- throw '提交数据错误';
- }
- if (data.name) {
- const count = await ctx.service.category.count({pid: projectId, name: data.name});
- if (count >= 1) {
- throw '存在同名类别';
- }
- }
- const result = await ctx.service.category.update(data, {id: data.id});
- if (!result) {
- throw '提交数据失败';
- }
- responseData.data = await ctx.service.category.getCategory(data.id);
- ctx.body = responseData;
- } catch (err) {
- this.log(err);
- ctx.body = {err: 1, msg: err.toString(), data: null};
- }
- }
- async setCategoryValue(ctx) {
- try {
- const responseData = {err: 0, msg: '', data: {}};
- const data = JSON.parse(ctx.request.body.data);
- if (!data.id) {
- throw '提交数据错误';
- }
- await ctx.service.categoryValue.setCategoryValue(data.id, data.updateValue);
- responseData.data.category = await ctx.service.category.getCategory(data.id);
- responseData.data.tenders = await ctx.service.tender.getList('', null, 1);
- ctx.body = responseData;
- } catch (err) {
- this.log(err);
- ctx.body = {err: 1, msg: err instanceof String ? err : '提交数据失败', data: null};
- }
- }
- /**
- * 删除分类(Ajax)
- *
- * @param ctx
- * @return {Promise<void>}
- */
- async deleteCategory(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const responseData = {
- err: 0, msg: '', data: null,
- };
- const data = JSON.parse(ctx.request.body.data);
- if (!data.id) {
- throw '提交数据错误';
- }
- await ctx.service.category.deleteCategory(projectId, data.id);
- ctx.body = responseData;
- } catch (err) {
- this.log(err);
- ctx.body = {err: 1, msg: err.toString(), data: null};
- }
- }
- /**
- * 调整分类层次排序(Ajax)
- *
- * @param ctx
- * @return {Promise<void>}
- */
- async resetCategoryLevel(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const responseData = {
- err: 0, msg: '', data: null,
- };
- const data = JSON.parse(ctx.request.body.data);
- await ctx.service.category.resetCategoryLevel(data);
- responseData.data = await ctx.service.category.getAllCategory(projectId);
- ctx.body = responseData;
- } catch (err) {
- this.log(err);
- ctx.body = {err: 1, msg: err.toString(), data: null};
- }
- }
- async selfCategoryLevel(ctx) {
- try {
- const data = JSON.parse(ctx.request.body.data);
- await ctx.service.projectAccount.defaultUpdate({
- id: ctx.session.sessionUser.accountId,
- self_category_level: data.self_category_level || ''
- });
- ctx.body = {
- err: 0, msg: '', data: null,
- };
- } catch (err) {
- ctx.log(err);
- ctx.ajaxErrorBody(err, '保存自定义分类失败');
- }
- }
- /** update porject info
- * @author wangfeng
- * @date 2018-10-12 15:48:05
- * @param ctx
- * @return {Promise<void>}
- */
- async updateinfo(ctx) {
- try {
- const projectId = ctx.params.id;
- const responseData = {
- err: 0, msg: '', data: null,
- };
- const conditionData = {
- id: projectId,
- };
- const data = ctx.request.body;
- const result = await ctx.service.project.update(data, conditionData);
- if (!result) {
- throw '提交数据失败';
- }
- ctx.redirect('/setting/info');
- } catch (err) {
- this.log(err);
- ctx.body = {err: 1, msg: err.toString(), data: null};
- }
- }
- async updateProjectSet(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const data = JSON.parse(ctx.request.body.data);
- const allowField = ['notice_setting']; // 暂时只一个
- if (!ctx.helper._.includes(allowField, data.field)) {
- throw '非配置的字段无法使用本方法';
- }
- const result = await ctx.service.project.updateProjectSet(projectId, data.field, data.pData);
- if (!result) {
- throw '提交数据失败';
- }
- ctx.body = { err: 0, msg: '', data: result };
- } catch (err) {
- this.log(err);
- ctx.body = { err: 1, msg: err.toString(), data: null };
- }
- }
- /**
- * 检测账户是否存在
- *
- * @param {Object} ctx -egg全局变量
- * @return {void}
- */
- async accountExist(ctx) {
- const projectData = ctx.session.sessionProject;
- const responseData = {
- err: 0, msg: '', data: null,
- };
- try {
- const data = JSON.parse(ctx.request.body.data);
- const account = data.account;
- if (projectData.id === undefined) {
- throw '不存在对应项目';
- }
- responseData.data = await ctx.service.projectAccount.isAccountExist(account, projectData.id);
- ctx.body = responseData;
- } catch (error) {
- ctx.body = {err: 1, msg: error.toString(), data: null};
- }
- }
- /**
- * 显示设置(Get)
- * @param {Object} ctx -egg全局变量
- * @return {void}
- */
- async show(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (!projectData) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const showList = await ctx.service.settingShow.getList(projectData.page_path);
- const sjsRela = await ctx.service.project.getSjsRela(projectId);
- const renderData = {projectData, showList, sjsRela, settingConst};
- await this.layout('setting/show.ejs', renderData);
- } catch (error) {
- this.log(error);
- ctx.redirect('/dashboard');
- }
- }
- /**
- * 更新显示设置列表
- * @param {Object} ctx -egg全局变量
- * @return {void}
- */
- async showListUpdate(ctx) {
- try {
- // 获取项目id
- const projectId = ctx.session.sessionProject.id;
- const {data} = ctx.request.body;
- const {id} = JSON.parse(data);
- const result = await ctx.service.settingShow.setDefaultLabel(id, projectId);
- const responseData = {err: 0, msg: '', data: result};
- ctx.body = responseData;
- } catch (error) {
- this.log(error);
- ctx.body = {err: 1, msg: error.toString(), data: null};
- }
- }
- async showSjsUpdate(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const data = JSON.parse(ctx.request.body.data);
- const result = await ctx.service.project.updateSjsRela(projectId, data.sub, data.field, data.key, data.value);
- ctx.body = {err: 0, msg: '', data: result};
- } catch (err) {
- this.log(err);
- this.ajaxErrorBody(err, '保存数据失败');
- }
- }
- async logs(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const settingType = ctx.params.type ? parseInt(ctx.params.type) : 0;
- const logs = await ctx.service.projectLog.getLogs(projectId, settingType);
- const renderData = {
- projectData,
- officeList,
- projectLog,
- settingType,
- logs,
- };
- await this.layout('setting/logs.ejs', renderData);
- } catch (error) {
- console.log(error);
- ctx.redirect('/dashboard');
- }
- }
- async fun(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- const funRela = await ctx.service.project.getFunRela(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const fun_set = await ctx.service.project.getFunSet(projectData.fun_set);
- console.log(fun_set);
- await this.layout('setting/fun.ejs', {
- projectData,
- funRela,
- imType,
- endMonth: funSet.endMonth,
- funSet: fun_set,
- }, 'setting/fun_modal.ejs');
- } catch (error) {
- ctx.helper.log(error);
- ctx.redirect('/dashboard');
- }
- }
- /**
- * 保存功能设置相关
- * @param ctx
- * @returns {Promise<void>}
- */
- async updateFun(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) {
- throw '没有对应的项目数据';
- }
- if (ctx.session.sessionUser.is_admin === 0) {
- throw '没有访问权限';
- }
- const data = JSON.parse(ctx.request.body.data);
- if (data) ctx.request.body = data;
- const rule = ctx.service.project.rule('fun');
- ctx.validate(rule);
- const result = await ctx.service.project.updateFunRela(projectId, ctx.request.body);
- if (!result) throw '保存数据失败';
- this.ctx.session.sessionProject.page_show.openChangeProject = data.openChangeProject ? 1 : 0;
- this.ctx.session.sessionProject.page_show.openChangeApply = data.openChangeApply ? 1 : 0;
- this.ctx.session.sessionProject.page_show.openChangePlan = data.openChangePlan ? 1 : 0;
- this.ctx.session.sessionProject.page_show.openChangeWhiteList = data.openChangeWhiteList ? 1 : 0;
- this.ctx.session.sessionProject.page_show.openChangeState = data.openChangeState ? 1 : 0;
- this.ctx.session.sessionProject.page_show.openMaterialTax = data.openMaterialTax ? 1 : 0;
- this.ctx.session.sessionProject.page_show.openMaterialChecklist = data.openMaterialChecklist ? 1 : 0;
- this.ctx.session.sessionProject.page_show.openMaterialSelf = data.openMaterialSelf ? 1 : 0;
- this.ctx.session.sessionProject.page_show.openMaterialEditForAudit = data.openMaterialEditForAudit ? 1 : 0;
- this.ctx.session.sessionProject.page_show.openStageStart = data.openStageStart ? 1 : 0;
- const result2 = await ctx.service.project.updatePageshow(projectId);
- if (!result2) throw '保存数据失败';
- if (data.addFunSet) {
- const funSet = projectData.fun_set ? JSON.parse(projectData.fun_set) : {};
- ctx.helper._.defaultsDeep(data.addFunSet, funSet);
- const result3 = await ctx.service.project.updateFunSet(projectId, data.addFunSet);
- if (!result3) throw '保存数据失败';
- }
- ctx.body = {err: 0, msg: '', data: null};
- } catch (error) {
- ctx.helper.log(error);
- this.ajaxErrorBody(error, '保存数据失败');
- }
- }
- async s2b(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) throw '没有对应的项目数据';
- if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
- const tenders = await ctx.service.tender.getAllDataByCondition({where: {project_id: projectId}});
- for (const t of tenders) {
- t.measure_type_str = t.measure_type === measureType.tz.value ? measureType.tz.title : measureType.gcl.title;
- const stages = await ctx.service.stage.getAllDataByCondition({where: {tid: t.id}});
- t.stage_count_str = `第${stages.length || 0}期`;
- const user = await ctx.service.projectAccount.getAccountInfoById(t.user_id);
- t.user_str = user.name + '-' + user.company;
- t.show_time = stages.length > 0 ? stages[stages.length - 1].cache_time_r || stages[stages.length - 1].in_time : t.create_time;
- }
- await this.layout('setting/s2b.ejs', {
- projectData,
- tenders,
- });
- } catch (error) {
- ctx.helper.log(error);
- ctx.redirect('/dashboard');
- }
- }
- async s2bUpdate(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) throw '没有对应的项目数据';
- if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
- const data = JSON.parse(ctx.request.body.data);
- if (!data.tid) throw '提交数据错误';
- const updateData = {};
- if (data.gxby_limit !== undefined) updateData.s2b_gxby_limit = data.gxby_limit;
- if (data.gxby_check !== undefined) updateData.s2b_gxby_check = data.gxby_check;
- if (data.dagl_limit !== undefined) updateData.s2b_dagl_limit = data.dagl_limit;
- if (data.dagl_check !== undefined) updateData.s2b_dagl_check = data.dagl_check;
- await ctx.service.tender.saveApiRela(data.tid, updateData);
- ctx.body = {err: 0, msg: '', data: null};
- } catch (error) {
- ctx.helper.log(error);
- this.ajaxErrorBody(error, '保存数据失败');
- }
- }
- async s2bUpdateStatus(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) throw '没有对应的项目数据';
- if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
- const data = JSON.parse(ctx.request.body.data);
- if (!data.type || data.status === undefined) throw '提交数据错误';
- const responseData = {err: 0, msg: '', data: null};
- switch (data.type) {
- case 'gxby':
- responseData.data = await this.ctx.service.s2bProj.updateGxbyStatus(projectId, data.status, data.limit, data.ratio);
- break;
- case 'dagl':
- responseData.data = await this.ctx.service.s2bProj.updateDaglStatus(projectId, data.status, data.limit, data.ratio);
- break;
- default:
- throw '提交数据错误';
- }
- ctx.body = responseData;
- } catch (error) {
- console.log(error);
- ctx.helper.log(error);
- this.ajaxErrorBody(error, '保存数据失败');
- }
- }
- async dataCollect(ctx) {
- try {
- if (!ctx.session.sessionProject.page_show.openDataCollect) {
- throw '该功能已关闭或无法查看';
- }
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) throw '没有对应的项目数据';
- projectData.data_collect_pages = projectData.data_collect_pages ? projectData.data_collect_pages.split(',') : [];
- if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
- const dataCollectAudits = await ctx.service.datacollectAudit.getList(projectId);
- // 获取所有项目参与者
- const accountList = await ctx.service.projectAccount.getAllDataByCondition({
- where: {project_id: ctx.session.sessionProject.id, enable: 1},
- columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
- });
- // const accountGroupList = accountGroup.map((item, idx) => {
- // const groupList = accountList.filter(item => item.account_group === idx);
- // return { groupName: item, groupList };
- // });
- const unitList = await ctx.service.constructionUnit.getAllDataByCondition({where: {pid: ctx.session.sessionProject.id}});
- const accountGroupList = unitList.map(item => {
- const groupList = accountList.filter(item1 => item1.company === item.name);
- return {groupName: item.name, companyId: item.id, groupList};
- });
- const categoryData = await ctx.service.category.getAllCategory(ctx.session.sessionProject.id);
- const tenders = await ctx.service.tender.getList('', null, 1);
- const dcTenders = await ctx.service.datacollectTender.getList(projectId);
- await this.layout('setting/datacollect.ejs', {
- projectData,
- dataCollectAudits,
- accountList,
- accountGroup: accountGroupList,
- categoryData,
- tenders,
- dcTenders,
- is_dz1: ['P0505', 'MI22U'].indexOf(ctx.session.sessionProject.code) !== -1 ? 5 : false,
- }, 'setting/datacollect_modal.ejs');
- } catch (error) {
- ctx.helper.log(error);
- ctx.session.postError = error.toString();
- ctx.redirect('/dashboard');
- }
- }
- async dataCollectSave(ctx) {
- try {
- if (ctx.session.sessionUser.is_admin === 0) throw '没有设置权限';
- const projectId = ctx.session.sessionProject.id;
- const responseData = {
- err: 0, msg: '', data: null,
- };
- const data = JSON.parse(ctx.request.body.data);
- if (!data.type) {
- throw '提交数据错误';
- }
- switch (data.type) {
- case 'show':
- responseData.data = await ctx.service.project.update({
- data_collect: data.data_collect,
- data_collect_pages: data.data_collect_pages.join(',')
- }, {id: projectId});
- ctx.session.sessionProject.dataCollect = data.data_collect;
- ctx.session.sessionProject.showDataCollect = data.data_collect ? 1 : 0;
- break;
- case 'add-audit':
- // 判断该用户是否已加入到表中,已加入则提示无需添加
- const auditInfo = await ctx.service.datacollectAudit.getDataByCondition({
- pid: projectId,
- uid: data.id
- });
- if (auditInfo) {
- throw '该用户已存在权限中,无需重复添加';
- }
- // const accountInfo = await ctx.service.projectAccount.getDataById(data.id);
- // const companyInfo = await ctx.service.datacollectAudit.getCompanyInfo(projectId, accountInfo.company_id);
- // if (companyInfo) {
- // throw '该用户所在单位已存在权限中,无需单独添加';
- // }
- await ctx.service.datacollectAudit.saveAudit(projectId, data.id);
- responseData.data = await ctx.service.datacollectAudit.getList(projectId);
- break;
- case 'add-company':
- const companyInfo = await ctx.service.datacollectAudit.getCompanyInfo(projectId, data.id);
- if (companyInfo) {
- throw '该单位已存在权限中,无需重复添加';
- }
- await ctx.service.datacollectAudit.saveCompany(projectId, data.id);
- responseData.data = await ctx.service.datacollectAudit.getList(projectId);
- break;
- case 'del-audit':
- const auditInfo2 = await ctx.service.datacollectAudit.getDataById(data.id);
- if (!auditInfo2) {
- throw '该用户已不存在权限中,移除失败';
- }
- await ctx.service.datacollectAudit.delAudit(data.id);
- responseData.data = await ctx.service.datacollectAudit.getList(projectId);
- break;
- case 'del-group':
- const groupInfo3 = await ctx.service.datacollectAudit.getDataById(data.id);
- if (!groupInfo3) {
- throw '该单位已不存在权限中,移除失败';
- }
- await ctx.service.datacollectAudit.delAudit(data.id);
- responseData.data = await ctx.service.datacollectAudit.getList(projectId);
- break;
- case 'del-company':
- const companyInfo2 = await ctx.service.datacollectAudit.getDataById(data.id);
- if (!companyInfo2) {
- throw '该单位已不存在权限中,移除失败';
- }
- await ctx.service.datacollectAudit.delAudit(data.id);
- responseData.data = await ctx.service.datacollectAudit.getList(projectId);
- break;
- case 'tender':
- if (ctx.session.sessionProject.page_show.addDataCollect !== parseInt(data.add_datacollect)) {
- ctx.session.sessionProject.page_show.addDataCollect = parseInt(data.add_datacollect);
- await ctx.service.project.updatePageshow(projectId);
- }
- await ctx.service.datacollectTender.updateList(projectId, data.tids);
- responseData.data = {
- dcTenders: await ctx.service.datacollectTender.getList(projectId),
- addDatacollect: ctx.session.sessionProject.page_show.addDataCollect,
- };
- break;
- default:
- throw '参数有误';
- }
- ctx.body = responseData;
- } catch (err) {
- this.log(err);
- ctx.body = {err: 1, msg: err.toString(), data: null};
- }
- }
- async manage(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (projectData === null) throw '没有对应的项目数据';
- if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
- const tenderList = await ctx.service.tender.getList('', null, 1);
- const removeTenders = await ctx.service.shenpiAudit.getRemoveTenders(tenderList);
- if (removeTenders.length > 0) {
- ctx.helper._.remove(tenderList, function(n) {
- return removeTenders.indexOf(n.id) !== -1;
- });
- }
- for (const t of tenderList) {
- t.visitor = (await this.ctx.service.tenderTourist.getTourists(t.id)).map(x => { return x.user_name; });
- await this.ctx.service.tenderCache.loadTenderCache(t, this.ctx.session.sessionUser.accountId);
- }
- const categoryData = await this.ctx.service.category.getAllCategory(this.ctx.session.sessionProject.id);
- // 获取所有项目参与者
- const accountList = await ctx.service.projectAccount.getAllDataByCondition({
- where: {project_id: ctx.session.sessionProject.id, enable: 1},
- columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
- });
- const unitList = await ctx.service.constructionUnit.getAllDataByCondition({where: {pid: ctx.session.sessionProject.id}});
- const accountGroupList = unitList.map(item => {
- const groupList = accountList.filter(item1 => item1.company === item.name);
- return {groupName: item.name, groupList};
- });
- const renderData = {
- projectData,
- tenderList,
- auditConst,
- auditType: auditConst.auditType,
- accountList,
- accountGroup: accountGroupList,
- categoryData,
- settingConst,
- measureType: tenderConst.measureType,
- jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.manage),
- uid: this.ctx.session.sessionUser.accountId,
- pid: this.ctx.session.sessionProject.id,
- scPermission: scheduleConst.permission,
- };
- renderData.selfCategoryLevel = await this.ctx.service.projectAccount.getSelfCategoryLevel(this.ctx.session.sessionUser.accountId);
- await this.layout('setting/manage.ejs', renderData, 'setting/manage_modal.ejs');
- } catch (error) {
- ctx.helper.log(error);
- ctx.redirect('/dashboard');
- }
- }
- async manageTenderSave(ctx) {
- try {
- if (ctx.session.sessionUser.is_admin === 0) throw '没有设置权限';
- const projectId = ctx.session.sessionProject.id;
- const responseData = {
- err: 0, msg: '', data: {},
- };
- const data = JSON.parse(ctx.request.body.data);
- if (!data.type) {
- throw '提交数据错误';
- }
- if (!data.tid) {
- throw '参数有误';
- }
- const tender = await ctx.service.tender.getDataById(data.tid);
- if (!tender) {
- throw '标段不存在';
- }
- const tenderInfo = await ctx.service.tenderInfo.getTenderInfo(tender.id);
- switch (data.type) {
- case 'msg':
- const lastRevise = await ctx.service.ledgerRevise.getLastestRevise(tender.id);
- const revising = (lastRevise && lastRevise.status !== auditConst.revise.status.checked) || false;
- // 获取审批流,游客账号,及投资进度账号信息
- responseData.data.tender = tender;
- responseData.data.revising = revising;
- responseData.data.shenpi = await ctx.service.shenpiAudit.getShenpi(tender.id, tenderInfo);
- const tourists = await ctx.service.tenderTourist.getTourists(tender.id);
- for (const t of tourists) {
- t.permission = await ctx.service.tenderTourist.getTouristPermission(t);
- }
- responseData.data.tourists = tourists;
- responseData.data.scheduleAuditList = ctx.session.sessionProject.page_show.xxjd ? await ctx.service.scheduleAudit.getAllDataByCondition({ where: { tid: tender.id } }) : [];
- responseData.data.constructionAuditList = ctx.session.sessionProject.page_show.openConstruction ? await ctx.service.constructionAudit.getList(tender.id) : [];
- break;
- case 'copy2otu':
- if (data.userType === 'tourist') {
- await ctx.service.tenderTourist.setOtherTender(data.tidList, data.auditList);
- } else if (data.userType === 'schedule') {
- await ctx.service.scheduleAudit.setOtherTender(data.tidList, data.auditList);
- } else if (data.userType === 'construction') {
- await ctx.service.constructionAudit.setOtherTender(data.tidList, data.auditList);
- } else {
- throw '参数有误';
- }
- break;
- default:
- throw '参数有误';
- }
- ctx.body = responseData;
- } catch (err) {
- this.log(err);
- ctx.body = { err: 1, msg: err.toString(), data: null };
- }
- }
- async spread(ctx) {
- try {
- // 获取项目数据
- const projectId = ctx.session.sessionProject.id;
- await this._checkMenu(projectId);
- const projectData = await ctx.service.project.getDataById(projectId);
- if (!projectData) throw '没有对应的项目数据';
- const projectSpread = await this.ctx.service.projectSpread.getProjectSpread(projectData.id);
- const sType = ctx.query.stype;
- const renderData = {
- BaseSetCol: sType.indexOf('stage') > 0 ? SpreadConst.BaseSetCol.Stage : SpreadConst.BaseSetCol.Ledger,
- sType,
- colSet: projectSpread[sType],
- jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.spread),
- };
- await this.layout('setting/spread.ejs', renderData, 'setting/spread_modal.ejs');
- } catch (error) {
- this.log(error);
- ctx.redirect('/dashboard');
- }
- }
- async saveSpread(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const data = JSON.parse(ctx.request.body.data);
- await this.ctx.service.projectSpread.updateProjectSet(projectId, data.sType, data.colSet);
- const projectSpread = await this.ctx.service.projectSpread.getProjectSpread(projectId);
- ctx.body = { err: 0, msg: '', data: { colSet: projectSpread[data.sType] } };
- } catch (error) {
- ctx.log(error);
- ctx.ajaxErrorBody(error, '保存列设置失败,请刷新后重试');
- }
- }
- async previewSpread(ctx) {
- try {
- const data = JSON.parse(ctx.request.body.data);
- const [billsSpread, posSpread] = this.ctx.service.projectSpread.generateRelaSpread(data.sType, data.colSet);
- ctx.body = { err: 0, msg: '', data: { billsSpread, posSpread } };
- } catch (error) {
- ctx.log(error);
- ctx.ajaxErrorBody(error, '保存列设置失败,请刷新后重试');
- }
- }
- async resetSpread(ctx) {
- try {
- const projectId = ctx.session.sessionProject.id;
- const data = JSON.parse(ctx.request.body.data);
- const colSet = SpreadConst.ProjectSpreadTemplate[data.sType];
- await this.ctx.service.projectSpread.updateProjectSet(projectId, data.sType, colSet);
- const projectSpread = await this.ctx.service.projectSpread.getProjectSpread(projectId);
- ctx.body = { err: 0, msg: '', data: { colSet: projectSpread[data.sType] } };
- } catch (error) {
- ctx.log(error);
- ctx.ajaxErrorBody(error, '保存列设置失败,请刷新后重试');
- }
- }
- }
- return SettingController;
- };
|