form-option.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. import { APPROVAL_STATUS_OPTIONS } from '@/constants/forecast'
  2. /**
  3. * 销售预测表单配置
  4. * @description 基于AvueJS的销售预测表单配置,支持新增和编辑销售预测功能
  5. */
  6. /**
  7. * 月份选项
  8. * @type {Array<SelectOption<number>>}
  9. */
  10. const MONTH_OPTIONS = [
  11. { label: '1月', value: 1 },
  12. { label: '2月', value: 2 },
  13. { label: '3月', value: 3 },
  14. { label: '4月', value: 4 },
  15. { label: '5月', value: 5 },
  16. { label: '6月', value: 6 },
  17. { label: '7月', value: 7 },
  18. { label: '8月', value: 8 },
  19. { label: '9月', value: 9 },
  20. { label: '10月', value: 10 },
  21. { label: '11月', value: 11 },
  22. { label: '12月', value: 12 }
  23. ]
  24. /**
  25. * 销售预测表单基础配置
  26. * @type {import('./types').FormOption}
  27. */
  28. export const forecastFormOption = {
  29. // 基础配置
  30. submitBtn: false, // 不显示默认提交按钮
  31. emptyBtn: false, // 不显示默认清空按钮
  32. labelWidth: 120, // 标签宽度
  33. column: [], // 列配置,将在运行时动态设置
  34. gutter: 20, // 栅格间隔
  35. menuBtn: false, // 不显示菜单按钮
  36. size: 'small', // 使用小尺寸组件
  37. // 分组配置
  38. group: [
  39. {
  40. label: '基本信息',
  41. icon: 'el-icon-document',
  42. prop: 'basic',
  43. column: [
  44. {
  45. label: '预测编码',
  46. prop: 'forecastCode',
  47. type: 'input',
  48. span: 12,
  49. placeholder: '请输入预测编码',
  50. disabled: true,
  51. display: false, // 新增时不显示
  52. rules: [{
  53. required: true,
  54. message: '请输入预测编码',
  55. trigger: 'blur'
  56. }]
  57. },
  58. {
  59. label: '年份',
  60. prop: 'year',
  61. type: 'year',
  62. span: 12,
  63. placeholder: '请选择年份',
  64. valueFormat: 'yyyy',
  65. rules: [{
  66. required: true,
  67. message: '请选择年份',
  68. trigger: 'change'
  69. }]
  70. },
  71. {
  72. label: '月份',
  73. prop: 'month',
  74. type: 'select',
  75. span: 12,
  76. placeholder: '请选择月份',
  77. dicData: MONTH_OPTIONS,
  78. rules: [{
  79. required: true,
  80. message: '请选择月份',
  81. trigger: 'change'
  82. }]
  83. },
  84. {
  85. label: '客户',
  86. prop: 'customerId',
  87. type: 'select',
  88. span: 12,
  89. slot: true,
  90. placeholder: '请选择客户',
  91. display: false,
  92. rules: [{
  93. required: true,
  94. message: '请选择客户',
  95. trigger: 'change'
  96. }]
  97. },
  98. {
  99. label: '客户编码',
  100. prop: 'customerCode',
  101. type: 'input',
  102. span: 12,
  103. placeholder: '选择客户后自动填充',
  104. disabled: true,
  105. display: false
  106. },
  107. {
  108. label: '客户名称',
  109. prop: 'customerName',
  110. type: 'input',
  111. span: 12,
  112. placeholder: '选择客户后自动填充',
  113. disabled: true
  114. }
  115. ]
  116. },
  117. {
  118. label: '产品信息',
  119. icon: 'el-icon-goods',
  120. prop: 'product',
  121. column: [
  122. {
  123. label: '品牌ID',
  124. prop: 'brandId',
  125. type: 'input',
  126. span: 12,
  127. placeholder: '请输入品牌ID',
  128. rules: [{
  129. required: true,
  130. message: '请输入品牌ID',
  131. trigger: 'blur'
  132. }]
  133. },
  134. {
  135. label: '品牌编码',
  136. prop: 'brandCode',
  137. type: 'input',
  138. span: 12,
  139. placeholder: '请输入品牌编码',
  140. rules: [{
  141. required: true,
  142. message: '请输入品牌编码',
  143. trigger: 'blur'
  144. }]
  145. },
  146. {
  147. label: '品牌名称',
  148. prop: 'brandName',
  149. type: 'input',
  150. span: 12,
  151. placeholder: '请输入品牌名称',
  152. rules: [{
  153. required: true,
  154. message: '请输入品牌名称',
  155. trigger: 'blur'
  156. }]
  157. },
  158. {
  159. label: '物料',
  160. prop: 'itemId',
  161. type: 'select',
  162. span: 12,
  163. slot: true,
  164. placeholder: '请选择物料',
  165. rules: [{
  166. required: true,
  167. message: '请选择物料',
  168. trigger: 'change'
  169. }]
  170. },
  171. {
  172. label: '物料编码',
  173. prop: 'itemCode',
  174. type: 'input',
  175. span: 12,
  176. placeholder: '选择物料后自动填充',
  177. disabled: true
  178. },
  179. {
  180. label: '物料名称',
  181. prop: 'itemName',
  182. type: 'input',
  183. span: 12,
  184. placeholder: '选择物料后自动填充',
  185. disabled: true
  186. },
  187. {
  188. label: '物料规格',
  189. prop: 'itemSpecs',
  190. type: 'input',
  191. span: 12,
  192. placeholder: '选择物料后自动填充',
  193. disabled: true
  194. },
  195. {
  196. label: '当前库存',
  197. prop: 'currentInventory',
  198. type: 'number',
  199. span: 12,
  200. placeholder: '请输入当前库存',
  201. min: 0,
  202. precision: 0,
  203. step: 1,
  204. controlsPosition: 'right',
  205. rules: [{
  206. required: true,
  207. message: '请输入当前库存',
  208. trigger: 'blur'
  209. }, {
  210. type: 'number',
  211. min: 0,
  212. message: '当前库存不能小于0',
  213. trigger: 'blur'
  214. }]
  215. },
  216. {
  217. label: '预测数量',
  218. prop: 'forecastQuantity',
  219. type: 'number',
  220. span: 12,
  221. placeholder: '请输入预测数量',
  222. min: 1,
  223. precision: 0,
  224. step: 1,
  225. controlsPosition: 'right',
  226. rules: [{
  227. required: true,
  228. message: '请输入预测数量',
  229. trigger: 'blur'
  230. }, {
  231. type: 'number',
  232. min: 1,
  233. message: '预测数量不能小于1',
  234. trigger: 'blur'
  235. }]
  236. }
  237. ]
  238. },
  239. {
  240. label: '审批信息',
  241. icon: 'el-icon-check',
  242. prop: 'approval',
  243. display: false, // 新增时不显示
  244. column: [
  245. {
  246. label: '审批状态',
  247. prop: 'approvalStatus',
  248. type: 'select',
  249. span: 8,
  250. placeholder: '审批状态',
  251. dicData: APPROVAL_STATUS_OPTIONS,
  252. disabled: true
  253. },
  254. {
  255. label: '审批人',
  256. prop: 'approver',
  257. type: 'input',
  258. span: 8,
  259. placeholder: '审批人',
  260. disabled: true
  261. },
  262. {
  263. label: '审批时间',
  264. prop: 'approvalTime',
  265. type: 'datetime',
  266. span: 8,
  267. placeholder: '审批时间',
  268. disabled: true,
  269. valueFormat: 'yyyy-MM-dd HH:mm:ss'
  270. },
  271. {
  272. label: '审批备注',
  273. prop: 'approvalRemark',
  274. type: 'textarea',
  275. span: 24,
  276. placeholder: '审批备注',
  277. disabled: true,
  278. minRows: 2,
  279. maxRows: 4
  280. }
  281. ]
  282. }
  283. ]
  284. }
  285. /**
  286. * 获取表单配置
  287. * @description 根据编辑模式动态生成AvueJS表单配置,支持字段显示/隐藏和禁用状态调整
  288. * @param {boolean} [isEdit=false] - 是否为编辑模式
  289. * @returns {import('./types').FormOption} AvueJS表单配置对象
  290. * @throws {Error} 当配置对象结构异常时抛出错误
  291. * @example
  292. * // 获取新增模式的表单配置
  293. * const createOption = getFormOption(false)
  294. *
  295. * // 获取编辑模式的表单配置
  296. * const editOption = getFormOption(true)
  297. */
  298. export function getFormOption(isEdit = false) {
  299. // 深拷贝配置对象
  300. const option = JSON.parse(JSON.stringify(forecastFormOption))
  301. if (isEdit) {
  302. adjustFieldsForEditMode(option)
  303. } else {
  304. adjustFieldsForCreateMode(option)
  305. }
  306. return option
  307. }
  308. /**
  309. * 调整编辑模式下的字段配置
  310. * @description 修改表单配置以适应编辑模式,显示审批信息、预测编码,禁用关键字段
  311. * @param {import('./types').FormOption} option - 表单配置对象
  312. * @returns {void} 直接修改传入的配置对象,无返回值
  313. * @private
  314. */
  315. function adjustFieldsForEditMode(option) {
  316. option.group?.forEach(group => {
  317. // 显示审批信息分组
  318. if (group.prop === 'approval') {
  319. group.display = true
  320. }
  321. group.column.forEach(field => {
  322. // 显示预测编码字段
  323. if (field.prop === 'forecastCode') {
  324. field.display = true
  325. }
  326. // 年份和月份在编辑模式下禁用
  327. if (field.prop === 'year' || field.prop === 'month') {
  328. field.disabled = true
  329. }
  330. // 品牌在编辑模式下禁用
  331. if (field.prop === 'brandId') {
  332. field.disabled = true
  333. }
  334. })
  335. })
  336. }
  337. /**
  338. * 调整新增模式下的字段配置
  339. * @description 修改表单配置以适应新增模式,隐藏审批信息和预测编码字段
  340. * @param {import('./types').FormOption} option - 表单配置对象
  341. * @returns {void} 直接修改传入的配置对象,无返回值
  342. * @private
  343. */
  344. function adjustFieldsForCreateMode(option) {
  345. option.group?.forEach(group => {
  346. // 隐藏审批信息分组
  347. if (group.prop === 'approval') {
  348. group.display = false
  349. }
  350. group.column.forEach(field => {
  351. // 隐藏预测编码字段
  352. if (field.prop === 'forecastCode') {
  353. field.display = false
  354. }
  355. })
  356. })
  357. }