formSchemas.ts 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /**
  2. * 表单 Schema 注册(P2 写入能力)
  3. * - entity 形态模块:字段清单驱动通用表单
  4. * - bill 形态模块:通用单据表单(表头 + 明细行,对齐 DepotBillSaveDTO)
  5. * 未登记 schema 的模块隐藏新增入口,仅保留列表/详情只读能力。
  6. */
  7. import type { DictKind } from '@/api/modules/dict'
  8. export type FieldType = 'input' | 'number' | 'select' | 'date' | 'textarea' | 'switch'
  9. export interface FieldDef {
  10. /** 提交字段名 */
  11. key: string
  12. label: string
  13. type: FieldType
  14. required?: boolean
  15. placeholder?: string
  16. /** select 类型:字典来源 */
  17. dictKind?: DictKind
  18. /** select 类型:静态选项 */
  19. options?: { label: string; value: any }[]
  20. /** 默认值 */
  21. defaultValue?: any
  22. }
  23. /** entity 模块 schema(基础资料 + 商品资料) */
  24. export const ENTITY_SCHEMAS: Record<string, FieldDef[]> = {
  25. supplier: [
  26. { key: 'name', label: '供应商名称', type: 'input', required: true },
  27. { key: 'contacts', label: '联系人', type: 'input' },
  28. { key: 'phoneNum', label: '电话', type: 'input' },
  29. { key: 'telephone', label: '手机', type: 'input' },
  30. { key: 'email', label: '邮箱', type: 'input' },
  31. { key: 'address', label: '地址', type: 'textarea' },
  32. { key: 'taxNum', label: '税号', type: 'input' },
  33. { key: 'bankName', label: '开户行', type: 'input' },
  34. { key: 'accountNumber', label: '账号', type: 'input' },
  35. { key: 'taxRate', label: '税率(%)', type: 'number' },
  36. { key: 'enabled', label: '启用', type: 'switch', defaultValue: 1 }
  37. ],
  38. customer: [
  39. { key: 'name', label: '客户名称', type: 'input', required: true },
  40. { key: 'contacts', label: '联系人', type: 'input' },
  41. { key: 'phoneNum', label: '电话', type: 'input' },
  42. { key: 'address', label: '地址', type: 'textarea' },
  43. { key: 'taxNum', label: '税号', type: 'input' },
  44. { key: 'taxRate', label: '税率(%)', type: 'number' },
  45. { key: 'enabled', label: '启用', type: 'switch', defaultValue: 1 }
  46. ],
  47. member: [
  48. { key: 'name', label: '会员名称', type: 'input', required: true },
  49. { key: 'phoneNum', label: '手机号', type: 'input' },
  50. { key: 'address', label: '地址', type: 'textarea' },
  51. { key: 'enabled', label: '启用', type: 'switch', defaultValue: 1 }
  52. ],
  53. depot: [
  54. { key: 'name', label: '仓库名称', type: 'input', required: true },
  55. {
  56. key: 'depotType', label: '仓库类型', type: 'select', required: true,
  57. options: [
  58. { label: '自有库', value: '自有库' },
  59. { label: '三方库', value: '三方库' }
  60. ]
  61. },
  62. { key: 'address', label: '地址', type: 'input' },
  63. { key: 'principal', label: '负责人', type: 'input' },
  64. { key: 'warehousing', label: '入库费', type: 'number' },
  65. { key: 'truckage', label: '运费', type: 'number' },
  66. { key: 'isDefault', label: '默认仓库', type: 'switch', defaultValue: 0 },
  67. { key: 'enabled', label: '启用', type: 'switch', defaultValue: 1 }
  68. ],
  69. account: [
  70. { key: 'name', label: '账户名称', type: 'input', required: true },
  71. { key: 'serialNo', label: '编号', type: 'input' },
  72. { key: 'initialAmount', label: '期初金额', type: 'number' },
  73. { key: 'isDefault', label: '默认账户', type: 'switch', defaultValue: 0 },
  74. { key: 'enabled', label: '启用', type: 'switch', defaultValue: 1 }
  75. ],
  76. person: [
  77. { key: 'name', label: '姓名', type: 'input', required: true },
  78. { key: 'type', label: '类型', type: 'input' },
  79. { key: 'enabled', label: '启用', type: 'switch', defaultValue: 1 }
  80. ],
  81. inoutItem: [
  82. { key: 'name', label: '项目名称', type: 'input', required: true },
  83. { key: 'type', label: '类型(收入/支出)', type: 'input' },
  84. { key: 'enabled', label: '启用', type: 'switch', defaultValue: 1 }
  85. ],
  86. category: [
  87. { key: 'name', label: '类别名称', type: 'input', required: true },
  88. { key: 'serialNo', label: '编号', type: 'input' },
  89. { key: 'sort', label: '排序', type: 'number' },
  90. { key: 'remark', label: '备注', type: 'textarea' }
  91. ],
  92. material: [
  93. { key: 'name', label: '商品名称', type: 'input', required: true },
  94. { key: 'barCode', label: '条码', type: 'input' },
  95. { key: 'categoryId', label: '商品类别', type: 'select', dictKind: 'category' },
  96. { key: 'unitId', label: '单位', type: 'select', dictKind: 'unit' },
  97. { key: 'standard', label: '规格', type: 'input' },
  98. { key: 'remark', label: '备注', type: 'textarea' },
  99. { key: 'enabled', label: '启用', type: 'switch', defaultValue: 1 }
  100. ],
  101. unit: [
  102. { key: 'name', label: '单位名称', type: 'input', required: true },
  103. { key: 'basicUnit', label: '基本单位', type: 'input' },
  104. { key: 'enabled', label: '启用', type: 'switch', defaultValue: 1 }
  105. ],
  106. interestRate: [
  107. { key: 'name', label: '名称', type: 'input', required: true },
  108. { key: 'rate', label: '日利率(%)', type: 'number', required: true },
  109. { key: 'remark', label: '备注', type: 'textarea' }
  110. ],
  111. contract: [
  112. { key: 'contractNo', label: '合同号', type: 'input', required: true },
  113. { key: 'contractName', label: '合同名称', type: 'input' },
  114. {
  115. key: 'contractType', label: '合同类型', type: 'select', required: true,
  116. options: [
  117. { label: '采购', value: 'PURCHASE' },
  118. { label: '销售', value: 'SALES' }
  119. ]
  120. },
  121. { key: 'organName', label: '往来单位', type: 'input' },
  122. { key: 'signDate', label: '签订日期', type: 'date' },
  123. { key: 'totalMoney', label: '合同金额', type: 'number' },
  124. { key: 'remark', label: '备注', type: 'textarea' },
  125. { key: 'enabled', label: '启用', type: 'switch', defaultValue: 1 }
  126. ],
  127. vehicle: [
  128. { key: 'vehicleNo', label: '车牌号', type: 'input', required: true },
  129. { key: 'driverName', label: '司机姓名', type: 'input' },
  130. { key: 'driverPhone', label: '联系电话', type: 'input' },
  131. { key: 'vehicleType', label: '车型', type: 'input' },
  132. { key: 'loadWeight', label: '载重(吨)', type: 'number' },
  133. { key: 'remark', label: '备注', type: 'textarea' },
  134. { key: 'enabled', label: '启用', type: 'switch', defaultValue: 1 }
  135. ]
  136. }
  137. /** 通用单据表头 schema(进销存单据:采购/销售/零售/仓库域,对齐 DepotBillSaveDTO) */
  138. export const BILL_HEAD_FIELDS: FieldDef[] = [
  139. { key: 'organId', label: '往来单位', type: 'select', required: true },
  140. { key: 'accountId', label: '结算账户', type: 'select', dictKind: 'account' },
  141. { key: 'operTime', label: '单据日期', type: 'date', required: true },
  142. { key: 'discount', label: '折扣率(%)', type: 'number' },
  143. { key: 'otherMoney', label: '其它费用', type: 'number' },
  144. { key: 'remark', label: '备注', type: 'textarea' }
  145. ]
  146. /** 单据明细行字段(含钢材追溯字段:炉号/批号/合同号/规格 + 收发重量 + 运费) */
  147. export interface BillItemDraft {
  148. materialId?: string
  149. materialName?: string
  150. barCode?: string
  151. materialUnit?: string
  152. depotId?: string
  153. depotName?: string
  154. operNumber?: number
  155. unitPrice?: number
  156. allPrice?: number
  157. furnaceNo?: string
  158. batchNo?: string
  159. contractNo?: string
  160. standard?: string
  161. shipWeight?: number
  162. recvWeight?: number
  163. freightUnitPrice?: number
  164. freightFee?: number
  165. remark?: string
  166. }
  167. /** 需要明细行的单据模块(DepotBill 系) */
  168. export const BILL_ITEM_MODULES = new Set([
  169. 'purchaseApply', 'purchaseOrder', 'purchaseIn', 'purchaseBack',
  170. 'salesOrder', 'salesOut', 'salesBack',
  171. 'retailOut', 'retailBack',
  172. 'otherIn', 'otherOut', 'allocation', 'assemble', 'disassemble',
  173. 'produceIn', 'checkEnter', 'replay',
  174. 'productionOrder'
  175. ])
  176. export function getEntitySchema(moduleKey: string): FieldDef[] | undefined {
  177. return ENTITY_SCHEMAS[moduleKey]
  178. }
  179. /** 单据表头差异化扩展字段(在通用 BILL_HEAD_FIELDS 后追加;缺省模块回退空数组) */
  180. export const BILL_HEAD_EXT_FIELDS: Record<string, FieldDef[]> = {
  181. purchaseOrder: [
  182. { key: 'contractNo', label: '合同号', type: 'select', dictKind: 'contract' },
  183. { key: 'contractOrderNo', label: '合同订单号', type: 'input' }
  184. ],
  185. purchaseIn: [
  186. { key: 'contractNo', label: '合同号', type: 'select', dictKind: 'contract' },
  187. { key: 'contractOrderNo', label: '合同订单号', type: 'input' },
  188. { key: 'paybackDays', label: '回款天数', type: 'number' },
  189. { key: 'interest', label: '利息', type: 'number' },
  190. { key: 'storageUnitPrice', label: '仓储单价', type: 'number' },
  191. { key: 'storageFee', label: '仓储费', type: 'number' },
  192. { key: 'vehicleNo', label: '车牌号', type: 'select', dictKind: 'vehicle' },
  193. { key: 'driverName', label: '司机姓名', type: 'input' },
  194. { key: 'driverPhone', label: '联系电话', type: 'input' }
  195. ],
  196. salesOut: [
  197. { key: 'contractNo', label: '合同号', type: 'select', dictKind: 'contract' },
  198. { key: 'invoiceNo', label: '发票', type: 'input' },
  199. { key: 'paybackDate', label: '回款日期', type: 'date' },
  200. { key: 'paybackMoney', label: '回款金额', type: 'number' },
  201. { key: 'vehicleNo', label: '车牌号', type: 'select', dictKind: 'vehicle' },
  202. { key: 'driverName', label: '司机姓名', type: 'input' },
  203. { key: 'driverPhone', label: '联系电话', type: 'input' }
  204. ]
  205. }
  206. export function getBillHeadExtFields(moduleKey: string): FieldDef[] {
  207. return BILL_HEAD_EXT_FIELDS[moduleKey] || []
  208. }