bill_attachment.dart 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /// 单据附件模型(对应 MgrServer MongoDB erp_bill_atts 文档)
  2. class BillAttachment {
  3. final String id;
  4. final String bilId;
  5. final String bilNo;
  6. final int srcItm; // 0=表头附件, >0=表身行号
  7. final int itm; // 附件序号
  8. final String fileName;
  9. final String ext;
  10. final String fileId; // GridFS 文件 ID
  11. final int tag;
  12. final String effDd;
  13. final String usr;
  14. const BillAttachment({
  15. required this.id,
  16. required this.bilId,
  17. required this.bilNo,
  18. required this.srcItm,
  19. required this.itm,
  20. required this.fileName,
  21. required this.ext,
  22. required this.fileId,
  23. required this.tag,
  24. required this.effDd,
  25. required this.usr,
  26. });
  27. factory BillAttachment.fromJson(Map<String, dynamic> json) {
  28. return BillAttachment(
  29. id: (json['_id'] is Map<String, dynamic>
  30. ? (json['_id']['\$oid'] as String?)
  31. : json['_id'] as String?) ??
  32. '',
  33. bilId: json['BIL_ID'] as String? ?? '',
  34. bilNo: json['BIL_NO'] as String? ?? '',
  35. srcItm: json['SRCITM'] as int? ?? 0,
  36. itm: json['ITM'] as int? ?? 1,
  37. fileName: json['FILENAME'] as String? ?? '',
  38. ext: json['EXT'] as String? ?? '',
  39. fileId: (json['FILEID'] is Map<String, dynamic>
  40. ? (json['FILEID']['\$oid'] as String?)
  41. : json['FILEID'] as String?) ??
  42. '',
  43. tag: json['TAG'] as int? ?? 1,
  44. effDd: json['EFF_DD'] as String? ?? '',
  45. usr: json['USR'] as String? ?? '',
  46. );
  47. }
  48. /// 是否是表头附件
  49. bool get isHeader => srcItm == 0;
  50. /// 是否是表身附件
  51. bool get isBody => srcItm > 0;
  52. /// 文件图标(根据扩展名)
  53. String get fileIcon {
  54. switch (ext.toLowerCase()) {
  55. case 'pdf':
  56. return 'pdf';
  57. case 'doc':
  58. case 'docx':
  59. return 'doc';
  60. case 'xls':
  61. case 'xlsx':
  62. return 'xls';
  63. case 'jpg':
  64. case 'jpeg':
  65. case 'png':
  66. case 'gif':
  67. case 'bmp':
  68. return 'image';
  69. default:
  70. return 'file';
  71. }
  72. }
  73. }