Blame view

src/views/system/communitySettingManageList.vue 4.32 KB
03f63ab4   wuxw   优化到商户信息
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
  <template>
    <div class="community-setting-manage-container">
      <el-row :gutter="20">
        <el-col :span="4">
          <el-card class="setting-type-card">
            <div class="setting-type-list">
              <div v-for="(item, index) in settingTypes" :key="index" class="setting-type-item"
                :class="{ 'active': conditions.settingType === item.statusCd }" @click="handleSwitchSettingType(item)">
                {{ item.name }}
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="20">
          <el-card>
            <div slot="header" class="flex justify-between">
              <span>{{ currentSettingName }}</span>
            </div>
            <div class="setting-content text-left">
              <el-form label-position="right" label-width="120px">
                <el-form-item v-for="(item, index) in settingKeys" :key="index" :label="item.settingName">
                  <el-input v-model="item.settingValue"
                    :placeholder="$t('communitySettingManage.inputPlaceholder', { name: item.settingName })" />
                  <div class="setting-remark">{{ item.remark }}</div>
                </el-form-item>
              </el-form>
              <div class="setting-tips">{{ $t('communitySettingManage.settingTips') }}</div>
              <div class="text-right">
                <el-button type="primary" @click="handleSaveSettings">
                  <i class="el-icon-check"></i>
                  {{ $t('common.submit') }}
                </el-button>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>
  </template>
  
  <script>
  import { getCommunityId } from '@/api/community/communityApi'
  import { getDict } from '@/api/community/communityApi'
  import {
    listCommunitySettingKey,
    saveCommunitySetting
  } from '@/api/system/communitySettingManageApi'
  
  export default {
    name: 'CommunitySettingManageList',
    data() {
      return {
        communityId: '',
        settingTypes: [],
        settingKeys: [],
        currentSettingName: '',
        conditions: {
          settingType: '',
          communityId: ''
        }
      }
    },
    created() {
      this.communityId = getCommunityId()
      this.conditions.communityId = this.communityId
      this.initData()
    },
    methods: {
      async initData() {
        try {
          const data = await getDict('community_setting_key', 'setting_type')
          this.settingTypes = data
          if (data && data.length > 0) {
            this.handleSwitchSettingType(data[0])
          }
        } catch (error) {
          console.error('获取字典数据失败:', error)
        }
      },
      async handleSwitchSettingType(item) {
        this.conditions.settingType = item.statusCd
        this.currentSettingName = item.name
        await this.loadSettingKeys()
      },
      async loadSettingKeys() {
        try {
          const params = {
            communityId: this.communityId,
            settingType: this.conditions.settingType
          }
          const { data } = await listCommunitySettingKey(params)
          this.settingKeys = data.map(item => {
            return {
              ...item,
              settingValue: item.settingValue || ''
            }
          })
        } catch (error) {
          console.error('获取设置项失败:', error)
        }
      },
      async handleSaveSettings() {
        try {
          const params = {
            communityId: this.communityId,
            keys: this.settingKeys,
            settingType: this.conditions.settingType
          }
          await saveCommunitySetting(params)
          this.$message.success(this.$t('common.saveSuccess'))
          this.loadSettingKeys()
        } catch (error) {
          console.error('保存设置失败:', error)
        }
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  .community-setting-manage-container {
    padding: 20px;
  
    .setting-type-card {
      height: 100%;
  
      .setting-type-list {
        .setting-type-item {
          padding: 10px;
          margin-bottom: 5px;
          cursor: pointer;
          border-radius: 4px;
          text-align: center;
  
          &:hover {
            background-color: #f5f7fa;
          }
  
          &.active {
            background-color: #409eff;
            color: white;
          }
        }
      }
    }
  
    .setting-content {
      padding: 20px;
  
      .setting-remark {
        margin-top: 5px;
        font-size: 12px;
        color: #909399;
      }
  
      .setting-tips {
        margin: 20px 0;
        font-size: 12px;
        color: #f56c6c;
      }
    }
  }
  </style>