seatonwan9
2025-08-14 a0fc5b1e703769a8936fd8671ec9cdd9adfda20a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<template>
  <div class="points-rule-list">
    <!-- 页面标题 -->
    <div class="page-title">积分规则管理</div>
 
    <!-- 规则列表卡片 -->
    <el-card shadow="never" class="rule-list-card">
      <!-- 筛选条件 -->
      <div class="filter-section">
        <div class="filter-row">
          <div class="filter-item">
            <span class="filter-label">生效时间:</span>
            <el-date-picker
                v-model="queryParams.dateRange"
                type="datetimerange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                format="YYYY-MM-DD HH:mm:ss"
                value-format="YYYY-MM-DD HH:mm:ss"
                  date-format="YYYY-MM-DD"
                  time-format="HH:mm:ss"
                style="margin-left: 8px;"
                @change="handleDateChange"
              />
          </div>
          
        </div>
        <div class="filter-actions">
          <el-button type="primary" @click="queryData">
            <el-icon><Search /></el-icon>
            查询
          </el-button>
          <el-button @click="resetQuery">
            <el-icon><Refresh /></el-icon>
            重置
          </el-button>
        </div>
      </div>
 
      <!-- 规则表格 -->
      <div class="table-section">
        <el-table :data="ruleList" stripe style="width: 100%">
          <el-table-column prop="id" label="序号" width="80" align="center" />
          <el-table-column prop="pointsName" label="名称"  align="ceter">
            <template #default="{ row }">
                 {{ row.pointsName}}{{ row.updatedAt}}V{{ row.version }}
            </template>
          </el-table-column>
      
          <el-table-column prop="effectiveStart" label="开始生效时间"   align="center" />
          <el-table-column prop="modifierName" label="修改人"  align="center" />
        
          <el-table-column label="操作"  align="center" fixed="right">
            <template #default="{ row }">
              <el-button type="primary" size="small" @click="editRule(row)">查看</el-button>
              <el-button type="primary" size="small" @click="editRule(row)">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
 
        <!-- 分页 -->
        <div class="pagination-section">
          <div class="pagination-info">
            共{{ total }}条
          </div>
          <el-pagination
            v-model:current-page="queryParams.pageNum"
            v-model:page-size="queryParams.pageSize"
            :page-sizes="[10, 20, 50, 100]"
            :total="total"
            layout="sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </el-card>
  </div>
</template>
 
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { dayjs, ElMessage } from 'element-plus'
import { Search, Refresh } from '@element-plus/icons-vue'
import pointsApi from '@/api/pointsApi'
import type { PointsRule, PointsQueryParams } from '@/types/points'
// 导入路由钩子
import { useRouter } from 'vue-router'
 
// 查询参数
const queryParams = reactive<PointsQueryParams>({
 // ruleType: '',
 // category: '',
 // status: '',
  dateRange: '',
  pageNum: 1,
  pageSize: 10,
})
 
// 规则列表
const ruleList = ref<PointsRule[]>([])
 
// 总数
const total = ref(0)
 
// 页面加载时获取数据
onMounted(() => {
  queryData()
})
 
// 查询数据
const queryData = async () => {
  try {
    const res = await pointsApi.getPointsRules(queryParams)
    // 模拟分页数据
    ruleList.value = res.data.list || []
    total.value = ruleList.value.length
  } catch (error) {
    ElMessage.error('获取积分规则失败')
    console.error('获取积分规则失败:', error)
  }
}
 
// 重置查询
const resetQuery = () => {
  Object.keys(queryParams).forEach(key => {
    queryParams[key as keyof PointsQueryParams] = '' as any
  })
  queryParams.pageNum = 1
  queryParams.pageSize = 10
  queryData()
}
 
// 处理分页大小变化
const handleSizeChange = (size: number) => {
  queryParams.pageSize = size
  queryData()
}
 
// 处理当前页码变化
const handleCurrentChange = (current: number) => {
  queryParams.pageNum = current
  queryData()
}
 
// 获取规则类型标签
const getRuleTypeLabel = (type: string) => {
  const typeMap: Record<string, string> = {
    acquisition: '获取',
    consumption: '消耗',
    conversion: '转换',
  }
  return typeMap[type] || type
}
 
// 获取分类标签
const getCategoryLabel = (category: string) => {
  const categoryMap: Record<string, string> = {
    resource_contribution: '资源贡献',
    resource_transaction: '资源交易',
    resource_dissemination: '资源传播',
    user_participation: '用户参与',
    other: '其他',
  }
  return categoryMap[category] || category
}
 
// 处理状态变化
const handleStatusChange = async (row: PointsRule) => {
  try {
    await pointsApi.savePointsRules({
      id: row.id,
      status: row.status
    })
    ElMessage.success('状态更新成功')
  } catch (error) {
    ElMessage.error('状态更新失败')
    // 恢复原来的状态
    row.status = row.status === 1 ? 0 : 1
    console.error('更新规则状态失败:', error)
  }
}
 
// 处理日期变化
const handleDateChange = (dates: [string, string] | null) => {
  if (dates) {
    queryParams.effectiveStartTime = dates[0]
    queryParams.effectiveEndTime = dates[1]
  } else {
    queryParams.effectiveStartTime = ''
    queryParams.effectiveEndTime = ''
  }
}
 
// 创建路由实例
const router = useRouter()
 
// 编辑规则
const editRule = (row: PointsRule) => {
  // 跳转到规则设置界面,并传入规则id
  router.push({
    path: '/points/settings',
    query: { ruleId: row.id }
  })
}
</script>
 
<style scoped lang="scss">
.points-rule-list {
  padding: 20px;
 
  .page-title {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 20px;
    color: #333;
  }
 
  .rule-list-card {
    .filter-section {
      margin-bottom: 20px;
      display: flex;
      gap: 20px;
      .filter-row {
        display: flex;
        flex-wrap: wrap;
        gap: 16px;
        margin-bottom: 16px;
 
        .filter-item {
          display: flex;
          align-items: center;
          margin-bottom: 8px;
 
          .filter-label {
            margin-right: 8px;
            color: #606266;
          }
 
          .el-select {
            width: 180px;
          }
        }
      }
 
      .filter-actions {
        display: flex;
        justify-content: flex-end;
        gap: 10px;
      }
    }
 
    .table-section {
      .pagination-section {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-top: 16px;
        padding: 10px 0;
 
        .pagination-info {
          color: #606266;
        }
      }
    }
  }
}
</style>