p-honggang.li
7 天以前 522737d66480d2f42b8e83c2ddde0efa3b740f38
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
270
271
272
<template>
  <div class="points-rule-list">
    <!-- 列表页面 -->
    <div v-if="currentView === '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"
                  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 type="index" label="序号" width="80" align="center" />
            <el-table-column prop="pointsName" label="名称"  align="ceter">
              <template #default="{ row }">
                   {{ row.pointsName}}{{ dayjs(row.updatedAt).format('YYYYMMDD')}}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="viewRule(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>
 
    <!-- 编辑页面 -->
    <div v-if="currentView === 'edit'" class="edit-container">
      <SettingsComponent 
        :ruleId="currentRuleId"
        @goBack="goBackToList"
        @saveSuccess="handleSaveSuccess"
      />
    </div>
 
    <!-- 查看详情页面 -->
    <div v-if="currentView === 'view'" class="view-container">
      <RuleDetailComponent 
        :ruleId="currentRuleId"
        @goBack="goBackToList"
      />
    </div>
  </div>
</template>
 
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { dayjs, ElMessage } from 'element-plus'
import pointsApi from '@/api/pointsApi'
import type { PointsRule, PointsQueryParams } from '@/types/points'
import SettingsComponent from '@/views/pointsManage/settings/index.vue'
import RuleDetailComponent from '@/views/pointsManage/ruleDetail/index.vue'
 
// 当前视图状态:'list' | 'edit' | 'view'
const currentView = ref<'list' | 'edit' | 'view'>('list')
 
// 查询参数
const queryParams = reactive<PointsQueryParams>({
  dateRange: '',
  pageNum: 1,
  pageSize: 10,
})
 
// 规则列表
const ruleList = ref<PointsRule[]>([])
 
// 总数
const total = ref(0)
 
// 当前选中的规则ID
const currentRuleId = ref<string>('')
 
// 页面加载时获取数据
onMounted(() => {
  queryData()
})
 
// 查询数据
const queryData = async () => {
  try {
    const res = await pointsApi.getPointsRules(queryParams)
    // 模拟分页数据
    ruleList.value = res.data.list || []
    total.value = res.data.total
  } 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 handleDateChange = (dates: [string, string] | null) => {
  if (dates) {
    queryParams.effectiveStartTime = dayjs(dates[0]).format('YYYY-MM-DD HH:mm:ss');
    queryParams.effectiveEndTime = dayjs(dates[1]).format('YYYY-MM-DD HH:mm:ss');
  } else {
    queryParams.effectiveStartTime = ''
    queryParams.effectiveEndTime = ''
  }
}
 
// 编辑规则
const editRule = (row: PointsRule) => {
  currentRuleId.value = row.id?.toString() || ''
  currentView.value = 'edit'
}
 
// 查看规则
const viewRule = (row: PointsRule) => {
  currentRuleId.value = row.id?.toString() || ''
  currentView.value = 'view'
}
 
// 返回列表页面
const goBackToList = () => {
  currentView.value = 'list'
  currentRuleId.value = ''
}
 
// 处理保存成功
const handleSaveSuccess = () => {
  // ElMessage.success('保存成功')
  goBackToList()
  // 重新加载列表数据
  queryData()
}
</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;
        }
      }
    }
  }
 
  .edit-container,
  .view-container {
    // 确保组件能够正确显示
    width: 100%;
  }
}
</style>