timer-budget.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <script lang="ts" setup>
  2. /**
  3. * @Name: timer-budget.vue
  4. * @Description: 自动化-分时预算
  5. * @Author: Cheney
  6. */
  7. import { ref } from 'vue';
  8. import SelectTmpl from './select-tmpl.vue';
  9. import TimerBudgetTable from '/@/components/TimerBudgetTable/index.vue';
  10. import XEUtils from 'xe-utils';
  11. import { userFormData } from './common';
  12. import SaveRuleDialog from '/@/views/components/auto/auto-campaigns/save-rule-dialog.vue';
  13. import { ElMessage } from 'element-plus';
  14. interface Props {
  15. data: {
  16. campaignId: string;
  17. campaignType: string;
  18. profileId: string;
  19. ruleType: number;
  20. };
  21. RuleStatusButton?: { [key: string]: any };
  22. }
  23. const props = defineProps<Props>();
  24. const emits = defineEmits(['refresh']);
  25. const formRef = ref();
  26. const { formData, submitFormData } = userFormData(props);
  27. const submitDialogVisible = ref(false);
  28. function checkConditions(rule: any, value: any, callback: any) {
  29. for (const bidList of formData.value.rule.conditions) {
  30. for (const info of bidList) {
  31. if (info.value && XEUtils.toNumber(info.value) > 0) {
  32. return callback();
  33. }
  34. }
  35. }
  36. callback(new Error('请先设置预算!'));
  37. }
  38. async function submitForm() {
  39. await submitFormData();
  40. ElMessage.success('保存成功');
  41. emits('refresh');
  42. }
  43. function handleSubmit() {
  44. formRef.value.validate(async (valid: boolean) => {
  45. if (!valid) {
  46. return;
  47. } else {
  48. if (formData.value.useTmpl) {
  49. await submit();
  50. } else {
  51. submitDialogVisible.value = true;
  52. }
  53. }
  54. });
  55. }
  56. function cancel() {
  57. emits('refresh');
  58. }
  59. </script>
  60. <template>
  61. <div class="mx-5">
  62. <div class="asj-h2">分时预算</div>
  63. <SelectTmpl :data="formData" />
  64. <el-card class="mt-3">
  65. <el-form :model="formData" label-position="top" style="margin-top: 20px" ref="formRef">
  66. <el-form-item prop="rule.conditions" :rules="[{ validator: checkConditions, trigger: 'blur'}]">
  67. <template #label>
  68. <span class="custom-title-icon"></span>
  69. <span class="asj-h3">设置预算</span>
  70. </template>
  71. <TimerBudgetTable
  72. :data="formData.rule.conditions"
  73. @click="formRef.clearValidate('rule.conditions')"
  74. :disabled="formData.useTmpl" />
  75. </el-form-item>
  76. </el-form>
  77. </el-card>
  78. <SaveRuleDialog
  79. v-model="submitDialogVisible"
  80. :formData="formData"
  81. :formRef="formRef"
  82. @submit="submitForm"
  83. />
  84. <div class="auto-page-foot">
  85. <el-button style="width: 200px" @click="cancel">取消</el-button>
  86. <el-button style="width: 200px" type="primary" @click="handleSubmit">提交</el-button>
  87. </div>
  88. </div>
  89. </template>
  90. <style scoped>
  91. .custom-title-icon {
  92. padding-right: 10px;
  93. }
  94. .custom-title-icon:before {
  95. content: '';
  96. width: 4px;
  97. height: 15px;
  98. background: #3569d6;
  99. position: absolute;
  100. transform: translateY(25%);
  101. }
  102. </style>