formConfig.tsx 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { convertEnumArr } from "@/utils";
  2. import { ProFormColumnsType } from "@ant-design/pro-components";
  3. function formConfig(props: { paragraphList?: any[], enumList?: { [key: string]: any }, paymentType: any[] }): ProFormColumnsType<{
  4. name: string;
  5. state: string;
  6. }>[] {
  7. let { paragraphList, enumList, paymentType } = props
  8. // console.log("paragraphList",paragraphList)
  9. return [
  10. {
  11. title: '开始付费段落',
  12. dataIndex: 'beginPayChapterNo',
  13. valueType: 'select',
  14. fieldProps: {
  15. showSearch: true, placeholder: '请选择开始收费段落'
  16. },
  17. formItemProps: {
  18. style: { marginBottom: 15 },
  19. rules: [
  20. {
  21. required: true,
  22. message: '此项为必填项',
  23. },
  24. ],
  25. },
  26. valueEnum: () => {
  27. return new Map(paragraphList?.map(item => [item.chapterNo, item.chapterName]))
  28. }
  29. },
  30. {
  31. title: 'VIP阅读',
  32. dataIndex: 'vipFree',
  33. valueType: 'segmented',
  34. formItemProps: {
  35. style: { marginBottom: 15 },
  36. },
  37. valueEnum: () => {
  38. let arr = enumList?.VIP_FREE?.values
  39. return new Map(arr?.map(({ value, description }: any) => [value, description]))
  40. }
  41. },
  42. {
  43. title: '付费方式',
  44. dataIndex: 'paymentType',
  45. valueType: 'checkbox',
  46. fieldProps: {
  47. onChange: (value) => {
  48. paymentType[1](value)
  49. }
  50. },
  51. formItemProps: {
  52. style: { marginBottom: 15 },
  53. },
  54. valueEnum: () => {
  55. let arr = enumList?.PAYMENT_TYPE?.values
  56. let obj = {}
  57. if (paymentType?.[0]?.includes('0')) {
  58. obj = { "1": { disabled: true }, '2': { disabled: true }, '3': { disabled: true } }
  59. }
  60. if (paymentType?.[0]?.join().match(/[123]/g)) {
  61. obj = { "0": { disabled: true } }
  62. }
  63. let enumObj = convertEnumArr(arr, obj)
  64. return enumObj
  65. }
  66. },
  67. {
  68. title: '收费金额',
  69. dataIndex: 'paymentAmount',
  70. valueType: 'money',
  71. hideInForm: !paymentType?.[0]?.includes('2'),
  72. formItemProps: {
  73. style: { marginBottom: 15 },
  74. },
  75. },
  76. {
  77. title: '收费书币',
  78. dataIndex: 'paymentCoin',
  79. valueType: 'digit',
  80. hideInForm: !paymentType?.[0]?.join().match(/[13]/g),
  81. formItemProps: {
  82. style: { marginBottom: 15 },
  83. },
  84. },
  85. {
  86. title: '备注',
  87. dataIndex: 'remark',
  88. valueType: 'textarea',
  89. formItemProps: {
  90. style: { marginBottom: 15 },
  91. },
  92. }
  93. ]
  94. }
  95. export default formConfig