AddRuleGroupDialog.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <el-dialog
  3. title="新增规则组"
  4. :visible.sync="innerVisible"
  5. width="560px"
  6. :close-on-click-modal="false"
  7. @close="reset"
  8. >
  9. <el-form ref="form" :model="form" label-width="140px" label-position="right">
  10. <el-form-item label="规则组卡种类型" required>
  11. <el-select
  12. v-model="form.cardType"
  13. placeholder="请选择"
  14. style="width: 100%"
  15. @change="form.ruleGroupId = ''"
  16. >
  17. <el-option label="借记卡圈客规则" value="debitCard" />
  18. <el-option label="信用卡圈客规则" value="creditCard" />
  19. </el-select>
  20. </el-form-item>
  21. <el-form-item label="规则组" required>
  22. <el-select
  23. v-model="form.ruleGroupId"
  24. placeholder="请选择"
  25. filterable
  26. :filter-method="filterRuleGroup"
  27. style="width: 100%"
  28. no-data-text="暂无可选规则组"
  29. no-match-text="未找到匹配的规则组"
  30. >
  31. <el-option
  32. v-for="rg in filteredGroups"
  33. :key="rg.id"
  34. :label="`${rg.id}(${rg.name})`"
  35. :value="rg.id"
  36. />
  37. </el-select>
  38. <div class="hint">仅展示「已上线」状态且与卡种类型匹配的规则组</div>
  39. </el-form-item>
  40. </el-form>
  41. <div slot="footer" class="dialog-footer">
  42. <el-button @click="handleCancel">取 消</el-button>
  43. <el-button type="primary" @click="handleSave">保 存</el-button>
  44. </div>
  45. </el-dialog>
  46. </template>
  47. <script>
  48. import ruleGroupStore from '@/store/ruleGroupStore'
  49. export default {
  50. name: 'AddRuleGroupDialog',
  51. props: {
  52. visible: { type: Boolean, default: false },
  53. excludeIds: { type: Array, default: () => [] }
  54. },
  55. data() {
  56. return {
  57. form: { cardType: '', ruleGroupId: '' },
  58. filterKeyword: ''
  59. }
  60. },
  61. computed: {
  62. innerVisible: {
  63. get() { return this.visible },
  64. set(v) { this.$emit('update:visible', v) }
  65. },
  66. filteredGroups() {
  67. const all = ruleGroupStore.list.filter((rg) => rg.status === 'online')
  68. return all.filter((rg) => {
  69. if (this.form.cardType && rg.type !== this.form.cardType) return false
  70. if (this.excludeIds.includes(rg.id)) return false
  71. if (this.filterKeyword) {
  72. const k = this.filterKeyword.toLowerCase()
  73. if (!rg.id.toLowerCase().includes(k) && !rg.name.toLowerCase().includes(k)) {
  74. return false
  75. }
  76. }
  77. return true
  78. })
  79. }
  80. },
  81. watch: {
  82. visible(v) {
  83. if (v) this.reset()
  84. }
  85. },
  86. methods: {
  87. reset() {
  88. this.form = { cardType: '', ruleGroupId: '' }
  89. this.filterKeyword = ''
  90. },
  91. filterRuleGroup(k) {
  92. this.filterKeyword = k
  93. },
  94. handleSave() {
  95. if (!this.form.cardType) {
  96. this.$message.error('请选择规则组卡种类型')
  97. return
  98. }
  99. if (!this.form.ruleGroupId) {
  100. this.$message.error('请选择规则组')
  101. return
  102. }
  103. const rg = ruleGroupStore.getById(this.form.ruleGroupId)
  104. if (!rg) {
  105. this.$message.error('所选规则组不存在')
  106. return
  107. }
  108. this.$emit('save', {
  109. id: rg.id,
  110. name: rg.name,
  111. description: rg.description || '-',
  112. logic: rg.logic,
  113. ruleCount: (rg.rules || []).length
  114. })
  115. this.innerVisible = false
  116. },
  117. handleCancel() {
  118. this.innerVisible = false
  119. }
  120. }
  121. }
  122. </script>
  123. <style scoped>
  124. .hint { color: #909399; font-size: 12px; margin-top: 4px; }
  125. .dialog-footer { text-align: center; }
  126. </style>