12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445 |
- '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,
- jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.user),
- // 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,
- jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.user),
- // 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,
- company: null,
- fujianOssPath: ctx.app.config.fujianOssPath,
- jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.setting.user),
- };
- 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: {},
- };
- 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;
- case 'import-users':
- responseData.data = await ctx.service.projectAccount.addUsers(projectData.id, data.users);
- 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 projectSpread = await ctx.service.projectSpread.getProjectSpreadType(projectId);
- const renderData = {projectData, showList, sjsRela, settingConst, projectSpread};
- 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 sType = ctx.query.stype;
- const code = ctx.query.code;
- const projectSpread = await this.ctx.service.projectSpread.getProjectSpread(projectData.id, code);
- const renderData = {
- BaseSetCol: SpreadConst.BaseSetCol[sType],
- sType,
- code,
- 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.code, data.sType, data.colSet);
- const projectSpread = await this.ctx.service.projectSpread.getProjectSpread(projectId, data.code);
- 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 spreadTemplate = SpreadConst.ProjectSpreadTemplate.find(x => { return x.code === data.code; });
- const colSet = spreadTemplate.template[data.sType];
- await this.ctx.service.projectSpread.updateProjectSet(projectId, data.code, data.sType, colSet);
- const projectSpread = await this.ctx.service.projectSpread.getProjectSpread(projectId, data.code);
- ctx.body = { err: 0, msg: '', data: { colSet: projectSpread[data.sType] } };
- } catch (error) {
- ctx.log(error);
- ctx.ajaxErrorBody(error, '保存列设置失败,请刷新后重试');
- }
- }
- }
- return SettingController;
- };
|