client.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  4. // 客户
  5. const Client = {
  6. name: {
  7. type: String,
  8. required: true,
  9. maxLength: 200,
  10. field: { label: '企业名称', filter: true, required: true },
  11. },
  12. legal: {
  13. type: String,
  14. required: true,
  15. maxLength: 200,
  16. field: { label: '联系人', filter: true, required: true },
  17. },
  18. mobile: {
  19. type: String,
  20. required: true,
  21. maxLength: 200,
  22. field: { label: '联系电话', filter: true, required: true },
  23. },
  24. address: {
  25. type: String,
  26. maxLength: 200,
  27. field: { label: '地址' },
  28. }, // 存储内容
  29. account_bank: {
  30. type: String,
  31. maxLength: 200,
  32. field: { label: '开户行' },
  33. },
  34. account: { type: String, maxLength: 200, field: { label: '银行账号' } },
  35. taxes_no: { type: String, maxLength: 200, field: { label: '税号' } },
  36. type: {
  37. type: String,
  38. maxLength: 200,
  39. field: {
  40. label: '类型',
  41. notable: true,
  42. noform: true,
  43. list: [
  44. { label: '客户', value: '客户' },
  45. { label: '供应商', value: '供应商' },
  46. ],
  47. },
  48. },
  49. status: {
  50. type: String,
  51. maxLength: 200,
  52. default: '0',
  53. field: {
  54. label: '状态',
  55. filter: 'select',
  56. type: 'select',
  57. format: (i => (i === '0' ? '使用' : '禁用')).toString(),
  58. list: [
  59. { label: '使用', value: '0' },
  60. { label: '禁用', value: '1' },
  61. ],
  62. },
  63. }, // 状态:0=>使用;1禁用
  64. };
  65. const schema = new Schema(Client, { toJSON: { virtuals: true } });
  66. schema.index({ id: 1 });
  67. schema.index({ name: 1 });
  68. schema.index({ legal: 1 });
  69. schema.index({ mobile: 1 });
  70. schema.index({ type: 1 });
  71. schema.plugin(metaPlugin);
  72. module.exports = app => {
  73. const { mongoose } = app;
  74. return mongoose.model('Client', schema, 'client');
  75. };