From 62aad25f1414e262ee2d6f25d45ca393f593a083 Mon Sep 17 00:00:00 2001 From: rhinel Date: Mon, 27 Sep 2021 22:58:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=95=B4=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=87=83=E6=B0=94=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/config-codes.js | 21 +- server/controllers-rest.js | 46 + server/services-auth.js | 3 + server/services-electric.js | 2 +- server/services-gas.js | 541 +++++++++++ server/services-house.js | 46 +- server/services-lease.js | 12 +- server/services-month.js | 3 + server/services-rent.js | 27 +- src/pcside/common/print-cal-table.vue | 47 +- .../components/dashboard/dashboard-main.vue | 8 +- src/pcside/components/gas/gas-history.vue | 430 +++++++++ src/pcside/components/gas/gas-index.vue | 9 + src/pcside/components/gas/gas-main.vue | 859 ++++++++++++++++++ src/pcside/components/lease/lease-history.vue | 10 + src/pcside/components/lease/lease-main.vue | 177 +++- src/pcside/components/rent/rent-history.vue | 25 + src/pcside/components/rent/rent-main.vue | 34 +- src/pcside/components/rent/rent-month.vue | 70 +- src/pcside/components/system/system-main.vue | 177 ++++ src/pcside/js/routes.js | 21 + src/pcside/js/stores.js | 19 + 22 files changed, 2553 insertions(+), 34 deletions(-) create mode 100644 server/services-gas.js create mode 100644 src/pcside/components/gas/gas-history.vue create mode 100644 src/pcside/components/gas/gas-index.vue create mode 100644 src/pcside/components/gas/gas-main.vue diff --git a/server/config-codes.js b/server/config-codes.js index cadd686..8596395 100644 --- a/server/config-codes.js +++ b/server/config-codes.js @@ -41,6 +41,12 @@ const codeList = { 3014: '查询失败', 3015: '获取带计费房屋列表失败', 3016: '获取房屋详情失败', + // 租住信息 + 3031: '租住列表获取失败', + 3032: '入住/修改失败', + 3033: '搬出失败', + 3034: '租住历史获取失败', + 3035: '租住历史删除失败', // 水费管理,增, 3021: '抄表失败', 3022: '水费聚合列表获取失败', @@ -50,12 +56,6 @@ const codeList = { 3026: '抄表记录删除失败', 3027: '计费历史删除失败', 3028: '查询失败', - // 租住信息 - 3031: '租住列表获取失败', - 3032: '入住/修改失败', - 3033: '搬出失败', - 3034: '租住历史获取失败', - 3035: '租住历史删除失败', // 电费管理,增, 3041: '抄表失败', 3042: '电费聚合列表获取失败', @@ -66,6 +66,15 @@ const codeList = { 3047: '计费历史删除失败', 3048: '查询失败', 3049: '远程抄表失败', + // 燃气费管理,增, + 3081: '抄表失败', + 3082: '燃气费聚合列表获取失败', + 3083: '燃气表计费失败', + 3084: '抄表历史获取失败', + 3085: '计费历史获取失败', + 3086: '抄表记录删除失败', + 3087: '计费历史删除失败', + 3088: '查询失败', // 收租管理 3051: '添加月份失败', 3052: '获取月份周期列表失败', diff --git a/server/controllers-rest.js b/server/controllers-rest.js index 1188b8c..bd955d3 100644 --- a/server/controllers-rest.js +++ b/server/controllers-rest.js @@ -5,6 +5,7 @@ const serviceMonth = require('./services-month') const serviceHouse = require('./services-house') const serviceWater = require('./services-water') const serviceElect = require('./services-electric') +const serviceGas = require('./services-gas') const serviceLease = require('./services-lease') const code = require('./config-codes') @@ -196,6 +197,51 @@ const inner = (req, res, next) => { } else { next() } + } else if (req.params.class === 'gas') { + // 添加燃气表数接口 + if (req.params.function === 'add') { + serviceGas + .gasAdd(req, res) + .then(data => res.json(code(req, 0, data))) + .catch(err => res.json(code(req, 3021, err))) + } else if (req.params.function === 'mainList') { + serviceGas + .gasMainList(req, res) + .then(data => res.json(code(req, 0, data))) + .catch(err => res.json(code(req, 3022, err))) + } else if (req.params.function === 'cal') { + serviceGas + .gascalGas(req, res) + .then(data => res.json(code(req, 0, data))) + .catch(err => res.json(code(req, 3023, err))) + } else if (req.params.function === 'list') { + serviceGas + .gasList(req, res) + .then(data => res.json(code(req, 0, data))) + .catch(err => res.json(code(req, 3024, err))) + } else if (req.params.function === 'calList') { + serviceGas + .gasCalList(req, res) + .then(data => res.json(code(req, 0, data))) + .catch(err => res.json(code(req, 3025, err))) + } else if (req.params.function === 'del') { + serviceGas + .gasDel(req, res) + .then(data => res.json(code(req, 0, data))) + .catch(err => res.json(code(req, 3026, err))) + } else if (req.params.function === 'delCal') { + serviceGas + .gasCalDel(req, res) + .then(data => res.json(code(req, 0, data))) + .catch(err => res.json(code(req, 3027, err))) + } else if (req.params.function === 'findByDate') { + serviceGas + .gasFindByDate(req, res) + .then(data => res.json(code(req, 0, data))) + .catch(err => res.json(code(req, 3028, err))) + } else { + next() + } } else if (req.params.class === 'lease') { // 租住管理接口 if (req.params.function === 'mainList') { diff --git a/server/services-auth.js b/server/services-auth.js index 126e074..4bdc781 100644 --- a/server/services-auth.js +++ b/server/services-auth.js @@ -143,6 +143,7 @@ module.exports = { const { defaultCalWaterPrice, defaultCalElePrice, + defaultCalGasPrice, defaultElseInfo, } = req.body @@ -150,6 +151,7 @@ module.exports = { .dbModel('admin', {//* //标记,更新默认计费方式,修改类型 defaultCalWaterPrice: Object, // 默认水费计费,全拼 defaultCalElePrice: Object, // 默认电费计费,全拼 + defaultCalGasPrice: Object, // 默认燃气费计费,全拼 defaultElseInfo: Object, // 默认用户信息,全拼 }) .findOneAndUpdate({ @@ -158,6 +160,7 @@ module.exports = { $set: { defaultCalWaterPrice, defaultCalElePrice, + defaultCalGasPrice, defaultElseInfo, }, }) diff --git a/server/services-electric.js b/server/services-electric.js index d303161..b4f7e5b 100644 --- a/server/services-electric.js +++ b/server/services-electric.js @@ -65,7 +65,7 @@ module.exports = { .exec() if (!house) { - return Promise.reject(new FoundError('房屋不存在,无法更新抄水表ID')) + return Promise.reject(new FoundError('房屋不存在,无法更新抄电表ID')) } // 3返回数据 diff --git a/server/services-gas.js b/server/services-gas.js new file mode 100644 index 0000000..160b948 --- /dev/null +++ b/server/services-gas.js @@ -0,0 +1,541 @@ +const FoundError = require('./config-error') +const db = require('./models') + +const servicesHouse = require('./services-house') + +module.exports = { + + gasAdd: async req => { + // 校验数据,错误退出 + // 1插入数据,错误退出 + // 2更新房屋挂载ID,错误退出 + // 3返回add对象 + + if (!req.body.haoId) { + return Promise.reject(new FoundError('请选择房屋')) + } + + if (!req.body.gas) { + return Promise.reject(new FoundError('请填写燃气表数')) + } + + if (!req.body.addTime) { + return Promise.reject(new FoundError('请填写抄表时间')) + } + + // 0code 1 校验房屋ID + await servicesHouse + .houseFind(req) + + // 1插入燃气表抄表记录 + const addData = await db + .dbModel('gas', {//* //标记,初始燃气表数数据类,新增类型 + userId: db.db.Schema.Types.ObjectId, // 用户ID + haoId: db.db.Schema.Types.ObjectId, // 房屋ID + gas: Number, // 燃气表数,全拼 + remark: String, // 备注,全拼 + addTime: String, // 抄表时间 + status: Number, // 状态 + createTime: Number, // 创建时间 + }) + .create({ + userId: req.userId, + haoId: req.body.haoId, + gas: req.body.gas, + remark: req.body.remark || '', + addTime: req.body.addTime, + status: 1, + createTime: Date.now(), + }) + + if (!addData) { + return Promise.reject(new FoundError('抄表失败')) + } + + // 2更新房屋最新燃气表数信息 + const house = await db + .dbModel('house', {//* //标记,更新房屋数据类,扩增最新抄表数引用类型 + gasId: db.db.Schema.Types.ObjectId, + updateTime: Number, // 更新时间 + }) + .findOneAndUpdate({ _id: req.body.haoId }, { + gasId: addData._id, + updateTime: Date.now(), + }) + .exec() + + if (!house) { + return Promise.reject(new FoundError('房屋不存在,无法更新抄燃气表ID')) + } + + // 3返回数据 + return { _id: addData._id } + }, + + gasMainList: async req => { + // 1查询房屋数据,抄表记录,计费记录,租户信息 + // 2燃气费小计计费 + // 3返回list对象 + + // 初始化该库 + db.dbModel('gas') + db.dbModel('gascal') + db.dbModel('lease') + + // 1数据库查询 + const dbInfo = await db + .dbModel('house') + .find({}, { + fang: 1, + hao: 1, + gasId: 1, + calGasId: 1, + leaseId: 1, + }) + .populate({ + path: 'gasId', + model: 'gas', + select: 'gas remark addTime', + match: { status: 1 }, + }) + .populate({ + path: 'calGasId', + model: 'gascal', + select: 'tnew addTime', + match: { status: 1 }, + }) + .populate({ + path: 'leaseId', + model: 'lease', + select: 'calGasPrice', + match: { status: 1 }, + }) + .where('userId') + .equals(db.db.Types.ObjectId(req.userId)) + .where('status') + .equals(1) + .sort('fang hao') + .lean() + .exec() + + // 2数据计算 + dbInfo.forEach((item) => { + // 字段提供 + if (!item.fanghao) { + item.fanghao = item.fang + item.hao + } + // 上次燃气费ID初始化 + if (!item.calGasId) item.calGasId = {} + if (item.calGasId.tnew) { + item.calGasId.tnew.addTime = item.calGasId.addTime + item.calGasId = item.calGasId.tnew + } + // 抄燃气ID初始化 + if (!item.gasId) item.gasId = {} + // 收费方式初始化 + if (!item.leaseId) item.leaseId = {} + if (item.leaseId.calGasPrice) { + item.leaseId = item.leaseId.calGasPrice + } + // 差距计算 + if (!item.gap) { + item.gap = (item.gasId.gas || 0) - (item.calGasId.gas || 0) + } + if (item.gap <= 0) { + item.gap = 0 + } + + // 小计计算 + // 燃气表计费,前端计算,后端获取数据时计算,前端入住搬出月结时计算 + let calResult = 0 + let calGap = item.gap + calGap = Math.max(calGap, item.leaseId.minPrice || 0) + + if (item.leaseId.calType === 'single') { + calResult = calGap * (item.leaseId.singlePrice || 0) + } else if (item.leaseId.calType === 'step' && item.leaseId.stepPrice) { + item.leaseId.stepPrice.forEach((stepPrice, i, stepPrices) => { + // 假阶梯,取范围内的计算,大于按照最大的 + if (!stepPrice.price) return + const prevPrices = stepPrices[i - 1] || {} + if ( + (calGap > (prevPrices.step || 0) && calGap <= stepPrice.step) + || (i === (stepPrices.length - 1) && calGap >= stepPrice.step) + ) { + calResult = calGap * stepPrice.price + } + }) + } + calResult = Math.round(calResult * 100) / 100 + if (!item.result) { + item.result = calResult + } + }) + + // 3返回数据 + return dbInfo + }, + + gasList: async req => { + // 1查询抄表记录,房屋数据 + // 2返回list对象 + + if (!req.body.haoId) { + return Promise.reject(new FoundError('缺少房屋ID')) + } + + // 0code 1 校验房屋ID + await servicesHouse + .houseFind(req) + + // 初始化该库 + db.dbModel('house') + + // 1数据库查询 + const dbInfo = await db + .dbModel('gas') + .find({ haoId: db.db.Types.ObjectId(req.body.haoId) }) + .populate({ + path: 'haoId', + model: 'house', + select: 'fang hao haoId addTime', + match: { status: 1 }, + }) + .where('userId') + .equals(db.db.Types.ObjectId(req.userId)) + .where('status') + .equals(1) + .sort('-createTime -_id') + .lean() + .exec() + + dbInfo.forEach(gas => { + // loading字段提供 + if (!gas.gettingdelGas) gas.gettingdelGas = false + // del提示字段提供 + if (!gas.dGasPopFlag) gas.dGasPopFlag = false + // 房屋 + if (gas.haoId && !gas.fanghao) { + gas.fanghao = gas.haoId.fang + gas.haoId.hao + } + }) + + // 2返回数据 + return dbInfo + }, + + gasCalList: async req => { + // 查询计费记录,房屋数据 + // 返回list对象 + + if (!req.body.haoId) { + return Promise.reject(new FoundError('缺少房屋ID')) + } + + // 0code 1 校验房屋ID + await servicesHouse + .houseFind(req) + + // 1初始化该库 + db.dbModel('house') + + // 1数据库查询 + const dbInfo = await db + .dbModel('gascal') + .find({ haoId: db.db.Types.ObjectId(req.body.haoId) }) + .populate({ + path: 'haoId', + model: 'house', + select: 'fang hao haoId addTime', + match: { status: 1 }, + }) + .where('userId') + .equals(db.db.Types.ObjectId(req.userId)) + .where('status') + .equals(1) + .sort('-createTime -_id') + .lean() + .exec() + + dbInfo.forEach(gasCal => { + // loading字段提供 + if (!gasCal.gettingdelCalGas) gasCal.gettingdelCalGas = false + // del提示字段提供 + if (!gasCal.dCalGasPopFlag) gasCal.dCalGasPopFlag = false + // 房屋 + if (gasCal.haoId && !gasCal.fanghao) { + gasCal.fanghao = gasCal.haoId.fang + gasCal.haoId.hao + } + // 小计 + if (!gasCal.gap) { + gasCal.gap = (gasCal.tnew.gas || 0) - (gasCal.old.gas || 0) + } + if (gasCal.gap <= 0) gasCal.gap = 0 + }) + + // 2返回数据 + return dbInfo + }, + + gascalGas: async req => { + // 不做数据校验 + // 1插入数据(存储新抄表记录,旧抄表记录,计费信息),错误退出 + // 2更新房屋挂载ID,错误提出 + // 3返回add对象 + + if (!req.body.haoId) { + return Promise.reject(new FoundError('请选择房屋')) + } + + // 0code 1 校验房屋ID + await servicesHouse + .houseFind(req) + + // 1插入数据 + const addInfo = await db + .dbModel('gascal', {//* //标记,初始燃气表计费数数据类,新增类型 + userId: db.db.Schema.Types.ObjectId, // 用户ID + haoId: db.db.Schema.Types.ObjectId, // 房屋ID,全拼 + tnew: { + gas: Number, // 抄表数 + remark: String, // 抄表备注 + addTime: String, // 抄表时间 + }, + old: { + gas: Number, // 底表数 + remark: String, // 底表备注 + addTime: String, // 底表时间 + }, + calGas: { + minPrice: Number, // 本次计费低消 + calType: String, // 计费类型 + singlePrice: Number, // single单价 + stepPrice: [{ // 阶梯价格 + step: Number, // 阶梯 + price: Number, // 单价 + }], + }, + remark: String, // 计费备注 + addTime: String, // 计费时间 + fix: Boolean, // 结果是否修正 + calGasResult: Number, // 计算结果 + status: Number, // 状态 + createTime: Number, // 创建时间 + }) + .create({ + userId: req.userId, + haoId: req.body.haoId, + tnew: req.body.tnew, + old: req.body.old, + calGas: req.body.calGas, + remark: req.body.remark, + addTime: req.body.addTime, + fix: req.body.fix, + calGasResult: req.body.calGasResult, + status: 1, + createTime: Date.now(), + }) + + if (!addInfo) { + return Promise.reject(new FoundError('插入失败')) + } + + // 2更新房屋信息 + const house = await db + .dbModel('house', {//* //标记,更新房屋数据类,扩增最新计费数据引用类型 + calGasId: db.db.Schema.Types.ObjectId, + updateTime: Number, // 更新时间 + }) + .findOneAndUpdate({ _id: req.body.haoId }, { + calGasId: addInfo._id, + updateTime: Date.now(), + }) + .exec() + + if (!house) { + return Promise.reject(new FoundError('房屋不存在,无法燃气费计费更新ID')) + } + + // 3返回数据 + return { _id: addInfo._id } + }, + + gasDel: async req => { + // 校验数据,错误退出 + // 1修改状态,错误退出 + // 2查询上一条数据 + // 3更新房屋挂载ID,错误退出 + // 4返回del对象 + + if (!req.body._id) { + return Promise.reject(new FoundError('ID不存在')) + } + + // 0code 1 校验房屋ID + await servicesHouse + .houseFind(req) + + // 1根据ID修改状态 + const gasDel = await db + .dbModel('gas', {//* //标记,初始燃气表类型数据类,删除类型 + status: Number, // 状态 + updateTime: Number, // 更新时间 + }) + .findOneAndUpdate({ _id: req.body._id }, { + status: 0, + updateTime: Date.now(), + }) + .exec() + + if (!gasDel || !gasDel.status) { + return Promise.reject(new FoundError('删除失败')) + } + + // 2查询上一条数据 + const gasPrev = await db + .dbModel('gas') + .findOne({}) + .where('userId') + .equals(db.db.Types.ObjectId(req.userId)) + .where('haoId') + .equals(db.db.Types.ObjectId(req.body.haoId)) + .where('status') + .equals(1) + .sort('-createTime -_id') + .exec() + + const gasPrevId = gasPrev ? gasPrev.id : null + + // 3更新房屋信息 + const house = await db + .dbModel('house', {//* //标记,更新房屋数据类,扩增最新抄燃气表数引用类型 + gasId: db.db.Schema.Types.ObjectId, + updateTime: Number, // 更新时间 + }) + .findOneAndUpdate({ _id: req.body.haoId }, { + gasId: gasPrevId, + updateTime: Date.now(), + }) + .exec() + + if (!house) { + return Promise.reject(new FoundError('房屋不存在,无法删除燃气度数')) + } + + // 4返回ID + return { _id: req.body._id } + }, + + gasCalDel: async req => { + // 校验数据,错误退出 + // 1修改状态,错误退出 + // 2查询上一条数据 + // 3更新房屋挂载ID,错误退出 + // 4返回del对象 + + if (!req.body._id) { + return Promise.reject(new FoundError('ID不存在')) + } + + // 0code 1 校验房屋ID + await servicesHouse + .houseFind(req) + + // 1根据ID修改状态 + const gasCalDel = await db + .dbModel('gascal', {//* //标记,初始燃气费计费数据类,删除类型 + status: Number, // 状态 + updateTime: Number, // 更新时间 + }) + .findOneAndUpdate({ _id: req.body._id }, { + status: 0, + updateTime: Date.now(), + }) + .exec() + + if (!gasCalDel || !gasCalDel.status) { + return Promise.reject(new FoundError('删除失败')) + } + + // 2查询上一条数据 + const gasCalDelPrev = await db + .dbModel('gascal') + .findOne({}) + .where('userId') + .equals(db.db.Types.ObjectId(req.userId)) + .where('haoId') + .equals(db.db.Types.ObjectId(req.body.haoId)) + .where('status') + .equals(1) + .sort('-createTime -_id') + .exec() + + const gasCalDelPrevId = gasCalDelPrev ? gasCalDelPrev.id : null + + // 3更新房屋最新燃气表计费信息 + const house = await db + .dbModel('house', {//* //标记,更新房屋数据类,扩增最新燃气表计费引用类型 + calGasId: db.db.Schema.Types.ObjectId, + updateTime: Number, // 更新时间 + }) + .findOneAndUpdate({ _id: req.body.haoId }, { + calGasId: gasCalDelPrevId, + updateTime: Date.now(), + }) + .exec() + + if (!house) { + return Promise.reject(new FoundError('房屋不存在,无法删除燃气费计费')) + } + + // 4返回ID + return { _id: req.body._id } + }, + + gasFindByDate: async req => { + // 1获取时间 + // 2查询燃气表 + + // 1获取时间 + const today = new Date().toLocaleDateString() + const date = req.body.gasDate || today + + const time = new Date(date).getTime() + const firstLeft = ' new Date(this.addTime).getTime() >= ' + const secondLfet = ' new Date(this.addTime).getTime() < ' + const all = `return${firstLeft}${time} &&${secondLfet}${time + 86400000}` + + db.dbModel('house') + + // 2查询燃气表 + const gasByDate = await db + .dbModel('gas') + .find({}) + .populate({ + path: 'haoId', + model: 'house', + select: 'fang hao haoId addTime', + match: { status: 1 }, + }) + // eslint-disable-next-line no-new-func + .$where(new Function(all)) + .where('userId') + .equals(db.db.Types.ObjectId(req.userId)) + .where('status') + .equals(1) + .sort('-addTime -createTime') + .lean() + .exec() + + gasByDate.forEach(gas => { + // 房屋 + if (gas.haoId && !gas.fanghao) { + gas.fanghao = gas.haoId.fang + gas.haoId.hao + } + }) + + // 3返回数据 + return gasByDate + }, + +} diff --git a/server/services-house.js b/server/services-house.js index 8f562ec..bbc7e47 100644 --- a/server/services-house.js +++ b/server/services-house.js @@ -238,7 +238,24 @@ module.exports = { .lean() .exec() - return { calWaters, calElectrics } + // 查询燃气费信息 + const calGass = await db + .dbModel('gascal') + .find({ haoId: db.db.Types.ObjectId(house._id) }, { + old: 1, + tnew: 1, + addTime: 1, + }) + .where('userId') + .equals(db.db.Types.ObjectId(req.userId)) + .where('status') + .equals(1) + .limit(3) + .sort('-addTime') + .lean() + .exec() + + return { calWaters, calElectrics, calGass } }) const dbSearchInfo = await Promise.all(dbSearch) @@ -269,9 +286,20 @@ module.exports = { } }) + // 计算燃气费小计 + dbSearchInfo[i].calGass.forEach(l => { + if (!l.gap) { + l.gap = (l.tnew.gas || 0) - (l.old.gas || 0) + } + if (l.gap <= 0) { + l.gap = 0 + } + }) + // 获取数据 dbInfo[i].calWaters = dbSearchInfo[i].calWaters dbInfo[i].calElectrics = dbSearchInfo[i].calElectrics + dbInfo[i].calGass = dbSearchInfo[i].calGass } // 3返回数据 @@ -287,6 +315,8 @@ module.exports = { db.dbModel('watercal') db.dbModel('electric') db.dbModel('electriccal') + db.dbModel('gas') + db.dbModel('gascal') db.dbModel('rent') if (!req.body.haoId) { @@ -327,6 +357,18 @@ module.exports = { model: 'electriccal', match: { status: 1 }, }) + // 抄燃气表信息 + .populate({ + path: 'gasId', + model: 'gas', + match: { status: 1 }, + }) + // 燃气表计费信息 + .populate({ + path: 'calGasId', + model: 'gascal', + match: { status: 1 }, + }) // 最新计费信息 .populate({ path: 'rentId', @@ -345,8 +387,10 @@ module.exports = { // 3字段初始化 if (!dbInfo.waterId) dbInfo.waterId = {} if (!dbInfo.electricId) dbInfo.electricId = {} + if (!dbInfo.gasId) dbInfo.gasId = {} if (!dbInfo.calWaterId) dbInfo.calWaterId = {} if (!dbInfo.calElectricId) dbInfo.calElectricId = {} + if (!dbInfo.calGasId) dbInfo.calGasId = {} if (!dbInfo.leaseId) dbInfo.leaseId = {} if (!dbInfo.rentId) dbInfo.rentId = {} diff --git a/server/services-lease.js b/server/services-lease.js index 225687b..d02341e 100644 --- a/server/services-lease.js +++ b/server/services-lease.js @@ -93,6 +93,16 @@ module.exports = { }], }, + calGasPrice: { + minPrice: Number, // 本次计费低消 + calType: String, // 计费类型 + singlePrice: Number, // single单价 + stepPrice: [{ // 阶梯价格 + step: Number, // 阶梯 + price: Number, // 单价 + }], + }, + rent: Number, // 租金 deposit: Number, // 押金 addTime: String, // 入住时间 @@ -165,7 +175,7 @@ module.exports = { .exec() if (!house) { - return Promise.reject(new FoundError('房屋不存在,无法删除水度数')) + return Promise.reject(new FoundError('房屋不存在,无法删除居住信息')) } // 4返回ID diff --git a/server/services-month.js b/server/services-month.js index b5f172a..07a8610 100644 --- a/server/services-month.js +++ b/server/services-month.js @@ -63,6 +63,7 @@ module.exports = { status: Number, // 状态 defaultCalWaterPrice: Object, // 本月度默认水费计费方式 defaultCalElePrice: Object, // 本月度默认电费计费方式 + defaultCalGasPrice: Object, // 本月度默认燃气费计费方式 createTime: Number, // 创建时间 }) .create({ @@ -71,6 +72,7 @@ module.exports = { remark: req.body.remark, defaultCalWaterPrice: req.body.defaultCalWaterPrice, defaultCalElePrice: req.body.defaultCalElePrice, + defaultCalGasPrice: req.body.defaultCalGasPrice, status: 1, createTime: Date.now(), }) @@ -95,6 +97,7 @@ module.exports = { remark: 1, defaultCalWaterPrice: 1, defaultCalElePrice: 1, + defaultCalGasPrice: 1, createTime: 1, updateTime: 1, }) diff --git a/server/services-rent.js b/server/services-rent.js index 2cb94d9..9c12eaf 100644 --- a/server/services-rent.js +++ b/server/services-rent.js @@ -6,7 +6,7 @@ const servicesHouse = require('./services-house') module.exports = { rentListByMonth: async req => { - // 通过房屋查询所有最新挂载信息:电费计费,水费计费,租约信息 + // 通过房屋查询所有最新挂载信息:电费计费,水费计费,燃气费计费,租约信息 // 0初始化字段后 // 1再根据monthId查询月度信息 // 1根据房屋Id插入monthId信息 @@ -19,6 +19,7 @@ module.exports = { // 初始化该库 db.dbModel('watercal') db.dbModel('electriccal') + db.dbModel('gascal') db.dbModel('lease') // 1数据库查询 @@ -29,6 +30,7 @@ module.exports = { hao: 1, calWaterId: 1, calElectricId: 1, + calGasId: 1, leaseId: 1, }) .populate({ @@ -41,6 +43,11 @@ module.exports = { model: 'electriccal', match: { status: 1 }, }) + .populate({ + path: 'calGasId', + model: 'gascal', + match: { status: 1 }, + }) .populate({ path: 'leaseId', model: 'lease', @@ -73,6 +80,7 @@ module.exports = { // 字段初始化 if (!house.calWaterId) house.calWaterId = {} if (!house.calElectricId) house.calElectricId = {} + if (!house.calGasId) house.calGasId = {} if (!house.leaseId) house.leaseId = {} // loading字段提供 if (!house.gettingdelRent) house.gettingdelRent = false @@ -92,7 +100,7 @@ module.exports = { rentAdd: async req => { // 不做数据校验 - // 1插入数据(存储新水费记录,电费记录,租住信息),错误退出 + // 1插入数据(存储新水费记录,电费记录,燃气费记录,租住信息),错误退出 // 2更新房屋挂载ID,错误提出 // 3返回add对象 @@ -116,6 +124,7 @@ module.exports = { monthId: db.db.Schema.Types.ObjectId, // 月度周期ID,全拼 calWater: Object, // 水费计费 calElectric: Object, // 电费计费 + calGas: Object, // 燃气费计费 lease: Object, // 租住信息 fanghao: String, // 房屋 remark: String, // 计费备注 @@ -131,6 +140,7 @@ module.exports = { monthId: req.body.monthId, calWater: req.body.calWater, calElectric: req.body.calElectric, + calGas: req.body.calGas, lease: req.body.lease, fanghao: req.body.fanghao, remark: req.body.remark, @@ -605,14 +615,16 @@ module.exports = { // 分类统计 list[time][rent.lease.payType] += rent.calRentResult list[time].all += rent.calRentResult - // 非房租都认为是水电费 + // 非房租都认为是水电燃气费 // (rent.calWater ? rent.calWater.calWaterResult : 0) + - // (rent.calElectric ? rent.calElectric.calElectricResult : 0) + // (rent.calElectric ? rent.calElectric.calElectricResult : 0) + + // (rent.calGas ? rent.calGas.calGasResult : 0) rent.cost = rent.calRentResult - rent.lease.rent - // 修复不足整月时应收小于房租的问题,反推计算水电数和房租数 + // 修复不足整月时应收小于房租的问题,反推计算水电燃气数和房租数 if (rent.cost < 0) { const cost = (rent.calWater ? rent.calWater.calWaterResult : 0) + (rent.calElectric ? rent.calElectric.calElectricResult : 0) + + (rent.calGas ? rent.calGas.calGasResult : 0) rent.lease.rent = rent.calRentResult - cost rent.cost = cost } @@ -706,9 +718,10 @@ module.exports = { dbInfo.forEach(rent => { list[rent.lease.payType] += rent.calRentResult list.all += rent.calRentResult - // 非房租都认为是水电费 + // 非房租都认为是水电燃气费 // (i.calWater ? i.calWater.calWaterResult : 0) + - // (i.calElectric ? i.calElectric.calElectricResult : 0) + // (i.calElectric ? i.calElectric.calElectricResult : 0) + + // (i.calGas ? i.calGas.calGasResult : 0) rent.cost = rent.calRentResult - rent.lease.rent // 默认字段提供 if (!rent.checkBill) rent.checkBill = false diff --git a/src/pcside/common/print-cal-table.vue b/src/pcside/common/print-cal-table.vue index 2bb519d..ab8928f 100644 --- a/src/pcside/common/print-cal-table.vue +++ b/src/pcside/common/print-cal-table.vue @@ -51,7 +51,6 @@ : '--' }}元 - {{ item.rents[0].calElectric @@ -81,6 +80,35 @@ : '--' }}元 + + {{ + item.rents[0].calGas + ? item.rents[0].calGas.tnew.gas + : '--' + }}方 + + + {{ + item.rents[0].calGas + ? item.rents[0].calGas.old.gas + : '--' + }}方 + + + {{ + item.rents[0].calGas + ? item.rents[0].calGas.tnew.gas + - item.rents[0].calGas.old.gas + : '--' + }}方 + + + {{ + item.rents[0].calGas + ? getCal(item.rents[0].calGas, 'gas') + : '--' + }}元 + @@ -122,22 +150,27 @@ // 计算张贴的价格 getCal(rent, type) { // 用于张贴展示,不做真实计费,所有计费按月度周期来计算 - const { - calType, - minPrice, - singlePrice, - stepPrice, - } = type === 'water' ? ( + let defaultCal = type === 'water' ? ( this.monthDet.defaultCalWaterPrice || this.defaultCalWaterPrice ) : ( this.monthDet.defaultCalElePrice || this.defaultCalElePrice ) + defaultCal = type === 'gas' ? ( + this.monthDet.defaultCalGasPrice + || this.defaultCalGasPrice + ) : defaultCal + const { + calType, minPrice, singlePrice, stepPrice, + } = defaultCal let gap = type === 'water' ? (rent.tnew.water - rent.old.water) : (rent.tnew.electric - rent.old.electric) + gap = type === 'gas' + ? (rent.tnew.gas - rent.old.gas) + : gap gap = Math.max(0, gap, minPrice) let result = 0 diff --git a/src/pcside/components/dashboard/dashboard-main.vue b/src/pcside/components/dashboard/dashboard-main.vue index 60d55a4..c20fb3f 100644 --- a/src/pcside/components/dashboard/dashboard-main.vue +++ b/src/pcside/components/dashboard/dashboard-main.vue @@ -364,12 +364,12 @@
业务一:房屋管理
1、房屋添加、修改、删除。
- 业务二:水电管理
- 1、抄数:水电、信息更新。
- 2、计费:水电计费可调整计费参数。
+ 业务二:水电燃气管理
+ 1、抄数:水电燃气、信息更新。
+ 2、计费:水电燃气计费可调整计费参数。
3、中途搬入搬出可只进行计费,更新表底信息。
业务三:收租
- 1、收租:房租(周期,周期内可多次),周期内可有多个租户,多次收租,计租必须先进行水电计费(或空计),可调整计费情况。
+ 1、收租:房租(周期,周期内可多次),周期内可有多个租户,多次收租,计租必须先进行水电燃气计费(或空计),可调整计费情况。
2、搬出入住/修改:计费信息初始化,必须为上次收租结束/空置处理结束/本次计费之前,用户自行确认。
3、空置作计费处理,不收租。
diff --git a/src/pcside/components/gas/gas-history.vue b/src/pcside/components/gas/gas-history.vue new file mode 100644 index 0000000..1936a2b --- /dev/null +++ b/src/pcside/components/gas/gas-history.vue @@ -0,0 +1,430 @@ + + + diff --git a/src/pcside/components/gas/gas-index.vue b/src/pcside/components/gas/gas-index.vue new file mode 100644 index 0000000..ce6c883 --- /dev/null +++ b/src/pcside/components/gas/gas-index.vue @@ -0,0 +1,9 @@ + + + diff --git a/src/pcside/components/gas/gas-main.vue b/src/pcside/components/gas/gas-main.vue new file mode 100644 index 0000000..074b2dd --- /dev/null +++ b/src/pcside/components/gas/gas-main.vue @@ -0,0 +1,859 @@ + + + diff --git a/src/pcside/components/lease/lease-history.vue b/src/pcside/components/lease/lease-history.vue index 3a454b8..f0b8154 100644 --- a/src/pcside/components/lease/lease-history.vue +++ b/src/pcside/components/lease/lease-history.vue @@ -113,6 +113,16 @@ :lease="scope.row" /> + + + + + + + + + + + + + + + + 单一价格 + + + 阶梯价格 + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + 删除 + + + +
+ + + 新增阶梯 + + + @@ -590,6 +719,16 @@ :lease="scope.row.leaseId" />
+ + + state.config.typesVal, defaultCalWaterPrice: state => state.config.defaultCalWaterPrice, defaultCalElePrice: state => state.config.defaultCalElePrice, + defaultCalGasPrice: state => state.config.defaultCalGasPrice, defaultStep: state => state.config.defaultStep, }), }, @@ -945,7 +1101,7 @@ // 时间 this.lease.addTime = (row.leaseId.addTime && new Date(row.leaseId.addTime)) || new Date() - // 水费电费初始化 + // 水费电费燃气初始化 if (!row.leaseId || !row.leaseId._id) { this.lease.calWaterPrice = Object.assign( {}, @@ -955,6 +1111,10 @@ {}, JSON.parse(JSON.stringify(this.defaultCalElePrice)) ) + this.lease.calGasPrice = Object.assign( + {}, + JSON.parse(JSON.stringify(this.defaultCalGasPrice)) + ) return } @@ -985,6 +1145,21 @@ } }) if (!this.lease.calElePrice.stepPrice.length) this.addStep(this.lease.calElePrice) + + // 燃气费 + Object.keys(this.lease.calGasPrice).forEach(key => { + if ( + this.lease.calGasPrice[key].constructor === Array + && row.leaseId.calGasPrice[key] + ) { + this.lease.calGasPrice[key] = JSON.parse( + JSON.stringify(row.leaseId.calGasPrice[key]) + ) + } else if (row.leaseId.calGasPrice[key]) { + this.lease.calGasPrice[key] = row.leaseId.calGasPrice[key] + } + }) + if (!this.lease.calGasPrice.stepPrice.length) this.addStep(this.lease.calGasPrice) } await new Promise(r => setTimeout(r, 300)) }, diff --git a/src/pcside/components/rent/rent-history.vue b/src/pcside/components/rent/rent-history.vue index 0ebfc1a..c78d386 100644 --- a/src/pcside/components/rent/rent-history.vue +++ b/src/pcside/components/rent/rent-history.vue @@ -166,6 +166,17 @@ :rent="getRent(props)" /> + + + @@ -215,6 +226,20 @@ + + + + + diff --git a/src/pcside/components/rent/rent-main.vue b/src/pcside/components/rent/rent-main.vue index e8cee51..9a057d5 100644 --- a/src/pcside/components/rent/rent-main.vue +++ b/src/pcside/components/rent/rent-main.vue @@ -63,7 +63,7 @@ '记录以下(已配置)计费方式作为本月' + '默认计费方式(存副本),作用于水电张贴计算'" /> - + @@ -87,7 +87,7 @@ - + @@ -111,6 +111,30 @@ + + +
+ 低消:{{ addMonthList.defaultCalGasPrice.minPrice || 0 }}方 +
+
+ 单价:{{ addMonthList.defaultCalGasPrice.singlePrice || 0 }}方/吨 +
+
+ 阶梯: +
+ {{ item.step }}吨及以下¥{{ item.price }}方/吨; +
+ 超出按最后阶梯计算。 +
+
+ 暂无计费方式 +
+
+
state.config.defaultCalWaterPrice, defaultCalElePrice: state => state.config.defaultCalElePrice, + defaultCalGasPrice: state => state.config.defaultCalGasPrice, }), }, beforeCreate() { @@ -317,6 +343,7 @@ this.addMonthList.remark = row.remark this.addMonthList.defaultCalWaterPrice = row.defaultCalWaterPrice || {} this.addMonthList.defaultCalElePrice = row.defaultCalElePrice || {} + this.addMonthList.defaultCalGasPrice = row.defaultCalGasPrice || {} this.amldInput = false this.amldDialogTitle = '修改收租周期' } else if (this.addMonthListflag) { @@ -330,12 +357,15 @@ let { defaultCalWaterPrice, defaultCalElePrice, + defaultCalGasPrice, } = this defaultCalWaterPrice = JSON.parse(JSON.stringify(defaultCalWaterPrice)) defaultCalElePrice = JSON.parse(JSON.stringify(defaultCalElePrice)) + defaultCalGasPrice = JSON.parse(JSON.stringify(defaultCalGasPrice)) this.addMonthList = Object.assign({}, this.addMonthList, this.addMonthListClear, { defaultCalWaterPrice, defaultCalElePrice, + defaultCalGasPrice, }) this.dialogId = Date.now() }, diff --git a/src/pcside/components/rent/rent-month.vue b/src/pcside/components/rent/rent-month.vue index 7785453..6d9acad 100644 --- a/src/pcside/components/rent/rent-month.vue +++ b/src/pcside/components/rent/rent-month.vue @@ -36,7 +36,7 @@ title="请确认计租信息,保存计租副本" type="info" /> - + @@ -63,7 +63,7 @@
- + @@ -90,6 +90,33 @@ + + +
+ 计费方式:{{ + addRent.calGas.calGas.calType == 'single' ? + '单一价格' : '阶梯价格' + }}
+ 最低消费:{{ addRent.calGas.calGas.minPrice }}吨
+ 本次表数:{{ addRent.calGas.tnew.gas }}吨
+ ({{ getTime(addRent.calGas.tnew.addTime) }})
+ 上次表数:{{ addRent.calGas.old.gas }}吨
+ ({{ getTime(addRent.calGas.old.addTime) }})
+ 计费单价:¥{{ eandwCalGetPrice(addRent, 'gas', 'calGas') }}元/吨
+ 水费:¥{{ + addRent.calGas.calGasResult + }}元({{ + addRent.calGas.fix ? '修' : '计' + }})
+ 计费时间:{{ getTime(addRent.calGas.addTime) }} +
+
+ 暂无 +
+
+
+ + +
@@ -401,6 +440,21 @@ + + + + + @@ -677,7 +731,7 @@ state.config.typesVal, defaultCalWaterPrice: state => state.config.defaultCalWaterPrice, defaultCalElePrice: state => state.config.defaultCalElePrice, + defaultCalGasPrice: state => state.config.defaultCalGasPrice, }), }, watch: { @@ -965,6 +1022,7 @@ // 用于展示 this.addRent.calWater = row.calWaterId this.addRent.calElectric = row.calElectricId + this.addRent.calGas = row.calGasId // 编辑部分 this.addRent.lease = {}.hasOwnProperty.call(row.leaseId, 'rent') ? JSON.parse(JSON.stringify(row.leaseId)) : this.addRent.lease @@ -1307,6 +1365,10 @@