class Partner { final int id; final String? code; final String name; final String type; // supplier | customer | supplier,customer(两者) final String? contact; final String? phone; final String? address; final String? bankAccount; final double balance; // 期初余额(存档字段,不参与应收应付聚合) final String status; final String? remark; const Partner({ required this.id, this.code, required this.name, required this.type, this.contact, this.phone, this.address, this.bankAccount, this.balance = 0, this.status = 'enabled', this.remark, }); /// 类型徽章文案(原型 b-供应商/b-客户/b-两者):SET 双值 = 两者 String get typeLabel { final isSupplier = type.contains('supplier'); final isCustomer = type.contains('customer'); if (isSupplier && isCustomer) return '两者'; return isCustomer ? '客户' : '供应商'; } factory Partner.fromJson(Map json) => Partner( id: (json['id'] as num).toInt(), code: json['code'] as String?, name: json['name'] as String, type: json['type'] as String, contact: json['contact'] as String?, phone: json['phone'] as String?, address: json['address'] as String?, bankAccount: json['bank_account'] as String?, balance: (json['balance'] as num?)?.toDouble() ?? 0, status: json['status'] as String? ?? 'enabled', remark: json['remark'] as String?, ); Map toJson() => { 'name': name, 'type': type, if (code != null) 'code': code, if (contact != null) 'contact': contact, if (phone != null) 'phone': phone, if (address != null) 'address': address, if (bankAccount != null) 'bank_account': bankAccount, if (remark != null) 'remark': remark, }; }