context.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. 'use strict';
  2. module.exports = {
  3. test() {
  4. // this 就是 ctx 对象,在其中可以调用 ctx 上的其他方法,或访问属性
  5. },
  6. // 将参数变为模糊查询
  7. alterRegexName(query) {
  8. if (query.name) {
  9. query.name = { $regex: query.name };
  10. }
  11. },
  12. // 传入的五级地区 转成 ObjectId
  13. alterDeptId(query) {
  14. if (query.dept1) {
  15. query.dept1 = this.app.mongoose.Types.ObjectId(query.dept1);
  16. }
  17. if (query.dept2) {
  18. query.dept2 = this.app.mongoose.Types.ObjectId(query.dept2);
  19. }
  20. if (query.dept3) {
  21. query.dept3 = this.app.mongoose.Types.ObjectId(query.dept3);
  22. }
  23. if (query.dept4) {
  24. query.dept4 = this.app.mongoose.Types.ObjectId(query.dept4);
  25. }
  26. if (query.dept5) {
  27. query.dept5 = this.app.mongoose.Types.ObjectId(query.dept5);
  28. }
  29. return query;
  30. },
  31. // 根据【数组对象的某一属性】排序
  32. compareTo(property, sort) {
  33. return function(a, b) {
  34. const value1 = a[property];
  35. const value2 = b[property];
  36. if (sort == 'DESC') {
  37. return value2 - value1;
  38. } else if (sort == 'ASC') {
  39. return value1 - value2;
  40. }
  41. this.ctx.error('排序值错误,请输入 \'ASC\'|| \'DESC\'');
  42. };
  43. },
  44. // 响应成功
  45. success(result) {
  46. this.body = {
  47. data: result || '',
  48. code: 0,
  49. };
  50. },
  51. // 响应失败
  52. error(msg, code) {
  53. this.body = {
  54. message: msg || '数据异常',
  55. code: code || 1,
  56. };
  57. },
  58. logic(result, msg, code) {
  59. result ? this.success(result) : this.error(msg, code);
  60. },
  61. // 1.老年人健康状况-visit
  62. health() {
  63. const health = [];
  64. health.push('健康');
  65. health.push('一般');
  66. health.push('较差');
  67. return health;
  68. },
  69. // 2.老年人精神状态-visit
  70. mind() {
  71. const mind = [];
  72. mind.push('良好');
  73. mind.push('一般');
  74. mind.push('较差');
  75. return mind;
  76. },
  77. // 3.老年人安全情况-visit
  78. security() {
  79. const security = [];
  80. security.push('安全');
  81. security.push('一般');
  82. security.push('较差');
  83. return security;
  84. },
  85. // 4.巡防员性别分布统计-visit
  86. userBySex() {
  87. const userBySex = [];
  88. userBySex.push('男性巡防员');
  89. userBySex.push('女性巡防员');
  90. return userBySex;
  91. },
  92. // 5.党员群众认证状态-visit
  93. selectAuthAndLook() {
  94. const selectAuthAndLook = [];
  95. selectAuthAndLook.push('认证');
  96. selectAuthAndLook.push('未认证');
  97. return selectAuthAndLook;
  98. },
  99. // 6.巡访员巡访问方式统计-visit
  100. visitWay() {
  101. const visitWay = [];
  102. visitWay.push('电话问候');
  103. visitWay.push('上门巡访');
  104. visitWay.push('其它');
  105. return visitWay;
  106. },
  107. // 1.年龄分布-info
  108. fournums() {
  109. const fournums = [];
  110. fournums.push('60-70岁');
  111. fournums.push('70-80岁');
  112. fournums.push('80-85岁');
  113. fournums.push('85岁以上');
  114. return fournums;
  115. },
  116. // 2.性别-info
  117. sex() {
  118. const sex = [];
  119. sex.push('男');
  120. sex.push('女');
  121. return sex;
  122. },
  123. // 2-1.性别-info
  124. infoSex() {
  125. const infoSex = [];
  126. infoSex.push('老年人男性人数');
  127. infoSex.push('老年人女性人数');
  128. return infoSex;
  129. },
  130. // 3.能力评估-info
  131. ability() {
  132. const ability = [];
  133. ability.push('完全自理');
  134. ability.push('半失能');
  135. ability.push('失能');
  136. return ability;
  137. },
  138. // 4.健康状况-info
  139. oldHealth() {
  140. const oldHealth = [];
  141. oldHealth.push('健康');
  142. oldHealth.push('残疾');
  143. oldHealth.push('老年人慢性病');
  144. oldHealth.push('患重特大疾病');
  145. return oldHealth;
  146. },
  147. // 5.老年人类别-info
  148. oldType() {
  149. const oldType = [];
  150. oldType.push('失独');
  151. oldType.push('留守');
  152. oldType.push('独居');
  153. oldType.push('空巢');
  154. oldType.push('失能');
  155. oldType.push('特困');
  156. oldType.push('居家');
  157. oldType.push('重残');
  158. oldType.push('高龄');
  159. return oldType;
  160. },
  161. // 6.探访频次-info
  162. visitFrequency() {
  163. const visitFrequency = [];
  164. visitFrequency.push('每天');
  165. visitFrequency.push('每周');
  166. visitFrequency.push('每月');
  167. visitFrequency.push('每季');
  168. visitFrequency.push('其他');
  169. return visitFrequency;
  170. },
  171. // 7.收入来源-info
  172. oldIncome() {
  173. const oldIncome = [];
  174. oldIncome.push('转移性收入');
  175. oldIncome.push('财产性收入');
  176. oldIncome.push('工资性收入');
  177. oldIncome.push('家庭经营性收入');
  178. oldIncome.push('其它');
  179. return oldIncome;
  180. },
  181. // 8.可支配收入-info
  182. income() {
  183. const income = [];
  184. income.push('5000元以下');
  185. income.push('5000~10000元');
  186. income.push('10000元以上');
  187. return income;
  188. },
  189. // 9.生活经济状况-info
  190. livingCondition() {
  191. const livingCondition = [];
  192. livingCondition.push('特困供养人员');
  193. livingCondition.push('一般家庭');
  194. livingCondition.push('建档立卡贫困户');
  195. livingCondition.push('低保');
  196. return livingCondition;
  197. },
  198. // 10.关爱服务-info
  199. oldDemand() {
  200. const oldDemand = [];
  201. oldDemand.push('权益维护');
  202. oldDemand.push('文化娱乐');
  203. oldDemand.push('生产帮助');
  204. oldDemand.push('生活照料');
  205. oldDemand.push('紧急救助');
  206. oldDemand.push('医疗保健');
  207. oldDemand.push('精神慰藉');
  208. oldDemand.push('安全监护');
  209. oldDemand.push('其它');
  210. return oldDemand;
  211. },
  212. // 当前月份的数组(01,02,03...)
  213. monthNowArr() {
  214. const monthArr = [];
  215. const monthNow = new Date().getMonth() + 1;
  216. for (let i = 1; i <= monthNow; i++) {
  217. if (i < 10) {
  218. monthArr.push('0' + i);
  219. } else {
  220. monthArr.push(i.toString());
  221. }
  222. }
  223. return monthArr;
  224. },
  225. };