client.js 2.0 KB

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