ruleGroupStore.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // 规则组数据 store(demo 用,刷新后重置为初始种子数据)
  2. import Vue from 'vue'
  3. const now = () => {
  4. const d = new Date()
  5. const pad = (n) => String(n).padStart(2, '0')
  6. return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
  7. }
  8. const state = Vue.observable({
  9. list: [
  10. {
  11. id: 'RG20260401001',
  12. name: '层层礼-借记卡新客圈选',
  13. type: 'debitCard',
  14. logic: 'AND',
  15. description: '2025/9/30 前开户 + MSC 属于卓越/运筹 + TRB < 50万',
  16. status: 'online',
  17. creator: '张运营',
  18. createdAt: '2026-04-01 09:15:30',
  19. updater: '王审核',
  20. updatedAt: '2026-04-05 11:20:18',
  21. rules: [
  22. {
  23. id: 'r1',
  24. metaCode: '001',
  25. ruleName: '层层礼开户时间',
  26. config: { accountType: 'I', operator: '<', date: '2025-09-30' }
  27. },
  28. {
  29. id: 'r2',
  30. metaCode: '010',
  31. ruleName: '层层礼,MSC',
  32. config: { operator: 'in', values: ['premier', 'advance'] }
  33. },
  34. {
  35. id: 'r3',
  36. metaCode: '050',
  37. ruleName: 'TRB值不含家庭账户余额(连续3个月达标)',
  38. config: { month: '2025-12', nm: { n: 3, m: 6 }, operator: '<', amount: 500000 }
  39. },
  40. {
  41. id: 'r4',
  42. metaCode: '051',
  43. ruleName: '2025年12月月末余额(连续3个月达标)',
  44. config: { month: '2025-12', nm: { n: 3, m: 6 }, operator: '<', amount: 500000 }
  45. }
  46. ]
  47. },
  48. {
  49. id: 'RG20260410002',
  50. name: '信用卡-高净值持卡客户',
  51. type: 'creditCard',
  52. logic: 'AND',
  53. description: 'MSC 属于卓越/尊尚 且 月末余额 ≥ 100 万',
  54. status: 'online',
  55. creator: '李产品',
  56. createdAt: '2026-04-10 16:55:02',
  57. updater: '李产品',
  58. updatedAt: '2026-04-10 16:55:02',
  59. rules: [
  60. {
  61. id: 'r1',
  62. metaCode: '010',
  63. ruleName: '信用卡MSC',
  64. config: { operator: 'in', values: ['premier', 'excellence'] }
  65. },
  66. {
  67. id: 'r2',
  68. metaCode: '051',
  69. ruleName: '月末余额 ≥ 100万',
  70. config: { month: '2026-03', nm: { n: 3, m: 6 }, operator: '>=', amount: 1000000 }
  71. }
  72. ]
  73. },
  74. {
  75. id: 'RG20260420003',
  76. name: '借记卡-跨境候选客群',
  77. type: 'debitCard',
  78. logic: 'OR',
  79. description: 'TRB ≥ 50 万 或 月末余额 ≥ 50 万',
  80. status: 'draft',
  81. creator: '赵市场',
  82. createdAt: '2026-04-20 11:48:33',
  83. updater: '赵市场',
  84. updatedAt: '2026-04-25 09:30:01',
  85. rules: [
  86. {
  87. id: 'r1',
  88. metaCode: '050',
  89. ruleName: 'TRB ≥ 50万',
  90. config: { month: '2026-04', nm: { n: 1, m: 1 }, operator: '>=', amount: 500000 }
  91. }
  92. ]
  93. }
  94. ]
  95. })
  96. let seq = state.list.length + 1
  97. function genId() {
  98. const d = new Date()
  99. const pad = (n) => String(n).padStart(2, '0')
  100. const stamp = `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}`
  101. return `RG${stamp}${String(seq++).padStart(3, '0')}`
  102. }
  103. export default {
  104. get list() {
  105. return state.list
  106. },
  107. query({ id = '', name = '', type = '' } = {}) {
  108. return state.list.filter((t) => {
  109. if (id && !t.id.includes(id)) return false
  110. if (name && !t.name.includes(name)) return false
  111. if (type && t.type !== type) return false
  112. return true
  113. })
  114. },
  115. getById(id) {
  116. return state.list.find((t) => t.id === id)
  117. },
  118. create(payload) {
  119. const record = {
  120. id: genId(),
  121. name: payload.name,
  122. type: payload.type,
  123. logic: payload.logic || 'AND',
  124. description: payload.description || '',
  125. status: 'draft',
  126. creator: '当前用户',
  127. createdAt: now(),
  128. updater: '当前用户',
  129. updatedAt: now(),
  130. rules: payload.rules || []
  131. }
  132. state.list.unshift(record)
  133. return record
  134. },
  135. update(id, payload) {
  136. const target = state.list.find((t) => t.id === id)
  137. if (!target) return null
  138. target.name = payload.name
  139. target.type = payload.type
  140. target.logic = payload.logic || 'AND'
  141. target.description = payload.description || ''
  142. target.rules = payload.rules || []
  143. target.updater = '当前用户'
  144. target.updatedAt = now()
  145. return target
  146. },
  147. remove(id) {
  148. const idx = state.list.findIndex((t) => t.id === id)
  149. if (idx >= 0) state.list.splice(idx, 1)
  150. },
  151. publish(id) {
  152. const target = state.list.find((t) => t.id === id)
  153. if (!target) return
  154. target.status = 'online'
  155. target.updater = '当前用户'
  156. target.updatedAt = now()
  157. }
  158. }