SeoMarketPlanForm.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <a-spin :spinning="confirmLoading">
  3. <JFormContainer :disabled="disabled">
  4. <template #detail>
  5. <a-form ref="formRef" class="antd-modal-form" :labelCol="labelCol" :wrapperCol="wrapperCol">
  6. <a-row>
  7. <a-col :span="24">
  8. <a-form-item label="套餐类型" v-bind="validateInfos.marketType">
  9. <j-dict-select-tag v-model:value="formData.marketType" dictCode="dict_market_type" placeholder="请选择套餐类型" allow-clear />
  10. </a-form-item>
  11. </a-col>
  12. <a-col :span="24">
  13. <a-form-item label="套餐名称" v-bind="validateInfos.planName">
  14. <a-input v-model:value="formData.planName" placeholder="请输入套餐名称" allow-clear />
  15. </a-form-item>
  16. </a-col>
  17. <a-col :span="24">
  18. <a-form-item label="关键词数量" v-bind="validateInfos.keywordCount">
  19. <a-input-number v-model:value="formData.keywordCount" placeholder="请输入关键词数量" style="width: 100%" />
  20. </a-form-item>
  21. </a-col>
  22. <a-col :span="24">
  23. <a-form-item label="关键词达标目标" v-bind="validateInfos.target">
  24. <a-input-number v-model:value="formData.target" placeholder="请输入关键词达标目标" style="width: 100%" />
  25. </a-form-item>
  26. </a-col>
  27. <a-col :span="24">
  28. <a-form-item label="服务时间" v-bind="validateInfos.serviceTime">
  29. <a-input-number v-model:value="formData.serviceTime" placeholder="请输入服务时间" style="width: 100%" />
  30. </a-form-item>
  31. </a-col>
  32. <a-col :span="24">
  33. <a-form-item label="价格" v-bind="validateInfos.price">
  34. <a-input-number v-model:value="formData.price" placeholder="请输入价格" style="width: 100%" />
  35. </a-form-item>
  36. </a-col>
  37. </a-row>
  38. </a-form>
  39. </template>
  40. </JFormContainer>
  41. </a-spin>
  42. </template>
  43. <script lang="ts" setup>
  44. import { ref, reactive, defineExpose, nextTick, defineProps, computed, onMounted } from 'vue';
  45. import { defHttp } from '/@/utils/http/axios';
  46. import { useMessage } from '/@/hooks/web/useMessage';
  47. import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
  48. import { getValueType } from '/@/utils';
  49. import { saveOrUpdate } from '../SeoMarketPlan.api';
  50. import { Form } from 'ant-design-vue';
  51. import JFormContainer from '/@/components/Form/src/container/JFormContainer.vue';
  52. const props = defineProps({
  53. formDisabled: { type: Boolean, default: false },
  54. formData: { type: Object, default: () => ({}) },
  55. formBpm: { type: Boolean, default: true },
  56. });
  57. const formRef = ref();
  58. const useForm = Form.useForm;
  59. const emit = defineEmits(['register', 'ok']);
  60. const formData = reactive<Record<string, any>>({
  61. id: '',
  62. marketType: '',
  63. planName: '',
  64. keywordCount: undefined,
  65. target: undefined,
  66. serviceTime: undefined,
  67. price: undefined,
  68. });
  69. const { createMessage } = useMessage();
  70. const labelCol = ref<any>({ xs: { span: 24 }, sm: { span: 5 } });
  71. const wrapperCol = ref<any>({ xs: { span: 24 }, sm: { span: 16 } });
  72. const confirmLoading = ref<boolean>(false);
  73. //表单验证
  74. const validatorRules = reactive({
  75. marketType: [{ required: true, message: '请输入套餐类型!' }],
  76. planName: [{ required: true, message: '请输入套餐名称!' }],
  77. keywordCount: [{ required: true, message: '请输入关键词数量!' }],
  78. target: [{ required: true, message: '请输入关键词达标目标!' }],
  79. serviceTime: [{ required: true, message: '请输入服务时间!' }],
  80. price: [{ required: true, message: '请输入价格!' }],
  81. });
  82. const { resetFields, validate, validateInfos } = useForm(formData, validatorRules, { immediate: false });
  83. // 表单禁用
  84. const disabled = computed(() => {
  85. if (props.formBpm === true) {
  86. if (props.formData.disabled === false) {
  87. return false;
  88. } else {
  89. return true;
  90. }
  91. }
  92. return props.formDisabled;
  93. });
  94. /**
  95. * 新增
  96. */
  97. function add() {
  98. edit({});
  99. }
  100. /**
  101. * 编辑
  102. */
  103. function edit(record) {
  104. nextTick(() => {
  105. resetFields();
  106. const tmpData = {};
  107. Object.keys(formData).forEach((key) => {
  108. if (record.hasOwnProperty(key)) {
  109. tmpData[key] = record[key];
  110. }
  111. });
  112. //赋值
  113. Object.assign(formData, tmpData);
  114. });
  115. }
  116. /**
  117. * 提交数据
  118. */
  119. async function submitForm() {
  120. // 触发表单验证
  121. await validate();
  122. confirmLoading.value = true;
  123. const isUpdate = ref<boolean>(false);
  124. //时间格式化
  125. let model = formData;
  126. if (model.id) {
  127. isUpdate.value = true;
  128. }
  129. //循环数据
  130. for (let data in model) {
  131. //如果该数据是数组并且是字符串类型
  132. if (model[data] instanceof Array) {
  133. let valueType = getValueType(formRef.value.getProps, data);
  134. //如果是字符串类型的需要变成以逗号分割的字符串
  135. if (valueType === 'string') {
  136. model[data] = model[data].join(',');
  137. }
  138. }
  139. }
  140. await saveOrUpdate(model, isUpdate.value)
  141. .then((res) => {
  142. if (res.success) {
  143. createMessage.success(res.message);
  144. emit('ok');
  145. } else {
  146. createMessage.warning(res.message);
  147. }
  148. })
  149. .finally(() => {
  150. confirmLoading.value = false;
  151. });
  152. }
  153. defineExpose({
  154. add,
  155. edit,
  156. submitForm,
  157. });
  158. </script>
  159. <style lang="less" scoped>
  160. .antd-modal-form {
  161. padding: 14px;
  162. }
  163. </style>